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/vmware-install.pl

4. Test it.

Run it to list VMs:

$ vmware-cmd -H 192.168.2.202 -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 192.168.2.202 -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 192.168.2.22 -h 192.168.2.200 -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  127.0.0.1:5988      127.0.0.1:60509     FIN_WAIT_2       3513  sfcb-HTTP-Daemo
tcp         0       0  127.0.0.1:60509     127.0.0.1:5988      CLOSE_WAIT       2937  hostd-worker
tcp         0       0  192.168.2.200:5989  192.168.2.22:49411  FIN_WAIT_2       3509  sfcb-HTTPS-Daem
tcp         0       0  127.0.0.1:8307      127.0.0.1:58948     ESTABLISHED    251019  hostd-worker
tcp         0       0  127.0.0.1:58948     127.0.0.1:8307      ESTABLISHED      3183  rhttpproxy-work
tcp         0       0  127.0.0.1:80        127.0.0.1:56343     ESTABLISHED      3183  rhttpproxy-work
tcp         0       0  127.0.0.1:56343     127.0.0.1:80        ESTABLISHED      3715  sfcb-vmware_bas
tcp         0       0  192.168.2.200:6102  192.168.2.7:55644   ESTABLISHED    250530  vmx-mks:52c84203-ce3d-47b4-ab22-1d30b2816298
Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s