Python pyVmomi.vim.ResourcePool() Examples
The following are 16
code examples of pyVmomi.vim.ResourcePool().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyVmomi.vim
, or try the search function
.
Example #1
Source File: deploy_ova.py From pyvmomi-community-samples with Apache License 2.0 | 7 votes |
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
Example #2
Source File: ezmomi.py From ezmomi with MIT License | 6 votes |
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
Example #3
Source File: create_random_marvel_vms.py From pyvmomi-community-samples with Apache License 2.0 | 6 votes |
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])
Example #4
Source File: vsphere.py From ocs-ci with MIT License | 6 votes |
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
Example #5
Source File: vsphere.py From ocs-ci with MIT License | 6 votes |
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
Example #6
Source File: vmware.py From skylight with GNU General Public License v3.0 | 5 votes |
def find_resource_pool_by_name(content, resource_pool_name): return find_object_by_name(content, resource_pool_name, [vim.ResourcePool])
Example #7
Source File: vmware_guest2.py From skylight with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: virtualcenter.py From wrapanapi with MIT License | 5 votes |
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]
Example #9
Source File: virtualcenter.py From wrapanapi with MIT License | 5 votes |
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
Example #10
Source File: virtualcenter.py From wrapanapi with MIT License | 5 votes |
def list_resource_pools(self): return [str(h.name) for h in self.get_obj_list(vim.ResourcePool)]
Example #11
Source File: vmutils.py From devops with Apache License 2.0 | 5 votes |
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)
Example #12
Source File: vm.py From ADLES with Apache License 2.0 | 5 votes |
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
Example #13
Source File: vsphere_class.py From ADLES with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: deploy_vsphere_template_with_nuage.py From vspk-examples with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #15
Source File: deploy_ova.py From pyvmomi-community-samples with Apache License 2.0 | 5 votes |
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))
Example #16
Source File: create_random_marvel_vms.py From pyvmomi-community-samples with Apache License 2.0 | 4 votes |
def main(): """ Simple command-line program for creating Dummy VM based on Marvel character names """ args = get_args() if args.public_key_file: with open(args.public_key_file) as key_file: marvel_public_key = key_file.readline().strip() else: marvel_public_key = input('Marvel public key: ').strip() if args.private_key_file: with open(args.private_key_file) as key_file: marvel_private_key = key_file.readline().strip() else: marvel_private_key = input('Marvel private key: ').strip() if args.disable_ssl_verification: service_instance = connect.SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) else: service_instance = connect.SmartConnect(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) if not service_instance: print("Could not connect to the specified host using specified " "username and password") return -1 atexit.register(connect.Disconnect, service_instance) content = service_instance.RetrieveContent() # datacenter = get_obj(content, [vim.Datacenter], args.datacenter) vmfolder = get_obj(content, [vim.Folder], args.folder) resource_pool = get_obj(content, [vim.ResourcePool], args.resource_pool) print("Connecting to Marvel API and retrieving " + str(args.count) + " random character(s) ...") characters = get_marvel_characters(args.count, marvel_public_key, marvel_private_key) for name in characters: vm_name = 'MARVEL-' + name create_dummy_vm(vm_name, service_instance, vmfolder, resource_pool, args.datastore) if args.opaque_network: vm = get_obj(content, [vim.VirtualMachine], vm_name) add_nic(service_instance, vm, args.opaque_network) return 0 # Start program