VMware/vCLI

VMware vCLI
Works on both ESX and ESXi

vSphere Command-Line Interface - http://www.vmware.com/support/developer/vcli/

Download vCLI 5.0 Update 1 - http://www.vmware.com/download/download.do?downloadGroup=VCLI50U1

Documentation
vSphere Command-Line Interface - http://www.vmware.com/support/developer/vcli/

-

Release Notes

Getting Started with vSphere Command-Line Interfaces (PDF)

vSphere Command-Line Interface Concepts and Examples (PDF)

vSphere Command-Line Interface Reference

Command-Line Management of vSphere 5.0 for Service Console Users (PDF)

-

vSphere SDK for Perl Documentation

vSphere Management Assistant Documentation

Easy Method
Deploy vMA - http://www.vmware.com/support/developer/vima

"The vSphere Management Assistant (vMA) allows administrators and developers to run scripts and agents to manage ESXi hosts and vCenter Server systems. vMA is a virtual machine that includes prepackaged software, a logging component, and an authentication component that supports non-interactive login."

vCLI is included with the vMA.

Manual Method
Install vCLI 5.0 Update 1 manually

Download from http://www.vmware.com/download/download.do?downloadGroup=VCLI50U1 with a VMware account.

Install RHEL possible dependencies: yum -y install gcc make perl unzip wget perl-IO-Zlib libxml2-devel perl-XML-LibXML perl-XML-LibXML-Common openssl-devel cpan e2fsprogs perl-IO-Socket-SSL

Install Ubuntu 11.04 dependencies: apt-get install gcc make perl unzip wget libxml-libxml-perl perl-doc

tar -zvxf VMware-vSphere-CLI-5.0.0-422456.x86_64.tar.gz cd vmware-vsphere-cli-distrib export ftp_proxy= export http_proxy= ./vmware-install.pl --default
 * 1) vSphere CLI 5.0.0 build-3422456 for Linux installer
 * 1) answer 'yes' to license agreement

Test with: vicfg-hostops --server [SERVER] --username root --password [PASSWORD] --operation info

Install Issues
Install CPAN modules: cpan YAML

CPAN error: Running make install make had returned bad status, install seems impossible

Install make package and redo CPAN config. yum -y install make rm -f /usr/lib/perl5/5.8.8/CPAN/Config.pm /usr/share/perl5/CPAN/Config.pm

---

Update cpan: cpan Bundle::CPAN

---

Proxy Install Issue: http_proxy not set. please set environment variable 'http_proxy' e.g. export http_proxy=http://myproxy.mydomain.com:0000.

ftp_proxy not set. please set environment variable 'ftp_proxy' e.g. export ftp_proxy=http://myproxy.mydomain.com:0000.

export ftp_proxy= export http_proxy=
 * 1) solution:

---

Aged perl issues: The following Perl modules were found on the system but may be too old to work with vSphere CLI: - version 0.78 or newer - LWP::Protocol::https 5.805 or newer

apt-cache search LWP::Protocol::https libcrypt-ssleay-perl - Support for https protocol in LWP cpan LWP::Protocol::https
 * 1) Which package provided?  It is very outdated...
 * 1) solution - cpan fix for 'LWP::Protocol::https' package:

cpan version
 * 1) solution - cpan fix for 'version' package:

cpan YAML
 * 1) solution - stop the YAML messages:

---

Server version unavailable: Server version unavailable at 'https://10.10.23.140:443/sdk/vimService.wsdl' at /usr/share/perl/5.10/VMware/VICommon.pm line 545,  line 2.

curl -k https://10.10.23.140/sdk
 * 1) Test connection - should return nothing

/usr/lib/vmware-vcli/apps/general/connect.pl --server 10.10.23.140 --username root --password Password1 /usr/lib/vmware-vcli/apps/general/connect.pl --url https://10.10.23.140/sdk --username root --password Password1 /usr/lib/vmware-vcli/apps/general/connect.pl --verbose --url https://10.10.23.140/sdk --username root --password Passowrd1 # doesn't seem to give much else Connection Successful Server Time : 2011-10-07T17:59:14.920323Z Server version unavailable at 'https://10.10.23.140:443/sdk/vimService.wsdl' at /usr/share/perl/5.10/VMware/VICommon.pm line 545.
 * 1) quick test:
 * 1) should return:
 * 1) not:


 * 1) solution - cause is a proxy??

VMware Communities: Error: Server version unavailable at... http://communities.vmware.com/thread/240659?tstart=0

apt-get install libxml2-dev libcompress-zlib-perl libxml-perl cpan XML::LibXML
 * 1) dependencies:

VMware Communities: Error: Server version unavailable at... - http://communities.vmware.com/message/1811182#1811182 :"I was able to fix my issue by adding the line suggested at the top of VICommon.pl." $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
 * 1) SOLUTION:

Kenneth's quick solution: sed -i "s/package Util;/package Util;\n\$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;/g"  /usr/lib/perl5/5.8.8/VMware/VICommon.pm

sed -i "s/$ssl_opts{SSL_verify_mode} ||= 1;/$ssl_opts{SSL_verify_mode} ||= 0;/g" /usr/lib/perl5/site_perl/5.8.8/LWP/Protocol/https.pm
 * 1) if that doesn't work...

yum install perl-IO-Socket-SSL
 * 1) if that still doesn't work???


 * Solution: http://communities.vmware.com/message/1721204#1721204

As detailed here:

http://search.cpan.org/~sullr/Net-SSLGlue-0.2/lib/Net/SSLGlue/LWP.pm and here:

http://www.dagolden.com/index.php/1395/with-lwp-6-you-probably-need-mozillaca/

The LWP libraries started doing certificate verification by default with version 6.

This causes the current vcli to fail to connect to a vSphere without a trusted and verifiable certificate.

I fixed this error by doing the following:

yum install perl-IO-Socket-SSL

vi /usr/lib/perl5/site_perl/5.8.8/LWP/Protocol/https.pm

Look for the following line near the top: $ssl_opts{SSL_verify_mode} ||= 1;

Change it to: $ssl_opts{SSL_verify_mode} ||= 0;

This is on CentOS 5.5, you might have different paths on different platforms.

This fixed the error for me, I guess we need to wait for an updated vcli that disables certificate verification as part of the LWP calls.

---

-bash: /usr/bin/esxcli: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
 * 1) esxcli

This library is provided by the 32bit glibc package. On a 64bit system, this may not be available. Stupid VMware! glibc-2.5-*.i686

Uninstall
You can decide to remove this software from your system at any time by invoking the following command: /usr/bin/vmware-uninstall-vSphere-CLI.pl

Login options
--config=CONFIG     # or VI_CONFIG --server=SERVER     # or VI_SERVER --username=USERNAME # or VI_USERNAME --password=PASSWORD # or VI_PASSWORD --vihost=HOST       # or '-h' - target host if connected to vCenter Server

Config file: (--config=CONFIG or VI_CONFIG) VI_SERVER= VI_USERNAME= VI_PASSWORD=

vicfg-hostops
vicfg-hostops --operation [OPERATION] enter    # enter maintenance mode exit     # exit maintenance mode reboot   # reboot server shutdown # shutdown server info     # server info
 * 1) also esxcfg-hostops
 * 2) Operation to perform:

vmkfstools
Help:

For a summary of command usage, type '/usr/bin/vmkfstools --help'. For documentation, type 'perldoc /usr/bin/vmkfstools'.

Paths:
 * Datastore prefix style: [ds_name] 
 * '[myStorage1] testvms/VM1/VM1.vmx' (Linux)
 * "[myStorage1] testvms\VM1\VM1.vmx" (Windows)
 * UUID-based path: folder/subfolder/file
 * '/vmfs/volumes/mystorage/testvms/VM1/VM1.vmx' (Linux)
 * "/vmfs/volumes/mystorage/testvms/VM1/VM1.vmx" (Windows)

Clone vmdk:

vmkfstools -d thin -i [old.vmdk] [new.vmdk] vmkfstools --diskformat thin --clonevirtualdisk [old.vmdk] [new.vmdk]
 * 1) --diskformat: [zeroedthick|eagerzeroedthick|thin]

vmkfstools -d thin -i /vmfs/volumes/fio1/myvm/myvm.vmdk /vmfs/volumes/fio1/myvm2/myvm2.vmdk

vifs --mkdir '[fio2] newvm' vmkfstools -d thin -i '[fio] myvm/myvm.vmdk' '[fio2] newvm/newvm2.vmdk'

NOTE: Will not create folders, these have to be pre-created. You will get an erroneous error about original vmdk not found.

Rename vmdk:

vmkfstools -E [old.vmdk] [new.vmdk] vmkfstools --renamevirtualdisk [old.vmdk] [new.vmdk]

References:
 * VMware KB: Manually creating a VMFS volume using vmkfstools -C - http://kb.vmware.com/kb/1009829

Spanning Extents
for i in /vmfs/devices/disks/mpx* ; do echo -e "d\nw" | fdisk $i ; done
 * 1) remove partitions:

for i in /vmfs/devices/disks/mpx* ; do echo -e "n\np\n1\n\n+100G\nt\nfb\nx\nb\n1\n128\nw\n" | fdisk $i ; done
 * 1) create 100GB partitions:

FIRST=mpx.vmhba2:C0:T0:L0:1 vmkfstools -C vmfs3 -b 4M /vmfs/devices/disks/$FIRST -S mega
 * 1) create VMFS on first:

for i in /vmfs/devices/disks/mpx* ; do echo "0" | vmkfstools --spanfs /vmfs/devices/disks/$i /vmfs/devices/disks/$FIRST ; done
 * 1) add others: (will soft fail on self)

vifs
Help:


 * vifs - perform file system operations on remote hosts - http://www.vmware.com/support/developer/vcli/vcli41/doc/reference/vifs.html
 * For a summary of command usage, type '/usr/bin/vifs --help'.
 * For documentation, type 'perldoc /usr/bin/vifs'.

vifs [] [--copy | --dir  | --help | --force | --get   | --listdc | --listds [--dc ] | --mkdir  | --move | --put   | --rm  | --rmdir  ]

List datastores: vifs --listds

Upload a file to the remote datastore: vifs  -p "tmp/backup/VM.pl" "[StorageName] VM/VM.txt" -Z "ha-datacenter"

Example of installing driver. vifs --server esx41 --username root --password Password1 --listds

vifs --server esx41 --username root --password Password1 --dir '[newpu]'

vifs --server esx41 --username root --password Password1 --mkdir '[newpu] fio-driver'

vifs --server esx41 --username root --password Password1 --put fio-driver.zip '[newpu] fio-driver/fio-driver.zip'


 * 1) install driver with esxcli

vifs --server esx41 --username root --password Password1 --rm '[newpu] fio-driver' --force

NFS Mount
vicfg-nas -a newpu -o newpu -s /home/esx # add: --add | -a # read only: --readonly | -y # nas server: --nasserver | -o

vicfg-nas -l # --list

vicfg-nas -d newpu # --delete

vmware-cmd
Help:
 * vmware-cmd - perform virtual machine operations - http://www.vmware.com/support/developer/vcli/vcli41/doc/reference/vmware-cmd.html
 * vmware-cmd --help

Target host:
 * If connecting to a vCenter Server, use '-h' to specify the target host

List registered VMs vmware-cmd -l                     # list full ugly path of all registered VMX files vmware-cmd -s register [VM.vmx]   # register VMX file vmware-cmd -s unregister [VM.vmx] # unregister VMX file

vmware-cmd -s unregister '[fio1] kk-27/kk-27.vmx'
 * 1) Example:

Power states: vmware-cmd [VM.vmx] getstate             # on, off, suspended, or unknown vmware-cmd [VM.vmx] start vmware-cmd [VM.vmx] stop [hard/soft] vmware-cmd [VM.vmx] reset [hard/soft]    # reboot a VM vmware-cmd [VM.vmx] suspend [hard/soft] vmware-cmd [VM.vmx] getuptime            # in seconds of guest OS

Snapshot: vmware-cmd [VM.vmx] createsnapshot   vmware-cmd [VM.vmx] revertsnapshot       # revert to current snapshot vmware-cmd [VM.vmx] removesnapshots      # removes all snapshots vmware-cmd [VM.vmx] hassnapshot          # returns 1 if snapshot exists

Answer: vmware-cmd [VM.vmx] answer # prompt user to answer question if pending

Connect Devices: vmware-cmd [VM.vmx] connectdevice  - connect a cd-rom or nic vmware-cmd [VM.vmx] disconnectdevice  - disconnect a cd-rom or nic

Guest tools heart beat: vmware-cmd [VM.vmx] gettoolslastactive - seconds since last heartbeat from guest tools # 0 -- VMware Tools are not installed or not running. (initially set to this when VM powered on) # 1 -- Guest operating system is responding normally. # 2 to 5 -- Intermittent heartbeat. There might be a problem with the guest operating system. # 6 to 100 -- No heartbeat. Guest operating system might have stopped responding.

All Commands: Server Operations: vmware-cmd -l vmware-cmd -s register <config_file_path> vmware-cmd -s unregister <config_file_path>

VM Operations: vmware-cmd getstate vmware-cmd start <powerop_mode> vmware-cmd stop <powerop_mode> vmware-cmd reset <powerop_mode> vmware-cmd suspend <powerop_mode> vmware-cmd setguestinfo vmware-cmd getguestinfo vmware-cmd getproductinfo vmware-cmd connectdevice <device_name> vmware-cmd disconnectdevice <device_name> vmware-cmd getconfigfile vmware-cmd getuptime vmware-cmd answer vmware-cmd gettoolslastactive vmware-cmd hassnapshot vmware-cmd createsnapshot vmware-cmd revertsnapshot vmware-cmd removesnapshots

Other commands:
 * setguestinfo - write variable to memory under direction of VMware support
 * getguestinfo - read variable from memory under direction of VMware support
 * getproductinfo - product, platform, build, majorversion (product major version number), or minorversion (product minor version number)
 * product = embeddedEsx
 * platform = vmnix-x86
 * build = 702118 * actually useful *
 * majorversion = 5
 * minorversion = 0
 * getconfigfile - worthless! Returns the path to the config file you provided!

Server version unavailable at VICommon.pm
Error: Server version unavailable at 'https://esx1:443/sdk/vimService.wsdl' at /usr/lib/perl5/5.8.8/VMware/VICommon.pm line 545.

Temporary Solution: export PERL_LWP_SSL_VERIFY_HOSTNAME=0

Permanent Solution: sed -i "s/package Util;/package Util;\n\$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;/g"  /usr/lib/perl5/5.8.8/VMware/VICommon.pm