當前位置: 首頁>>代碼示例>>Python>>正文


Python DatabaseManager.get_all方法代碼示例

本文整理匯總了Python中services.DatabaseManager.DatabaseManager.get_all方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseManager.get_all方法的具體用法?Python DatabaseManager.get_all怎麽用?Python DatabaseManager.get_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在services.DatabaseManager.DatabaseManager的用法示例。


在下文中一共展示了DatabaseManager.get_all方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: checkTopolgoyUniqueness

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkTopolgoyUniqueness(topology):
    db = DatabaseManager()
    # check names
    logger.debug("Check uniqueness of name of the toplogy \"%s\"." % topology.name)
    for top in db.get_all(Topology):
        if topology.ext_name == top.ext_name and topology.id != top.id:
            raise NotUniqueException("Topology name \"%s\" is already used." % topology.name)
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:9,代碼來源:Checker.py

示例2: checkSecurityGroupUniqueness

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkSecurityGroupUniqueness(security_group):
    db = DatabaseManager()
    existing_security_groups = db.get_all(SecurityGroup)
    logger.debug("Check uniqueness of name of the security group \"%s\"." % security_group.name)
    for existing_security_group in existing_security_groups:
        if security_group.name == existing_security_group.name and security_group != existing_security_group:
            raise NotUniqueException("SecurityGroup:\"%s\" is already existing." % security_group.name)
    logger.debug("Check rules of security group \"%s\"." % security_group.name)
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:10,代碼來源:Checker.py

示例3: checkFlavor

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkFlavor(flavor):
    db = DatabaseManager()
    existing_flavors = db.get_all(Flavor)
    if flavor.name in [existing_flavor.name for existing_flavor in existing_flavors]:
        logger.debug("flavor \"%s\" is available." % flavor)
    else:
        raise NotFoundException(
            "flavor:\"%s\" is not available. Available flavors: %s" % (
                flavor, [existing_flavor.name for existing_flavor in existing_flavors]))
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:11,代碼來源:Checker.py

示例4: checkImage

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkImage(image):
    db = DatabaseManager()
    existing_images = db.get_all(Image)
    if image.name in [existing_image.name for existing_image in existing_images]:
        logger.debug("image \"%s\" is available." % image)
    else:
        raise NotFoundException(
            "image:\"%s\" is not available. Available images: %s" % (
                image, [existing_image.name for existing_image in existing_images]))
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:11,代碼來源:Checker.py

示例5: checkKey

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkKey(key):
    db = DatabaseManager()
    existing_keys = db.get_all(Key)
    if key.name in [existing_key.name for existing_key in existing_keys]:
        logger.debug("key \"%s\" is available." % key)
    else:
        raise NotFoundException(
            "key:\"%s\" is not available. Available keys: %s" % (
                key, [existing_key.name for existing_key in existing_keys]))
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:11,代碼來源:Checker.py

示例6: checkNetwork

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkNetwork(network):
    try:
        db = DatabaseManager()
        existing_networks = db.get_all(Network)
        found_private_net = False
        found_subnet = False
        found_public_net = False
        for existing_network in existing_networks:
            if network.private_net == existing_network.ext_id and not found_private_net:
                if existing_network.public == False:
                    logger.debug("private_network \"%s\" is available." % network.private_net)
                    found_private_net = True
                else:
                    raise InvalidInputException(
                        "private_network:\"%s\" is available but it is marked as public and not as private as defined." % network.private_net)
                for subnet in existing_network.subnets:
                    if network.private_subnet == subnet.ext_id and not found_subnet:
                        found_subnet = True
                if found_subnet:
                    logger.debug("private_subnet \"%s\" is available." % network.private_subnet)
                else:
                    raise InvalidInputException("private_subnet:\"%s\" is not available." % network.private_subnet)
            if network.public_net == existing_network.ext_id and not found_public_net:
                if existing_network.public == True:
                    logger.debug("public_network \"%s\" is available." % network.public_net)
                    found_public_net = True
                else:
                    raise InvalidInputException(
                        "network:\"%s\" is available but it is marked as private and not as public as defined." % network.public_net)
        if not network.private_net and not network.private_subnet and not network.public_net:
            logger.debug("Networks were not defined.")
        elif network.private_net and network.private_subnet and network.public_net:
            if found_private_net and found_subnet and found_public_net:
                logger.debug("All defined networks are available for network: %s" % network)
            if not found_private_net:
                raise NotFoundException("Not found private network: %s" % network)
            if not found_subnet:
                raise NotFoundException("Not found private subnet network: %s" % network)
            if not found_public_net:
                raise NotFoundException("Not found public network: %s" % network)
        elif network.private_net and network.private_subnet and not network.public_net:
            if found_private_net and found_subnet and not found_public_net:
                logger.debug("All defined networks are available for network: %s" % network)
            if not found_private_net:
                raise NotFoundException("Not found private network: %s" % network)
            if not found_subnet:
                raise NotFoundException("Not found private subnet network: %s" % network)
        elif not network.private_net and network.public_net:
            raise InvalidInputException("Private net is not defined but the public.")
        else:
            raise InvalidInputException("Error while checking networks.")
    except Exception, exc:
        exc.message = 'Network:\"%s\"->%s' % (network.name, exc.message)
        raise exc
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:56,代碼來源:Checker.py

示例7: checkServiceUniqueness

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkServiceUniqueness(service):
    db = DatabaseManager()
    # check uniqueness of service
    logger.debug("Check uniqueness of name of the service %s." % service.service_type)
    if service.service_type:
        for existing_service in db.get_all(Service):
            if service.service_type == existing_service.service_type and service != existing_service:
                raise NotUniqueException(
                    "Service:\"%s\" is already existing." % service.service_type)
    else:
        raise NotDefinedException("service_type is not defined.")
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:13,代碼來源:Checker.py

示例8: checkServiceType

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
def checkServiceType(service_type):
    db = DatabaseManager()
    services = db.get_all(Service)
    found = False
    for service in services:
        if service.service_type == service_type:
            found = True
            logger.debug("service_type \"%s\" is available." % service_type)
    if not found:
        raise NotFoundException(
            "service_type:\"%s\" is not available. Available service_types:%s" % (
                service_type, [service.service_type for
                               service in services]))
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:15,代碼來源:Checker.py

示例9: test_create_service

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
    def test_create_service(self):
        db = DatabaseManager()
        if len(db.get_all(Service)) > 0:
            self.fail('The Database must be empty: ' + str())

        connection = httplib.HTTPConnection('%s:8090' % HOST)
        headers = {'Content-type': 'application/json'}

        sent_service = {"service_type": "controller", 'image': "nubomedia-broker", 'flavor': "m1.medium",
                        'size': {'def': 1, 'max': 1, 'min': 1}, 'config': {'hostname': 'ControlServer'}}

        sent_service_json = json.dumps(sent_service)

        connection.request('POST', '/services', sent_service_json, headers)
        resp = connection.getresponse()

        self.assertEqual(resp.status, 200)

        service = db.get_by_service_type(Service, sent_service["service_type"])[0]

        self.assertIsNotNone(service)

        self.assertEqual(service.service_type, sent_service["service_type"])
        self.assertEqual(service.image, sent_service["image"])
        self.assertEqual(service.flavor, sent_service["flavor"])
        self.assertEqual(service.size, sent_service['size'])
        self.assertEqual(service.config, sent_service['config'])

        sent_service['flavor'] = "m1.small"

        sent_service_json = json.dumps(sent_service)

        connection.request('PUT', '/services/' + str(service.id), sent_service_json, headers)
        resp = connection.getresponse()

        self.assertEqual(resp.status, 200)

        service = db.get_by_service_type(Service, sent_service["service_type"])[0]
        self.assertIsNotNone(service)
        self.assertEqual(service.service_type, sent_service["service_type"])
        self.assertEqual(service.image, sent_service["image"])
        self.assertEqual(service.flavor, sent_service["flavor"])
        self.assertEqual(service.size, sent_service['size'])
        self.assertEqual(service.config, sent_service['config'])

        connection.request('DELETE', '/services/' + str(service.id), sent_service_json, headers)

        time.sleep(2)

        self.assertEqual(len(db.get_by_service_type(Service, sent_service["service_type"])), 0)
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:52,代碼來源:test_service_create_unittest.py

示例10: DatabaseManager

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
    resp = (response.read())

    logger.debug(resp)

    logger.debug('\n###################CREATE SECURITY GROUPS###################')
    connection.request('GET', '/secgroups')
    response = connection.getresponse()
    resp = (response.read())

    logger.debug(resp)

    logger.debug('\n###################CREATE SERVICE###########################')

    db = DatabaseManager()

    lst = [db.get_all(SecurityGroup)]
    _json = create_service(lst)

    connection.request('POST', '/services', _json, headers)
    response = connection.getresponse()
    resp = (response.read())

    logger.debug(resp)


    logger.debug('\n####################GET SERVICES############################')
    connection.request('GET', '/services')

    response = connection.getresponse()
    resp = (response.read())
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:32,代碼來源:test_api.py

示例11: dump_to_dict

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [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

示例12: get_template

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [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

示例13: get_all

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
 def get_all(cls):
     db = DatabaseManager()
     return db.get_all(SecurityGroup)
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:5,代碼來源:SecurityGroupOrchestrator.py

示例14: get_all_subnets

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
 def get_all_subnets(cls):
     db = DatabaseManager()
     networks = db.get_all(Subnet)
     return networks
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:6,代碼來源:NetworkOrchestrator.py

示例15: get_all_networks

# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_all [as 別名]
 def get_all_networks(cls):
     db = DatabaseManager()
     networks = db.get_all(Network)
     return networks
開發者ID:MobileCloudNetworking,項目名稱:imsaas,代碼行數:6,代碼來源:NetworkOrchestrator.py


注:本文中的services.DatabaseManager.DatabaseManager.get_all方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。