[VMware] 在 Linux 上使用 VMware vSphere CLI 列出 ESXi 上所有的虛擬機器

[VMware] 在 Linux 上使用 VMware vSphere CLI 列出 ESXi 上所有的虛擬機器

VMware vSphere Client 因為只有 Windows 版本,

像我想要在 Linux 上,對 vm 做一些操作就有些不便…

今天裝了 VMware vSphere CLI (支援 Windows/Linux),來看看它能做些什麼~

 

1. 下載 VMware vSphere CLI

先到 VMware 的網站下載 VMware vSphere CLI,

像我下載的是 VMware vSphere CLI 5.5 Update 1 的 Linux x64 版本~

 

2. 安裝 VMware vSphere CLI

將抓下來的檔案解閈後,執行 vmware-install.pl 安裝:

tar zxvf VMware-vSphere-CLI-5.5.0-1549297.x86_64.tar.gz
cd vmware-vsphere-cli-distrib/
sudo ./vmware-install.pl

 

裝好之後的東襾預設都在 /usr/bin 下面:

 ls_esx   

3. 使用 vmware-cmd 來列出所有的虛擬機器

vmware-cmd 的指令都是要先指定 ESXi server 或是 vCenter server 的位置,

和登入的名稱與密碼,再接上要操作的指令。

例如想要列出 10.1.116.132 這台 ESXi 上的虛擬機器的話,指令是:

vmware-cmd --server 10.1.116.132 --username --root PASSWORD -l

 

執行後的結果如下:

vmware_cmd_list  

 

不過 vmware-cmd 可以做的事情並不多,

看看它的 help,大概可以做些啟動或是關機等等的操作,

但像如果想要列出某個 vm 的所有 snapshot 的話就不行了:

   Usage: vmware-cmd <options> <vm-cfg-path> <vm-action> <arguments>
vmware-cmd -s <options> <server-action> <arguments>
Options:
Connection Options:
-H or --server <host>            specifies an ESX host or a vCenter Server
-h or --vihost <target host>     specifies a target host if host is a virtual center
-O <port>                        specifies an alternative port
-Q <protocol>                    specifies an alternative protocol
-U or --username <username>      specifies a username
-P or --password <password>      specifies a password
--sessionfile                    specifies a sessionfile path
--passthroughauth                specifies a login by sspi option
--credstore                      specifies to fetch Credential store information
--encoding                       specifies encoding option
General Options:
-h More detailed help.
-q Quiet. Minimal output
-v Verbose.
Server Operations:
vmware-cmd -l
vmware-cmd -s register <config_file_path> <datacenter> <resource pool>
vmware-cmd -s unregister <config_file_path>
VM Operations:
vmware-cmd <cfg> getstate
vmware-cmd <cfg> start <powerop_mode>
vmware-cmd <cfg> stop <powerop_mode>
vmware-cmd <cfg> reset <powerop_mode>
vmware-cmd <cfg> suspend <powerop_mode>
vmware-cmd <cfg> setguestinfo <variable> <value>
vmware-cmd <cfg> getguestinfo <variable>
vmware-cmd <cfg> getproductinfo <prodinfo>
vmware-cmd <cfg> connectdevice <device_name>
vmware-cmd <cfg> disconnectdevice <device_name>
vmware-cmd <cfg> getconfigfile
vmware-cmd <cfg> getuptime
vmware-cmd <cfg> answer
vmware-cmd <cfg> gettoolslastactive
vmware-cmd <cfg> hassnapshot
vmware-cmd <cfg> createsnapshot <name> <description> <quiesce> <memory>
vmware-cmd <cfg> revertsnapshot
vmware-cmd <cfg> removesnapshots

 

 

(本頁面已被瀏覽過 987 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料