As I introduced in the article on vim-cmd commands, you can use a very simple command as follows to create a new virtual machine. Alternatively, you can ignore the path after the datastore and provide only datastore name (The [ and ] are still needed).
# vim-cmd vmsvc/createdummyvm testVM “[datastore1] testVM/testVM.vmx"
Bothered by SLOW Web UI to manage vSphere? Want to manage ALL your VMware vCenters, AWS, Azure, Openstack, container behind a SINGLE pane of glass? Want to search, analyze, report, visualize VMs, hosts, networks, datastores, events as easily as Google the Web? Find out more about vSearch 3.0: the search engine for all your private and public clouds.
Other than the name and configuration file path in data store, there is no additional information provided such as the size of the disk, memory capacity, etc. Normally, you have to go through a wizard of several pages to create a new virtual machine.
So, what’s special about the virtual machine created by the vim-cmd? The sub-command name itself “createdummyvm” has hinted something. The new virtual machine is a dummy virtual machine – which means it does not have guest OS installed and cannot even be powered on. Besides that, it’s also a very small sized virtual machine in terms of memory and hard disk. The “Edit Settings” dialog box shows that the dummy virtual machine has 1M memory and 32M of disk, probably is good enough for DOS of 20+ years ago.
Although you cannot do much useful with the dummy virtual machine, it’s good for testing. Except that there is no guest OS (consequently, no VMware Tools), a dummy virtual machine is a virtual machine. A great use case of dummy virtual machines is for testing – what if you want a populated inventory as your testing environment?
You can create a test environment with hundreds of virtual machines very quickly.
# vi /var/opt/createvms.py
#!/bin/python import os import sys for i in range(0, int(sys.argv)): vmname = "testvm%d" % i os.system("vim-cmd vmsvc/createdummyvm " + vmname + " \"[datastore1] /" + vmname + ".vmx\"")
After the Python script is ready, mark it as executable as follows. When you run the python code, you can specify the number of dummy virtual machines to create. There is no limit with the script, but there is a limit on vSphere ESXi side. I think it’s 512 virtual machines per host. Don’t try a number bigger than that at all.
# chmod 755 /var/opt/createvms.py # /var/opt/createvms.py 200
You can change the script to name the virtual machine name prefix to whatever name you want.