예제 #1
0
    def test_traverse_and_replace(self):
        obj = [
            {
                'id': '===id1==='
            },
            {
                'id': '===id2===',
                'x': [{
                    'bar': '===id1==='
                }]
            },
            ['===id1===', '===id2==='],
            '===id3===',
            '===nonid0===',
            '===id3===',
        ]
        utils.traverse_and_replace(obj)
        self.assertNotEqual('===id1===', obj[0]['id'])
        self.assertNotEqual('===id2===', obj[1]['id'])
        self.assertNotEqual('===id1===', obj[1]['x'][0]['bar'])
        self.assertNotEqual('===id1===', obj[2][0])
        self.assertNotEqual('===id2===', obj[2][1])
        self.assertNotEqual('===id3===', obj[3])
        self.assertEqual('===nonid0===', obj[4])
        self.assertNotEqual('===id3===', obj[5])

        self.assertEqual(obj[0]['id'], obj[1]['x'][0]['bar'])
        self.assertEqual(obj[0]['id'], obj[2][0])

        self.assertEqual(obj[1]['id'], obj[2][1])

        self.assertEqual(obj[3], obj[5])
예제 #2
0
    def test_traverse_and_replace(self):
        obj = [
            {'id': '===id1==='},
            {'id': '===id2===', 'x': [{'bar': '===id1==='}]},
            ['===id1===', '===id2==='],
            '===id3===',
            '===nonid0===',
            '===id3===',
        ]
        utils.traverse_and_replace(obj)
        self.assertNotEqual('===id1===', obj[0]['id'])
        self.assertNotEqual('===id2===', obj[1]['id'])
        self.assertNotEqual('===id1===', obj[1]['x'][0]['bar'])
        self.assertNotEqual('===id1===', obj[2][0])
        self.assertNotEqual('===id2===', obj[2][1])
        self.assertNotEqual('===id3===', obj[3])
        self.assertEqual('===nonid0===', obj[4])
        self.assertNotEqual('===id3===', obj[5])

        self.assertEqual(obj[0]['id'], obj[1]['x'][0]['bar'])
        self.assertEqual(obj[0]['id'], obj[2][0])

        self.assertEqual(obj[1]['id'], obj[2][1])

        self.assertEqual(obj[3], obj[5])
예제 #3
0
def do_environment_apps_edit(mc, args):
    """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
    """

    jp_obj = None
    if not args.filename:
        jp_obj = json.load(sys.stdin)
    else:
        with open(args.filename) as fpatch:
            jp_obj = json.load(fpatch)

    jpatch = jsonpatch.JsonPatch(jp_obj)

    environment_id = args.id
    session_id = args.session_id
    environment = mc.environments.get(environment_id, session_id)

    object_model = jpatch.apply(environment.services)
    utils.traverse_and_replace(object_model)

    mc.services.put(
        environment_id,
        path='/',
        data=jpatch.apply(environment.services),
        session_id=session_id)
def do_environment_apps_edit(mc, args):
    """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
    """

    jp_obj = None
    if not args.filename:
        jp_obj = json.load(sys.stdin)
    else:
        with open(args.filename) as fpatch:
            jp_obj = json.load(fpatch)

    jpatch = jsonpatch.JsonPatch(jp_obj)

    environment_id = args.id
    session_id = args.session_id
    environment = mc.environments.get(environment_id, session_id)

    object_model = jpatch.apply(environment.services)
    utils.traverse_and_replace(object_model)

    mc.services.put(
        environment_id,
        path='/',
        data=jpatch.apply(environment.services),
        session_id=session_id)
예제 #5
0
    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)