vmcreate.pl - Create virtual machines.
vmcreate.pl --url <web service URL> --username <server login name>
--password <server login password> [--filename <input XML file location>]
[--schema <schema file location>]
This VI Perl command-line utility provides an interface for creating one or more new virtual machines based on the parameters specified in the input XML file.
Optional. The location of the XML file which contains the specifications of the virtual machines to be created. If this option is not specified, then the default file 'create_vm.xml' will be used from the current dirctory. The user can use this file as a referance to create there own input XML files and specify the file's location using <filename> option.
Optional. The location of the schema file against which the input XML file is validated. If this option is not specified, then the file 'schema.xsd' will be used from the current dirctory. This file need not be modified by the user.
The parameters for creating the virtual machine are specified in an XML file. The structure of the input XML file is:
<virtual-machines>
<VM>
<!--Several parameters like machine name, guest OS, memory etc-->
</VM>
.
.
.
<VM>
</VM>
</virtual-machines>
Following are the input parameters:
Required. Name of the virtual machine to be created.
Required. Name of the host.
Required. Name of the datacenter.
Optional. Guest operating system identifier. Default: 'winXPProGuest'.
Optional. Name of the datastore. Default: Any accessible datastore with free space greater than the disksize specified.
Optional. Capacity of the virtual disk (in KB). Default: 4096
Optional. Size of virtual machine's memory (in MB). Default: 256
Optional. Number of virtual processors in a virtual machine. Default: 1
Optional. Network name. Default: Any accessible network.
Optional. Flag to specify whether or not to connect the device when the virtual machine starts. Default: 1
Create five new virtual machines with the following configuration :
Machine 1:
Name : Virtual_1
Host : 192.168.111.2
Datacenter : Dracula
Guest Os : Windows Server 2003, Enterprise Edition
Datastore : storage1
Disk size : 4096 KB
Memory : 256 MB
Number of CPUs : 1
Network : VM Network
nic_poweron flag : 0
Machine 2:
Name : Virtual_2
Host : <Any Invalid Name, say Host123>
Datacenter : Dracula
Guest Os : Red Hat Enterprise Linux 4
Datastore : storage1
Disk size : 4096 KB
Memory : 256 MB
Number of CPUs : 1
Network : VM Network
nic_poweron flag : 0
Machine 3:
Name : Virtual_3
Host : 192.168.111.2
Datacenter : Dracula
Guest Os : Windows XP Professional
Datastore : <Invalid datastore name, say DataABC>
Disk size : 4096 KB
Memory : 256 MB
Number of CPUs : 1
Network : VM Network
nic_poweron flag : 0
Machine 4: Name : Virtual_4 Host : 192.168.111.2 Datacenter : Dracula Guest Os : Solaris 9 Datastore : storage1 Disk size : <No disk size; default value will be used> Memory : 128 MB Number of CPUs : 1 Network : VM Network nic_poweron flag : 0
Machine 5:
Name : Virtual_5
Host : 192.168.111.2
Datacenter : Dracula
Guest Os : <No guest OS, default will be used>
Datastore : storage1
Disk size : 2048 KB
Memory : 128 MB
Number of CPUs : 1
Network : <No network name, default will be used>
nic_poweron flag : 1
As per the above specifications for five VMs, the input XML file should be as follows:
<?xml version="1.0"?>
<virtual-machines>
<VM>
<vmname>Virtual_1</vmname>
<vmhost>192.168.111.2</vmhost>
<datacenter>Dracula</datacenter>
<guestid>winNetEnterpriseGuest</guestid>
<datastore>storage1</datastore>
<disksize>4096</disksize>
<memory>256</memory>
<num_cpus>1</num_cpus>
<nic_network>VM Network</nic_network>
<nic_poweron>0</nic_poweron>
</VM>
<VM>
<vmname>Virtual_2</vmname>
<vmhost>Host123</vmhost>
<datacenter>Dracula</datacenter>
<guestid>rhel4Guest</guestid>
<datastore>storage1</datastore>
<disksize>4096</disksize>
<memory>256</memory>
<num_cpus>1</num_cpus>
<nic_network>VM Network</nic_network>
<nic_poweron>0</nic_poweron>
</VM>
<VM>
<vmname>Virtual_3</vmname>
<vmhost>192.168.111.2</vmhost>
<datacenter>Dracula</datacenter>
<guestid>winXPProGuest</guestid>
<datastore>DataABC</datastore>
<disksize>4096</disksize>
<memory>256</memory>
<num_cpus>1</num_cpus>
<nic_network>VM Network</nic_network>
<nic_poweron>0</nic_poweron>
</VM>
<VM>
<vmname>Virtual_4</vmname>
<vmhost>192.168.111.2</vmhost>
<datacenter>Dracula</datacenter>
<guestid>solaris9Guest</guestid>
<datastore>storage1</datastore>
<disksize></disksize>
<memory>128</memory>
<num_cpus>1</num_cpus>
<nic_network>VM Network</nic_network>
<nic_poweron>0</nic_poweron>
</VM>
<VM>
<vmname>Virtual_5</vmname>
<vmhost>192.168.111.2</vmhost>
<datacenter>Dracula</datacenter>
<guestid></guestid>
<datastore>storage1</datastore>
<disksize>2048</disksize>
<memory>128</memory>
<num_cpus>1</num_cpus>
<nic_network></nic_network>
<nic_poweron>1</nic_poweron>
</VM>
</virtual-machines>
The command to run the vmcreate script is:
vmcreate.pl --url https://192.168.111.52:443/sdk/webService
--username administrator --password mypassword
--filename create_vm.xml --schema schema.xsd
The script will continue to create the next virtual machines even if some previous machine creation process is failed.
The output of the above script is:
-------------------------------------------------------------- Successfully created virtual machine: 'Virtual_1'
Error creating VM 'Virtual_2': Host 'Host123' not found
Error creating VM 'Virtual_3': Datastore DataABC not available.
Successfully created virtual machine: 'Virtual_4'
Successfully created virtual machine: 'Virtual_5' --------------------------------------------------------------
Create operation work with VMware VirtualCenter 2.0 or later.