本文整理汇总了Python中services.DatabaseManager.DatabaseManager类的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager类的具体用法?Python DatabaseManager怎么用?Python DatabaseManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: checkTopolgoyUniqueness
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,代码行数:7,代码来源:Checker.py
示例2: get
def get(cls, id):
db = DatabaseManager()
try:
service = db.get_by_id(Service, id)
except NotFoundException as e:
raise e
return service
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:7,代码来源:ServiceOrchestrator.py
示例3: get
def get(cls, id):
db = DatabaseManager()
try:
security_group = db.get_by_id(SecurityGroup, id)
except NotFoundException as e:
raise e
return security_group
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:7,代码来源:SecurityGroupOrchestrator.py
示例4: checkSecurityGroupUniqueness
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,代码行数:8,代码来源:Checker.py
示例5: delete
def delete(cls, id):
db = DatabaseManager()
try:
service_to_remove = db.get_by_id(Service, id)
except NotFoundException as e:
raise e
db.remove(service_to_remove)
return service_to_remove
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:8,代码来源:ServiceOrchestrator.py
示例6: delete
def delete(cls, id):
db = DatabaseManager()
try:
security_group_to_remove = db.get_by_id(SecurityGroup, id)
except NotFoundException as e:
raise e
db.remove(security_group_to_remove)
return security_group_to_remove
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:8,代码来源:SecurityGroupOrchestrator.py
示例7: __init__
class Register:
def __init__(self):
self.db = DatabaseManager()
def register_unit(self, unit, ws):
unit.ws = ws
unit.state = 'STARTED'
self.db.update(unit)
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:9,代码来源:Register.py
示例8: checkKey
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,代码行数:9,代码来源:Checker.py
示例9: checkFlavor
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,代码行数:9,代码来源:Checker.py
示例10: checkImage
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,代码行数:9,代码来源:Checker.py
示例11: checkNetwork
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,代码行数:54,代码来源:Checker.py
示例12: checkServiceUniqueness
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,代码行数:11,代码来源:Checker.py
示例13: create
def create(cls, service_args):
try:
conf = sys_util().get_sys_conf()
service_manager = FactoryAgent().get_agent(conf["service_manager"])
service = service_manager.create(service_args)
checker = FactoryAgent().get_agent(conf["checker"])
checker.check(service=service)
db = DatabaseManager()
db.persist(service)
except Exception, msg:
raise
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:11,代码来源:ServiceOrchestrator.py
示例14: create
def create(cls, secgroup_args):
_sec_rules = secgroup_args.get("rules")
_new_sec_rules = []
for _sec_rule_args in _sec_rules:
_new_sec_rule = Rule(**_sec_rule_args)
_new_sec_rules.append(_new_sec_rule)
new_secgroup = SecurityGroup(name=secgroup_args.get('name'), rules=_new_sec_rules)
conf = sys_util().get_sys_conf()
checker = FactoryAgent().get_agent(conf['checker'])
checker.check(security_group=new_secgroup)
db = DatabaseManager()
db.persist(new_secgroup)
return new_secgroup
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:13,代码来源:SecurityGroupOrchestrator.py
示例15: checkServiceType
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,代码行数:13,代码来源:Checker.py
示例16: test_create_service
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,代码行数:50,代码来源:test_service_create_unittest.py
示例17: update
def update(cls, service_args, id):
db = DatabaseManager()
try:
updated_service = db.get_by_id(Service, id)
except NotFoundException as e:
raise e
updated_service.config = service_args.get("config") or updated_service.config
updated_service.flavor = service_args.get("flavor") or updated_service.flavor
updated_service.image = service_args.get("image") or updated_service.image
updated_service.service_type = service_args.get("service_type") or updated_service.service_type
updated_service.size = service_args.get("size") or updated_service.size
conf = sys_util().get_sys_conf()
checker = FactoryAgent().get_agent(conf["checker"])
checker.check(service=updated_service)
db.update(updated_service)
return updated_service
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:16,代码来源:ServiceOrchestrator.py
示例18: update
def update(cls, secgroup_args, id):
db = DatabaseManager()
try:
updated_secgroup = db.get_by_id(SecurityGroup, id)
except NotFoundException as e:
raise e
_sec_rules = secgroup_args.get('rules')
_new_sec_rules = []
for _sec_rule_args in _sec_rules:
_new_sec_rule = Rule(**_sec_rule_args)
_new_sec_rules.append(_new_sec_rule)
updated_secgroup.rules = _new_sec_rules or updated_secgroup.rules
updated_secgroup.name = secgroup_args.get('name') or updated_secgroup.name
check(security_group=updated_secgroup)
db.update(updated_secgroup)
return updated_secgroup
开发者ID:MobileCloudNetworking,项目名称:imsaas,代码行数:16,代码来源:SecurityGroupOrchestrator.py
示例19: __init__
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())
开发者ID:MobileCloudNetworking,项目名称:maas,代码行数:10,代码来源:RuntimeAgent.py
示例20: CheckerThread
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,代码行数:72,代码来源:RuntimeAgent.py
注:本文中的services.DatabaseManager.DatabaseManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论