当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseManager.get_by_name方法代码示例

本文整理汇总了Python中services.DatabaseManager.DatabaseManager.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.get_by_name方法的具体用法?Python DatabaseManager.get_by_name怎么用?Python DatabaseManager.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在services.DatabaseManager.DatabaseManager的用法示例。


在下文中一共展示了DatabaseManager.get_by_name方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dump_to_dict

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
 def dump_to_dict(self):
     db = DatabaseManager()
     resource = {}
     server_config = {}
     server_config['type'] = self.type
     properties = {}
     properties['name'] = self.name
     properties['image'] = self.image
     properties['flavor'] = self.flavor
     if self.key_name is not None: properties['key_name'] = self.key_name
     if self.availability_zone is not None: properties['availability_zone'] = self.availability_zone
     if self.network_ports is not None:
         networks = []
         LOG.debug(self.network_ports)
         for network_port in self.network_ports:
             networks.append({'port': { 'get_resource' : network_port.name}})
         properties['networks'] = networks
     if self.user_data:
         properties['user_data_format'] = 'RAW'
         properties['user_data'] = {}
         properties['user_data']['str_replace'] = {}
         properties['user_data']['str_replace']['template'] = ''
         _user_data = ''
         _user_data_list = []
         for command in self.user_data:
             _user_data += "%s\n" % command.command
         properties['user_data']['str_replace']['template'] = SysUtil.literal_unicode((_user_data))
         properties['user_data']['str_replace']['params'] = {'':''}
         if self.requirements:
             params = {}
             for requirement in self.requirements:
                 try:
                     source_service_instances = db.get_by_name(ServiceInstance,requirement.source)
                 except:
                     LOG.debug('ERROR: Entry %s was not found in Table ServiceInstance' % requirement.source)
                     raise
                 source_units = []
                 if source_service_instances:
                     source_service_instance = source_service_instances[0]
                     source_units = source_service_instance.units
                     LOG.debug(source_units)
                     if source_units:
                         if requirement.parameter == 'private_ip' or requirement.parameter == 'public_ip':
                             #Get requested network specified in the requirement
                             _networks = [network for network in source_service_instance.networks if network.name == requirement.obj_name ]
                             _network = None
                             if _networks:
                                 _network_id = _networks[0].private_net
                             else:
                                 LOG.debug('ERROR: obj_name %s was not found in networks of ServiceInstance %s' % (requirement.obj_name,source_service_instance))
                                 raise
                             #Get network name of the specified network id
                             _network_names = [network.name for network in db.get_all(Network) if network.ext_id == _network_id]
                             _network_name = None
                             if _network_names:
                                 _network_name = _network_names[0]
                             else:
                                 LOG.debug('ERROR: Cannot find network with id %s in Table Network' % _network_id)
                             if requirement.parameter == "private_ip":
                                 ip_number = 0
                             elif requirement.parameter == "public_ip":
                                 ip_number = 1
                             #Create the variable
                             _params = {}
                             _first_unit = source_units[0]
                             _template = '$%s' % _first_unit.hostname
                             _params['$%s' % _first_unit.hostname] = {'get_attr': [_first_unit.hostname, 'networks', _network_name, ip_number]}
                             for source_unit in source_units[1:]:
                                 _template += ';$%s' % source_unit.hostname
                                 _params['$%s' % source_unit.hostname] = {'get_attr': [source_unit.hostname, 'networks', _network_name, ip_number]}
                         param = {}
                         param[requirement.name] = {}
                         param[requirement.name]['str_replace'] = {}
                         param[requirement.name]['str_replace']['template'] = _template
                         param[requirement.name]['str_replace']['params'] = _params
                         params.update(param)
                     else:
                         LOG.debug('ERROR: Units for ServiceInstance %s were not found.' % requirement.source)
                         raise Exception
                 else:
                     LOG.debug('ERROR: ServiceInstance %s was not found' % requirement.source)
                     raise Exception
             properties['user_data']['str_replace']['params'] = params
     server_config['properties'] = properties
     resource[self.name] = server_config
     return resource
开发者ID:MobileCloudNetworking,项目名称:maas,代码行数:88,代码来源:TemplateManager.py

示例2: CheckerThread

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
class CheckerThread(threading.Thread):
    def __init__(self, topology):
        super(CheckerThread, self).__init__()
        self.heatclient = HeatClient()
        self.topology = topology
        self.db = DatabaseManager()
        self.is_stopped = False
        self.is_dns_configured = False
        self.novac = NovaClient()
        #self.dns_configurator = ImsDnsClient()
        self.neutronc = NeutronClient(utilSys.get_endpoint('network', region_name=SysUtil().get_sys_conf()['os_region_name']), utilSys.get_token())

    def run(self):
        while not self.is_stopped:
            self.update_topology_state()
            if self.topology.state == 'DELETED':
                TopologyOrchestrator.delete(self.topology)
                self.is_stopped = True
            for si in self.topology.service_instances:
                if not self.is_stopped:
                    for unit in si.units:
                        if len(unit.ports) == 0:
                            self.set_ips(unit)
            if self.topology.state == 'DEPLOYED' and not self.is_dns_configured:
                #self.configure_dns()
                self.configure_topology()
                self.is_dns_configured = True
            time.sleep(30)


    def configure_dns(self):
        for si in self.topology.service_instances:
            for unit in si.units:
                try:
                    self.dns_configurator.configure_dns_entry(si.service_type, unit.hostname)(unit.ips['mgmt'])
                except:
                    logging.debug("this service instance is not needed in the dns")

    def configure_topology(self):
        for si in self.topology.service_instances:
            si.adapter_instance = FactoryServiceAdapter.get_agent(si.service_type, si.adapter)
            for unit in si.units:
                try:
                    config = {}
                    config['hostname'] = unit.hostname
                    config['ips'] = unit.ips
                    config['floating_ips'] = unit.floating_ips
                    config['hostname'] = unit.hostname
                except:
                    logging.debug("there was an issue getting the config for the vnf")

                try:
                    logging.info("sending requests to the adapter %s with config" % config)
                    si.adapter_instance.preinit(config)
                    si.adapter_instance.install(config)
                except Exception,e:
                    logging.error("error while configuring vnf %s" % e)

                # add relations
                for ext_service in si.relation:
                    service_list = self.db.get_by_name(ServiceInstance, ext_service.name)
                    if len(service_list) == 1:
                        ext_si = service_list[0]
                        for ext_unit in ext_si.units:
                            logging.info("sending request add_dependency to the adapter %s with config %s and ext_unit %s" % (si.service_type, config, ext_unit))
                            si.adapter_instance.add_dependency(config, ext_unit, ext_si)
                try:
                    # TODO add add_relation methods
                    si.adapter_instance.pre_start(config)
                    si.adapter_instance.start(config)
                except Exception,e:
                    logging.error("error while configuring vnf %s" % e)
开发者ID:MobileCloudNetworking,项目名称:maas,代码行数:74,代码来源:RuntimeAgent.py

示例3: dump_to_dict

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
 def dump_to_dict(self):
     db = DatabaseManager()
     resource = {}
     server_config = {}
     server_config["type"] = self.type
     properties = {}
     properties["name"] = self.name
     properties["image"] = self.image
     properties["flavor"] = self.flavor
     if self.key_name is not None:
         properties["key_name"] = self.key_name
     if self.availability_zone is not None:
         properties["availability_zone"] = self.availability_zone
     if self.network_ports is not None:
         networks = []
         logger.debug(self.network_ports)
         for network_port in self.network_ports:
             networks.append({"port": {"get_resource": network_port.name}})
         properties["networks"] = networks
     if self.user_data:
         properties["user_data_format"] = "RAW"
         properties["user_data"] = {}
         properties["user_data"]["str_replace"] = {}
         properties["user_data"]["str_replace"]["template"] = ""
         _user_data = ""
         _user_data_list = []
         for command in self.user_data:
             _user_data += "%s\n" % command.command
         properties["user_data"]["str_replace"]["template"] = SysUtil.literal_unicode((_user_data))
         properties["user_data"]["str_replace"]["params"] = {"": ""}
         if self.requirements:
             params = {}
             for requirement in self.requirements:
                 try:
                     source_service_instances = db.get_by_name(ServiceInstance, requirement.source)
                 except:
                     logger.debug("ERROR: Entry %s was not found in Table ServiceInstance" % requirement.source)
                     raise
                 source_units = []
                 if source_service_instances:
                     source_service_instance = source_service_instances[0]
                     source_units = source_service_instance.units
                     logger.debug(source_units)
                     if source_units:
                         if requirement.parameter == "private_ip" or requirement.parameter == "public_ip":
                             # Get requested network specified in the requirement
                             _networks = [
                                 network
                                 for network in source_service_instance.networks
                                 if network.name == requirement.obj_name
                             ]
                             _network = None
                             if _networks:
                                 _network_id = _networks[0].private_net
                             else:
                                 logger.debug(
                                     "ERROR: obj_name %s was not found in networks of ServiceInstance %s"
                                     % (requirement.obj_name, source_service_instance)
                                 )
                                 raise
                             # Get network name of the specified network id
                             _network_names = [
                                 network.name for network in db.get_all(Network) if network.ext_id == _network_id
                             ]
                             _network_name = None
                             if _network_names:
                                 _network_name = _network_names[0]
                             else:
                                 logger.debug("ERROR: Cannot find network with id %s in Table Network" % _network_id)
                             if requirement.parameter == "private_ip":
                                 ip_number = 0
                             elif requirement.parameter == "public_ip":
                                 ip_number = 1
                             # Create the variable
                             _params = {}
                             _first_unit = source_units[0]
                             _template = "$%s" % _first_unit.hostname
                             _params["$%s" % _first_unit.hostname] = {
                                 "get_attr": [_first_unit.hostname, "networks", _network_name, ip_number]
                             }
                             for source_unit in source_units[1:]:
                                 _template += ";$%s" % source_unit.hostname
                                 _params["$%s" % source_unit.hostname] = {
                                     "get_attr": [source_unit.hostname, "networks", _network_name, ip_number]
                                 }
                         param = {}
                         param[requirement.name] = {}
                         param[requirement.name]["str_replace"] = {}
                         param[requirement.name]["str_replace"]["template"] = _template
                         param[requirement.name]["str_replace"]["params"] = _params
                         params.update(param)
                     else:
                         logger.debug("ERROR: Units for ServiceInstance %s were not found." % requirement.source)
                         raise Exception
                 else:
                     logger.debug("ERROR: ServiceInstance %s was not found" % requirement.source)
                     raise Exception
             properties["user_data"]["str_replace"]["params"] = params
     server_config["properties"] = properties
     resource[self.name] = server_config
#.........这里部分代码省略.........
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:103,代码来源:TemplateManager.py

示例4: TopologyManager

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
class TopologyManager(ABCTopologyManager):

    def __init__(self):
        self.db = DatabaseManager()

    def create(self, config):
        ###Topology arguments
        top_name = config.get('name')
        top_state = 'DEFINED'
        top_service_instances = []
        logger.debug("Parse Topology \"%s\"" % top_name)
        ###Parse all service instances described in config file
        sis_config = config.get('service_instances')
        for si_config in sis_config:
            si_args = {}
            si_args['state'] = 'DEFINED'
            service = None
            if si_config.get('service_type'):
                service_type = si_config.get('service_type')
                logger.debug('Fetching service of service_type \"%s\"' % service_type)
                service_list = self.db.get_by_service_type(Service, service_type)
                if len(service_list) == 1:
                    service = service_list[0]
                    logger.debug('Service \"%s\" is available.' % service)
                    si_args['service_type'] = service.service_type
                    si_args['image'] = service.image
                    si_args['flavor'] = service.flavor
                    si_args['configuration'] = service.configuration
                    si_args['key'] = service.key
                    si_args['size'] = service.size
                    si_args['adapter'] = service.adapter
                    si_args['requirements'] = []
                    for requirement in service.requirements:
                        func = Requirement.__init__
                        needed_parameters = func.func_code.co_varnames[1:func.func_code.co_argcount]
                        args = {}
                        for param in needed_parameters:
                            args[param] = requirement.__dict__.get(param)
                        new_requirement = Requirement(**args)
                        si_args['requirements'].append(new_requirement)
                    si_args['networks'] = []
                    for network in service.networks:
                        func = Network_Instance.__init__
                        needed_parameters = func.func_code.co_varnames[1:func.func_code.co_argcount]
                        args = {}
                        for param in needed_parameters:
                            args[param] = network.__dict__.get(param)
                        new_network = Network_Instance(**args)
                        si_args['networks'].append(new_network)
                    si_args['user_data'] = []
                    for command in service.user_data:
                        func = Command.__init__
                        needed_parameters = func.func_code.co_varnames[1:func.func_code.co_argcount]
                        args = {}
                        for param in needed_parameters:
                            args[param] = command.__dict__.get(param)
                        new_command = Command(**args)
                        si_args['user_data'].append(new_command)
                else:
                    raise NotFoundException('service_type:\"%s\" is not available.' % service_type)
            else:
                raise NotDefinedException("service_type is not defined.")
            for si_item in si_config:
                if si_item == "name":
                    si_args['name'] = si_config.get(si_item)
                    logger.debug("Parsing service instance \"%s\"" % si_args['name'])
                elif si_item == "service_type":
                    si_args['service_type'] = si_config.get(si_item)
                elif si_item == "adapter":
                    si_args['adapter'] = si_config.get(si_item)
                elif si_item == "image":
                    image_name = si_config.get(si_item)
                    image_list = self.db.get_by_name(Image, image_name)
                    if len(image_list) == 1:
                        image = image_list[0]
                        si_args['image'] = image
                    else:
                        raise NotFoundException('image:\"%s\" is not available.' % image_name)
                elif si_item == "flavor":
                    flavor_name = si_config.get(si_item)
                    flavor_list = self.db.get_by_name(Flavor, flavor_name)
                    if len(flavor_list) == 1:
                        flavor = flavor_list[0]
                        si_args['flavor'] = flavor
                    else:
                        raise NotFoundException('flavor:\"%s\" is not available.' % flavor_name)
                elif si_item == "key":
                    key_name = si_config.get(si_item)
                    key_list = self.db.get_by_name(Key, key_name)
                    if len(key_list) == 1:
                        key = key_list[0]
                        si_args['key'] = key
                    else:
                        raise NotFoundException('key:\"%s\" is not available.' % key_name)
                elif si_item == "size":
                    si_args['size'].update(si_config.get(si_item))
                elif si_item == "networks":
                    networks = []
                    _networks = si_config.get(si_item)
                    logger.debug("Fetch SecurityGroups for networks %s." % _networks)
#.........这里部分代码省略.........
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:103,代码来源:TopologyManager.py

示例5: CheckerThread

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
class CheckerThread(threading.Thread):
    def __init__(self, topology):
        super(CheckerThread, self).__init__()
        self.heatclient = HeatClient()
        self.topology = topology
        self.db = DatabaseManager()
        self.is_stopped = False
        self.is_dnsaas = False
        self.dnsaas = None
        self.novac = NovaClient()
        self.dns_configurator = None
        self.neutronc = NeutronClient(
            utilSys.get_endpoint("network", region_name=SysUtil().get_sys_conf()["os_region_name"]), utilSys.get_token()
        )
        self.dns_configurator = None

    def run(self):
        while not self.is_stopped:
            self.update_topology_state()
            if self.topology.state == "DELETED":
                TopologyOrchestrator.delete(self.topology)
                self.is_stopped = True
            for si in self.topology.service_instances:
                if not self.is_stopped:
                    for unit in si.units:
                        if len(unit.ports) == 0:
                            self.set_ips(unit)
            time.sleep(30)

    def provision(self, dnsaas):
        if dnsaas is not None:
            self.dns_configurator = ImsDnsClient(dnsaas)
            self.is_dnsaas = True
        while not self.topology.state == "DEPLOYED":
            logger.info("topology not yet in status deployed, currently %s" % self.topology.state)
            time.sleep(5)
        self.configure_topology()

    def configure_topology(self):
        for si in self.topology.service_instances:
            si.adapter_instance = FactoryServiceAdapter.get_agent(si.service_type, si.adapter)
            for unit in si.units:
                try:
                    config = {}
                    config["hostname"] = unit.hostname
                    config["ips"] = unit.ips
                    config["zabbix_ip"] = os.environ["ZABBIX_IP"]
                    config["floating_ips"] = unit.floating_ips
                    config["hostname"] = unit.hostname
                except:
                    logging.error("there was an issue getting the config for the vnf")

                try:
                    logging.info("sending requests to the adapter %s with config" % config)
                    si.adapter_instance.preinit(config)
                    si.adapter_instance.install(config)
                except Exception, e:
                    logging.error("error while configuring vnf %s" % e)

                # add relations
                for ext_service in si.relation:
                    logger.info(
                        "solving dependencies between si %s and external service %s" % (si.name, ext_service.name)
                    )
                    if ext_service.name == "dns" and self.is_dnsaas is True:
                        ext_unit = Unit(hostname=None, state="INITIALISING")
                        ext_si = ServiceInstance(
                            name="dns", service_type="dns", state="INITIALISING", image="test", flavor="test", size={}
                        )
                        ext_unit.ips["mgmt"] = os.environ["DNSAAS_IP"]
                        self.dns_configurator.configure_dns_entry(si.service_type)(unit.ips["mgmt"], unit.hostname)
                        si.adapter_instance.add_dependency(config, ext_unit, ext_si)
                    else:
                        service_list = self.db.get_by_name(ServiceInstance, ext_service.name)
                        if len(service_list) == 1:
                            ext_si = service_list[0]
                            for ext_unit in ext_si.units:
                                logging.info(
                                    "sending request add_dependency to the adapter %s with config %s and ext_unit %s"
                                    % (si.service_type, config, ext_unit)
                                )
                                si.adapter_instance.add_dependency(config, ext_unit, ext_si)
                try:
                    si.adapter_instance.pre_start(config)
                    si.adapter_instance.start(config)
                except Exception, e:
                    logging.error("error while configuring vnf %s" % e)
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:89,代码来源:RuntimeAgent.py

示例6: get_template

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
    def get_template(topology):
        #name = topology.name
        _template = {}
        _template['heat_template_version'] = '2013-05-23'
        _resources = {}
        _outputs = {}
        LOG.debug("create Template for Topology: %s" % topology.name)

        db = DatabaseManager()

        for service_instance in topology.service_instances:
            _software_config = None
            #Create SoftwareConfig for user_data
            if service_instance.user_data:
                _inputs = []
                if service_instance.requirements:
                    for requirement in service_instance.requirements:
                        _inputs.append(requirement.name)
                _software_config = SoftwareConfig(name='%s-SoftwareConfig' % service_instance.name, config=service_instance.user_data, group=service_instance.name, inputs=_inputs)

            for unit in service_instance.units:
                #Create input values for user_data for SoftwareDeployment
                if service_instance.requirements or service_instance.user_data:
                    _input_values = {}
                    for requirement in service_instance.requirements:
                        try:
                            source_service_instances = db.get_by_name(ServiceInstance,requirement.source)
                        except:
                            LOG.debug('ERROR: Entry %s was not found in Table ServiceInstance' % requirement.source)
                            raise
                        source_units = []
                        if source_service_instances:
                            source_service_instance = source_service_instances[0]
                            source_units = source_service_instance.units
                            LOG.debug(source_units)
                            if source_units:
                                if requirement.parameter == 'private_ip' or requirement.parameter == 'public_ip':
                                    #Get requested network specified in the requirement
                                    _networks = [network for network in source_service_instance.networks if network.name == requirement.obj_name ]
                                    _network = None
                                    if _networks:
                                        _network_id = _networks[0].private_net
                                    else:
                                        LOG.debug('ERROR: obj_name %s was not found in networks of ServiceInstance %s' % (requirement.obj_name,source_service_instance))
                                        raise
                                    #Get network name of the specified network id
                                    _network_names = [network.name for network in db.get_all(Network) if network.ext_id == _network_id]
                                    _network_name = None
                                    if _network_names:
                                        _network_name = _network_names[0]
                                    else:
                                        LOG.debug('ERROR: Cannot find network with id %s in Table Network' % _network_id)
                                    if requirement.parameter == "private_ip":
                                        ip_number = 0
                                    elif requirement.parameter == "public_ip":
                                        ip_number = 1
                                    #Create the variable
                                    _param_params = {}
                                    _first_unit = source_units[0]
                                    _param_template = '$%s' % _first_unit.hostname
                                    _param_params['$%s' % _first_unit.hostname] = {'get_attr': [_first_unit.hostname, 'networks', _network_name, ip_number]}
                                    for source_unit in source_units[1:]:
                                        _param_template += ';$%s' % source_unit.hostname
                                        _param_params['$%s' % source_unit.hostname] = {'get_attr': [source_unit.hostname, 'networks', _network_name, ip_number]}
                                param = {}
                                param[requirement.name] = {}
                                param[requirement.name]['str_replace'] = {}
                                param[requirement.name]['str_replace']['template'] = _param_template
                                param[requirement.name]['str_replace']['params'] = _param_params
                                _input_values.update(param)
                            else:
                                LOG.debug('ERROR: Units for ServiceInstance %s were not found.' % requirement.source)
                                raise Exception
                        else:
                            LOG.debug('ERROR: ServiceInstance %s was not found' % requirement.source)
                            raise Exception
                    _software_deployment = SoftwareDeployment(name='%s-SoftwareDeployment' % unit.hostname, config=_software_config, server=unit, input_values=_input_values)
                    _resources.update(_software_deployment.dump_to_dict())

                #Create Ports and floating IPs for this unit
                _ports = []
                _floating_ips = []
                if service_instance.networks:
                    i=1
                    for network in service_instance.networks:
                        ###Creating Port for this service instance
                        _new_port = None
                        #prepare port args for this service instance
                        _port_args = {}
                        _port_args['name'] = '%s-port-%s' % (unit.hostname, i)
                        _port_args['private_net_id'] = network.private_net
                        _port_args['private_subnet_id'] = network.private_subnet
                        _port_args['fixed_ip'] = network.fixed_ip
                        if network.security_groups:
                            _port_args['security_groups'] = network.security_groups
                        _new_port = Port(**_port_args)
                        _ports.append(_new_port)
                        if network.public_net:
                            _new_floating_ip_args = {}
                            _new_floating_ip_args['name'] = '%s-floating_ip-%s' % (unit.hostname, i)
#.........这里部分代码省略.........
开发者ID:MobileCloudNetworking,项目名称:maas,代码行数:103,代码来源:TemplateManagerConfig.py

示例7: ServiceManager

# 需要导入模块: from services.DatabaseManager import DatabaseManager [as 别名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_name [as 别名]
class ServiceManager(ABCServiceManager):

    def __init__(self):
        self.db = DatabaseManager()

    def create(self, config):
        ###Service arguments
        service_type = config.get('service_type')
        logger.debug("Parse Service \"%s\"" % service_type)
        ###Parse each item described in config file
        new_service_args={}
        for service_item in config.keys():
            if service_item == "service_type":
                new_service_args['service_type'] = config.get(service_item)
            elif service_item == "image":
                image_name = config.get(service_item)
                image_list = self.db.get_by_name(Image, image_name)
                if len(image_list) == 1:
                    image = image_list[0]
                    new_service_args['image'] = image
                else:
                    raise NotFoundException('image:\"%s\" is not available.' % image_name)
            elif service_item == "flavor":
                flavor_name = config.get(service_item)
                flavor_list = self.db.get_by_name(Flavor, flavor_name)
                if len(flavor_list) == 1:
                    flavor = flavor_list[0]
                    new_service_args['flavor'] = flavor
                else:
                    raise NotFoundException('flavor:\"%s\" is not available.' % flavor_name)
            elif service_item == "key":
                key_name = config.get(service_item)
                key_list = self.db.get_by_name(Key, key_name)
                if len(key_list) == 1:
                    key = key_list[0]
                    new_service_args['key'] = key
                else:
                    raise NotFoundException('key:\"%s\" is not available.' % key_name)
            elif service_item == "size":
                new_service_args['size'] = config.get(service_item)
            elif service_item == "networks":
                networks = []
                _networks = config.get(service_item)
                logger.debug("Fetch SecurityGroups for networks %s." % _networks)
                for _net_inst in _networks:
                    secgroups = []
                    for _secgroup_name in _net_inst.get('security_groups'):
                        lst = self.db.get_by_name(SecurityGroup, _secgroup_name)
                        if len(lst) > 0:
                            _secgroup = lst[0]
                        else:
                            raise NotFoundException('SecurityGroup:\"%s\" is not available.'  % _secgroup_name)
                        secgroups.append(_secgroup)
                    _net_inst['security_groups'] = secgroups
                    networks.append(Network_Instance(**_net_inst))
                new_service_args['networks'] = networks
            elif service_item == "configuration":
                new_service_args['configuration'] = config.get(service_item)
            elif service_item == "requirements":
               requirements = []
               for _req in config.get(service_item):
                   _req_args = _req
                   requirement = Requirement(**_req_args)
                   requirements.append(requirement)
               new_service_args['requirements'] = requirements
            elif service_item == "user_data":
                user_data = []
                for _user_data_item in  config.get(service_item):
                    command = Command(_user_data_item)
                    user_data.append(command)
                new_service_args['user_data'] = user_data
            elif service_item == "version":
                new_service_args['version'] = config.get(service_item)
            elif service_item == "adapter":
                new_service_args['adapter'] = config.get(service_item)
            else:
                raise InvalidInputException("paramter \"%s\" is not provided by Services." % config.get(service_item))


        ###Create Service
        print(new_service_args)
        new_service = Service(**new_service_args)
        logger.debug(new_service)
        return new_service

    def update(self):
        pass

    def dynamic_create(self, dict):
        logger.debug(dict)
        t = Topology(**dict)
        logger.debug(t.__dict__)
        return t

    def get_attrs(self,_class):
        return [k for k in dir(_class) if not k.startswith('__') ]

    def get_service_instance(self, _class, _name):
        return self.db.get_by_name(_class, _name)
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:101,代码来源:ServiceManager.py


注:本文中的services.DatabaseManager.DatabaseManager.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。