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


Python vim.Datastore方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def __init__(self, parent=None, path=None, ftype=None):
        self._file_manager = None
        if isinstance(parent, vim.Datastore):
            # Iteratively look for the Datacenter parent
            self._datacenter_mo = get_datacenter_for_datastore(parent)
            self._datastore_mo = parent
            self._ftype = FOLDER
            if path:
                self._path = path
            else:
                self._path = ''
        elif isinstance(parent, File):
            self._datacenter_mo = parent._datacenter_mo
            self._datastore_mo = parent.datastore_mo
            self._ftype = ftype
            if parent._path == '':
                self._path = path
            else:
                self._path = '{}/{}'.format(parent._path, path)
        else:
            raise Exception(
                "Invalid type '{}' for datastore_file".format(type(parent))) 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:24,代码来源:datastore_file.py

示例2: pick_datastore

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def pick_datastore(self, allowed_datastores):
        """ Pick a datastore based on free space.
         Args:
             allowed_datastores: A list of allowed datastore names that can be deployed on
         Returns:
             pyVmomi.vim.Datastore: The managed object of the datastore.
        """
        possible_datastores = [
            ds for ds in self.system.get_obj_list(vim.Datastore)
            if ds.name in allowed_datastores and ds.summary.accessible and
            ds.summary.multipleHostAccess and ds.overallStatus != "red"]
        if not possible_datastores:
            raise DatastoreNotFoundError(item_type='datastores')
        possible_datastores.sort(
            key=lambda ds: float(ds.summary.freeSpace) / float(ds.summary.capacity),
            reverse=True)
        return possible_datastores[0] 
开发者ID:RedHatQE,项目名称:wrapanapi,代码行数:19,代码来源:virtualcenter.py

示例3: get_datastore

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_datastore(self, name):
        """Fetch the Datastore object(for a datastore) or StoragePod object (for a datastore
        cluster) from a provided name

        Args:
            name: The name of the datastore or datastore cluster
        Returns: A object of vim.Datastore or vim.StoragePod
        """

        if name in self.list_datastore() and name not in self.list_datastore_cluster():
            datastore = self.get_obj(vimtype=vim.Datastore, name=name)
        elif name in self.list_datastore_cluster():
            datastore = self.get_obj(vimtype=vim.StoragePod, name=name)
        else:
            raise ValueError("{ds} was not found as a datastore on {p}".format(
                ds=name, p=self.hostname))

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

示例4: make_vsphere

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def make_vsphere(filename=None):
    """
    Creates a vSphere object using either a JSON file or by prompting the user.

    :param str filename: Name of JSON file with connection info
    :return: vSphere object
    :rtype: :class:`Vsphere`
    """
    from adles.vsphere.vsphere_class import Vsphere
    if filename is not None:
        info = read_json(filename)
        if info is None:
            raise VsphereException("Failed to create vSphere object")
        return Vsphere(username=info.get("user"),
                       password=info.get("pass"),
                       hostname=info.get("host"),
                       port=info.get("port", 443),
                       datacenter=info.get("datacenter"),
                       datastore=info.get("datastore"))
    else:
        logging.info("Enter information to connect to the vSphere environment")
        datacenter = input("Datacenter  : ")
        datastore = input("Datastore   : ")
        return Vsphere(datacenter=datacenter, datastore=datastore) 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:26,代码来源:vsphere_utils.py

示例5: get_args

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_args():
    """
    Adds additional args for the vMotion
    """
    parser = cli.build_arg_parser()

    parser.add_argument('-dd', '--datastore-dest',
                        required=False,
                        help=' Datastore of the destination')

    parser.add_argument('-t', '--target-esx-host',
                        required=False,
                        help="name of the destination esx host")

    parser.add_argument('-v', '--vm-name',
                        required=True,
                        help="name of the vm")
    my_args = parser.parse_args()
    return cli.prompt_for_password(my_args) 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:21,代码来源:relocate_vm.py

示例6: get_args

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_args():
    """
    Adds additional args for listing all snapshots of a fcd

    -d datastore
    -v vdisk
    """
    parser = cli.build_arg_parser()

    parser.add_argument('-d', '--datastore',
                        required=True,
                        action='store',
                        help='Datastore name where disk is located')

    parser.add_argument('-v', '--vdisk',
                        required=True,
                        action='store',
                        help='First Class Disk name to delete snapshot for')

    my_args = parser.parse_args()
    return cli.prompt_for_password(my_args) 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:23,代码来源:fcd_list_vdisk_snapshots.py

示例7: main

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def main():
    args = get_args()

    # connect to vc
    si = SmartConnect(
        host=args.host,
        user=args.user,
        pwd=args.password,
        port=args.port)
    # disconnect vc
    atexit.register(Disconnect, si)

    content = si.RetrieveContent()
    # Get list of ds mo
    ds_obj_list = get_obj(content, [vim.Datastore], args.name)
    for ds in ds_obj_list:
        print_datastore_info(ds)

# start 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:21,代码来源:list_dc_datastore_info.py

示例8: get_obj

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_obj(content, vimtype, name):
    """
    Retrieves the managed object for the name and type specified

    Sample Usage:

    get_obj(content, [vim.Datastore], "Datastore Name")
    """
    obj = None
    container = content.viewManager.CreateContainerView(
        content.rootFolder, vimtype, True)
    for c in container.view:
        if c.name == name:
            # print(Item: + c.name) # for debugging
            obj = c
            break
    if not obj:
        raise RuntimeError("Managed Object " + name + " not found.")
    return obj 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:21,代码来源:get_portgroup.py

示例9: get_obj

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_obj(content, vimtype, name):
    """
    Retrieves the managed object for the name and type specified

    Sample Usage:

    get_obj(content, [vim.Datastore], "Datastore Name")
    """
    obj = None
    container = content.viewManager.CreateContainerView(
        content.rootFolder, vimtype, True)
    for c in container.view:
        if c.name == name:
            obj = c
            break
    if not obj:
        raise RuntimeError("Managed Object " + name + " not found.")
    return obj 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:20,代码来源:disk.py

示例10: find_object_by_name

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

示例11: find_datastore_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def find_datastore_by_name(self, datastore_name, datacenter_name):
        """
        Fetches the Datastore

        Args:
            datastore_name (str): Name of the Datastore
            datacenter_name (str): Name of the Datacenter

        Returns:
            vim.Datastore: Datastore instance

        """
        dc = self.find_datacenter_by_name(datacenter_name)
        folder = dc.datastoreFolder
        return self.find_object_by_name(
            self.get_content,
            datastore_name,
            [vim.Datastore],
            folder=folder
        ) 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:22,代码来源:vsphere.py

示例12: get_datastore_type_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def get_datastore_type_by_name(self, datastore_name, datacenter_name):
        """
        Gets the Datastore Type

        Args:
            datastore_name (str): Name of the Datastore
            datacenter_name (str): Name of the Datacenter

        Returns:
            str: Datastore type. Either VMFS or vsan

        """
        datastore = self.find_datastore_by_name(
            datastore_name,
            datacenter_name
        )
        return self.get_datastore_type(datastore) 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:19,代码来源:vsphere.py

示例13: test_infrastructure_cache

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def test_infrastructure_cache(realtime_instance):
    cache = InfrastructureCache(float('inf'))
    config = VSphereConfig(realtime_instance, logger)
    mock_api = VSphereRestAPI(config, log=logger)

    mors = {MagicMock(spec=k, _moId="foo"): object() for k in ALL_RESOURCES_WITH_METRICS * 2}
    with cache.update():
        for k, v in iteritems(mors):
            cache.set_mor_props(k, v)
        cache.set_all_tags(mock_api.get_resource_tags_for_mors(mors))

    for r in ALL_RESOURCES_WITH_METRICS:
        assert len(list(cache.get_mors(r))) == 2

    for k, v in iteritems(mors):
        assert cache.get_mor_props(k) == v

    vm_mor = vim.VirtualMachine(moId='VM4-4-1')
    vm2_mor = vim.VirtualMachine(moId='i-dont-have-tags')
    datastore = vim.Datastore(moId='NFS-Share-1')

    assert cache.get_mor_tags(vm_mor) == ['my_cat_name_1:my_tag_name_1', 'my_cat_name_2:my_tag_name_2']
    assert cache.get_mor_tags(datastore) == ['my_cat_name_2:my_tag_name_2']
    assert cache.get_mor_tags(vm2_mor) == [] 
开发者ID:DataDog,项目名称:integrations-core,代码行数:26,代码来源:test_cache.py

示例14: find_datastore_by_name

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

示例15: find_datastore_cluster_by_name

# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Datastore [as 别名]
def find_datastore_cluster_by_name(self, datastore_cluster_name):
        """
        Function to get datastore cluster managed object by name
        Args:
            datastore_cluster_name: Name of datastore cluster

        Returns: Datastore cluster managed object if found else None

        """
        data_store_clusters = get_all_objs(self.content, [vim.StoragePod])
        for dsc in data_store_clusters:
            if dsc.name == datastore_cluster_name:
                return dsc
        return None 
开发者ID:mgmt-sa-tiger-team,项目名称:skylight,代码行数:16,代码来源:vmware.py


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