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


Python VIMor.get_attribute_type方法代码示例

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


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

示例1: handler_delete_snapshot

# 需要导入模块: from pysphere.vi_mor import VIMor [as 别名]
# 或者: from pysphere.vi_mor.VIMor import get_attribute_type [as 别名]
    def handler_delete_snapshot(self, task_id, parameters):
        snapshot_id = parameters['snapshot_id']
        vm_id = parameters['vm_id']
        snapshot_mor = VIMor(snapshot_id, MORTypes.VirtualMachineSnapshot)

        request = VI.RemoveSnapshot_TaskRequestMsg()

        mor_snap = request.new__this(snapshot_mor)
        mor_snap.set_attribute_type(snapshot_mor.get_attribute_type())
        request.set_element__this(mor_snap)
        request.set_element_removeChildren(False)

        TaskStatusHandler.update_task(task_id, 'Starting background task...')

        task = (yield self.application.executor.submit(self.server._proxy.RemoveSnapshot_Task, request))._returnval

        TaskStatusHandler.update_task(task_id, 'Background task started, waiting for completion...')

        vi_task = yield self.application.executor.submit(VITask, task, self.server)

        status = yield self.application.executor.submit(vi_task.wait_for_state, [vi_task.STATE_SUCCESS,
                                                                                 vi_task.STATE_ERROR])

        if status == vi_task.STATE_ERROR:
            raise VIException(vi_task.get_error_message(),
                              FaultTypes.TASK_ERROR)

        TaskStatusHandler.update_task(task_id, 'Snapshot deleted')
        TaskStatusHandler.delete_task(task_id)

        self.send_vm_update(vm_id)
开发者ID:orestv,项目名称:tornado_test,代码行数:33,代码来源:handlers.py

示例2: register_vm

# 需要导入模块: from pysphere.vi_mor import VIMor [as 别名]
# 或者: from pysphere.vi_mor.VIMor import get_attribute_type [as 别名]
    def register_vm(self, path, name=None, sync_run=True, folder=None,
                    template=False, resourcepool=None, host=None):
        """Adds an existing virtual machine to the folder.
        @path: a datastore path to the virtual machine.
            Example "[datastore] path/to/machine.vmx".
        @name: the name to be assigned to the virtual machine.
            If this parameter is not set, the displayName configuration
            parameter of the virtual machine is used.
        @sync_run: if True (default) waits for the task to finish, and returns
            a VIVirtualMachine instance with the new VM (raises an exception if
            the task didn't succeed). If @sync_run is set to False the task is
            started and a VITask instance is returned
        @folder_name: folder in which to register the virtual machine.
        @template: Flag to specify whether or not the virtual machine
            should be marked as a template.
        @resourcepool: MOR of the resource pool to which the virtual machine should
            be attached. If imported as a template, this parameter is not set.
        @host: The target host on which the virtual machine will run. This
            parameter must specify a host that is a member of the ComputeResource
            indirectly specified by the pool. For a stand-alone host or a cluster
            with DRS, the parameter can be omitted, and the system selects a default.
        """
        if not folder:
            folders = self._get_managed_objects(MORTypes.Folder)
            folder = [_mor for _mor, _name in folders.iteritems()
                          if _name == 'vm'][0]
        try:
            request = VI.RegisterVM_TaskRequestMsg()
            _this = request.new__this(folder)
            _this.set_attribute_type(folder.get_attribute_type())
            request.set_element__this(_this)
            request.set_element_path(path)
            if name:
                request.set_element_name(name)
            request.set_element_asTemplate(template)
            if resourcepool:
                pool = request.new_pool(resourcepool)
                pool.set_attribute_type(resourcepool.get_attribute_type())
                request.set_element_pool(pool)
            if host:
                if not VIMor.is_mor(host):
                    host = VIMor(host, MORTypes.HostSystem)
                    hs = request.new_host(host)
                    hs.set_attribute_type(host.get_attribute_type())
                    request.set_element_host(hs)

            task = self._proxy.RegisterVM_Task(request)._returnval
            vi_task = VITask(task, self)
            if sync_run:
                status = vi_task.wait_for_state([vi_task.STATE_SUCCESS,
                                                 vi_task.STATE_ERROR])
                if status == vi_task.STATE_ERROR:
                    raise VITaskException(vi_task.info.error)
                return

            return vi_task

        except (VI.ZSI.FaultException), e:
            raise VIApiException(e)
开发者ID:DiegoSanjuan,项目名称:pysphere-1,代码行数:61,代码来源:vi_server.py

示例3: handler_create_snapshot

# 需要导入模块: from pysphere.vi_mor import VIMor [as 别名]
# 或者: from pysphere.vi_mor.VIMor import get_attribute_type [as 别名]
    def handler_create_snapshot(self, task_id, parameters):
        vm_id = parameters['vm_id']
        snapshot_name = parameters['snapshot_name']
        snapshot_description = parameters['snapshot_description']

        vm_mor = VIMor(vm_id, MORTypes.VirtualMachine)

        request = VI.CreateSnapshot_TaskRequestMsg()
        mor_vm = request.new__this(vm_mor)
        mor_vm.set_attribute_type(vm_mor.get_attribute_type())
        request.set_element__this(mor_vm)
        request.set_element_name(snapshot_name)
        if snapshot_description:
            request.set_element_description(snapshot_description)
        request.set_element_memory(True)
        request.set_element_quiesce(False)

        vi_task = self.server._proxy.CreateSnapshot_Task(request)._returnval

        vi_task = VITask(vi_task, self.server)

        state = None
        while state not in (vi_task.STATE_SUCCESS, vi_task.STATE_ERROR):
            time.sleep(1)

            state = yield self.application.executor.submit(vi_task.get_state)
            progress = yield self.application.executor.submit(vi_task.get_progress)
            progress = progress or 100
            TaskStatusHandler.update_task(task_id, 'Creating snapshot %s, %d%%...' % (snapshot_name, progress))

        if state == vi_task.STATE_ERROR:
            error_message = yield self.application.executor.submit(vi_task.get_error_message)
            TaskStatusHandler.update_task(task_id, 'Error creating snapshot {0}: {1}'.format(
                snapshot_name, error_message))
            TaskStatusHandler.delete_task(task_id)
            raise Exception(error_message)

        TaskStatusHandler.update_task(task_id, 'Snapshot %s created!' % (snapshot_name,))
        TaskStatusHandler.delete_task(task_id)

        self.send_vm_update(vm_id)
开发者ID:orestv,项目名称:tornado_test,代码行数:43,代码来源:handlers.py

示例4: handler_revert_to_snapshot

# 需要导入模块: from pysphere.vi_mor import VIMor [as 别名]
# 或者: from pysphere.vi_mor.VIMor import get_attribute_type [as 别名]
    def handler_revert_to_snapshot(self, task_id, parameters):
        vm_id = parameters['vm_id']
        snapshot_id = parameters['snapshot_id']

        vm_mor = VIMor(vm_id, MORTypes.VirtualMachine)
        snapshot_mor = VIMor(snapshot_id, MORTypes.VirtualMachineSnapshot)

        vm_properties_future = self.application.executor.submit(self.server._get_object_properties, vm_mor, ['name', 'snapshot'])

        request = VI.RevertToSnapshot_TaskRequestMsg()

        mor_snap = request.new__this(snapshot_mor)
        mor_snap.set_attribute_type(snapshot_mor.get_attribute_type())
        request.set_element__this(mor_snap)

        vm_name = None
        snapshot_name = None
        vm_properties = yield vm_properties_future
        for prop in vm_properties.PropSet:
            if prop.Name == 'name':
                vm_name = prop.Val
            elif prop.Name == 'snapshot':
                snapshot_dict = ActionHandler.build_snapshot_dict(prop.Val.RootSnapshotList)
                snapshot_name = snapshot_dict[snapshot_mor].Name

        TaskStatusHandler.update_task(task_id, 'Reverting {0} to {1}...'.format(vm_name, snapshot_name))

        vi_task = self.server._proxy.RevertToSnapshot_Task(request)._returnval

        vi_task = VITask(vi_task, self.server)
        status = yield self.application.executor.submit(
            vi_task.wait_for_state, [vi_task.STATE_SUCCESS,
                                     vi_task.STATE_ERROR])
        if status == vi_task.STATE_ERROR:
            raise VIException(vi_task.get_error_message(),
                              FaultTypes.TASK_ERROR)

        TaskStatusHandler.update_task(task_id, 'Successfully reverted {0} to {1}'.format(vm_name, snapshot_name))
        TaskStatusHandler.delete_task(task_id)

        self.send_vm_update(vm_id)
开发者ID:orestv,项目名称:tornado_test,代码行数:43,代码来源:handlers.py

示例5: _retrieve_properties_traversal

# 需要导入模块: from pysphere.vi_mor import VIMor [as 别名]
# 或者: from pysphere.vi_mor.VIMor import get_attribute_type [as 别名]
    def _retrieve_properties_traversal(self, property_names=[],
                                      from_node=None, obj_type='ManagedEntity'):
        """Uses VI API's property collector to retrieve the properties defined
        in @property_names of Managed Objects of type @obj_type ('ManagedEntity'
        by default). Starts the search from the managed object reference
        @from_node (RootFolder by default). Returns the corresponding
        objectContent data object."""
        try:
            if not from_node:
                from_node = self._do_service_content.RootFolder

            elif isinstance(from_node, tuple) and len(from_node) == 2:
                from_node = VIMor(from_node[0], from_node[1])
            elif not VIMor.is_mor(from_node):
                raise VIException("from_node must be a MOR object or a "
                                  "(<str> mor_id, <str> mor_type) tuple",
                                  FaultTypes.PARAMETER_ERROR)

            request, request_call = self._retrieve_property_request()


            _this = request.new__this(
                                     self._do_service_content.PropertyCollector)
            _this.set_attribute_type(MORTypes.PropertyCollector)

            request.set_element__this(_this)
            do_PropertyFilterSpec_specSet = request.new_specSet()

            props_set = []
            do_PropertySpec_propSet =do_PropertyFilterSpec_specSet.new_propSet()
            do_PropertySpec_propSet.set_element_type(obj_type)
            do_PropertySpec_propSet.set_element_pathSet(property_names)
            props_set.append(do_PropertySpec_propSet)

            objects_set = []
            do_ObjectSpec_objSet = do_PropertyFilterSpec_specSet.new_objectSet()
            mor_obj = do_ObjectSpec_objSet.new_obj(from_node)
            mor_obj.set_attribute_type(from_node.get_attribute_type())
            do_ObjectSpec_objSet.set_element_obj(mor_obj)
            do_ObjectSpec_objSet.set_element_skip(False)

            #Recurse through all ResourcePools
            rp_to_rp = VI.ns0.TraversalSpec_Def('rpToRp').pyclass()
            rp_to_rp.set_element_name('rpToRp')
            rp_to_rp.set_element_type(MORTypes.ResourcePool)
            rp_to_rp.set_element_path('resourcePool')
            rp_to_rp.set_element_skip(False)
            rp_to_vm= VI.ns0.TraversalSpec_Def('rpToVm').pyclass()
            rp_to_vm.set_element_name('rpToVm')
            rp_to_vm.set_element_type(MORTypes.ResourcePool)
            rp_to_vm.set_element_path('vm')
            rp_to_vm.set_element_skip(False)

            spec_array_resource_pool = [do_ObjectSpec_objSet.new_selectSet(),
                                        do_ObjectSpec_objSet.new_selectSet()]
            spec_array_resource_pool[0].set_element_name('rpToRp')
            spec_array_resource_pool[1].set_element_name('rpToVm')

            rp_to_rp.set_element_selectSet(spec_array_resource_pool)

            #Traversal through resource pool branch
            cr_to_rp = VI.ns0.TraversalSpec_Def('crToRp').pyclass()
            cr_to_rp.set_element_name('crToRp')
            cr_to_rp.set_element_type(MORTypes.ComputeResource)
            cr_to_rp.set_element_path('resourcePool')
            cr_to_rp.set_element_skip(False)
            spec_array_computer_resource =[do_ObjectSpec_objSet.new_selectSet(),
                                           do_ObjectSpec_objSet.new_selectSet()]
            spec_array_computer_resource[0].set_element_name('rpToRp');
            spec_array_computer_resource[1].set_element_name('rpToVm');
            cr_to_rp.set_element_selectSet(spec_array_computer_resource)

            #Traversal through host branch
            cr_to_h = VI.ns0.TraversalSpec_Def('crToH').pyclass()
            cr_to_h.set_element_name('crToH')
            cr_to_h.set_element_type(MORTypes.ComputeResource)
            cr_to_h.set_element_path('host')
            cr_to_h.set_element_skip(False)

            #Traversal through hostFolder branch
            dc_to_hf = VI.ns0.TraversalSpec_Def('dcToHf').pyclass()
            dc_to_hf.set_element_name('dcToHf')
            dc_to_hf.set_element_type(MORTypes.Datacenter)
            dc_to_hf.set_element_path('hostFolder')
            dc_to_hf.set_element_skip(False)
            spec_array_datacenter_host = [do_ObjectSpec_objSet.new_selectSet()]
            spec_array_datacenter_host[0].set_element_name('visitFolders')
            dc_to_hf.set_element_selectSet(spec_array_datacenter_host)

            #Traversal through vmFolder branch
            dc_to_vmf = VI.ns0.TraversalSpec_Def('dcToVmf').pyclass()
            dc_to_vmf.set_element_name('dcToVmf')
            dc_to_vmf.set_element_type(MORTypes.Datacenter)
            dc_to_vmf.set_element_path('vmFolder')
            dc_to_vmf.set_element_skip(False)
            spec_array_datacenter_vm = [do_ObjectSpec_objSet.new_selectSet()]
            spec_array_datacenter_vm[0].set_element_name('visitFolders')
            dc_to_vmf.set_element_selectSet(spec_array_datacenter_vm)

            #Traversal through datastore branch
#.........这里部分代码省略.........
开发者ID:asafvala,项目名称:pysphere,代码行数:103,代码来源:vi_server.py


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