UnixPower on Networking
  http://www.unix-power.net/

 
 Top - Linux - VMware ESXi vSphere CLIの使い方



■仮想マシンのコマンド操作


仮想マシンをvSphereCLIで操作するコマンドのメモ書きです。下記ではESXiのIPが192.168.1.170という前提です。

・仮想マシンの一覧を表示


# vmware-cmd -H 192.168.1.170 -l


・仮想マシンを起動する


# vmware-cmd -H 192.168.1.170 "[datastore] CentOS1/CentOS1.vmx" start


・仮想マシンをシャットダウンする


# vmware-cmd -H 192.168.1.170 "[datastore] CentOS1/CentOS1.vmx" stop soft


・仮想マシンを電源オフする


# vmware-cmd -H 192.168.1.170 "[datastore] CentOS1/CentOS1.vmx" stop hard


・仮想マシンをインベントリに登録する


# vmware-cmd -H 192.168.1.170 -s register "[datastore] CentOS1/CentOS1.vmx"


・仮想マシンをインベントリから削除する


# vmware-cmd -H 192.168.1.170 -s unregister "[datastore] CentOS1/CentOS1.vmx"


■ESXiのコマンド操作


・ESXiの情報を取得


# vicfg-hostops --server 192.168.1.170 --operation info
Enter password:

Host Name : esxi1.xxxxxx.com
Manufacturer : FUJITSU-SV
Model : PRIMERGY
Processor Type : Intel(R) Xeon(R) CPU E5420 @ 2.50GHz
CPU Cores : 4 CPUs x 2493 GHz
Memory Capacity : 6142.85546875 MB
VMotion Enabled : no
In Maintenance Mode : no
Last Boot Time : 2012-10-06T10:48:57.822218Z


・メンテナンスモード開始


# vicfg-hostops --server 192.168.1.170 --operation enter


・メンテナンスモード終了


# vicfg-hostops --server 192.168.1.170 --operation exit


・ホスト再起動


# vicfg-hostops --server 192.168.1.170 --operation reboot


・ホスト停止


# vicfg-hostops --server 192.168.1.170 --operation shutdown


■ファイル操作


・ローカルからESXiへコピー


# vifs --server 192.168.1.170 -p "C:\tmp\test.txt" "[datastore] test.txt"


・ESXiからローカルへコピー


# vifs --server 192.168.1.170 -g "[datastore] test.txt" "C:\tmp\test.txt"


・データストア1からデータストア2へファイルコピー


# vifs --server 192.168.1.170 -c "[datastore1] test.txt" "[datastore2] test.txt"


・データストア1からデータストア2へファイル移動


# vifs --server 192.168.1.170 -m "[datastore1] test.txt" "[datastore2] test.txt"


・データストア1のファイル削除


# vifs --server 192.168.1.170 -r "[datastore1] test.txt"


・データストア一覧表示


# vifs --server 192.168.1.170 -S


■パッチ適用作業


vSphere CLIを用いてESXiホストにアップデートパッチを適用します。パッチは以下からダウンロードしてください。パッチをダウンロードしたらアップデートを適用するESXiホストにデータストアブラウザからアップロードします。

http://www.vmware.com/patchmgr/findPatch.portal


パッチをダウンロードしたらアップデートを適用するESXiホストにデータストアブラウザからアップロードします。まず現状のESXiに適用されているパッチを以下のコマンドで確認します。

# esxcli --server 192.168.12.200 software vib list
Name                           Version                           Vendor  Acceptance Level  Install Date
-----------------------------  ----------------------------------  ------  ----------------  ------------
ata-pata-amd                   0.3.10-3vmw.510.0.0.799733          VMware  VMwareCertified   2013-01-19
ata-pata-atiixp                0.4.6-4vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
ata-pata-cmd64x                0.2.5-3vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
ata-pata-hpt3x2n               0.3.4-3vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
ata-pata-pdc2027x              1.0-3vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
ata-pata-serverworks           0.4.3-3vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
ata-pata-sil680                0.4.8-3vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
ata-pata-via                   0.3.3-2vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
block-cciss                    3.6.14-10vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
ehci-ehci-hcd                  1.0-3vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
esx-base                       5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
esx-dvfilter-generic-fastpath  5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
esx-tboot                      5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
esx-xlibs                      5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
esx-xserver                    5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
ima-qla4xxx                    2.01.31-1vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
ipmi-ipmi-devintf              39.1-4vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
ipmi-ipmi-msghandler           39.1-4vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
ipmi-ipmi-si-drv               39.1-4vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
misc-cnic-register             1.1-1vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
misc-drivers                   5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19
net-be2net                     4.1.255.11-1vmw.510.0.0.799733      VMware  VMwareCertified   2013-01-19
net-bnx2                       2.0.15g.v50.11-7vmw.510.0.0.799733  VMware  VMwareCertified   2013-01-19
net-bnx2x                      1.61.15.v50.3-1vmw.510.0.0.799733   VMware  VMwareCertified   2013-01-19
net-cnic                       1.10.2j.v50.7-3vmw.510.0.0.799733   VMware  VMwareCertified   2013-01-19
net-e1000                      8.0.3.1-2vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
net-e1000e                     1.1.2-3vmw.510.0.0.799733           VMware  VMwareCertified   2013-01-19
net-enic                       1.4.2.15a-1vmw.510.0.0.799733       VMware  VMwareCertified   2013-01-19
net-forcedeth                  0.61-2vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
net-igb                        2.1.11.1-3vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
net-ixgbe                      3.7.13.6iov-10vmw.510.0.0.799733    VMware  VMwareCertified   2013-01-19
net-nx-nic                     4.0.558-3vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
net-r8168                      8.013.00-3vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
net-r8169                      6.011.00-2vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
net-s2io                       2.1.4.13427-3vmw.510.0.0.799733     VMware  VMwareCertified   2013-01-19
net-sky2                       1.20-2vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
net-tg3                        3.110h.v50.4-4vmw.510.0.0.799733    VMware  VMwareCertified   2013-01-19
net-vmxnet3                    1.1.3.0-3vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
ohci-usb-ohci                  1.0-3vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
sata-ahci                      3.0-13vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
sata-ata-piix                  2.12-6vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
sata-sata-nv                   3.5-4vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
sata-sata-promise              2.12-3vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
sata-sata-sil24                1.1-1vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
sata-sata-sil                  2.3-4vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
sata-sata-svw                  2.3-3vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
scsi-aacraid                   1.1.5.1-9vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
scsi-adp94xx                   1.0.8.12-6vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
scsi-aic79xx                   3.1-5vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
scsi-bnx2i                     1.9.1d.v50.1-5vmw.510.0.0.799733    VMware  VMwareCertified   2013-01-19
scsi-fnic                      1.5.0.3-1vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
scsi-hpsa                      5.0.0-21vmw.510.0.0.799733          VMware  VMwareCertified   2013-01-19
scsi-ips                       7.12.05-4vmw.510.0.0.799733         VMware  VMwareCertified   2013-01-19
scsi-lpfc820                   8.2.3.1-127vmw.510.0.0.799733       VMware  VMwareCertified   2013-01-19
scsi-megaraid-mbox             2.20.5.1-6vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
scsi-megaraid-sas              5.34-4vmw.510.0.0.799733            VMware  VMwareCertified   2013-01-19
scsi-megaraid2                 2.00.4-9vmw.510.0.0.799733          VMware  VMwareCertified   2013-01-19
scsi-mpt2sas                   10.00.00.00-5vmw.510.0.0.799733     VMware  VMwareCertified   2013-01-19
scsi-mptsas                    4.23.01.00-6vmw.510.0.0.799733      VMware  VMwareCertified   2013-01-19
scsi-mptspi                    4.23.01.00-6vmw.510.0.0.799733      VMware  VMwareCertified   2013-01-19
scsi-qla2xxx                   902.k1.1-9vmw.510.0.0.799733        VMware  VMwareCertified   2013-01-19
scsi-qla4xxx                   5.01.03.2-4vmw.510.0.0.799733       VMware  VMwareCertified   2013-01-19
scsi-rste                      2.0.2.0088-1vmw.510.0.0.799733      VMware  VMwareCertified   2013-01-19
uhci-usb-uhci                  1.0-3vmw.510.0.0.799733             VMware  VMwareCertified   2013-01-19
vmware-fdm                     5.1.0-880146                        VMware  VMwareCertified   2013-02-11
tools-light                    5.1.0-0.0.799733                    VMware  VMwareCertified   2013-01-19


ダウンロードしたパッチプログラムのリストを表示するには以下のコマンドを実行します。


# esxcli --server 192.168.12.200 software sources vib list -d "[datastore]/Patch/ESXi510-201212001.zip"
Name                           Version                             Vendor  Creation Date  Acceptance Level  Status
-----------------------------  ----------------------------------  ------  -------------  ----------------  ---------
scsi-bnx2i                     1.9.1d.v50.1-5vmw.510.0.0.799733    VMware  2012-08-02     VMwareCertified   Installed
sata-sata-promise              2.12-3vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
net-forcedeth                  0.61-2vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
esx-xserver                    5.1.0-0.0.799733                    VMware  2012-08-02     VMwareCertified   Installed
misc-cnic-register             1.1-1vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
net-tg3                        3.110h.v50.4-4vmw.510.0.0.799733    VMware  2012-08-02     VMwareCertified   Installed
scsi-megaraid-sas              5.34-4vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
esx-xlibs                      5.1.0-0.0.799733                    VMware  2012-08-02     VMwareCertified   Installed
scsi-megaraid-mbox             2.20.5.1-6vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
scsi-ips                       7.12.05-4vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
net-e1000e                     1.1.2-3vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
sata-ahci                      3.0-13vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
sata-sata-svw                  2.3-3vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
esx-base                       5.1.0-0.8.911593                    VMware  2012-11-16     VMwareCertified   Downgrade
net-cnic                       1.10.2j.v50.7-3vmw.510.0.0.799733   VMware  2012-08-02     VMwareCertified   Installed
net-e1000                      8.0.3.1-2vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
ata-pata-serverworks           0.4.3-3vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
esx-base                       5.1.0-0.9.914609                    VMware  2012-11-18     VMwareCertified   Installed
scsi-mptspi                    4.23.01.00-6vmw.510.0.0.799733      VMware  2012-08-02     VMwareCertified   Installed
ata-pata-hpt3x2n               0.3.4-3vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
net-s2io                       2.1.4.13427-3vmw.510.0.0.799733     VMware  2012-08-02     VMwareCertified   Installed
net-bnx2                       2.0.15g.v50.11-7vmw.510.0.0.799733  VMware  2012-08-02     VMwareCertified   Installed
scsi-megaraid2                 2.00.4-9vmw.510.0.0.799733          VMware  2012-08-02     VMwareCertified   Installed
ata-pata-amd                   0.3.10-3vmw.510.0.0.799733          VMware  2012-08-02     VMwareCertified   Installed
ipmi-ipmi-si-drv               39.1-4vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
scsi-lpfc820                   8.2.3.1-127vmw.510.0.0.799733       VMware  2012-08-02     VMwareCertified   Installed
ata-pata-atiixp                0.4.6-4vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
esx-dvfilter-generic-fastpath  5.1.0-0.0.799733                    VMware  2012-08-02     VMwareCertified   Installed
net-sky2                       1.20-2vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
scsi-qla2xxx                   902.k1.1-9vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
net-r8169                      6.011.00-2vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
net-bnx2x                      1.61.15.v50.3-1vmw.510.0.0.799733   VMware  2012-08-02     VMwareCertified   Installed
scsi-mpt2sas                   10.00.00.00-5vmw.510.0.0.799733     VMware  2012-08-02     VMwareCertified   Installed
sata-ata-piix                  2.12-6vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
scsi-hpsa                      5.0.0-21vmw.510.0.0.799733          VMware  2012-08-02     VMwareCertified   Installed
ata-pata-via                   0.3.3-2vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
scsi-aacraid                   1.1.5.1-9vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
scsi-rste                      2.0.2.0088-1vmw.510.0.0.799733      VMware  2012-08-02     VMwareCertified   Installed
ata-pata-cmd64x                0.2.5-3vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
sata-sata-sil                  2.3-4vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
net-igb                        2.1.11.1-3vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
scsi-qla4xxx                   5.01.03.2-4vmw.510.0.0.799733       VMware  2012-08-02     VMwareCertified   Installed
block-cciss                    3.6.14-10vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
scsi-aic79xx                   3.1-5vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
net-vmxnet3                    1.1.3.0-3vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
uhci-usb-uhci                  1.0-3vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
sata-sata-nv                   3.5-4vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
sata-sata-sil24                1.1-1vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
net-ixgbe                      3.7.13.6iov-10vmw.510.0.0.799733    VMware  2012-08-02     VMwareCertified   Installed
ipmi-ipmi-msghandler           39.1-4vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
scsi-adp94xx                   1.0.8.12-6vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
ata-pata-sil680                0.4.8-3vmw.510.0.0.799733           VMware  2012-08-02     VMwareCertified   Installed
ata-pata-pdc2027x              1.0-3vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
misc-drivers                   5.1.0-0.0.799733                    VMware  2012-08-02     VMwareCertified   Installed
net-enic                       1.4.2.15a-1vmw.510.0.0.799733       VMware  2012-08-02     VMwareCertified   Installed
net-be2net                     4.1.255.11-1vmw.510.0.0.799733      VMware  2012-08-02     VMwareCertified   Installed
net-nx-nic                     4.0.558-3vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
ima-qla4xxx                    2.01.31-1vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
tools-light                    5.1.0-0.9.914609                    VMware  2012-11-18     VMwareCertified   Installed
ehci-ehci-hcd                  1.0-3vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
ohci-usb-ohci                  1.0-3vmw.510.0.0.799733             VMware  2012-08-02     VMwareCertified   Installed
net-r8168                      8.013.00-3vmw.510.0.0.799733        VMware  2012-08-02     VMwareCertified   Installed
esx-tboot                      5.1.0-0.0.799733                    VMware  2012-08-02     VMwareCertified   Installed
tools-light                    5.1.0-0.8.911593                    VMware  2012-11-16     VMwareCertified   Downgrade
scsi-fnic                      1.5.0.3-1vmw.510.0.0.799733         VMware  2012-08-02     VMwareCertified   Installed
ipmi-ipmi-devintf              39.1-4vmw.510.0.0.799733            VMware  2012-08-02     VMwareCertified   Installed
scsi-mptsas                    4.23.01.00-6vmw.510.0.0.799733      VMware  2012-08-02     VMwareCertified   Installed


次にESXiホストをメンテナンスモードに切り替えます。ESXiホストのIPは192.168.12.200という前提です。


# vicfg-hostops --server 192.168.12.200 --operation enter
Host esxi1.unix-power.local entered into maintenance mode successfully.


メンテナンスモードに切り替え後、以下のコマンドでパッチを適用します。


# esxcli --server 192.168.12.200 software vib update \
  -d "[datastore]/Patch/ESXi510-201212001.zip"
Installation Result
   Message: The update completed successfully, \
   but the system needs to be rebooted for the changes to be effective.
   Reboot Required: true
   VIBs Installed: VMware_bootbank_esx-base_5.1.0-0.9.914609, \
                   VMware_locker_tools-light_5.1.0-0.9.914609
   VIBs Removed: VMware_bootbank_esx-base_5.1.0-0.0.799733, \
                 VMware_locker_tools-light_5.1.0-0.0.799733
   <省略>


Reboot Required: trueと表示されていますので以下のコマンドで再起動を行います。


# vicfg-hostops --server 192.168.12.200 --operation enter
Host esxi1.unix-power.local entered into maintenance mode successfully.


再起動が完了すれば以下のコマンドでメンテナンスモードを解除します。


# vicfg-hostops --server 192.168.12.200 --operation exit
Host esxi1.unix-power.local exited from maintenance mode successfully.


実際に適用されたパッチを以下のコマンドで確認してみます。


# esxcli --server 192.168.12.200 software vib list | grep 2013-02-18
esx-base                   5.1.0-0.9.914609             VMware  VMwareCertified   2013-02-18
tools-light                5.1.0-0.9.914609             VMware  VMwareCertified   2013-02-18



 
 関連記事
 vSphere CLIのインストール
 Copyright(C) 2003-2015 UnixPower on Networking All rights reserved.