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


Python CloudStackProvider.deploy_virtual_machine方法代码示例

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


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

示例1: do

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

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

			vm_credentials = get_credentials_for(
				environment=workflow_dict['environment'],
				credential_type=CredentialType.VM)

			cs_provider = CloudStackProvider(credentials=cs_credentials)

			cs_plan_attrs = PlanAttr.objects.get(plan=workflow_dict['plan'])

			workflow_dict['hosts'] = []
			workflow_dict['instances'] = []
			workflow_dict['databaseinfraattr'] = []
			workflow_dict['vms_id'] = []
			bundles = list(cs_plan_attrs.bundle.all())

			for index, vm_name in enumerate(workflow_dict['names']['vms']):

				if bundles.__len__()==1:
					bundle = bundles[0]
				else:
					bundle = LastUsedBundle.get_next_bundle(plan=workflow_dict['plan'], bundle= bundles)

				if workflow_dict['enginecod'] == workflow_dict['MONGODB'] and index == 2:
					offering = cs_plan_attrs.get_weaker_offering()
				else:
					offering = cs_plan_attrs.get_stronger_offering()

				LOG.debug("Deploying new vm on cs with bundle %s and offering %s" % (bundle,offering))

				vm = cs_provider.deploy_virtual_machine(
					offering=offering.serviceofferingid,
					bundle= bundle,
					project_id=cs_credentials.project,
					vmname=vm_name,
				)

				if not vm:
					raise Exception("CloudStack could not create the virtualmachine")

				LOG.debug("New virtualmachine: %s" % vm)

				workflow_dict['vms_id'].append(vm['virtualmachine'][0]['id'])

				host = Host()
				host.address = vm['virtualmachine'][0]['nic'][0]['ipaddress']
				host.hostname = host.address
				host.cloud_portal_host = True
				host.save()
				LOG.info("Host created!")

				workflow_dict['hosts'].append(host)

				host_attr = HostAttr()
				host_attr.vm_id = vm['virtualmachine'][0]['id']
				host_attr.vm_user = vm_credentials.user
				host_attr.vm_password = vm_credentials.password
				host_attr.host = host
				host_attr.save()
				LOG.info("Host attrs custom attributes created!")

				instance = Instance()
				instance.address = host.address
				if workflow_dict['enginecod'] == workflow_dict['MYSQL']:
					instance.port = 3306
				elif workflow_dict['enginecod'] == workflow_dict['MONGODB']:
					instance.port = 27017
				instance.is_active = True
				if workflow_dict['enginecod'] == workflow_dict['MONGODB'] and index == 2:
					instance.is_arbiter = True
				else:
					instance.is_arbiter = False

				instance.hostname = host
				instance.databaseinfra = workflow_dict['databaseinfra']
				instance.save()
				LOG.info("Instance created!")

				workflow_dict['instances'].append(instance)

				if  workflow_dict['qt']==1:

					LOG.info("Updating databaseinfra endpoint...")
					databaseinfra = workflow_dict['databaseinfra']
					databaseinfra.endpoint = instance.address + ":%i" %(instance.port)
					databaseinfra.save()
					workflow_dict['databaseinfra'] = databaseinfra

					return True

			return True
		except Exception as e:
			traceback = full_stack()
#.........这里部分代码省略.........
开发者ID:allanfreitas,项目名称:database-as-a-service,代码行数:103,代码来源:create_virtualmachines.py

示例2: do

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

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

            vm_credentials = get_credentials_for(
                environment=workflow_dict['environment'],
                credential_type=CredentialType.VM)

            cs_provider = CloudStackProvider(credentials=cs_credentials)

            cs_plan_attrs = PlanAttr.objects.get(plan=workflow_dict['plan'])

            workflow_dict['hosts'] = []
            workflow_dict['instances'] = []
            workflow_dict['databaseinfraattr'] = []
            workflow_dict['vms_id'] = []
            bundles = list(cs_plan_attrs.bundle.all())

            for index, vm_name in enumerate(workflow_dict['names']['vms']):

                if len(bundles) == 1:
                    bundle = bundles[0]
                else:
                    bundle = LastUsedBundle.get_next_bundle(
                        plan=workflow_dict['plan'], bundle=bundles)

                if index == 2:
                    offering = cs_plan_attrs.get_weaker_offering()
                else:
                    offering = cs_plan_attrs.get_stronger_offering()

                try:
                    DatabaseInfraOffering.objects.get(
                        databaseinfra=workflow_dict['databaseinfra'])
                except ObjectDoesNotExist:
                    LOG.info("Creating databaseInfra Offering...")
                    dbinfra_offering = DatabaseInfraOffering()
                    dbinfra_offering.offering = offering
                    dbinfra_offering.databaseinfra = workflow_dict[
                        'databaseinfra']
                    dbinfra_offering.save()

                LOG.debug(
                    "Deploying new vm on cs with bundle %s and offering %s" % (bundle, offering))

                vm = cs_provider.deploy_virtual_machine(
                    offering=offering.serviceofferingid,
                    bundle=bundle,
                    project_id=cs_credentials.project,
                    vmname=vm_name,
                    affinity_group_id=cs_credentials.get_parameter_by_name(
                        'affinity_group_id'),
                )

                if not vm:
                    raise Exception(
                        "CloudStack could not create the virtualmachine")

                LOG.debug("New virtualmachine: %s" % vm)

                workflow_dict['vms_id'].append(vm['virtualmachine'][0]['id'])

                host = Host()
                host.address = vm['virtualmachine'][0]['nic'][0]['ipaddress']
                host.hostname = host.address
                host.cloud_portal_host = True
                host.save()
                LOG.info("Host created!")

                workflow_dict['hosts'].append(host)

                host_attr = HostAttr()
                host_attr.vm_id = vm['virtualmachine'][0]['id']
                host_attr.vm_user = vm_credentials.user
                host_attr.vm_password = vm_credentials.password
                host_attr.host = host
                host_attr.save()
                LOG.info("Host attrs custom attributes created!")

                if index in (0, 1):
                    instance = Instance()
                    instance.address = host.address
                    instance.port = 6379
                    instance.is_active = True
                    instance.hostname = host
                    instance.databaseinfra = workflow_dict['databaseinfra']
                    instance.instance_type = Instance.REDIS
                    instance.save()
                    LOG.info("Instance created!")

                    workflow_dict['instances'].append(instance)

                if workflow_dict['qt'] == 1:

                    LOG.info("Updating databaseinfra endpoint...")
#.........这里部分代码省略.........
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:103,代码来源:create_virtualmachines.py

示例3: do

# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import deploy_virtual_machine [as 别名]
    def do(self, workflow_dict):
        try:

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

            vm_credentials = get_credentials_for(
                environment=workflow_dict['target_environment'],
                credential_type=CredentialType.VM)

            cs_provider = CloudStackProvider(credentials=cs_credentials)

            target_offering = workflow_dict['target_offering']

            cs_plan_attrs = PlanAttr.objects.get(plan=workflow_dict['target_plan'])
            bundles = list(cs_plan_attrs.bundle.all())

            workflow_dict['target_hosts'] = []
            workflow_dict['target_instances'] = []

            for index, source_instance in enumerate(workflow_dict['source_instances']):

                source_host = workflow_dict['source_hosts'][index]
                vm_name = source_host.hostname.split('.')[0]

                if len(bundles) == 1:
                    bundle = bundles[0]
                else:
                    bundle = LastUsedBundle.get_next_bundle(plan=workflow_dict['target_plan'], bundle=bundles)

                if index == 2:
                    offering = cs_plan_attrs.get_weaker_offering()
                else:
                    offering = target_offering

                vm = cs_provider.deploy_virtual_machine(offering=offering.serviceofferingid,
                                                        bundle=bundle,
                                                        project_id=cs_credentials.project,
                                                        vmname=vm_name,
                                                        affinity_group_id=cs_credentials.get_parameter_by_name('affinity_group_id'),
                                                        )

                if not vm:
                    raise Exception("CloudStack could not create the virtualmachine")

                host = Host()
                host.address = vm['virtualmachine'][0]['nic'][0]['ipaddress']
                host.hostname = host.address
                host.save()
                workflow_dict['target_hosts'].append(host)

                source_host.future_host = host
                source_host.save()

                host_attr = HostAttr()
                host_attr.vm_id = vm['virtualmachine'][0]['id']
                host_attr.vm_user = vm_credentials.user
                host_attr.vm_password = vm_credentials.password
                host_attr.host = host
                host_attr.save()
                LOG.info("Host attrs custom attributes created!")

                instance = Instance()
                instance.address = host.address
                instance.dns = host.address
                instance.port = source_instance.port

                instance.is_active = source_instance.is_active
                instance.is_arbiter = source_instance.is_arbiter
                instance.instance_type = source_instance.instance_type
                instance.hostname = host

                instance.databaseinfra = workflow_dict['databaseinfra']
                instance.save()
                LOG.info("Instance created!")

                source_instance.future_instance = instance
                source_instance.save()

                workflow_dict['target_instances'].append(instance)

            return True
        except Exception:
            traceback = full_stack()

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

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


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