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


Python vim.ResourcePool方法代码示例

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


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

示例1: get_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_resource_pool(self, cluster, pool_name):
        """
        Find a resource pool given a pool name for desired cluster
        """
        pool_obj = None

        # get a list of all resource pools in this cluster
        cluster_pools_list = cluster.resourcePool.resourcePool

        # get list of all resource pools with a given text name
        pool_selections = self.get_obj(
            [vim.ResourcePool],
            pool_name,
            return_all=True
        )

        # get the first pool that exists in a given cluster
        if pool_selections:
            for p in pool_selections:
                if p in cluster_pools_list:
                    pool_obj = p
                    break

        return pool_obj 
开发者ID:snobear,项目名称:ezmomi,代码行数:26,代码来源:ezmomi.py

示例2: create_dummy_vm

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def create_dummy_vm(vm_name, service_instance, vm_folder, resource_pool,
                    datastore):
    """Creates a dummy VirtualMachine with 1 vCpu, 128MB of RAM.

    :param name: String Name for the VirtualMachine
    :param service_instance: ServiceInstance connection
    :param vm_folder: Folder to place the VirtualMachine in
    :param resource_pool: ResourcePool to place the VirtualMachine in
    :param datastore: DataStrore to place the VirtualMachine on
    """
    datastore_path = '[' + datastore + '] ' + vm_name

    # bare minimum VM shell, no disks. Feel free to edit
    vmx_file = vim.vm.FileInfo(logDirectory=None,
                               snapshotDirectory=None,
                               suspendDirectory=None,
                               vmPathName=datastore_path)

    config = vim.vm.ConfigSpec(name=vm_name, memoryMB=128, numCPUs=1,
                               files=vmx_file, guestId='dosGuest',
                               version='vmx-07')

    print("Creating VM {}...".format(vm_name))
    task = vm_folder.CreateVM_Task(config=config, pool=resource_pool)
    tasks.wait_for_tasks(service_instance, [task]) 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:27,代码来源:create_random_marvel_vms.py

示例3: get_largest_free_rp

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_largest_free_rp(si, dc):
    """
    Get the resource pool with the largest unreserved memory for VMs.
    """
    viewManager = si.content.viewManager
    containerView = viewManager.CreateContainerView(dc, [vim.ResourcePool],
                                                    True)
    largestRp = None
    unreservedForVm = 0
    try:
        for rp in containerView.view:
            if rp.runtime.memory.unreservedForVm > unreservedForVm:
                largestRp = rp
                unreservedForVm = rp.runtime.memory.unreservedForVm
    finally:
        containerView.Destroy()
    if largestRp is None:
        raise Exception("Failed to find a resource pool in dc %s" % dc.name)
    return largestRp 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:21,代码来源:deploy_ova.py

示例4: get_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_pool(self, name, dc, cluster):
        """
        Gets the Resource pool

        Args:
            name (str): Resource pool name
            dc (str): Datacenter name
            cluster (str): Cluster name

        Returns:
            vim.ResourcePool: Resource pool instance

        """
        cluster_obj = self.get_cluster(cluster, dc)
        for rp in cluster_obj.resourcePool.resourcePool:
            if rp.name == name:
                return rp 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:19,代码来源:vsphere.py

示例5: get_all_vms_in_dc

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_all_vms_in_dc(self, dc):
        """
        Fetches all VMs in Datacenter

        Args:
            dc (str): Datacenter name

        Returns:
            list: List of VMs instance in a Datacenter

        """
        vms = []
        dc = self.get_dc(dc)
        vmfolder = dc.vmFolder
        vmlist = vmfolder.childEntity
        for each in vmlist:
            if hasattr(each, 'childEntity'):
                for vm in each.childEntity:
                    vms.append(vm)
            else:
                # Direct VMs created in cluster
                # This are the VMs created directly on cluster
                # without ResourcePool
                vms.append(each)
        return vms 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:27,代码来源:vsphere.py

示例6: find_resource_pool_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def find_resource_pool_by_name(content, resource_pool_name):
    return find_object_by_name(content, resource_pool_name, [vim.ResourcePool]) 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:4,代码来源:vmware.py

示例7: get_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_resource_pool(self, cluster=None, host=None, resource_pool=None):
        """ Get a resource pool, filter on cluster, esxi_hostname or resource_pool if given """

        cluster_name = cluster or self.params.get('cluster', None)
        host_name = host or self.params.get('esxi_hostname', None)
        resource_pool_name = resource_pool or self.params.get('resource_pool', None)

        # get the datacenter object
        datacenter = find_obj(self.content, [vim.Datacenter], self.params['datacenter'])
        if not datacenter:
            self.module.fail_json(msg='Unable to find datacenter "%s"' % self.params['datacenter'])

        # if cluster is given, get the cluster object
        if cluster_name:
            cluster = find_obj(self.content, [vim.ComputeResource], cluster_name, folder=datacenter)
            if not cluster:
                self.module.fail_json(msg='Unable to find cluster "%s"' % cluster_name)
        # if host is given, get the cluster object using the host
        elif host_name:
            host = find_obj(self.content, [vim.HostSystem], host_name, folder=datacenter)
            if not host:
                self.module.fail_json(msg='Unable to find host "%s"' % host_name)
            cluster = host.parent
        else:
            cluster = None

        # get resource pools limiting search to cluster or datacenter
        resource_pool = find_obj(self.content, [vim.ResourcePool], resource_pool_name, folder=cluster or datacenter)
        if not resource_pool:
            if resource_pool_name:
                self.module.fail_json(msg='Unable to find resource_pool "%s"' % resource_pool_name)
            else:
                self.module.fail_json(msg='Unable to find resource pool, need esxi_hostname, resource_pool, or cluster')
        return resource_pool 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:36,代码来源:vmware_guest2.py

示例8: _get_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def _get_resource_pool(self, resource_pool_name=None):
        """ Returns a resource pool managed object for a specified name.

        Args:
            resource_pool_name (string): The name of the resource pool. If None, first one will be
        picked.
        Returns:
             pyVmomi.vim.ResourcePool: The managed object of the resource pool.
        """
        if resource_pool_name is not None:
            return self.system.get_obj(vim.ResourcePool, resource_pool_name)
        elif self.system.default_resource_pool is not None:
            return self.system.get_obj(vim.ResourcePool, self.system.default_resource_pool)
        else:
            return self.system.get_obj_list(vim.ResourcePool)[0] 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:17,代码来源:virtualcenter.py

示例9: _set_vm_relocate_spec

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def _set_vm_relocate_spec(self, resource_pool, host, sparse, progress_callback,
                              deploy_on_ds_cluster):
        """Set properties for Virtual Machine Relocate Operation specification """

        vm_reloc_spec = vim.VirtualMachineRelocateSpec()

        # Set resource pool
        if isinstance(resource_pool, vim.ResourcePool):
            vm_reloc_spec.pool = resource_pool
        elif isinstance(resource_pool, vim.ClusterComputeResource):
            vm_reloc_spec.pool = resource_pool.resourcePool
        else:
            if deploy_on_ds_cluster:
                vm_reloc_spec.pool = self._get_cluster_compute_resource(resource_pool).resourcePool
            else:
                vm_reloc_spec.pool = self._get_resource_pool(resource_pool)
        progress_callback("Picked resource pool `{}`".format(vm_reloc_spec.pool.name))

        # Target Host for the VM, this could be none
        vm_reloc_spec.host = (host if isinstance(host, vim.HostSystem)
                              else self.system.get_obj(vim.HostSystem, host))
        if sparse:
            vm_reloc_spec.transform = vim.VirtualMachineRelocateTransformation().sparse
            progress_callback("Transformation has been set to sparse")
        else:
            vm_reloc_spec.transform = vim.VirtualMachineRelocateTransformation().flat
            progress_callback("Transformation has been set to flat")

        return vm_reloc_spec 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:31,代码来源:virtualcenter.py

示例10: list_resource_pools

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def list_resource_pools(self):
        return [str(h.name) for h in self.get_obj_list(vim.ResourcePool)] 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:4,代码来源:virtualcenter.py

示例11: get_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_resource_pool(si, name, folder=None):
    """
    Find a resource pool by its name and return it
    """
    return _get_obj(si.RetrieveContent(), [vim.ResourcePool], name,
                    folder) 
开发者ID:avinetworks,项目名称:devops,代码行数:8,代码来源:vmutils.py

示例12: __init__

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def __init__(self, vm=None, name=None, folder=None, resource_pool=None,
                 datastore=None, host=None):
        """
        :param vm: VM instance to use instead of calling :meth:`create`
        :type vm: vim.VirtualMachine
        :param str name: Name of the VM
        :param folder: Folder in inventory to create the VM in
        :type folder: vim.Folder
        :param resource_pool: Resource pool to use for the VM
        :type resource_pool: vim.ResourcePool
        :param datastore: Datastore the VM is stored on
        :type datastore: vim.Datastore
        :param host: Host the VM runs on
        :type host: vim.HostSystem
        """
        self._log = logging.getLogger('VM')
        if vm is not None:
            self._vm = vm
            self.name = vm.name
            self.folder = vm.parent
            self.resource_pool = vm.resourcePool
            self.datastore = vm.datastore[0]
            self.host = vm.summary.runtime.host
            self.network = vm.network
            self.runtime = vm.runtime
            self.summary = vm.summary
        else:
            self._vm = None
            self.name = name
            self.folder = folder  # vim.Folder that will contain the VM
            self.resource_pool = resource_pool  # vim.ResourcePool to use VM
            self.datastore = datastore  # vim.Datastore object to store VM on
            self.host = host  # vim.HostSystem 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:35,代码来源:vm.py

示例13: get_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_pool(self, pool_name=None):
        """
        Finds and returns the named vim.ResourcePool.

        :param str pool_name: Name of the resource pool
        [default: first pool found in datacenter]
        :return: The resource pool found
        :rtype: vim.ResourcePool or None
        """
        return self.get_item(vim.ResourcePool, pool_name) 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:12,代码来源:vsphere_class.py

示例14: find_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def find_resource_pool(vc, logger, name):
    """
    Find a resource pool by its name and return it
    """

    content = vc.content
    obj_view = content.viewManager.CreateContainerView(content.rootFolder, [vim.ResourcePool], True)
    rp_list = obj_view.view

    for rp in rp_list:
        logger.debug('Checking resource pool %s' % rp.name)
        if rp.name == name:
            logger.debug('Found resource pool %s' % rp.name)
            return rp
    return None 
开发者ID:nuagenetworks,项目名称:vspk-examples,代码行数:17,代码来源:deploy_vsphere_template_with_nuage.py

示例15: get_rp

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ResourcePool [as 别名]
def get_rp(si, dc, name):
    """
    Get a resource pool in the datacenter by its names.
    """
    viewManager = si.content.viewManager
    containerView = viewManager.CreateContainerView(dc, [vim.ResourcePool],
                                                    True)
    try:
        for rp in containerView.view:
            if rp.name == name:
                return rp
    finally:
        containerView.Destroy()
    raise Exception("Failed to find resource pool %s in datacenter %s" %
                    (name, dc.name)) 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:17,代码来源:deploy_ova.py


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