2015-01-09 67 views
1

我想找到我的VMServer上的所有Linux機器。你可以使用PySphere獲得客戶操作系統嗎?

我可以運行以下命令獲取所有虛擬機的列表。 的VM = server.get_registered_vms() MYLIST = [] 用於虛擬機VM: 虛擬機名= server.get_vm_by_path(VM) mylist.append(virtual_machine.get_properties) 打印VM

但有任何方式獲取VMServer具有的客戶操作系統。即,我不想要一種解決方法,要求機器處於打開狀態並需要輸入大量密碼。

回答

2

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 
+0

基本上它只是 「virtual_machine.get_property( 'guest_full_name')」 –

相關問題