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


Python vim.Datacenter方法代码示例

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


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

示例1: get_parent_datacenter

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def get_parent_datacenter(self, obj):
        """ Walk the parent tree to find the objects datacenter """
        if isinstance(obj, vim.Datacenter):
            return obj
        if obj in self.parent_datacenters:
            return self.parent_datacenters[obj]
        datacenter = None
        while True:
            if not hasattr(obj, 'parent'):
                break
            obj = obj.parent
            if isinstance(obj, vim.Datacenter):
                datacenter = obj
                break
        self.parent_datacenters[obj] = datacenter
        return datacenter 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:18,代码来源:vmware_guest2.py

示例2: vm_folder_traversal

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def vm_folder_traversal():
    """
    Build the traversal spec for the property collector to traverse vmFolder
    """

    TraversalSpec = vmodl.query.PropertyCollector.TraversalSpec
    SelectionSpec = vmodl.query.PropertyCollector.SelectionSpec

    # Traversal through vmFolder branch
    dcToVmf = TraversalSpec(name='dcToVmf', type=vim.Datacenter, path='vmFolder', skip=False)
    dcToVmf.selectSet.append(SelectionSpec(name='visitFolders'))

    # Recurse through the folders
    visitFolders = TraversalSpec(name='visitFolders', type=vim.Folder, path='childEntity', skip=False)
    visitFolders.selectSet.extend((SelectionSpec(name='visitFolders'), SelectionSpec(name='dcToVmf'),))

    return SelectionSpec.Array((visitFolders, dcToVmf,)) 
开发者ID:vmware-archive,项目名称:vsphere-storage-for-docker,代码行数:19,代码来源:vm_listener.py

示例3: setup_cluster_vapi1

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def setup_cluster_vapi1(context):
    """Create a cluster from the Datacenter managed object."""
    cluster1_name = context.testbed.config['CLUSTER1_NAME']

    # Get the host folder for the Datacenter2 using the save identifier
    datacenter_name = context.testbed.config['DATACENTER2_NAME']
    datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]

    # Create a managed object from the datacenter identifier
    datacenter_mo = vim.Datacenter(datacenter, context.soap_stub)

    # Using pyvmomi to get the host folder on which to create the cluster
    folder_mo = datacenter_mo.hostFolder
    cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
                                           vim.cluster.ConfigSpecEx())

    print("Created Cluster '{}' ({})".format(cluster_mo._moId, cluster1_name))

    context.testbed.entities['CLUSTER_IDS'] = {
        cluster1_name: cluster_mo._moId
    } 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:23,代码来源:cluster.py

示例4: setup_cluster_vim

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def setup_cluster_vim(context):
    """Create a cluster using only the VIM API"""
    cluster1_name = context.testbed.config['CLUSTER1_NAME']

    # Get the host folder for the Datacenter2 using the save identifier
    datacenter_name = context.testbed.config['DATACENTER2_NAME']

    for entity in context.service_instance.content.rootFolder.childEntity:
        if isinstance(entity,
                      vim.Datacenter) and entity.name == datacenter_name:
            folder_mo = entity.hostFolder
            cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
                                                   vim.cluster.ConfigSpecEx())

            print("Created Cluster '{}' ({})".format(cluster_mo._moId,
                                                     cluster1_name))

            context.testbed.entities['CLUSTER_IDS'] = {
                cluster1_name: cluster_mo._moId
            }
            break 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:23,代码来源:cluster.py

示例5: detect_vm_folder

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def detect_vm_folder(context, datacenter_name, folder_name):
    """Find vm folder based on datacenter and folder name"""
    datacenter = datacenter_helper.get_datacenter(context.client,
                                                  datacenter_name)
    if not datacenter:
        print("Datacenter '{}' not found".format(datacenter_name))
        return None

    folder_summaries = context.client.vcenter.Folder.list(
        Folder.FilterSpec(type=Folder.Type.VIRTUAL_MACHINE,
                          names=set([folder_name]),
                          datacenters=set([datacenter])))
    if len(folder_summaries) > 0:
        folder = folder_summaries[0].folder
        print("Detected VM Folder '{}' as {}".format(folder_name, folder))
        context.testbed.entities['VM_FOLDER_IDS'][folder_name] = folder
        return True
    else:
        print("VM Folder '{}' missing in Datacenter {}".
              format(folder_name, datacenter_name))
        return False 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:23,代码来源:folder.py

示例6: __init__

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def __init__(self, host, user, password, datacenter, cluster, debug=False, filtervms=False, filteruser=False,
                 filtertag=None):
        # 4-1-CONNECT
        si = connect.SmartConnect(host=host, port=443, user=user, pwd=password, sslContext=_create_unverified_context())
        self.conn = si
        self.si = si
        self.vcip = host
        self.url = "https://%s:%s@%s/sdk" % (user, password, host)
        self.rootFolder = si.content.rootFolder
        self.dc = find(si, self.rootFolder, vim.Datacenter, datacenter)
        self.macaddr = []
        self.clu = cluster
        self.distributed = False
        self.filtervms = filtervms
        self.filtervms = filtervms
        self.filteruser = filteruser
        self.filtertag = filtertag
        self.debug = debug
        return 
开发者ID:karmab,项目名称:kcli,代码行数:21,代码来源:__init__.py

示例7: report

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

示例8: get_info

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def get_info(self):
        """
        Retrieves and formats basic information about the vSphere instance.

        :return: formatted server information
        :rtype: str
        """
        about = self.content.about
        info_string = "\n"
        info_string += "Host address: %s:%d\n" % (self.hostname, self.port)
        info_string += "Datacenter  : %s\n" % self.datacenter.name
        info_string += "Datastore   : %s\n" % self.datastore.name
        info_string += "Full name   : %s\n" % about.fullName
        info_string += "Vendor      : %s\n" % about.vendor
        info_string += "Version     : %s\n" % about.version
        info_string += "API type    : %s\n" % about.apiType
        info_string += "API version : %s\n" % about.apiVersion
        info_string += "OS type     : %s" % about.osType
        return info_string 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:21,代码来源:vsphere_class.py

示例9: get_folder

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

        :param str folder_name: Name of folder [default: Datacenter vmFolder]
        :return: The folder found
        :rtype: vim.Folder
        """
        if folder_name:  # Try to find the named folder in the datacenter
            return self.get_obj(self.datacenter, [vim.Folder], folder_name)
        else:  # Default to the VM folder in the datacenter
            # Reference: pyvmomi/docs/vim/Datacenter.rst
            self._log.warning("Could not find folder '%s' in Datacenter '%s', "
                              "defaulting to vmFolder",
                              folder_name, self.datacenter.name)
            return self.datacenter.vmFolder 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:18,代码来源:vsphere_class.py

示例10: main

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def main():
    try:
        si = None
        try:
            print "Trying to connect to VCENTER SERVER . . ."
            si = connect.Connect(inputs['vcenter_ip'], 443, inputs['vcenter_user'], inputs['vcenter_password'])
        except IOError, e:
            pass
            atexit.register(Disconnect, si)

        print "Connected to VCENTER SERVER !"
        
        content = si.RetrieveContent()
        datacenter = get_obj(content, [vim.Datacenter], inputs['datacenter'])
	cluster = get_obj(content, [vim.ClusterComputeResource], inputs['cluster'])
	network_folder = datacenter.networkFolder
	#Create DV Switch
	dv_switch = create_dvSwitch(si, content, network_folder, cluster)
	#Add port group to this switch
	add_dvPort_group(si, dv_switch) 
开发者ID:reubenur-rahman,项目名称:vmware-pyvmomi-examples,代码行数:22,代码来源:create_dvs_and_dvport_group.py

示例11: find_object_by_name

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

示例12: get_pool

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

示例13: destroy_pool

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def destroy_pool(self, pool, dc, cluster):
        """
        Deletes the Resource Pool

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

        """
        vms_in_pool = self.get_all_vms_in_pool(pool, dc, cluster)
        logger.info(f"VM's in resource pool {pool}: {[vm.name for vm in vms_in_pool]}")
        self.destroy_vms(vms_in_pool)

        # get resource pool instance
        pi = self.get_pool(pool, dc, cluster)
        WaitForTask(pi.Destroy())
        logger.info(f"Successfully deleted resource pool {pool}") 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:20,代码来源:vsphere.py

示例14: check_folder_exists

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def check_folder_exists(self, name, cluster, dc):
        """
        Checks whether folder exists in Templates

        Args:
            name (str): Folder name
            cluster (str): Cluster name
            dc (str): Datacenter name

        Returns:
            bool: True if folder exists, False otherwise

        """
        _rc = False
        dc = self.get_dc(dc)

        vms = dc.vmFolder.childEntity
        for vm in vms:
            if vm.name == name:
                _rc = True
        return _rc 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:23,代码来源:vsphere.py

示例15: destroy_folder

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datacenter [as 别名]
def destroy_folder(self, name, cluster, dc):
        """
        Removes the folder from Templates

        Args:
            name (str): Folder name
            cluster (str): Cluster name
            dc (str): Datacenter name

        """
        if self.check_folder_exists(name, cluster, dc):
            dc = self.get_dc(dc)
            vms = dc.vmFolder.childEntity
            for vm in vms:
                if vm.name == name:
                    for dvm in vm.childEntity:
                        self.poweroff_vms([dvm])
                    logger.info(f"Destroying folder {name} in templates")
                    WaitForTask(vm.Destroy())
        else:
            logger.info(f"Folder {name} doesn't exist in templates") 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:23,代码来源:vsphere.py


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