Monday, May 11, 2015

VMware CLI management

I'm trying to use command line interface as much as I can.  Below are some examples of VMware CLI management.

Get a list of all VMs:
vim-cmd vmsvc/getallvms
Take a look at template:
/vmfs/volumes/541abff4-d8f5aafc-5d95-002590e90bb0 # /vmfs/volumes/datastore1/vmwa
re-ovftool/ovftool prve-loadtest.ova
Deploy VM from Windows ovf tool:
C:\Program Files (x86)\VMware\VMware OVF Tool>ovftool --disableVerification --no
SSLVerify -dm=thick --datastore=datastore1 --name=loadtest1  --net:"VM Net
work"="VM Network" c:\Users\igrinkin\loadtest.ova vi://root:root_password@hypervisor1
Opening OVA source: c:\Users\igrinkin\loadtest.ova
Opening VI target: vi://root@10.107.130.29:443/
Deploying to VI: vi://root@10.107.130.29:443/
Transfer Completed
The manifest validates
Warning:
 - No manifest entry found for: 'loadtest1-disk1.vmdk'.
Completed successfully

Copy VM to another ESX server

ssh hypervisor1
cd /vmfs/volumes/datastore1/
scp -r /vmfs/volumes/datastore1/testvm/ hypervisor2:/vmfs/volumes/datastore1/
Open hypervisor2 in vSphere
Configuration - Storage - right-click on datastore1 - Browse to "testvm" folder - click on testvm.vmx - Add to inventory
Remove VM from hypervisor1 to cleanup
You can easily script it to emulate what Vcenter does.

Add a second hard drive to VM without reboot

Add second drive to live server.
Run
echo "- - -" > /sys/class/scsi_host/host2/scan
fdisk should show you the second drive.  Create partition and format.
mkfs.ext3 -m0 /dev/sdb1
tune2fs -c0 -i0 /dev/sdb1

No comments: