本文整理汇总了Python中dbaas_cloudstack.provider.CloudStackProvider.register_networkapi_equipment方法的典型用法代码示例。如果您正苦于以下问题:Python CloudStackProvider.register_networkapi_equipment方法的具体用法?Python CloudStackProvider.register_networkapi_equipment怎么用?Python CloudStackProvider.register_networkapi_equipment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbaas_cloudstack.provider.CloudStackProvider
的用法示例。
在下文中一共展示了CloudStackProvider.register_networkapi_equipment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do
# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import register_networkapi_equipment [as 别名]
def do(self, workflow_dict):
try:
if 'hosts' not in workflow_dict:
return False
if len(workflow_dict['hosts']) == 1:
return True
cs_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.CLOUDSTACK)
LOG.info("Get credential fot network api...")
networkapi_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.NETWORKAPI)
cs_provider = CloudStackProvider(credentials=cs_credentials,
networkapi_credentials=networkapi_credentials)
if not cs_provider:
raise Exception("Could not create CloudStackProvider object")
return False
workflow_dict['databaseinfraattr'] = []
networkapi_equipment_id = cs_provider.register_networkapi_equipment(
equipment_name=workflow_dict['names']['infra'])
if not networkapi_equipment_id:
raise Exception("Could not register networkapi equipment")
return False
workflow_dict['networkapi_equipment_id'] = networkapi_equipment_id
for host in workflow_dict['hosts']:
LOG.info("Creating Secondary ips...")
host_attr = HostAttr.objects.get(host=host)
reserved_ip = cs_provider.reserve_ip(
project_id=cs_credentials.project,
vm_id=host_attr.vm_id)
if not reserved_ip:
return False
total = DatabaseInfraAttr.objects.filter(
databaseinfra=workflow_dict['databaseinfra']).count()
databaseinfraattr = DatabaseInfraAttr()
databaseinfraattr.ip = reserved_ip['secondary_ip']
if total == 0:
databaseinfraattr.is_write = True
LOG.info("Updating databaseinfra endpoint...")
databaseinfra = workflow_dict['databaseinfra']
databaseinfra.endpoint = databaseinfraattr.ip + \
":%i" % 3306
databaseinfra.save()
workflow_dict['databaseinfra'] = databaseinfra
ip_desc = 'Write IP'
else:
databaseinfraattr.is_write = False
ip_desc = 'Read IP'
networkapi_ip_id = cs_provider.register_networkapi_ip(equipment_id=networkapi_equipment_id,
ip=reserved_ip[
'secondary_ip'],
ip_desc=ip_desc)
databaseinfraattr.cs_ip_id = reserved_ip['cs_ip_id']
databaseinfraattr.networkapi_equipment_id = networkapi_equipment_id
databaseinfraattr.networkapi_ip_id = networkapi_ip_id
databaseinfraattr.databaseinfra = workflow_dict[
'databaseinfra']
databaseinfraattr.save()
workflow_dict['databaseinfraattr'].append(databaseinfraattr)
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0010)
workflow_dict['exceptions']['traceback'].append(traceback)
return False