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


Python VApp.add_vms方法代码示例

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


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

示例1: create_from_vapp

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
    def create_from_vapp(self, request):
        logging.info("__INIT__create[VappVm] source_catalog_name[%s]",
                     request.source_vapp)
        res = vapp_vm_pb2.CreateVappVmResult()
        res.created = False
        source_vapp_resource = self.get_vapp_resource(
            request.target_vdc, vapp_name=request.source_vapp)
        target_vapp_resource = self.get_vapp_resource(
            request.target_vdc, vapp_name=request.target_vapp)

        specs = [{
            'vapp': source_vapp_resource,
            'source_vm_name': request.source_vm_name,
            'target_vm_name': request.target_vm_name,
            'hostname': request.hostname,
            'password': request.password,
            'password_auto': request.password_auto,
            'password_reset': request.password_reset,
            'cust_script': request.cust_script,
            'network': request.network,
            # 'storage_profile': request.storage_profile
        }]

        try:
            vapp = VApp(self.client, resource=target_vapp_resource)
            create_vapp_vm_resp = vapp.add_vms(
                specs,
                power_on=request.power_on,
                all_eulas_accepted=request.all_eulas_accepted)
            task_monitor = self.client.get_task_monitor()
            task = task_monitor.wait_for_status(
                task=create_vapp_vm_resp,
                timeout=60,
                poll_frequency=2,
                fail_on_statuses=None,
                expected_target_statuses=[
                    TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                    TaskStatus.CANCELED
                ],
                callback=None)

            st = task.get('status')
            if st != TaskStatus.SUCCESS.value:
                raise errors.VappVmCreateError(
                    etree.tostring(task, pretty_print=True))

            message = 'status : {0} '.format(st)
            logging.info(message)
            res.created = True

        except Exception as e:
            errmsg = '''__ERROR_create[VappVm] failed for vm {0}. __ErrorMessage__ {1}'''
            logging.warn(errmsg.format(request.target_vm_name, str(e)))
            self.context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            self.context.set_details(errmsg)

            return res

        logging.info("__DONE__create[VappVm]")
        return res
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:62,代码来源:vapp_vm.py

示例2: test_0002_add_vm

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
 def test_0002_add_vm(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, href=vdc_resource.get('href'))
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     assert vapp_resource.get('name') == self.config['vcd']['vapp']
     vapp = VApp(self.client, resource=vapp_resource)
     catalog_item = org.get_catalog_item(self.config['vcd']['catalog'],
                                         self.config['vcd']['template'])
     source_vapp_resource = self.client.get_resource(
         catalog_item.Entity.get('href'))
     spec = {'source_vm_name': self.config['vcd']['vm'],
             'vapp': source_vapp_resource}
     spec['target_vm_name'] = self.config['vcd']['hostname']
     spec['hostname'] = self.config['vcd']['hostname']
     spec['network'] = self.config['vcd']['network']
     spec['ip_allocation_mode'] = self.config['vcd']['ip_allocation_mode']
     spec['storage_profile'] = vdc.get_storage_profile(
         self.config['vcd']['storage_profile'])
     vms = [spec]
     result = vapp.add_vms(vms)
     task = self.client.get_task_monitor().wait_for_status(
                         task=result,
                         timeout=60,
                         poll_frequency=2,
                         fail_on_statuses=None,
                         expected_target_statuses=[
                             TaskStatus.SUCCESS,
                             TaskStatus.ABORTED,
                             TaskStatus.ERROR,
                             TaskStatus.CANCELED],
                         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
开发者ID:rdbwebster,项目名称:pyvcloud,代码行数:37,代码来源:vcd_vapp_vm.py

示例3: copy_to

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
    def copy_to(self, source_vapp_name, target_vapp_name, target_vm_name):
        """Copy VM from one vApp to another.

        :param: str source vApp name
        :param: str target vApp name
        :param: str target VM name

        :return: an object containing EntityType.TASK XML data which represents
                    the asynchronous task that is copying VM

        :rtype: lxml.objectify.ObjectifiedElement
        """
        from pyvcloud.vcd.vapp import VApp
        vm_resource = self.get_resource()
        resource_type = ResourceType.VAPP.value
        if self.is_powered_off(vm_resource):
            records1 = self.___validate_vapp_records(
                vapp_name=source_vapp_name, resource_type=resource_type)

            source_vapp_href = records1[0].get('href')

            records2 = self.___validate_vapp_records(
                vapp_name=target_vapp_name, resource_type=resource_type)

            target_vapp_href = records2[0].get('href')

            source_vapp = VApp(self.client, href=source_vapp_href)
            target_vapp = VApp(self.client, href=target_vapp_href)
            target_vapp.reload()
            spec = {
                'vapp': source_vapp.get_resource(),
                'source_vm_name': self.get_resource().get('name'),
                'target_vm_name': target_vm_name
            }
            return target_vapp.add_vms([spec],
                                       deploy=False,
                                       power_on=False,
                                       all_eulas_accepted=True
                                       )
        else:
            raise InvalidStateException("VM Must be powered off.")
开发者ID:vmware,项目名称:pyvcloud,代码行数:43,代码来源:vm.py

示例4: add_vm

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
def add_vm(ctx, name, source_vapp, source_vm, catalog, target_vm, hostname,
           network, ip_allocation_mode, storage_profile, password_auto,
           accept_all_eulas):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        source_vapp_resource = None
        if catalog is None:
            source_vapp_resource = vdc.get_vapp(source_vapp)
        else:
            catalog_item = org.get_catalog_item(catalog, source_vapp)
            source_vapp_resource = client.get_resource(
                catalog_item.Entity.get('href'))
        assert source_vapp_resource is not None
        vapp_resource = vdc.get_vapp(name)
        vapp = VApp(client, resource=vapp_resource)
        spec = {'source_vm_name': source_vm, 'vapp': source_vapp_resource}
        if target_vm is not None:
            spec['target_vm_name'] = target_vm
        if hostname is not None:
            spec['hostname'] = hostname
        if network is not None:
            spec['network'] = network
            spec['ip_allocation_mode'] = ip_allocation_mode
        if storage_profile is not None:
            spec['storage_profile'] = vdc.get_storage_profile(storage_profile)
        if password_auto is not None:
            spec['password_auto'] = password_auto
        task = vapp.add_vms([spec], all_eulas_accepted=accept_all_eulas)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
开发者ID:vmware,项目名称:vca-cli,代码行数:38,代码来源:vapp.py

示例5: create_from_catalog

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
    def create_from_catalog(self, request):
        logging.info("__INIT__create[VappVm] source_catalog_name[%s]",
                     request.source_catalog_name)
        res = vapp_vm_pb2.CreateVappVmResult()
        res.created = False

        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)

        try:
            vdc_resource = org.get_vdc(request.target_vdc)
            vdc = VDC(
                self.client, name=request.target_vdc, resource=vdc_resource)

            vapp_resource = vdc.get_vapp(request.target_vapp)
            vapp = VApp(
                self.client, name=request.target_vapp, resource=vapp_resource)

            catalog_item = org.get_catalog_item(request.source_catalog_name,
                                                request.source_template_name)
            source_vapp_resource = self.client.get_resource(
                catalog_item.Entity.get('href'))
            specs = [{
                'source_vm_name': request.source_vm_name,
                'vapp': source_vapp_resource,
                'target_vm_name': request.target_vm_name,
                'hostname': request.hostname,
                'network': request.network,
                'ip_allocation_mode': request.ip_allocation_mode,
                # 'storage_profile': request.storage_profile
            }]
            create_vapp_vm_resp = vapp.add_vms(
                specs,
                power_on=request.power_on,
                all_eulas_accepted=request.all_eulas_accepted)
            task_monitor = self.client.get_task_monitor()
            task = task_monitor.wait_for_status(
                task=create_vapp_vm_resp,
                timeout=60,
                poll_frequency=2,
                fail_on_statuses=None,
                expected_target_statuses=[
                    TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                    TaskStatus.CANCELED
                ],
                callback=None)

            st = task.get('status')
            if st != TaskStatus.SUCCESS.value:
                raise errors.VappVmCreateError(
                    etree.tostring(task, pretty_print=True))

            message = 'status : {0} '.format(st)
            logging.info(message)
            res.created = True

        except Exception as e:
            errmsg = '''__ERROR_create[VappVm] failed for vm {0}. __ErrorMessage__ {1}'''
            logging.warn(errmsg.format(request.target_vm_name, str(e)))
            self.context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            self.context.set_details(errmsg)

            return res

        logging.info("__DONE__create[VappVm]")
        return res
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:68,代码来源:vapp_vm.py

示例6: create

# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import add_vms [as 别名]
def create(client):
    print("=============== __LOG__Create_VDC  =======================\n\n")

    vdc_name = "ACME_PAYG"
    vapp_name = "test2"

    org_resource = client.get_org()
    org = Org(client, resource=org_resource)
    print("Org name: ", org.get_name())
    print("Vdc name: ", vdc_name)

    try:
        vdc_resource = org.get_vdc(vdc_name)
        vdc = VDC(client, name=vdc_name, resource=vdc_resource)

        vapp_resource = vdc.get_vapp(vapp_name)
        vapp = VApp(client, name=vapp_name, resource=vapp_resource)
        print("vapp : ", vapp)

        catalog_item = org.get_catalog_item('ACME', 'tinyova')

        source_vapp_resource = client.get_resource(
            catalog_item.Entity.get('href'))

        print("source_vapp_resource: ", source_vapp_resource)

        spec = {
            'source_vm_name': 'Tiny Linux template',
            'vapp': source_vapp_resource
        }

        storage_profiles = [{
            'name': 'Performance',
            'enabled': True,
            'units': 'MB',
            'limit': 0,
            'default': True
        }]

        spec['target_vm_name'] = 'ubuntu_pcp_11'
        spec['hostname'] = 'ubuntu'
        spec['network'] = 'global'
        spec['ip_allocation_mode'] = 'dhcp'
        #spec['storage_profile'] = storage_profiles

        vms = [spec]
        result = vapp.add_vms(vms)

        print("result: ", result)
        #task = client.get_task_monitor().wait_for_status(
        #                    task=result,
        #                    timeout=60,
        #                    poll_frequency=2,
        #                    fail_on_statuses=None,
        #                    expected_target_statuses=[
        #                        TaskStatus.SUCCESS,
        #                        TaskStatus.ABORTED,
        #                        TaskStatus.ERROR,
        #                        TaskStatus.CANCELED],
        #                    callback=None)

        #st = task.get('status')
        #if st == TaskStatus.SUCCESS.value:
        #    message = 'status : {0} '.format(st)
        #    logging.info(message)
        #else:
        #    print("st : ", st)
        #    raise Exception(task)
        print("=============================================\n\n")
        return True
    except Exception as e:
        error_message = '__ERROR_ [create_vdc] failed for vdc {0} '.format(
            vdc_name)
        logging.warn(error_message, e)
        return False
开发者ID:gefeng24,项目名称:terraform-provider-vcloud-director,代码行数:77,代码来源:test_vapp_vm.py


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