コード例 #1
0
    def test_to_dictionary(self):
        """test to_dictionary

        If model contains object entry (not dict)
        we try to convert to dict using 'to_dictionary' method.
        """

        class Struct(object):
            def __init__(self, d):
                self.__dict__ = d

            def to_dictionary(self):
                return self.__dict__

            def __getitem__(self, item):
                return self.__dict__[item]

        d = {'?': {'id': '1', 'type': 't1'},
             'apps': [Struct({'?': {'id': '2', 'type': 't2'},
                              'instances': [Struct(
                                  {'?': {'id': '3', 'type': 't3'}})]})]
             }

        model = Struct(d)

        congress_rules = congress.CongressRulesManager()
        tenant_id = uuidutils.generate_uuid()
        rules = congress_rules.convert(model, tenant_id=tenant_id)
        rules_str = ", \n".join(map(str, rules))

        self.assertTrue('murano:objects+("1", "{0}", "t1")'.format(tenant_id)
                        in rules_str)
        self.assertTrue('murano:objects+("2", "1", "t2")' in rules_str)
        self.assertTrue('murano:objects+("3", "2", "t3")' in rules_str)
コード例 #2
0
    def clone(env_template_id, tenant_id, env_template_name, is_public):
        """Clones environment-template with specified params, in particular - name.

           :param env_template_params: Dict, e.g. {'name': 'temp-name'}
           :param tenant_id: Tenant Id
           :return: Created Template
        """

        template = EnvTemplateServices.get_env_template(env_template_id)
        env_template_params = template.to_dict()
        env_template_params['id'] = uuidutils.generate_uuid()
        env_template_params['tenant_id'] = tenant_id
        env_template_params['name'] = env_template_name
        env_template_params['is_public'] = is_public
        env_temp_desc = EnvTemplateServices.get_description(env_template_id)
        if "services" in env_temp_desc:
            env_template_params['services'] = env_temp_desc['services']

        env_template = models.EnvironmentTemplate()
        env_template.update(env_template_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(env_template)
        env_template.update({'description': env_template_params})
        env_template.save(unit)
        return env_template
コード例 #3
0
ファイル: environments.py プロジェクト: schaertelr/murano
    def create(environment_params, context):
        # tagging environment by tenant_id for later checks
        """Creates environment with specified params, in particular - name

           :param environment_params: Dict, e.g. {'name': 'env-name'}
           :param context: request context to get the tenant id and the token
           :return: Created Environment
        """
        objects = {"?": {"id": uuidutils.generate_uuid()}}
        network_driver = EnvironmentServices.get_network_driver(context)
        objects.update(environment_params)
        if not objects.get("defaultNetworks"):
            objects["defaultNetworks"] = EnvironmentServices.generate_default_networks(objects["name"], network_driver)
        objects["?"]["type"] = "io.murano.Environment"
        environment_params["tenant_id"] = context.tenant

        data = {"Objects": objects, "Attributes": []}

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        # saving environment as Json to itself
        environment.update({"description": data})
        environment.save(unit)

        return environment
コード例 #4
0
    def create(env_template_params, tenant_id):
        """Creates environment-template with specified params,
           in particular - name.

           :param env_template_params: Dict, e.g. {'name': 'temp-name'}
           :param tenant_id: Tenant Id
           :return: Created Template
        """

        env_template_params['id'] = uuidutils.generate_uuid()
        env_template_params['tenant_id'] = tenant_id
        env_template = models.EnvironmentTemplate()
        env_template.update(env_template_params)

        unit = db_session.get_session()
        with unit.begin():
            try:
                unit.add(env_template)
            except db_exc.DBDuplicateEntry:
                msg = _('Environment template specified name already exists')
                LOG.error(msg)
                raise db_exc.DBDuplicateEntry(explanation=msg)
        env_template.update({'description': env_template_params})
        env_template.save(unit)

        return env_template
コード例 #5
0
    def create(env_template_params, tenant_id):
        """Creates environment-template with specified params, in particular - name.

           :param env_template_params: Dict, e.g. {'name': 'temp-name'}
           :param tenant_id: Tenant Id
           :return: Created Template
        """

        env_template_params['id'] = uuidutils.generate_uuid()
        env_template_params['tenant_id'] = tenant_id
        env_template = models.EnvironmentTemplate()
        env_template.update(env_template_params)

        unit = db_session.get_session()
        with unit.begin():
            try:
                unit.add(env_template)
            except db_exc.DBDuplicateEntry:
                msg = 'Environment template specified name already exists'
                LOG.exception(msg)
                raise db_exc.DBDuplicateEntry(explanation=msg)
        env_template.update({'description': env_template_params})
        env_template.save(unit)

        return env_template
コード例 #6
0
    def test_to_dictionary(self):
        """If model contains object entry (not dict)
        we try to convert to dict using 'to_dictionary' method.
        """

        class Struct(object):
            def __init__(self, d):
                self.__dict__ = d

            def to_dictionary(self):
                return self.__dict__

            def __getitem__(self, item):
                return self.__dict__[item]

        d = {'?': {'id': '1', 'type': 't1'},
             'apps': [Struct({'?': {'id': '2', 'type': 't2'},
                              'instances': [Struct(
                                  {'?': {'id': '3', 'type': 't3'}})]})]
             }

        model = Struct(d)

        congress_rules = congress.CongressRulesManager()
        tenant_id = uuidutils.generate_uuid()
        rules = congress_rules.convert(model, tenant_id=tenant_id)
        rules_str = ", \n".join(map(str, rules))
        print rules_str

        self.assertTrue('murano:objects+("1", "{0}", "t1")'.format(tenant_id)
                        in rules_str)
        self.assertTrue('murano:objects+("2", "1", "t2")' in rules_str)
        self.assertTrue('murano:objects+("3", "2", "t3")' in rules_str)
コード例 #7
0
ファイル: environments.py プロジェクト: ovo-6/murano
    def create(environment_params, tenant_id):
        #tagging environment by tenant_id for later checks
        """Creates environment with specified params, in particular - name

           :param environment_params: Dict, e.g. {'name': 'env-name'}
           :param tenant_id: Tenant Id
           :return: Created Environment
        """

        objects = {
            '?': {
                'id': uuidutils.generate_uuid(),
            }
        }
        objects.update(environment_params)
        objects.update(
            EnvironmentServices.generate_default_networks(objects['name']))
        objects['?']['type'] = 'io.murano.Environment'
        environment_params['tenant_id'] = tenant_id

        data = {'Objects': objects, 'Attributes': []}

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        #saving environment as Json to itself
        environment.update({'description': data})
        environment.save(unit)

        return environment
コード例 #8
0
ファイル: environments.py プロジェクト: ativelkov/murano-api
    def create(environment_params, tenant_id):
        #tagging environment by tenant_id for later checks
        """
        Creates environment with specified params, in particular - name
        :param environment_params: Dict, e.g. {'name': 'env-name'}
        :param tenant_id: Tenant Id
        :return: Created Environment
        """

        objects = {'?': {
            'id': uuidutils.generate_uuid(),
        }}
        objects.update(environment_params)
        objects.update(
            EnvironmentServices.generate_default_networks(objects['name']))
        objects['?']['type'] = 'io.murano.Environment'
        environment_params['tenant_id'] = tenant_id

        data = {
            'Objects': objects,
            'Attributes': []
        }

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        #saving environment as Json to itself
        environment.update({'description': data})
        environment.save(unit)

        return environment
コード例 #9
0
    def clone(env_template_id, tenant_id, env_template_name, is_public):
        """Clones environment-template with specified params,
           in particular - name.

           :param env_template_params: Dict, e.g. {'name': 'temp-name'}
           :param tenant_id: Tenant Id
           :return: Created Template
        """

        template = EnvTemplateServices.get_env_template(env_template_id)
        env_template_params = template.to_dict()
        env_template_params['id'] = uuidutils.generate_uuid()
        env_template_params['tenant_id'] = tenant_id
        env_template_params['name'] = env_template_name
        env_template_params['is_public'] = is_public
        env_temp_desc = EnvTemplateServices.get_description(env_template_id)
        if "services" in env_temp_desc:
            env_template_params['services'] = env_temp_desc['services']

        env_template = models.EnvironmentTemplate()
        env_template.update(env_template_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(env_template)
        env_template.update({'description': env_template_params})
        env_template.save(unit)
        return env_template
コード例 #10
0
 def initialize(self, environment):
     if StatusReporter.transport is None:
         StatusReporter.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         StatusReporter.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     self._environment_id = environment.object_id
コード例 #11
0
 def __init__(self, environment):
     if InstanceReportNotifier.transport is None:
         InstanceReportNotifier.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         InstanceReportNotifier.transport,
         publisher_id=uuidutils.generate_uuid(),
         topics=['murano'])
     self._environment_id = environment.id
コード例 #12
0
 def __init__(self, environment):
     if InstanceReportNotifier.transport is None:
         InstanceReportNotifier.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         InstanceReportNotifier.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     self._environment_id = environment.id
コード例 #13
0
 def __init__(self, environment):
     if OpenStackBinding.transport is None:
         OpenStackBinding.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         OpenStackBinding.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     self._environment_id = environment.id
コード例 #14
0
 def initialize(self, environment):
     if InstanceReportNotifier.transport is None:
         InstanceReportNotifier.transport = \
             messaging.get_transport(config.CONF)
     self._notifier = messaging.Notifier(
         InstanceReportNotifier.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     self._environment_id = environment.object_id
コード例 #15
0
 def initialize(self, environment):
     if InstanceReportNotifier.transport is None:
         InstanceReportNotifier.transport = \
             messaging.get_transport(config.CONF)
     self._notifier = messaging.Notifier(
         InstanceReportNotifier.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     self._environment_id = environment.object_id
コード例 #16
0
 def __init__(self, environment):
     if StatusReporter.transport is None:
         StatusReporter.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         StatusReporter.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     if isinstance(environment, types.StringTypes):
         self._environment_id = environment
     else:
         self._environment_id = environment.id
コード例 #17
0
 def __init__(self, environment):
     if StatusReporter.transport is None:
         StatusReporter.transport = messaging.get_transport(CONF)
     self._notifier = messaging.Notifier(
         StatusReporter.transport,
         publisher_id=uuidutils.generate_uuid(),
         topic='murano')
     if isinstance(environment, six.string_types):
         self._environment_id = environment
     else:
         self._environment_id = environment.id
コード例 #18
0
ファイル: environments.py プロジェクト: schaertelr/murano
 def _objectify(data, replacements):
     if isinstance(data, dict):
         if isinstance(data.get("?"), dict):
             data["?"]["id"] = uuidutils.generate_uuid()
         result = {}
         for key, value in data.iteritems():
             result[key] = EnvironmentServices._objectify(value, replacements)
         return result
     elif isinstance(data, list):
         return [EnvironmentServices._objectify(v, replacements) for v in data]
     elif isinstance(data, (str, unicode)):
         for key, value in replacements.iteritems():
             data = data.replace("%" + key + "%", value)
     return data
コード例 #19
0
ファイル: environments.py プロジェクト: Magic-Mirror/murano
 def _objectify(data, replacements):
     if isinstance(data, dict):
         if isinstance(data.get('?'), dict):
             data['?']['id'] = uuidutils.generate_uuid()
         result = {}
         for key, value in six.iteritems(data):
             result[key] = EnvironmentServices._objectify(
                 value, replacements)
         return result
     elif isinstance(data, list):
         return [EnvironmentServices._objectify(v, replacements)
                 for v in data]
     elif isinstance(data, six.string_types):
         for key, value in six.iteritems(replacements):
             data = data.replace('%' + key + '%', value)
     return data
コード例 #20
0
 def _objectify(data, replacements):
     if isinstance(data, dict):
         if isinstance(data.get('?'), dict):
             data['?']['id'] = uuidutils.generate_uuid()
         result = {}
         for key, value in six.iteritems(data):
             result[key] = EnvironmentServices._objectify(
                 value, replacements)
         return result
     elif isinstance(data, list):
         return [EnvironmentServices._objectify(v, replacements)
                 for v in data]
     elif isinstance(data, six.string_types):
         for key, value in six.iteritems(replacements):
             data = data.replace('%' + key + '%', value)
     return data
コード例 #21
0
ファイル: environments.py プロジェクト: schaertelr/murano
    def generate_default_networks(env_name, network_driver):
        net_config = CONF.find_file(CONF.networking.network_config_file)
        if net_config:
            LOG.debug("Loading network configuration from file")
            with open(net_config) as f:
                data = yaml.safe_load(f)
                return EnvironmentServices._objectify(data, {"ENV": env_name})

        network_type = DEFAULT_NETWORK_TYPES[network_driver]
        LOG.debug("Setting '{0}' as environment's " "default network".format(network_type))
        return {
            "environment": {
                "?": {"id": uuidutils.generate_uuid(), "type": network_type},
                "name": env_name + "-network",
            },
            "flat": None,
        }
コード例 #22
0
ファイル: environments.py プロジェクト: ativelkov/murano-api
 def generate_default_networks(env_name):
     # TODO(ativelkov):
     # This is a temporary workaround. Need to find a better way:
     # These objects have to be created in runtime when the environment is
     # deployed for the first time. Currently there is no way to persist
     # such changes, so we have to create the objects on the API side
     return {
         'defaultNetworks': {
             'environment': {
                 '?': {
                     'id': uuidutils.generate_uuid(),
                     'type': DEFAULT_NETWORKS['environment']
                 },
                 'name': env_name + '-network'
             },
             'flat': None
         }
     }
コード例 #23
0
ファイル: environments.py プロジェクト: ovo-6/murano
 def generate_default_networks(env_name):
     # TODO(ativelkov):
     # This is a temporary workaround. Need to find a better way:
     # These objects have to be created in runtime when the environment is
     # deployed for the first time. Currently there is no way to persist
     # such changes, so we have to create the objects on the API side
     return {
         'defaultNetworks': {
             'environment': {
                 '?': {
                     'id': uuidutils.generate_uuid(),
                     'type': DEFAULT_NETWORKS['environment']
                 },
                 'name': env_name + '-network'
             },
             'flat': None
         }
     }
コード例 #24
0
ファイル: hybrid.py プロジェクト: hybrid-murano/murano-mitaka
def my_post_data(environment_id, session_id, data, path, request):
    if path:
        path = '/services/' + path
    else:
        path = '/services'

    unit = db_session.get_session()
    model = unit.query(models.Session).get(session_id)
    if model is None:
        msg = _('Session is not found')
        LOG.error(msg)
        raise exc.HTTPNotFound(explanation=msg)

    if path == '/services':
        env_description = model.description['Objects']
        if 'services' not in env_description:
            env_description['services'] = []
        if isinstance(data, list):
            common_utils.TraverseHelper.extend(path, data, env_description)
        else:
            common_utils.TraverseHelper.insert(path, data, env_description)

        session = models.Session()
        session.environment_id = model.environment_id
        session.user_id = model.user_id
        session.state = states.EnvironmentStatus.PENDING
        session.version = 2
        session.description = model.description
        session.description['Objects'] = env_description
        session.id = uuidutils.generate_uuid()
        session.description['SystemData']= {}
        session.description['SystemData']['SessionId'] = session.id
        session.description['SystemData']['TrustId'] = auth_utils.create_trust(request.context.auth_token, request.context.tenant)
        session.description['SystemData']['UserId'] = request.context.user
        session.description['SystemData']['Tenant'] = request.context.tenant
        session.description['SystemData']['Token'] = request.context.auth_token     # TODO: alloc long-term token
        with unit.begin():
            unit.add(session)

        session.save(unit)

    return data
コード例 #25
0
    def create(environment_params, context):
        # tagging environment by tenant_id for later checks
        """Creates environment with specified params, in particular - name

           :param environment_params: Dict, e.g. {'name': 'env-name'}
           :param context: request context to get the tenant id and the token
           :return: Created Environment
        """
        objects = {
            '?': {
                'id': uuidutils.generate_uuid(),
            }
        }
        network_driver = EnvironmentServices.get_network_driver(context)
        objects.update(environment_params)
        if not objects.get('defaultNetworks'):
            objects['defaultNetworks'] = \
                EnvironmentServices.generate_default_networks(objects['name'],
                                                              network_driver)
        objects['?']['type'] = 'io.murano.Environment'
        objects['?']['metadata'] = {}

        data = {
            'Objects': objects,
            'Attributes': [],
            'project_id': context.tenant,
            'user_id': context.user
        }

        environment_params['tenant_id'] = context.tenant
        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        # saving environment as Json to itself
        environment.update({'description': data})
        environment.save(unit)

        return environment
コード例 #26
0
    def generate_default_networks(env_name, network_driver):
        net_config = CONF.find_file(CONF.networking.network_config_file)
        if net_config:
            LOG.debug("Loading network configuration from file")
            with open(net_config) as f:
                data = yaml.safe_load(f)
                return EnvironmentServices._objectify(data, {'ENV': env_name})

        network_type = DEFAULT_NETWORK_TYPES[network_driver]
        LOG.debug("Setting '{0}' as environment's "
                  "default network".format(network_type))
        return {
            'environment': {
                '?': {
                    'id': uuidutils.generate_uuid(),
                    'type': network_type
                },
                'name': env_name + '-network'
            },
            'flat': None
        }
コード例 #27
0
ファイル: environments.py プロジェクト: Magic-Mirror/murano
    def create(environment_params, context):
        # tagging environment by tenant_id for later checks
        """Creates environment with specified params, in particular - name

           :param environment_params: Dict, e.g. {'name': 'env-name'}
           :param context: request context to get the tenant id and the token
           :return: Created Environment
        """
        objects = {'?': {
            'id': uuidutils.generate_uuid(),
        }}
        network_driver = EnvironmentServices.get_network_driver(context)
        objects.update(environment_params)
        if not objects.get('defaultNetworks'):
            objects['defaultNetworks'] = \
                EnvironmentServices.generate_default_networks(objects['name'],
                                                              network_driver)
        objects['?']['type'] = 'io.murano.Environment'
        environment_params['tenant_id'] = context.tenant

        data = {
            'Objects': objects,
            'Attributes': []
        }

        environment = models.Environment()
        environment.update(environment_params)

        unit = db_session.get_session()
        with unit.begin():
            unit.add(environment)

        # saving environment as Json to itself
        environment.update({'description': data})
        environment.save(unit)

        return environment
コード例 #28
0
ファイル: environments.py プロジェクト: Magic-Mirror/murano
    def generate_default_networks(env_name, network_driver):
        net_config = CONF.find_file(
            CONF.networking.network_config_file)
        if net_config:
            LOG.debug("Loading network configuration from file")
            with open(net_config) as f:
                data = yaml.safe_load(f)
                return EnvironmentServices._objectify(data, {
                    'ENV': env_name
                })

        network_type = DEFAULT_NETWORK_TYPES[network_driver]
        LOG.debug("Setting '{net_type}' as environment's "
                  "default network".format(net_type=network_type))
        return {
            'environment': {
                '?': {
                    'id': uuidutils.generate_uuid(),
                    'type': network_type
                },
                'name': env_name + '-network'
            },
            'flat': None
        }