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/
-
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
Installation
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
# vSphere CLI 5.0.0 build-3422456 for Linux installer tar -zvxf VMware-vSphere-CLI-5.0.0-422456.x86_64.tar.gz cd vmware-vsphere-cli-distrib export ftp_proxy= export http_proxy= # answer 'yes' to license agreement ./vmware-install.pl --default
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 .
# solution: export ftp_proxy= export http_proxy=
---
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
# Which package provided? It is very outdated... apt-cache search LWP::Protocol::https libcrypt-ssleay-perl - Support for https protocol in LWP # solution - cpan fix for 'LWP::Protocol::https' package: cpan LWP::Protocol::https
# solution - cpan fix for 'version' package: cpan version
# solution - stop the YAML messages: cpan YAML
---
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, <STDIN> line 2.
# Test connection - should return nothing curl -k https://10.10.23.140/sdk
# quick test: /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 # should return: Connection Successful Server Time : 2011-10-07T17:59:14.920323Z # not: Server version unavailable at 'https://10.10.23.140:443/sdk/vimService.wsdl' at /usr/share/perl/5.10/VMware/VICommon.pm line 545.
# solution - cause is a proxy??
VMware Communities: Error: Server version unavailable at... http://communities.vmware.com/thread/240659?tstart=0
# dependencies: apt-get install libxml2-dev libcompress-zlib-perl libxml-perl cpan XML::LibXML
# SOLUTION: 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;
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
# if that doesn't work... 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
# if that still doesn't work??? yum install perl-IO-Socket-SSL
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.
---
# esxcli -bash: /usr/bin/esxcli: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
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]
# also esxcfg-hostops # Operation to perform: enter # enter maintenance mode exit # exit maintenance mode reboot # reboot server shutdown # shutdown server info # server info
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] <relative_path>
- '[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] # --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
# remove partitions: for i in /vmfs/devices/disks/mpx* ; do echo -e "d\nw" | fdisk $i ; done # create 100GB 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 # create VMFS on first: FIRST=mpx.vmhba2:C0:T0:L0:1 vmkfstools -C vmfs3 -b 4M /vmfs/devices/disks/$FIRST -S mega # add others: (will soft fail on self) for i in /vmfs/devices/disks/mpx* ; do echo "0" | vmkfstools --spanfs /vmfs/devices/disks/$i /vmfs/devices/disks/$FIRST ; done
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 [<connection_options>] [--copy <source> <target> | --dir <remote_dir> | --help | --force | --get <remote_path> <local_path> | --listdc | --listds [--dc <datacenter>] | --mkdir <remote_dir> | --move <source> <target> | --put <local_path> <remote_path> | --rm <remote_path> | --rmdir <remote_dir> ]
List datastores:
vifs --listds
Upload a file to the remote datastore:
vifs <connection_options> -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' # 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
# Example: vmware-cmd -s unregister '[fio1] kk-27/kk-27.vmx'
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 <name> <description> <quiesce 0|1> <memory 0|1> 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 <device_name> - connect a cd-rom or nic vmware-cmd [VM.vmx] disconnectdevice <device_name> - 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> <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
Other commands:
- setguestinfo <variable> <value> - write variable to memory under direction of VMware support
- getguestinfo <variable> - read variable from memory under direction of VMware support
- getproductinfo <prodinfo> - 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!
Issues
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