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


Python VITask.get_state方法代码示例

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


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

示例1: create_vm

# 需要导入模块: from pysphere.vi_task import VITask [as 别名]
# 或者: from pysphere.vi_task.VITask import get_state [as 别名]

#.........这里部分代码省略.........
        if not ds:
            raise CreatorException("Datastore is not available")
        volume_name = "[%s]" % ds_name

        # add parameters to the create vm task
        create_vm_request = VI.CreateVM_TaskRequestMsg()
        config = create_vm_request.new_config()
        vmfiles = config.new_files()
        vmfiles.set_element_vmPathName(volume_name)
        config.set_element_files(vmfiles)
        config.set_element_name(vm_name)
        config.set_element_annotation(description)
        config.set_element_memoryMB(memory_size)
        config.set_element_numCPUs(cpu_count)
        config.set_element_guestId(guestosid)
        devices = []

        # add a scsi controller
        disk_ctrl_key = 1
        scsi_ctrl_spec = config.new_deviceChange()
        scsi_ctrl_spec.set_element_operation("add")
        scsi_ctrl = VI.ns0.VirtualLsiLogicController_Def("scsi_ctrl").pyclass()
        scsi_ctrl.set_element_busNumber(0)
        scsi_ctrl.set_element_key(disk_ctrl_key)
        scsi_ctrl.set_element_sharedBus("noSharing")
        scsi_ctrl_spec.set_element_device(scsi_ctrl)
        devices.append(scsi_ctrl_spec)

        # find ide controller
        if iso:
            ide_ctlr = None
            for dev in defaul_devs:
                if dev.typecode.type[1] == "VirtualIDEController":
                    ide_ctlr = dev
                    # add a cdrom based on a physical device
            if ide_ctlr:
                cd_spec = config.new_deviceChange()
                cd_spec.set_element_operation("add")
                cd_ctrl = VI.ns0.VirtualCdrom_Def("cd_ctrl").pyclass()
                cd_device_backing = VI.ns0.VirtualCdromIsoBackingInfo_Def("cd_device_backing").pyclass()
                ds_ref = cd_device_backing.new_datastore(ds)
                ds_ref.set_attribute_type(ds.get_attribute_type())
                cd_device_backing.set_element_datastore(ds_ref)
                cd_device_backing.set_element_fileName("%s %s" % (volume_name, iso))
                cd_ctrl.set_element_backing(cd_device_backing)
                cd_ctrl.set_element_key(20)
                cd_ctrl.set_element_controllerKey(ide_ctlr.get_element_key())
                cd_ctrl.set_element_unitNumber(0)
                cd_spec.set_element_device(cd_ctrl)
                devices.append(cd_spec)

        # create a new disk - file based - for the vm
        if disk_size != 0:
            disk_spec = config.new_deviceChange()
            disk_spec.set_element_fileOperation("create")
            disk_spec.set_element_operation("add")
            disk_ctlr = VI.ns0.VirtualDisk_Def("disk_ctlr").pyclass()
            disk_backing = VI.ns0.VirtualDiskFlatVer2BackingInfo_Def("disk_backing").pyclass()
            disk_backing.set_element_fileName(volume_name)
            disk_backing.set_element_diskMode("persistent")
            disk_ctlr.set_element_key(0)
            disk_ctlr.set_element_controllerKey(disk_ctrl_key)
            disk_ctlr.set_element_unitNumber(0)
            disk_ctlr.set_element_backing(disk_backing)
            disk_ctlr.set_element_capacityInKB(disk_size)
            disk_spec.set_element_device(disk_ctlr)
            devices.append(disk_spec)

        # add a NIC. the network Name must be set as the device name to create the NIC.
        for network_name in networks:
            nic_spec = config.new_deviceChange()
            nic_spec.set_element_operation("add")
            nic_ctlr = VI.ns0.VirtualPCNet32_Def("nic_ctlr").pyclass()
            nic_backing = VI.ns0.VirtualEthernetCardNetworkBackingInfo_Def("nic_backing").pyclass()
            nic_backing.set_element_deviceName(network_name)
            nic_ctlr.set_element_addressType("generated")
            nic_ctlr.set_element_backing(nic_backing)
            nic_ctlr.set_element_key(4)
            nic_spec.set_element_device(nic_ctlr)
            devices.append(nic_spec)

        config.set_element_deviceChange(devices)
        create_vm_request.set_element_config(config)
        folder_mor = create_vm_request.new__this(vmfmor)
        folder_mor.set_attribute_type(vmfmor.get_attribute_type())
        create_vm_request.set_element__this(folder_mor)
        rp_mor = create_vm_request.new_pool(rpmor)
        rp_mor.set_attribute_type(rpmor.get_attribute_type())
        create_vm_request.set_element_pool(rp_mor)
        host_mor = create_vm_request.new_host(hostmor)
        host_mor.set_attribute_type(hostmor.get_attribute_type())
        create_vm_request.set_element_host(host_mor)

        # CREATE THE VM - add option "wait"
        taskmor = self.esx_server._proxy.CreateVM_Task(create_vm_request)._returnval
        task = VITask(taskmor, self.esx_server)
        task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])
        if task.get_state() == task.STATE_ERROR:
            self._disconnect_from_esx()
            raise CreatorException("Error creating vm: %s" % task.get_error_message())
开发者ID:rkhozinov,项目名称:deployment_system,代码行数:104,代码来源:hatchery.py

示例2: VITask

# 需要导入模块: from pysphere.vi_task import VITask [as 别名]
# 或者: from pysphere.vi_task.VITask import get_state [as 别名]
    create_vm_request.set_element_config(config)
    folder_mor = create_vm_request.new__this(vmfmor)
    folder_mor.set_attribute_type(vmfmor.get_attribute_type())
    create_vm_request.set_element__this(folder_mor)
    rp_mor = create_vm_request.new_pool(rpmor)
    rp_mor.set_attribute_type(rpmor.get_attribute_type())
    create_vm_request.set_element_pool(rp_mor)
    host_mor = create_vm_request.new_host(hostmor)
    host_mor.set_attribute_type(hostmor.get_attribute_type())
    create_vm_request.set_element_host(host_mor)

    # CREATE THE VM
    taskmor = vsphere_client._proxy.CreateVM_Task(create_vm_request)._returnval
    task = VITask(taskmor, vsphere_client)
    task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])
    if task.get_state() == task.STATE_ERROR:
        vsphere_client.disconnect()
        module.fail_json(msg="Error creating vm: %s" %
                         task.get_error_message())
    else:
        # We always need to get the vm because we are going to gather facts
        vm = vsphere_client.get_vm_by_name(guest)

        # VM was created. If there is any extra config options specified, set
        # them here , disconnect from vcenter, then exit.
        if vm_extra_config:
            vm.set_extra_config(vm_extra_config)

        # Power on the VM if it was requested
        power_state(vm, state, True)
开发者ID:conlini,项目名称:frozen-ansible,代码行数:32,代码来源:vsphere_guest.py

示例3: create_vm

# 需要导入模块: from pysphere.vi_task import VITask [as 别名]
# 或者: from pysphere.vi_task.VITask import get_state [as 别名]

#.........这里部分代码省略.........
    scsi_ctrl_spec = config.new_deviceChange()
    scsi_ctrl_spec.set_element_operation('add')
    scsi_ctrl = VI.ns0.VirtualLsiLogicController_Def("scsi_ctrl").pyclass()
    scsi_ctrl.set_element_busNumber(0)
    scsi_ctrl.set_element_key(disk_ctrl_key)
    scsi_ctrl.set_element_sharedBus("noSharing")

    scsi_ctrl_spec.set_element_device(scsi_ctrl)
    devices.append(scsi_ctrl_spec)

     # find ide controller
    ide_ctlr = None
    for dev in defaul_devs:
        if dev.typecode.type[1] == "VirtualIDEController":
            ide_ctlr = dev

     # add a cdrom based on a physical device
    if ide_ctlr:
        cd_spec = config.new_deviceChange()
        cd_spec.set_element_operation('add')
        cd_ctrl = VI.ns0.VirtualCdrom_Def("cd_ctrl").pyclass()
        cd_device_backing = VI.ns0.VirtualCdromIsoBackingInfo_Def("cd_device_backing").pyclass()
        ds_ref = cd_device_backing.new_datastore(ds)
        ds_ref.set_attribute_type(ds.get_attribute_type())
        cd_device_backing.set_element_datastore(ds_ref)
        cd_device_backing.set_element_fileName("%s %s" % (volume_name,
                                                          cd_iso_location))
        cd_ctrl.set_element_backing(cd_device_backing)
        cd_ctrl.set_element_key(20)
        cd_ctrl.set_element_controllerKey(ide_ctlr.get_element_key())
        cd_ctrl.set_element_unitNumber(0)
        cd_spec.set_element_device(cd_ctrl)
        devices.append(cd_spec)

     # create a new disk - file based - for the vm
    disk_spec = config.new_deviceChange()
    disk_spec.set_element_fileOperation("create")
    disk_spec.set_element_operation("add")
    disk_ctlr = VI.ns0.VirtualDisk_Def("disk_ctlr").pyclass()
    disk_backing = VI.ns0.VirtualDiskFlatVer2BackingInfo_Def("disk_backing").pyclass()
    disk_backing.set_element_fileName(volume_name)
    disk_backing.set_element_diskMode("persistent")
    disk_backing.ThinProvisioned = True
    disk_ctlr.set_element_key(0)
    disk_ctlr.set_element_controllerKey(disk_ctrl_key)
    disk_ctlr.set_element_unitNumber(0)
    disk_ctlr.set_element_backing(disk_backing)
    disk_ctlr.set_element_capacityInKB(disksize)
    disk_spec.set_element_device(disk_ctlr)
    devices.append(disk_spec)

     # add a NIC. the network Name must be set as the device name to create the NIC.
    nic_spec = config.new_deviceChange()
    if network_name:
        nic_spec.set_element_operation("add")
        nic_ctlr = VI.ns0.VirtualPCNet32_Def("nic_ctlr").pyclass()
        nic_backing = VI.ns0.VirtualEthernetCardNetworkBackingInfo_Def("nic_backing").pyclass()
        nic_backing.set_element_deviceName(network_name)
        nic_ctlr.set_element_addressType("generated")
        nic_ctlr.set_element_backing(nic_backing)
        nic_ctlr.set_element_key(4)
        nic_spec.set_element_device(nic_ctlr)
        devices.append(nic_spec)

    config.set_element_deviceChange(devices)
    create_vm_request.set_element_config(config)
    folder_mor = create_vm_request.new__this(vmfmor)
    folder_mor.set_attribute_type(vmfmor.get_attribute_type())
    create_vm_request.set_element__this(folder_mor)
    rp_mor = create_vm_request.new_pool(rpmor)
    rp_mor.set_attribute_type(rpmor.get_attribute_type())
    create_vm_request.set_element_pool(rp_mor)
    host_mor = create_vm_request.new_host(hostmor)
    host_mor.set_attribute_type(hostmor.get_attribute_type())
    create_vm_request.set_element_host(host_mor)

    # CREATE THE VM
    taskmor = s._proxy.CreateVM_Task(create_vm_request)._returnval
    task = VITask(taskmor, s)
    task.wait_for_state([task.STATE_SUCCESS, task.STATE_ERROR])

    if task.get_state() == task.STATE_ERROR:
        raise Exception("Error creating vm: %s" %
                        task.get_error_message())

    # Here you should power your VM (refer to the pysphere documentation)
    # So it boots from the specified ISO location
    try:
        new_vm = s.get_vm_by_name(opts.name)
        connect_vm_cdroms(new_vm, s)
        try:
            new_vm.power_on()
        except Exception as e:
            print "Failed to power-on the new VM using:", opts.name
            print "Exception:", str(e)
    except Exception as e:
        print "Failed to locate the new VM using:", opts.name
        print "Exception:", str(e)
    # disconnect from the server
    s.disconnect()
开发者ID:settipalli,项目名称:vm-mgmt-lib,代码行数:104,代码来源:vm-mgmt-create.py


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