vsphere-automation-Python-sdk实践:过滤虚机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vsphere-automation-Python-sdk实践:过滤虚机相关的知识,希望对你有一定的参考价值。
通过集群过滤虚机- 登陆(参考之前文章)
- 区分大小写
>>> from com.vmware.vcenter_client import Cluster >>> cluster_id = client.vcenter.Cluster.list(Cluster.FilterSpec(names={‘SHVSAN-Cluster01‘}))[0].cluster >>> cluster_id ‘domain-c647‘ >>> client.vcenter.VM.list(client.vcenter.VM.FilterSpec(clusters={cluster_id})) [Summary(vm=‘vm-1937‘, name=‘rdshiot02‘, power_state=State(string=‘POWERED_ON‘), cpu_count=12, memory_size_mib=32768), Summary(vm=‘vm-1939‘, name=‘rdshiot03‘, power_state=State(string=‘POWERED_ON‘), cpu_count=12, memory_size_mib=32768)]
通过文件夹过滤虚机
>>> from com.vmware.vcenter_client import Folder
>>> filter_spec = Folder.FilterSpec(type=Folder.Type.VIRTUAL_MACHINE, names={‘Workspace of External Subnet‘})
>>> filter_spec
FilterSpec(folders=None, names={‘Workspace of External Subnet‘}, type=Type(string=‘VIRTUAL_MACHINE‘), parent_folders=None, datacenters=None)
>>> folder_id = client.vcenter.Folder.list(filter_spec)[0].folder
>>> folder_id
‘group-v368‘
>>> client.vcenter.VM.list(client.vcenter.VM.FilterSpec(folders={folder_id}))
[Summary(vm=‘vm-1285‘, name=‘shnode02‘, power_state=State(string=‘POWERED_ON‘), cpu_count=8, memory_size_mib=12288), Summary(vm=‘vm-16136‘, name=‘shoth02‘, power_state=State(string=‘POWERED_ON‘), cpu_count=8, memory_size_mib=32768)]
2019-12-19下次测试从内容库创建虚机
以上是关于vsphere-automation-Python-sdk实践:过滤虚机的主要内容,如果未能解决你的问题,请参考以下文章