“my-vmware-cmd” was developed to aid in the day-to-day management of our VDI environment. This script allows specific operations to be executed across a specified set of virtual machines by utilizing a subset of available VMware service console operations. Although specific to our VDI environment, the script is versatile in that it can be extended to other virtual machine environments.
Compatiable with:
VMware ESX 3.5 Update 3
VMware ESXi 3.5 Installable Update 3
VMware ESX 3.5 Update 2
VMware ESXi 3.5 Installable Update 2
VMware ESX 3.5 Update 1
VMware ESXi 3.5 Installable Update 1
VMware ESX 3.5
VMware ESXi 3.5 Installable
VMware ESX Server 3.0.3
VMware ESX Server 3.0.2 Update 1
VMware ESX Server 3.0.2
VMware ESX Server 3.0.1
VMware ESX Server 3.0.0
The script accepts a text file that specifies virtual machine display names. In addition to running the script locally on an ESX/ESXi host, the script can be executed remotely from a centralized host such as an administrative UNIX/Linux system that has access to the ESX/ESXi hosts that the virtual machines reside on.
Usage: Local execution- my-vmware-cmd.sh [operation] [vm_input_file] <optional_arguments> Remote execution- my-vmware-cmd.sh remote [ESX_ESXI_IP_ADDRESS] [operation] [vm_input_file] <optional_arguments> Operations: start [vm_input_file] -- Start all VMs in the input file stop [vm_input_file] -- Stop all VMs in the input file suspend [vm_input_file] -- Suspend all VMs in the input file resume [vm_input_file] -- Resume all suspended VMs in the input file reset [vm_input_file] -- Hard reset all VMs in the input file shutdown [vm_input_file] -- Shutdown all VMs in the input file (VMware Tools required) reboot [vm_input_file] -- Reboot all VMs in the input file (VMware Tools required) snap [vm_input_file] -- Create administrative pristine snapshot of all VMs in the input file revert [vm_input_file] -- Revert all VMs in the input file back to pristine state purge [vm_input_file] -- Removes from local inventory and purges all VMs in the input file mac [vm_input_file] [generic|nixdhcp] [http://NETWORK (172.30.0)|http://NETWORK (172.30.0)] [HOST_COUNT_START (200)] <NIC_#> default=0 -- Extracts MAC addresses and generates either a generic file or one compatible with *nix dhcpd ( e.g. my-vmware-cmd.sh mac [vm_input_file] generic ) ( e.g. my-vmware-cmd.sh mac [vm_input_file] nixdhcp 172.30.0 200 ) vnic [vm_input_file] <NIC_#> default=0 -- Change vNic portgroup for all VMs in the input file ( e.g. my-vmware-cmd.sh vnic [vm_input_file] 3 )
The majority of operations are relatively self explanatory; this document will focus on three operations that are specific to our VDI environment.
purge
mac
vnic
These operations will be demonstrated across 32 linked clones that have been generated from the developed ghetto-esx-linked-clones.sh script.
-
This operation unregisters and removes specified linked clones that have been generated from ghetto-esx(i)-linked-clones.sh. Linked clones must be purged prior to updating the Master VM image associated to the clones. The issue arises from the fact that linked clones are tied to the Master VMDK. Modifications to respective Master images are not possible until associated LCs are destroyed. When a “delete from disk” operation is issued in VIClient on said VMs, all attributes of the VMs will be removed including referenced VMDKs. In this circumstance, the Master VMDK in which all linked clones are referencing will be removed.
Basically, the purge operation handles linked clone deletions properly by locally unregistering specified linked clones and deleting their respective directories while leaving the Master VM image intact. One caveat to this process is that the inventory change will be reflected on Virtual Center as an orphaned VM. In this case, one just needs to issue ”remove from inventory” operations on the orphaned VMs.
Virtual Machine Input file(s):
[root@olga lamw]# cat vm_input_file_1 LinkedCLones-1 LinkedCLones-2 LinkedCLones-3 LinkedCLones-4 LinkedCLones-5 LinkedCLones-6 LinkedCLones-7 LinkedCLones-8 LinkedCLones-9 LinkedCLones-10 LinkedCLones-11 LinkedCLones-12 LinkedCLones-13 LinkedCLones-14 LinkedCLones-15 LinkedCLones-16 [root@olga lamw]# cat vm_input_file_2 LinkedCLones-17 LinkedCLones-18 LinkedCLones-19 LinkedCLones-20 LinkedCLones-21 LinkedCLones-22 LinkedCLones-23 LinkedCLones-24 LinkedCLones-25 LinkedCLones-26 LinkedCLones-27 LinkedCLones-28 LinkedCLones-29 LinkedCLones-30 LinkedCLones-31 LinkedCLones-32
Local Execution on ESX host:
[root@olga lamw]# vmware -v VMware ESX Server 3.5.0 build-123630 [root@olga lamw]# ./my-vmware-cmd.sh purge vm_input_file_1 ############################################################################### # # UCSB ResNet Virtual Machine Managment Tool for VMware ESX 3.5+ and ESXi # Author: william2003[at]gmail[dot]com # Created: 07/05/2008 # ############################################################################### Validating Virtual Machine list against VMs on ESX Server: olga.resnet.ucsb.edu "LinkedCLones-1" "LinkedCLones-2" "LinkedCLones-3" "LinkedCLones-4" "LinkedCLones-5" "LinkedCLones-6" "LinkedCLones-7" "LinkedCLones-8" "LinkedCLones-9" "LinkedCLones-10" "LinkedCLones-11" "LinkedCLones-12" "LinkedCLones-13" "LinkedCLones-14" "LinkedCLones-15" "LinkedCLones-16" Purge the following 16 Virtual Machine(s) y/n? y
Purging Virtual Machines in the specified list:
Purging has been confirmed for the following 16 Virtual machine(s) Unregistering "LinkedCLones-1" VM_ID=15856 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-1 Unregistering "LinkedCLones-2" VM_ID=15872 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-2 Unregistering "LinkedCLones-3" VM_ID=15888 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-3 Unregistering "LinkedCLones-4" VM_ID=15904 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-4 Unregistering "LinkedCLones-5" VM_ID=15920 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-5 Unregistering "LinkedCLones-6" VM_ID=15936 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-6 Unregistering "LinkedCLones-7" VM_ID=15952 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-7 Unregistering "LinkedCLones-8" VM_ID=15968 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-8 Unregistering "LinkedCLones-9" VM_ID=15984 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-9 Unregistering "LinkedCLones-10" VM_ID=16000 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-10 Unregistering "LinkedCLones-11" VM_ID=16016 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-11 Unregistering "LinkedCLones-12" VM_ID=16032 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-12 Unregistering "LinkedCLones-13" VM_ID=16048 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-13 Unregistering "LinkedCLones-14" VM_ID=16064 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-14 Unregistering "LinkedCLones-15" VM_ID=16080 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-15 Unregistering "LinkedCLones-16" VM_ID=16096 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-16 Start time: Mon Dec 8 22:45:36 PST 2008 End time: Mon Dec 8 22:46:11 PST 2008 Duration : 35 Seconds Completed purge for all specified Virtual Machines!
Remote Execution on non-ESX host (VIMA):
[vi-admin@vima-primp-industries ~]$ vmware -v -bash: vmware: command not found [vi-admin@vima-primp-industries ~]$ uname -a Linux vima-primp-industries.com 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux [vi-admin@vima-primp-industries ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.2 (Tikanga) [vi-admin@vima-primp-industries ~]$ [vi-admin@vima-primp-industries ~]$ ./my-vmware-cmd.sh remote 172.30.0.64 purge vm_input_file_2 ############################################################################### # # UCSB ResNet Virtual Machine Managment Tool for VMware ESX 3.5+ and ESXi # Author: william2003[at]gmail[dot]com # Created: 07/05/2008 # ############################################################################### Executing remote operation: "purge" on host: 172.30.0.64 with the following specified Virtual Machines: ##################################### LinkedCLones-17 LinkedCLones-18 LinkedCLones-19 LinkedCLones-20 LinkedCLones-21 LinkedCLones-22 LinkedCLones-23 LinkedCLones-24 LinkedCLones-25 LinkedCLones-26 LinkedCLones-27 LinkedCLones-28 LinkedCLones-29 LinkedCLones-30 LinkedCLones-31 LinkedCLones-32 ##################################### OPERATION WILL BE EXECUTED IMMEDIATELY ONCE AUTHENTICATION ON REMOTE HOST SUCCEEDS! Would you like to continue y/n? y
Purging Virtual Machines in the specified list:
root@172.30.0.64's password: Validating Virtual Machine list against VMs on ESX Server: olga.resnet.ucsb.edu Unregistering "LinkedCLones-17" VM_ID=16112 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-17 Unregistering "LinkedCLones-18" VM_ID=16128 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-18 Unregistering "LinkedCLones-19" VM_ID=16144 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-19 Unregistering "LinkedCLones-20" VM_ID=16160 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-20 Unregistering "LinkedCLones-21" VM_ID=16176 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-21 Unregistering "LinkedCLones-22" VM_ID=16192 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-22 Unregistering "LinkedCLones-23" VM_ID=16208 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-23 Unregistering "LinkedCLones-24" VM_ID=16224 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-24 Unregistering "LinkedCLones-25" VM_ID=16240 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-25 Unregistering "LinkedCLones-26" VM_ID=16256 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-26 Unregistering "LinkedCLones-27" VM_ID=16272 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-27 Unregistering "LinkedCLones-28" VM_ID=16288 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-28 Unregistering "LinkedCLones-29" VM_ID=16304 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-29 Unregistering "LinkedCLones-30" VM_ID=16320 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-30 Unregistering "LinkedCLones-31" VM_ID=16336 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-31 Unregistering "LinkedCLones-32" VM_ID=16352 and removing /vmfs/volumes/dlgCore-FC-LUN200.Templates/LinkedCLones-32 Start time: Mon Dec 8 22:56:45 PST 2008 End time: Mon Dec 8 22:57:19 PST 2008 Duration : 34 Seconds Completed purge for all specified Virtual Machines!
-
This operation extracts MAC addresses associated with specified VMs and outputs a file named: "dhcp-eth#-YYYY-MM-DD-HHMMSS". This outputted file can then be used to reserve IPs on either Windows or *nix DHCP servers. There are two output options, one being a generic output relating VM names to their respective MAC address and the other a prepared file that is compatible with popular *nix dhcpd releases.
Local Execution on ESXi host:
~ # vmware -v VMware ESX Server 3i 3.5.0 build-123629 ~ # ./my-vmware-cmd.sh mac vm_input_file generic ############################################################################### # # UCSB ResNet Virtual Machine Managment Tool for VMware ESX 3.x and ESXi # Author: william2003[at]gmail[dot]com # Created: 07/05/2008 # ############################################################################### Validating Virtual Machine list against VMs on ESX Server: olga.resnet.ucsb.edu Start time: Sat Dec 20 03:38:55 UTC 2008 End time: Sat Dec 20 03:38:58 UTC 2008 Duration : 3 Seconds Completed "dhcp-eth0-2008-12-20-033855" generation file for all specified Virtual Machines! ~ # ~ # cat dhcp-eth0-2008-12-20-033855 LinkedClones1 005056b45d33 LinkedClones10 005056b45a2f LinkedClones11 005056b450ec LinkedClones12 005056b44182 LinkedClones13 005056b43790 LinkedClones14 005056b40346 LinkedClones15 005056b407fb LinkedClones16 005056b42a3f LinkedClones17 005056b44c11 LinkedClones18 005056b41f24 LinkedClones19 005056b42308 LinkedClones2 005056b4440f LinkedClones20 005056b47039 LinkedClones21 005056b44219 LinkedClones22 005056b4699b LinkedClones23 005056b42e7c LinkedClones24 005056b4028b LinkedClones25 005056b46f1c LinkedClones26 005056b42299 LinkedClones27 005056b4225e LinkedClones28 005056b42eed LinkedClones29 005056b425fd LinkedClones3 005056b42502 LinkedClones30 005056b45556 LinkedClones31 005056b477c3 LinkedClones32 005056b425df LinkedClones4 005056b428d7 LinkedClones5 005056b4602f LinkedClones6 005056b46e43 LinkedClones7 005056b41139 LinkedClones8 005056b4683d LinkedClones9 005056b40566 ~ #
Remote Execution on non ESX host (VIMA):
[vi-admin@vima-primp-industries ~]$ vmware -v -bash: vmware: command not found [vi-admin@vima-primp-industries ~]$ uname -a Linux vima-primp-industries.com 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux [vi-admin@vima-primp-industries ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.2 (Tikanga) [vi-admin@vima-primp-industries ~]$ [vi-admin@vima-primp-industries ~]$ ./my-vmware-cmd.sh remote 172.30.0.64 mac vm_input_file linux 172.30.200 50 ############################################################################### # # UCSB ResNet Virtual Machine Managment Tool for VMware ESX 3.x and ESXi # Author: william2003[at]gmail[dot]com # Created: 07/05/2008 # ############################################################################### Connecting to 172.30.0.64 to extract MAC Addresses: root@172.30.0.64's password: Completed "dhcp-2008-12-06-182712" generation file for all specified Virtual Machines! [vi-admin@vima-primp-industries ~]$ cat dhcp-2008-12-06-182712 host LinkedClones-1 { hardware ethernet 00:50:56:b4:19:f8; fixed-address 172.30.200.50; } host LinkedClones-2 { hardware ethernet 00:50:56:b4:3f:7b; fixed-address 172.30.200.51; } host LinkedClones-3 { hardware ethernet 00:50:56:b4:36:af; fixed-address 172.30.200.52; } host LinkedClones-4 { hardware ethernet 00:50:56:b4:0a:13; fixed-address 172.30.200.53; } host LinkedClones-5 { hardware ethernet 00:50:56:b4:4c:cb; fixed-address 172.30.200.54; } host LinkedClones-6 { hardware ethernet 00:50:56:b4:26:a9; fixed-address 172.30.200.55; } host LinkedClones-7 { hardware ethernet 00:50:56:b4:7c:f0; fixed-address 172.30.200.56; } host LinkedClones-8 { hardware ethernet 00:50:56:b4:31:6f; fixed-address 172.30.200.57; } host LinkedClones-9 { hardware ethernet 00:50:56:b4:1f:75; fixed-address 172.30.200.58; } host LinkedClones-10 { hardware ethernet 00:50:56:b4:55:9b; fixed-address 172.30.200.59; } host LinkedClones-11 { hardware ethernet 00:50:56:b4:3b:8d; fixed-address 172.30.200.60; } host LinkedClones-12 { hardware ethernet 00:50:56:b4:45:b8; fixed-address 172.30.200.61; } host LinkedClones-13 { hardware ethernet 00:50:56:b4:1f:29; fixed-address 172.30.200.62; } host LinkedClones-14 { hardware ethernet 00:50:56:b4:5d:14; fixed-address 172.30.200.63; } host LinkedClones-15 { hardware ethernet 00:50:56:b4:03:98; fixed-address 172.30.200.64; } host LinkedClones-16 { hardware ethernet 00:50:56:b4:4f:81; fixed-address 172.30.200.65; } host LinkedClones-17 { hardware ethernet 00:50:56:b4:3b:43; fixed-address 172.30.200.66; } host LinkedClones-18 { hardware ethernet 00:50:56:b4:0b:85; fixed-address 172.30.200.67; } host LinkedClones-19 { hardware ethernet 00:50:56:b4:5e:0a; fixed-address 172.30.200.68; } host LinkedClones-20 { hardware ethernet 00:50:56:b4:12:14; fixed-address 172.30.200.69; } host LinkedClones-21 { hardware ethernet 00:50:56:b4:06:08; fixed-address 172.30.200.70; } host LinkedClones-22 { hardware ethernet 00:50:56:b4:45:55; fixed-address 172.30.200.71; } host LinkedClones-23 { hardware ethernet 00:50:56:b4:67:b0; fixed-address 172.30.200.72; } host LinkedClones-24 { hardware ethernet 00:50:56:b4:48:12; fixed-address 172.30.200.73; } host LinkedClones-25 { hardware ethernet 00:50:56:b4:48:c3; fixed-address 172.30.200.74; } host LinkedClones-26 { hardware ethernet 00:50:56:b4:38:50; fixed-address 172.30.200.75; } host LinkedClones-27 { hardware ethernet 00:50:56:b4:3f:ac; fixed-address 172.30.200.76; } host LinkedClones-28 { hardware ethernet 00:50:56:b4:68:c9; fixed-address 172.30.200.77; } host LinkedClones-29 { hardware ethernet 00:50:56:b4:72:a4; fixed-address 172.30.200.78; } host LinkedClones-30 { hardware ethernet 00:50:56:b4:66:78; fixed-address 172.30.200.79; } host LinkedClones-31 { hardware ethernet 00:50:56:b4:53:e7; fixed-address 172.30.200.80; } host LinkedClones-32 { hardware ethernet 00:50:56:b4:2f:8b; fixed-address 172.30.200.81; }
-
This operation reconfigures the portgroup of the specified vNic (default eth0) for a given set of VMs. This operation supports remote execution but requires 2 SSH authentications by design. The operation also requires that the VMs in question be powered off prior to execution. Unfortunately due to the limitation of the CLI, there is currently no dynamic way of modifying the vNic portgroup while the VM is powered on.
1. Portgroup Selection:
[root@olga lamw]# ./my-vmware-cmd.sh vnic vm_input_file_1 ############################################################################### # # UCSB ResNet Virtual Machine Managment Tool for VMware ESX 3.x and ESXi # Author: william2003[at]gmail[dot]com # Created: 07/05/2008 # ############################################################################### Validating Virtual Machine list against VMs on ESX Server: olga.resnet.ucsb.edu CHOICE VLAN ID PORTGROUP ------------------------------------------ 1 4095 trunk.PassThrough 2 3252 dev.3252-172.30.52-24 3 3249 dev.3249-172.30.49-24 4 3248 dev.3248-172.30.48-24 5 333 nc.333-172.30.0-24 6 90 labs.90-172.30.90-23 7 333 SC.NC333 8 100 SC.Core100 9 3251 VMk.3251 10 0 IsolatedNetwork 11 Quit Please select a portgroup to apply to the following Virtual Machine(s): 10
2. Portgroup configuration:
"LinkedClones-1" "LinkedClones-2" "LinkedClones-3" "LinkedClones-4" "LinkedClones-5" "LinkedClones-6" "LinkedClones-7" "LinkedClones-8" "LinkedClones-9" "LinkedClones-10" "LinkedClones-11" "LinkedClones-12" "LinkedClones-13" "LinkedClones-14" "LinkedClones-15" "LinkedClones-16" Would you like to update the Network configuration for "eth0" to apply "labs.90-172.30.90-23" to the following 16 Virtual Machine(s) y/n? y VM Network Portgroup update will take affect for the following 16 Virtual machine(s) Completed configuring LinkedClones-1 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-2 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-3 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-4 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-5 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-6 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-7 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-8 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-9 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-10 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-11 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-12 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-13 from "IsolatedNetwork" to "labs.90-172.30.90-23 Completed configuring LinkedClones-14 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-15 from "IsolatedNetwork" to "labs.90-172.30.90-23" Completed configuring LinkedClones-16 from "IsolatedNetwork" to "labs.90-172.30.90-23" Start time: Tue Dec 9 18:37:05 PST 2008 End time: Tue Dec 9 18:37:49 PST 2008 Duration : 44 Seconds Completed Network Configurations for all specified Virtual Machines!
-
1. When running "my-vmware-cmd" on ESXi and using operation "vnic", you may see the following warning output, this can be ignored, this is due to some of the limited capabilities of the binaries in the busy box environment.
Warning Message
Please select a portgroup to apply to the following Virtual Machine(s): bash: Network: unknown operand
It seems, somehow this file got upon the server in "DOS" format
dos2unix helped to get rid of error
--> "bash: /.../my-vmware-cmd.sh: /bin/bash^M: bad interpreter: ..."
when trying to run it after download ( note the "^M" ! ).
Thanks a lot - will give it a try now!
Trying to upgrade vCloud Usage Meter from 3.6.1 to 4.3. Since this requires a new appliance for 4.3, I need to run both old and new in parallel for a while to verify correct usage. To do this I need to change time on 3.6.1 to UTC to match UTC time on new 4.3 um. Not sue why I can't just set localtime on new um to that of 3.6.1 um but trying to follow recommended upgrade procedure. Anyone know how to convert localtime to UTC?
TIA.
Mark