本文整理匯總了Python中services.DatabaseManager.DatabaseManager.get_by_service_type方法的典型用法代碼示例。如果您正苦於以下問題:Python DatabaseManager.get_by_service_type方法的具體用法?Python DatabaseManager.get_by_service_type怎麽用?Python DatabaseManager.get_by_service_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類services.DatabaseManager.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_by_service_type方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_create_service
# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_service_type [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)
示例2: TopologyManager
# 需要導入模塊: from services.DatabaseManager import DatabaseManager [as 別名]
# 或者: from services.DatabaseManager.DatabaseManager import get_by_service_type [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)
#.........這裏部分代碼省略.........