码迷,mamicode.com
首页 > 编程语言 > 详细

vsphere-automation-Python-sdk实践:过滤虚机

时间:2019-12-19 23:09:47      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:vsphere   imp   war   spec   size   com   tom   大小   hot   

通过集群过滤虚机

  1. 登陆(参考之前文章)
  2. 区分大小写
    >>> 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实践:过滤虚机

标签:vsphere   imp   war   spec   size   com   tom   大小   hot   

原文地址:https://blog.51cto.com/sampsondotqiu/2460185

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!