VMWareSnips

From Custard
Jump to: navigation, search

Contents

VMWare ESXi VSphere CLI

Get the stuff

Installation

sudo apt-get install libssl-dev
sudo apt-get install libxml-libxml-perl
tar -zxvf VMware-vSphere-CLI-4.1.0-254719.i386.tar.gz
cd vmware-vsphere-cli-distrib/
sudo ./vmware-install.pl

I installed in /usr/local/bin

YMMV obv. You may need to install more libraries.


Usage

Create a session file

Optional. If you use a session, you need to use --sessionfile in each command instead of username / password

  • apps/session/save_session.pl --server 192.168.50.21 --savesessionfile /tmp/session
apps/session/save_session.pl --server 192.168.50.21 --savesessionfile /tmp/session
Enter username: root
Enter password: 
Session information saved.

List vmhosts on the server:

  • vmware-cmd -U root -P <password> --server 192.168.50.21 -l
  • vmware-cmd --sessionfile /tmp/session -l
jamesb@VMX-NODE0:~/vmware-vsphere-cli-distrib$ vmware-cmd -U root -P ******* --server 192.168.50.21 -l
...
/vmfs/volumes/4d8a8038-cb5b5320-dd78-001f0b61d59e/Test/Team_B.vmx
/vmfs/volumes/4d8a8038-cb5b5320-dd78-001f0b61d59e/Development/Team_A.vmx

Get ESXi Server info

  • vicfg-hostops --username root --password <password> --server 192.168.50.21 --operation info
  • vicfg-hostops --sessionfile /tmp/session --operation info
jamesb@VMX-NODE0:~/vmware-vsphere-cli-distrib$ vicfg-hostops --username root --password ******** --server 192.168.50.21 --operation info

Host Name            : vmhost.example.co.uk
Manufacturer         : HP
Model                : ProLiant DL360 G5
Processor Type       : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz
CPU Cores            : 8 CPUs x 1866 GHz
Memory Capacity      : 4093.71875 MB
VMotion Enabled      : no
In Maintenance Mode  : no
Last Boot Time       : 2011-07-26T16:57:25.643553Z

Shutdown ESXi Server

  • vicfg-hostops --username root --password <password> --server 192.168.50.21 --operation shutdown --force

nb. --force shuts down all running virtual machines

Reboot ESXi Server

  • vicfg-hostops --username root --password <password> --server 192.168.50.21 --operation reboot --force

nb. --force shuts down all running virtual machines

Powering ON a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx start soft

Powering OFF a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx stop soft

Suspend a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx suspend soft


Reset a Virtual Machine

  • vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>

/vmfs/volumes/Storage2/testvm/testvm.vmx reset soft


Convert VMWare image to VirtualBox

Prerequisites

  • Convert to raw bin
qemu-img convert MyVMWareMachine.vmdk raw-file.bin
  • Convert to VirtualBox image
VBoxManage convertdd raw-file.bin MyVirtualBoxMachine.vdi
  • Run Virtualbox and add the image to the library then Virtualbox again and compact the image with:
VBoxManage modifyvdi MyVirtualBoxMachine.vdi compact

And back to vmdk

qemu-img convert MyVirtualBoxMachine.vdi -O vmdk MyVMWareMachine.vmdk

External Documentation

Personal tools