Add environment apps edit to openstack CLI
usage: openstack environment apps edit [-h] [--session-id <SESSION>] <ENVIRONMENT_ID> <FILE> Edit environment's object model. Partially implements: blueprint openstack-client-plugin-support Change-Id: I9182bf69cb6c2cdf142ac669ab3ecaefe2ebe19f
This commit is contained in:
parent
d6d2bd5369
commit
97ab194c92
|
@ -12,8 +12,12 @@
|
|||
|
||||
"""Application-catalog v1 stack action implementation"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import jsonpatch
|
||||
|
||||
from muranoclient.common import utils as murano_utils
|
||||
from muranoclient.openstack.common.apiclient import exceptions
|
||||
from osc_lib.command import command
|
||||
|
@ -318,3 +322,69 @@ class EnvironmentDeploy(command.ShowOne):
|
|||
return(['services'], [data['services']])
|
||||
else:
|
||||
return self.dict2columns(data)
|
||||
|
||||
|
||||
class EnvironmentAppsEdit(command.Command):
|
||||
"""Edit environment's object model.
|
||||
|
||||
`FILE` is path to a file, that contains jsonpatch, that describes changes
|
||||
to be made to environment's object-model.
|
||||
|
||||
[
|
||||
{ "op": "add", "path": "/-",
|
||||
"value": { ... your-app object model here ... }
|
||||
},
|
||||
{ "op": "replace", "path": "/0/?/name",
|
||||
"value": "new_name"
|
||||
},
|
||||
]
|
||||
|
||||
NOTE: Values '===id1===', '===id2===', etc. in the resulting object-model
|
||||
will be substituted with uuids.
|
||||
|
||||
For more info on jsonpatch see RFC 6902
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(EnvironmentAppsEdit, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar="<ENVIRONMENT_ID>",
|
||||
help="ID of Environment to edit.",
|
||||
)
|
||||
parser.add_argument(
|
||||
'filename',
|
||||
metavar="<FILE>",
|
||||
help="File to read jsonpatch from (defaults to stdin).",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--session-id',
|
||||
metavar="<SESSION>",
|
||||
help="ID of configuration session to edit.",
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
LOG.debug("take_action(%s)", parsed_args)
|
||||
client = self.app.client_manager.application_catalog
|
||||
jp_obj = None
|
||||
if not parsed_args.filename:
|
||||
jp_obj = json.load(sys.stdin)
|
||||
else:
|
||||
with open(parsed_args.filename) as fpatch:
|
||||
jp_obj = json.load(fpatch)
|
||||
|
||||
jpatch = jsonpatch.JsonPatch(jp_obj)
|
||||
environment_id = parsed_args.id
|
||||
session_id = parsed_args.session_id
|
||||
environment = client.environments.get(environment_id, session_id)
|
||||
|
||||
object_model = jpatch.apply(environment.services)
|
||||
murano_utils.traverse_and_replace(object_model)
|
||||
|
||||
client.services.put(
|
||||
environment_id,
|
||||
path='/',
|
||||
data=jpatch.apply(environment.services),
|
||||
session_id=session_id)
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
import json
|
||||
import tempfile
|
||||
|
||||
import mock
|
||||
|
||||
from muranoclient.osc.v1 import environment as osc_env
|
||||
|
@ -34,6 +38,8 @@ class TestEnvironment(fakes.TestApplicationCatalog):
|
|||
environments
|
||||
self.session_mock = self.app.client_manager.application_catalog.\
|
||||
sessions
|
||||
self.services_mock = self.app.client_manager.application_catalog.\
|
||||
services
|
||||
self.environment_mock.reset_mock()
|
||||
|
||||
|
||||
|
@ -425,3 +431,40 @@ class TestEnvironmentDeploy(TestEnvironment):
|
|||
{}, ['fake services'], 'fake deployed', 'xyz123',
|
||||
'2015-12-16T17:31:54', '1')
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
|
||||
class TestEnvironmentAppsEdit(TestEnvironment):
|
||||
def setUp(self):
|
||||
super(TestEnvironmentAppsEdit, self).setUp()
|
||||
|
||||
# Command to test
|
||||
self.cmd = osc_env.EnvironmentAppsEdit(self.app, None)
|
||||
|
||||
def test_environment_deploy(self):
|
||||
fake = collections.namedtuple('fakeEnv', 'services')
|
||||
self.environment_mock.get.side_effect = [
|
||||
fake(services=[
|
||||
{'?': {'name': "foo"}}
|
||||
]),
|
||||
]
|
||||
|
||||
temp_file = tempfile.NamedTemporaryFile(prefix="murano-test", mode='w')
|
||||
json.dump([
|
||||
{'op': 'replace', 'path': '/0/?/name',
|
||||
'value': "dummy"
|
||||
}
|
||||
], temp_file)
|
||||
temp_file.file.flush()
|
||||
|
||||
arglist = ['fake', '--session-id', 'abc123', temp_file.name]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.services_mock.put.assert_called_once_with(
|
||||
'fake',
|
||||
session_id='abc123',
|
||||
path='/',
|
||||
data=[{'?': {'name': 'dummy'}}]
|
||||
)
|
||||
|
|
|
@ -41,6 +41,7 @@ openstack.application_catalog.v1 =
|
|||
environment_create = muranoclient.osc.v1.environment:EnvironmentCreate
|
||||
environment_delete = muranoclient.osc.v1.environment:EnvironmentDelete
|
||||
environment_deploy = muranoclient.osc.v1.environment:EnvironmentDeploy
|
||||
environment_apps_edit = muranoclient.osc.v1.environment:EnvironmentAppsEdit
|
||||
|
||||
category_list = muranoclient.osc.v1.category:ListCategories
|
||||
category_show = muranoclient.osc.v1.category:ShowCategory
|
||||
|
|
Loading…
Reference in New Issue