通过集群过滤虚机
- 登陆(参考之前文章)
- 区分大小写
>>> 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)]