vmcreate.pl - Create Virtual Machines as per the specifications provided in the input XML file.
vmcreate.pl [options]
This command provides an interface for creating one or more new virtual machines based on the parameters specified in the input valid XML file. The syntax of the XML file is validated against the specified schema 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 'vmcreate.xml' will be used from the ``../sampledata'' directory. 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 'vmcreate.xsd' will be used from the ``../schema'' directory. 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> <Virtual-Machine> <!--Several parameters like machine name, guest OS, memory etc--> </Virtual-Machine> . . . <Virtual-Machine> </Virtual-Machine> </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 data center.
Optional. Guest operating system identifier. Default: 'winXPProGuest'. For the complete list of available values, see Enum - VirtualMachineGuestOsIdentifier in the vSphere API reference.
Optional. Name of the datastore. Default: Any accessible datastore with free space greater than the disk size 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
To create five virtual machines as specified, use the following input XML file:
<?xml version="1.0"?> <Virtual-Machines> <Virtual-Machine> <Name>Virtual_1</Name> <Host>192.168.111.2</Host> <Datacenter>Dracula</Datacenter> <Guest-Id>winNetEnterpriseGuest</Guest-Id> <Datastore>storage1</Datastore> <Disksize>4096</Disksize> <Memory>256</Memory> <Number-of-Processor>1</Number-of-Processor> <Nic-Network>VM Network</Nic-Network> <Nic-Poweron>0</Nic-Poweron> </Virtual-Machine> <Virtual-Machine> <Name>Virtual_2</Name> <Host>Host123</Host> <Datacenter>Dracula</Datacenter> <Guest-Id>rhel4Guest</Guest-Id> <Datastore>storage1</Datastore> <Disksize>4096</Disksize> <Memory>256</Memory> <Number-of-Processor>1</Number-of-Processor> <Nic-Network>VM Network</Nic-Network> <Nic-Poweron>0</Nic-Poweron> </Virtual-Machine> <Virtual-Machine> <Name>Virtual_3</Name> <Host>192.168.111.2</Host> <Datacenter>Dracula</Datacenter> <Guest-Id>winXPProGuest</Guest-Id> <Datastore>DataABC</Datastore> <Disksize>4096</Disksize> <Memory>256</Memory> <Number-of-Processor>1</Number-of-Processor> <Nic-Network>VM Network</Nic-Network> <Nic-Poweron>0</Nic-Poweron> </Virtual-Machine> <Virtual-Machine> <Name>Virtual_4</Name> <Host>192.168.111.2</Host> <Datacenter>Dracula</Datacenter> <Guest-Id>solaris9Guest</Guest-Id> <Datastore>storage1</Datastore> <Disksize></Disksize> <Memory>128</Memory> <Number-of-Processor>1</Number-of-Processor> <Nic-Network>VM Network</Nic-Network> <Nic-Poweron>0</Nic-Poweron> </Virtual-Machine> <Virtual-Machine> <Name>Virtual_5</Name> <Host>192.168.111.2</Host> <Datacenter>Dracula</Datacenter> <Guest-Id></Guest-Id> <Datastore>storage1</Datastore> <Disksize>2048</Disksize> <Memory>128</Memory> <Number-of-Processor>1</Number-of-Processor> <Nic-Network></Nic-Network> <Nic-Poweron>1</Nic-Poweron> </Virtual-Machine> </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 continues to create the next virtual machine even if a previous machine creation process failed. Sample output of the command:
-------------------------------------------------------------- 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' --------------------------------------------------------------