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


Python CloudStackProvider.reserve_ip方法代码示例

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


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

示例1: do

# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import reserve_ip [as 别名]
	def do(self, workflow_dict):
		try:
			if not 'hosts' 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)

			cs_provider = CloudStackProvider(credentials=cs_credentials)

			workflow_dict['databaseinfraattr'] = []

			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

				else:
					databaseinfraattr.is_write = False

				databaseinfraattr.cs_ip_id = reserved_ip['cs_ip_id']
				databaseinfraattr.databaseinfra = workflow_dict[
					'databaseinfra']
				databaseinfraattr.save()

				workflow_dict['databaseinfraattr'].append(databaseinfraattr)

			return True
		except Exception as e:
			traceback = full_stack()

			workflow_dict['exceptions']['error_codes'].append(DBAAS_0010)
			workflow_dict['exceptions']['traceback'].append(traceback)

			return False
开发者ID:allanfreitas,项目名称:database-as-a-service,代码行数:66,代码来源:create_secondary_ip.py

示例2: do

# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import reserve_ip [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
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:94,代码来源:create_secondary_ip.py

示例3: do

# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import reserve_ip [as 别名]
    def do(self, workflow_dict):
        try:
            if 'target_hosts' not in workflow_dict:
                return False

            if len(workflow_dict['target_hosts']) == 1:
                return True

            cs_credentials = get_credentials_for(
                environment=workflow_dict['target_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            LOG.info("Get credential fot network api...")
            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['target_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['target_secondary_ips'] = []

            networkapi_equipment_id = workflow_dict['source_secondary_ips'][0].networkapi_equipment_id

            if not networkapi_equipment_id:
                raise Exception("Could not register networkapi equipment")
                return False

            for index, host in enumerate(workflow_dict['target_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

                databaseinfraattr = DatabaseInfraAttr()
                databaseinfraattr.ip = reserved_ip['secondary_ip']
                if index == 0:
                    databaseinfraattr.is_write = True
                    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()

                old_ip = workflow_dict['source_secondary_ips'][index]
                old_ip.equivalent_dbinfraattr = databaseinfraattr
                old_ip.save()

                workflow_dict['target_secondary_ips'].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
开发者ID:tsunli,项目名称:database-as-a-service,代码行数:76,代码来源:create_secondary_ip.py


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