Using the vSphere SDK/API in Ubuntu

The Perl vSphere SDK allows to use the esxcli and vmware-cmd from Linux which can be very convenient to script tasks and remotely manage vSphere VMs.

This is the setup for Ubuntu 12.04:

1. Install its requirements:

$ sudo apt-get install ia32-libs build-essential gcc uuid uuid-dev perl libssl-dev perl-doc liburi-perl libxml-libxml-perl libcrypt-ssleay-perl cpanminus
$ cpan -i LWP::UserAgent
$ cpan GAAS/Net-HTTP-6.03.tar.gz
$ cpan install GAAS/libwww-perl-6.03.tar.gz

2. Download and Install the package VMware-vSphere-Perl-SDK-5.5.0-292267.x86_64.tar

3. Untar VMware-vSphere-Perl-SDK-5.5.0-1292267.x86_64.tar and install it:

$ sudo ./vmware-vsphere-cli-distrib/

4. Test it.

Run it to list VMs:

$ vmware-cmd -H -U root -P ubuntu1! -l

/vmfs/volumes/51fe1a85-bb18fa16-4836-c8cbb8c706f5/vCenter 5.1/vCenter 5.1.vmx

Power on a VM

$ vmware-cmd -H -U root -P ubuntu "/vmfs/volumes/51fe1a85-bb18fa16-4836-c8cbb8c706f5/vCenter 5.1/vCenter 5.1.vmx” start

Test the esxcli command on the ESXi hosts to see the existing network connections:

$ esxcli -s -h -u root -p ubuntu1! network ip connection list|head
Proto  Recv Q  Send Q  Local Address       Foreign Address     State        World ID  World Name
-----  ------  ------  ------------------  ------------------  -----------  --------  --------------------------------------------
tcp         0       0     FIN_WAIT_2       3513  sfcb-HTTP-Daemo
tcp         0       0      CLOSE_WAIT       2937  hostd-worker
tcp         0       0  FIN_WAIT_2       3509  sfcb-HTTPS-Daem
tcp         0       0     ESTABLISHED    251019  hostd-worker
tcp         0       0      ESTABLISHED      3183  rhttpproxy-work
tcp         0       0     ESTABLISHED      3183  rhttpproxy-work
tcp         0       0        ESTABLISHED      3715  sfcb-vmware_bas
tcp         0       0   ESTABLISHED    250530  vmx-mks:52c84203-ce3d-47b4-ab22-1d30b2816298

2 thoughts on “Using the vSphere SDK/API in Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s