PySphere提供了方法get_properties
and get_property(property_name)
。如果設置了屬性guest_full_name
,您可以在這裏找到它。
從文檔:
>>> vm1.get_properties()
{'guest_id': 'ubuntuGuest',
'path': '[DataStore1] Ubuntu/Ubuntu-10.vmx',
'guest_full_name': 'Ubuntu Linux (32-bit)',
'name': 'Ubuntu 10.10 Desktop 2200',
'mac_address': '00:50:56:aa:01:a7'
}
因此,添加到您的腳本,你可以這樣做:
vms = server.get_registered_vms()
mylist = []
for vm in vms:
virtual_machine = server.get_vm_by_path(vm)
guest_os = virtual_machine.get_property('guest_full_name')
if server_guest_is_linux(guest_os):
mylist.append(virtual_machine)
print vm
def server_guest_is_linux(guest_os):
if 'linux' in guest_os.lower() \
or 'ubuntu' in guest_os.lower() \
or 'centos' in guest_os.lower():
return True
return False
基本上它只是 「virtual_machine.get_property( 'guest_full_name')」 –