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


Python vim.ComputeResource方法代码示例

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


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

示例1: report

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def report(self):
        si = self.si
        about = si.content.about
        print("Host: %s" % self.vcip)
        print("Datacenter: %s" % self.dc.name)
        print("Version: %s" % about.version)
        print("Api Version: %s" % about.apiVersion)
        print("Datacenter: %s" % self.dc.name)
        rootFolder = self.rootFolder
        o = si.content.viewManager.CreateContainerView(rootFolder, [vim.HostSystem], True)
        view = o.view
        o.Destroy()
        for h in view:
            print("Host: %s" % h.name)
        o = si.content.viewManager.CreateContainerView(rootFolder, [vim.ComputeResource], True)
        view = o.view
        o.Destroy()
        for clu in view:
            print("Cluster: %s" % clu.name)
            for dts in clu.datastore:
                print("Pool: %s" % dts.name) 
开发者ID:karmab,项目名称:kcli,代码行数:23,代码来源:__init__.py

示例2: find_object_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def find_object_by_name(module,content, object_name):
    try:
    	if(object_name == module.params['datacenter']):
    	    vmware_objects = get_all_objs(module,content,[vim.Datacenter])
    	elif (object_name == module.params['cluster']):
    	    vmware_objects = get_all_objs(module,content,[vim.ComputeResource])
    	elif (object_name == module.params['datastore']):
            vmware_objects = get_all_objs(module,content,[vim.Datastore])
    	elif (object_name == module.params['portgroup1'] or module.params['portgroup2'] or module.params['portgroup3'] ):
            vmware_objects = get_all_objs(module,content,[vim.dvs.DistributedVirtualPortgroup, vim.Network])
 
    	for object in vmware_objects:
            if object.name == object_name:
            	logger.info('object: %s',object.name)
            	return object
    	return None
    except Exception as err:
       module.fail_json(changed=False, msg= "Error Occured while Finding the Object by name. Error is %s" %(to_native(err))) 
开发者ID:vmware-archive,项目名称:ansible-module-chaperone,代码行数:20,代码来源:nsxt_vcenter_moids.py

示例3: get_resource_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [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

示例4: list_pools

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def list_pools(self):
        pools = []
        rootFolder = self.rootFolder
        si = self.si
        # dc = self.dc
        clu = find(si, rootFolder, vim.ComputeResource, self.clu)
        for dts in clu.datastore:
            pools.append(dts.name)
            # datastorename = dts.name
            # total = dssize(dts)[0].replace('GB', '')
            # available = dssize(dts)[1].replace('GB', '')
            # results[datastorename] = [float(total), float(available), dc.name]
        return pools 
开发者ID:karmab,项目名称:kcli,代码行数:15,代码来源:__init__.py

示例5: beststorage

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def beststorage(self):
        rootFolder = self.rootFolder
        si = self.si
        clu = find(si, rootFolder, vim.ComputeResource, self.clu)
        bestds = ''
        bestsize = 0
        for dts in clu.datastore:
            datastorename = dts.name
            available = float(dssize(dts)[1].replace('GB', ''))
            if available > bestsize:
                bestsize = available
                bestds = datastorename
        return bestds 
开发者ID:karmab,项目名称:kcli,代码行数:15,代码来源:__init__.py

示例6: _getisos

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def _getisos(self):
        rootFolder = self.rootFolder
        si = self.si
        clu = find(si, rootFolder, vim.ComputeResource, self.clu)
        isos = []
        results = {}
        searchspec = vim.host.DatastoreBrowser.SearchSpec()
        filequery = [vim.host.DatastoreBrowser.IsoImageQuery(), vim.host.DatastoreBrowser.FolderQuery()]
        filequeryflags = vim.host.DatastoreBrowser.FileInfo.Details()
        filequeryflags.fileSize = True
        filequeryflags.modification = False
        filequeryflags.fileOwner = False
        filequeryflags.fileType = False
        searchspec.query = filequery
        searchspec.details = filequeryflags
        searchspec.sortFoldersFirst = True
        searchspec.searchCaseInsensitive = True
        for dts in clu.datastore:
            datastorename = dts.name
            datastorepath = "[" + datastorename + "]"
            browser = dts.browser
            t = browser.SearchDatastore_Task(datastorepath, searchspec)
            waitForMe(t)
            result = t.info.result
            fileinfo = result.file
            for element in fileinfo:
                folderpath = element.path
                if not folderpath.endswith('iso') and 'ISO' in folderpath.upper():
                    t = browser.SearchDatastoreSubFolders_Task("%s%s" % (datastorepath, folderpath), searchspec)
                    waitForMe(t)
                    results = t.info.result
                    for r in results:
                        fileinfo = r.file
                        for isofile in fileinfo:
                            path = isofile.path
                            if path.endswith('.iso'):
                                isos.append("%s/%s/%s" % (datastorepath, folderpath, path))
        return isos 
开发者ID:karmab,项目名称:kcli,代码行数:40,代码来源:__init__.py

示例7: get_cluster

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

示例8: host_labels

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def host_labels(self):

        def _collect(node, level=1, dc=None, folder=None):
            inventory = {}
            if isinstance(node, vim.Folder) and not isinstance(node, vim.StoragePod):
                logging.debug("[Folder    ] {level} {name}".format(level=('-' * level).ljust(7), name=node.name))
                for child in node.childEntity:
                    inventory.update(_collect(child, level + 1, dc))
            elif isinstance(node, vim.Datacenter):
                logging.debug("[Datacenter] {level} {name}".format(level=('-' * level).ljust(7), name=node.name))
                inventory.update(_collect(node.hostFolder, level + 1, node.name))
            elif isinstance(node, vim.ComputeResource):
                logging.debug("[ComputeRes] {level} {name}".format(level=('-' * level).ljust(7), name=node.name))
                for host in node.host:
                    inventory.update(_collect(host, level + 1, dc, node))
            elif isinstance(node, vim.HostSystem):
                logging.debug("[HostSystem] {level} {name}".format(level=('-' * level).ljust(7), name=node.name))
                inventory[node._moId] = [
                    node.summary.config.name.rstrip('.'),
                    dc,
                    folder.name if isinstance(folder, vim.ClusterComputeResource) else ''
                ]
            else:
                logging.debug("[?         ] {level} {node}".format(level=('-' * level).ljust(7), node=node))
            return inventory

        labels = {}
        dcs = yield self.datacenter_inventory
        for dc in dcs:
            result = yield threads.deferToThread(lambda: _collect(dc))
            labels.update(result)
        return labels 
开发者ID:pryorda,项目名称:vmware_exporter,代码行数:34,代码来源:vmware_exporter.py

示例9: get_parent_tags_recursively

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def get_parent_tags_recursively(mor, infrastructure_data):
    # type: (vim.ManagedEntity, InfrastructureData) -> List[str]
    """Go up the resources hierarchy from the given mor. Note that a host running a VM is not considered to be a
    parent of that VM.

    rootFolder(vim.Folder):
      - vm(vim.Folder):
          VM1-1
          VM1-2
      - host(vim.Folder):
          HOST1
          HOST2

    """
    mor_props = infrastructure_data[mor]
    parent = mor_props.get('parent')
    if parent:
        tags = []
        parent_props = infrastructure_data.get(parent, {})
        parent_name = to_string(parent_props.get('name', 'unknown'))
        if isinstance(parent, vim.HostSystem):
            tags.append('vsphere_host:{}'.format(parent_name))
        elif isinstance(parent, vim.Folder):
            tags.append('vsphere_folder:{}'.format(parent_name))
        elif isinstance(parent, vim.ComputeResource):
            if isinstance(parent, vim.ClusterComputeResource):
                tags.append('vsphere_cluster:{}'.format(parent_name))
            tags.append('vsphere_compute:{}'.format(parent_name))
        elif isinstance(parent, vim.Datacenter):
            tags.append('vsphere_datacenter:{}'.format(parent_name))
        elif isinstance(parent, vim.Datastore):
            tags.append('vsphere_datastore:{}'.format(parent_name))

        parent_tags = get_parent_tags_recursively(parent, infrastructure_data)
        parent_tags.extend(tags)
        return parent_tags
    return [] 
开发者ID:DataDog,项目名称:integrations-core,代码行数:39,代码来源:utils.py

示例10: parse_service_instance

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ComputeResource [as 别名]
def parse_service_instance(clustername, service_instance):
    '''
    :param service_instance:
    :return:
    '''

    content = service_instance.RetrieveContent()
    object_view = content.viewManager.CreateContainerView(content.rootFolder, [], True)
    vm_info_list = []
    vm_info_list.append(["virtual_machine_name","virtual_machine_uuid","virtual_machine_ip","num_cpu",
        "num_vcpus","memory_size","guest_family","host_uuid","datastore","power_state"])

    for obj in object_view.view:
        if isinstance(obj, vim.ComputeResource):
            if isinstance(obj, vim.ClusterComputeResource) and obj.name == clustername :
                #instance_name,instance_id,address,num_sockets,num_vcpus_per_socket,memory_size_mib,guestFamily,host_uuid, datastore
                for h in obj.host:
                    nic = h.config.network.vnic[0].spec
                    esxi_config = h.summary.config
                    #host_ip = h.summary.config.name
                    #host_id = str(h).split(":")[1][:-1]
                    host_uuid = h.hardware.systemInfo.uuid

                    for vx in h.vm:
                        if vx.summary.config.template is False:
                            ## Check if guestFullName contains `Windows` to determine the guest os is windows
                            ## otherwise we assumed that it is linux.
                            os = "Windows" if "Windows" in vx.summary.config.guestFullName else "Linux"
                            power_state = "poweron" if vx.runtime.powerState == "poweredOn" else "poweroff"

                            ## We assume here that guest os datastore will always have url start as `ds:///vmfs/volumes`
                            datastore =  [ d.info.url for d in vx.datastore if d.info.url.startswith("ds:///vmfs/volumes")]
                            vm_info  = [vx.name, vx.config.instanceUuid, vx.summary.guest.ipAddress,
                                vx.config.hardware.numCPU, vx.config.hardware.numCoresPerSocket,
                                vx.summary.config.memorySizeMB, os, host_uuid, datastore[0], power_state]

                            vm_info_list.append(vm_info)
    object_view.Destroy()

    with open("{}.csv".format(clustername), 'w') as file:
        writer = csv.writer(file)
        writer.writerows(vm_info_list) 
开发者ID:nutanix,项目名称:blueprints,代码行数:44,代码来源:01_get_vmware_vm_info.py


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