Vous êtes sur la page 1sur 21

#!

/usr/bin/perl -w
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../";
use lib "/usr/lib/vmware-vcli/apps";
use lib "/opt/vmware-vsphere-cli-distrib/apps";
use VMware::VIRuntime;
use XML::LibXML;
use AppUtil::VMUtil;
use AppUtil::HostUtil;
use AppUtil::XMLInputUtil;
$Util::script_version = "1.0";
#################################################
# Defaults
#################################################
my $timezone = 110;
my $cpus = 1;
my $memory = 6144;
#################################################
sub check_missing_value;
my %opts = (
vmhost => {
type => "=s",
help => "The name of the host",
required => 0,
},
vmname => {
type => "=s",
help => "The name of the Virtual Machine",
required => 1,
},
vmname_destination => {
type => "=s",
help => "The name of the target virtual machine",
required => 1,
},
filename => {
type => "=s",
help => "The name of the configuration specification file",
required => 0,
default => "../sampledata/vmclone.xml",
},
timezone => {
type => "=s",
help => "Timezone, For Windows use Time Zone Index Values for Windo
ws (Index value for Stockholm is 110)
For Linux use tz (timezone) database valuse such as Europe/Sto
ckholm",
required => 0,
default => $timezone,
},
domainuserpassword => {
type => "=s",
help => "Password for Domain user",
required => 0,
},
autologon => {
type => "",
help => "Enables Autologon",
},
autologoncount => {
type => "=s",
help => "AutoLogonCount, How many times system will AutoLogon",
required => 0,
default => 1,
},
localadminpwd => {
type => "=s",
help => "Local Administrator Password, (Sets \"AutoLogon Enabled\" and \"A
utoLogonCount = 1\", unless AutoLogonCount greater than 1)",
required => 0,
},
customize_guest => {
type => "=s",
help => "Flag to specify whether or not to customize guest: yes,no",
required => 0,
default => 'no',
},
customize_vm => {
type => "=s",
help => "Flag to specify whether or not to customize virtual machine: "
. "yes,no",
required => 0,
default => 'no',
},
schema => {
type => "=s",
help => "The name of the schema file",
required => 0,
default => "../schema/vmclone.xsd",
},
datastore => {
type => "=s",
help => "Name of the Datastore",
required => 0,
},
snapname => {
type => "=s",
help => "Name of Snapshot from pristine base image",
required => 1,
},
convert => {
type => "=s",
help => "Convert destination disk type [source|sesparse]",
required => 0,
},
grainsize => {
type => "=s",
help => "Grainsize for SE Sparse disk [default 1024k]",
required => 0,
default => 1024,
},
guestid => {
type => "=s",
help => "Guest Operating System
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-
VM.html",
required => 0,
#default => $guestid,
},
resourcepool => {
type => "=s",
help => "Name of ResourcePool in vCenter",
required => 1,
},
dnsdomain => {
type => "=s",
help => "A DNS domain suffix such as dell.com.",
required => 1,
},
gateway => {
type => "=s",
help => "Default gateway to apply to VM",
required => 1,
},
dnsservers => {
type => "=s",
help => "(DNS - Domain Name Servers) Comma seperated list, 10.10.10.10,10.
10.10.11",
required => 1,
},
ipaddress => {
type => "=s",
help => "IP address to apply to the VM, Comma seperated list, Example: 10.
10.10.10,192.168.10.10",
required => 1,
},
netmask => {
type => "=s",
help => "Subnet Mask to apply to VM, Comma seperated list, Example: 25
5.255.0.0,255.255.255.0",
required => 1,
},
domain => {
type => "=s",
help => "Windows Domain to join",
required => 0,
},
plaintextpassword => {
type => "",
help => "Use Plaintext passwords",
},
domainuser => {
type => "=s",
help => "Username of user with permissions to join VM to domain",
required => 0,
},
runonce => {
type => "=s",
help => "A list of commands to run at first user logon, after guest cu
stomization.",
required => 0,
},
hudsoncred => {
type => "=s",
help => "hudson credential, after guest customization.",
required => 0,
},
memory => {
type => "=s",
help => "Amount of Memory (RAM) on the new VM",
required => 0,
default => $memory,
},
cpus => {
type => "=s",
help => "Number of CPUs on the new VM",
required => 0,
default => $cpus,
},
cluster => {
type => "=s",
help => "Name of the cluster",
required => 0,
},
);
Opts::add_options(%opts);
Opts::parse();
#Opts::validate(\&validate);
Opts::validate();
my $clone_name = Opts::get_option('vmname_destination');
Util::connect();
clone_vm();
Util::disconnect();
# Clone vm operation
# Gets destination host, compute resource views, and
# datastore info for creating the configuration
# specification to help create a clone of an existing
# virtual machine.
# ====================================================
sub clone_vm {
my $vm_name = Opts::get_option('vmname');
my $vm_snapshot_name = Opts::get_option('snapname');
my $convert = Opts::get_option('convert');
$convert = "" if (! $convert );
my $host_name = Opts::get_option('vmhost');
my $grainsize = Opts::get_option('grainsize');
my $resourcepool;
my $cluster_name = Opts::get_option('cluster');
my ($host_view, $cluster_view);
# Use host view if vm host name has been specified.
if ($host_name) {
$host_view = Vim::find_entity_view( view_type => 'HostSystem',
filter => {'name' => $host_name});
if (!$host_view) {
Util::trace(0, "Host '$host_name' not found\n");
return;
}
# Use cluster view if cluster name has been specified.
} elsif ( $cluster_name ) {
$cluster_view = Vim::find_entity_view(view_type => 'ClusterCompu
teResource',
filter => { name => $cluster_name });
if (!$cluster_view) {
Util::trace(0, "Cluster '$cluster_name' not found\n");
return;
}
# get all hosts under this cluster
my $host_views = Vim::find_entity_views(view_type => 'HostSystem
',
begin_entity => $cluster_view);
my @esxarr=();
my $size=@$host_views;
# query for available host in cluster
foreach (@$host_views) {
my $status = $_->summary->overallStatus->val;
#if ($status =~ /^green$/i) {
if (!( $status =~ /^red$/i)) {
$host_view = $_;
$host_name = $host_view->name;
Util::trace(0, "Host found: '$host_name' overall
status is '$status'\n");
last;
} else {
$host_view = $_;
$host_name = $host_view->name;
push ( @esxarr, $host_name );
Util::trace(0, "Host '$host_name' status found '
$status' and could not take any more VMs in cluster '$cluster_name'\n");
return if ( $#esxarr+1 eq $size );
}
}
} else {
Util::trace(0, "Please specify host name or cluster name for thi
s vm clone operation.\n");
return;
}

my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine',
filter => {'name' =>$vm_name});
if (Opts::get_option('resourcepool')) { $resourcepool = get_resource_poo
l();}

if(@$vm_views) {
foreach (@$vm_views) {
if ($host_view) {
my $comp_res_view = Vim::get_view(mo_ref => $hos
t_view->parent);
if (not $resourcepool) { $resourcepool = $comp_r
es_view->resourcePool; }
my $ds_name = Opts::get_option('datastore');
my %ds_info = HostUtils::get_datastore(host_view
=> $host_view,
datastore => $ds_name,
disksize => get_disksize());
if ($ds_info{mor} eq 0) {
if ($ds_info{name} eq 'datastore_error')
{
Util::trace(0, "\nDatastore $ds_
name not available.\n");
return;
}
if ($ds_info{name} eq 'disksize_error')
{
Util::trace(0, "\nThe free space
available is less than the"
. " specified di
sksize or the host"
. " is not acces
sible.\n");
return;
}
}
my ($vm_snapshot,$ref,$nRefs);
if(defined $_->snapshot) {
($ref, $nRefs) = find_snapshot_name ($_-
>snapshot->rootSnapshotList,
$vm_snapshot_name);
}
if (defined $ref && $nRefs == 1) {
$vm_snapshot = Vim::get_view (mo_ref =>$
ref->snapshot);
}
my ($diskLocator,$relocate_spec,$diskType,$diskI
d);
my $vm_device = $_->config->hardware->device;
foreach my $vdevice (@$vm_device) {
if($vdevice->isa('VirtualDisk')) {
$diskId = $vdevice->key;
last;
}
}
my $network_dev_key;
my $devices = $_->config->hardware->device;
foreach my $device (@$devices) {
if (ref $device eq "VirtualE1000") {
$network_dev_key = $device->key;
last;
}
}
if ($convert eq "sesparse" && Vim::get_service_c
ontent()->about->version eq "5.1.0") {
my $newdiskName = "[" . $ds_name . "] "
. $clone_name . "/" . $clone_name . ".vmdk";
$diskLocator = VirtualMachineRelocateSpe
cDiskLocator->new( datastore => $ds_info{mor},
diskBackingInfo => VirtualDiskFlatVer2BackingInfo->new(fileName => $newdiskName,
diskMode => 'persistent', deltaDiskFormat => 'seSparseFormat', deltaGrainSize =
> $grainsize),
diskId => $diskId);
$relocate_spec = VirtualMachineRelocateS
pec->new( datastore => $ds_info{mor},
host => $host_view,
diskMoveType => "createNewChildDiskBacking",
pool => $resourcepool,
disk => [$diskLocator]);
} else {
$relocate_spec = VirtualMachineRelocateS
pec->new( datastore => $ds_info{mor},
host => $host_view,
diskMoveType => "createNewChildDiskBacking",
pool => $resourcepool);
}
my $clone_spec ;
my $config_spec;
my $customization_spec;
if ((Opts::get_option('customize_vm') eq "yes")
&& (Opts::get_option('customize_
guest') ne "yes")) {
$config_spec = get_config_spec('network_
dev_key' => $network_dev_key);
$clone_spec = VirtualMachineCloneSpec->n
ew( powerOn => 1,
template => 0,
snapshot => $vm_snapshot,
location => $relocate_spec,
config => $config_spec,
);
}
elsif ((Opts::get_option('customize_guest') eq "
yes")
&& (Opts::get_option('customize_
vm') ne "yes")) {
$customization_spec = get_customization_
spec();
$clone_spec = VirtualMachineCloneSpec->n
ew( powerOn => 1,
template => 0,
snapshot => $vm_snapshot,
location => $relocate_spec,
customization => $customization_spec,
);
}
elsif ((Opts::get_option('customize_guest') eq "
yes")
&& (Opts::get_option('customize_
vm') eq "yes")) {
$customization_spec = get_customization_
spec();
$config_spec = get_config_spec('network_
dev_key' => $network_dev_key);
$clone_spec = VirtualMachineCloneSpec->n
ew( powerOn => 1,
template => 0,
snapshot => $vm_snapshot,
location => $relocate_spec,
customization => $customization_spec,
config => $config_spec,
);
}
else {
$clone_spec = VirtualMachineCloneSpec->n
ew( powerOn => 1,
template => 0,
snapshot => $vm_snapshot,
location => $relocate_spec,
);
}
Util::trace (0, "\nRequest virtual machine '" .
$clone_name . "' from '" . $vm_name . "' ...\n");
eval {
$_->CloneVM( folder => $_->parent,
name => $clone_n
ame,
spec => $clone_s
pec );
Util::trace (0, "\nRequest '$clone_name'
of virtual machine"
. " '$vm_name' s
uccessfully created.\n");
};
if ($@) {
if (ref($@) eq 'SoapFault') {
if (ref($@->detail) eq 'FileFaul
t') {
Util::trace(0, "\nFailed
to access the virtual "
." machi
ne files\n");
}
elsif (ref($@->detail) eq 'Inval
idState') {
Util::trace(0,"The opera
tion is not allowed "
."in the
current state.\n");
}
elsif (ref($@->detail) eq 'NotSu
pported') {
Util::trace(0," Operatio
n is not supported by the "
."curren
t agent \n");
}
elsif (ref($@->detail) eq 'VmCon
figFault') {
Util::trace(0,
"Virtual
machine is not compatible with the destination host.\n");
}
elsif (ref($@->detail) eq 'Inval
idPowerState') {
Util::trace(0,
"The att
empted operation cannot be performed "
."in the
current state.\n");
}
elsif (ref($@->detail) eq 'Dupli
cateName') {
Util::trace(0,
"The nam
e '$vm_name' already exists\n");
}
elsif (ref($@->detail) eq 'NoDis
ksToCustomize') {
Util::trace(0, "\nThe vi
rtual machine has no virtual disks that"
. " are
suitable for customization or no guest"
. " is p
resent on given virtual machine" . "\n");
}
elsif (ref($@->detail) eq 'HostN
otConnected') {
Util::trace(0, "\nUnable
to communicate with the remote host, "
."since it is di
sconnected" . "\n");
}
elsif (ref($@->detail) eq 'Uncus
tomizableGuest') {
Util::trace(0, "\nCustom
ization is not supported "
."for the guest
operating system" . "\n");
}
else {
Util::trace (0, "Fault"
. $@ . "" );
}
}
else {
Util::trace (0, "Fault" . $@ . "
" );
}
}
}
}
}
else {
Util::trace (0, "\nNo virtual machine found with name '$vm_name'
\n");
}
}
sub get_customization_spec() {
my @ipaddresses = split(',', Opts::get_option('ipaddress'));
my @gateway = Opts::get_option('gateway');
my @netmasks = split(',', Opts::get_option('netmask'));
my @dnsservers = split(',', Opts::get_option('dnsservers'));
my @winsservers = split(',', Opts::get_option('winsservers'));
my $dnsdomain = Opts::get_option('dnsdomain');
my $domain = Opts::get_option('domain');
my $localadminpwd = Opts::get_option('localadminpwd');
my $domainuser = Opts::get_option('domainuser');
my $domainuserpassword = Opts::get_option('domainuserpassword');
my $hudsoncred=Opts::get_option('hudsoncred');
#my $vmname = Opts::get_option('vmname_destination');
my $clone_name = Opts::get_option('vmname_destination');
my $plaintextpassword;
if (Opts::get_option('plaintextpassword')) {
$plaintextpassword = 1;
} else {
$plaintextpassword = 0;
}
my $autologon;
if (Opts::get_option('autologon')) {
$autologon = 1;
} else {
$autologon = 0;
}
my $autologoncount = Opts::get_option('autologoncount');
$timezone = Opts::get_option('timezone');
my $fullname = "COMPANY";
my $orgname = "COMPANY";
my $licensekey;
my $licensemode = Opts::get_option('licensemode');
my $licenses = Opts::get_option('licenses');
my $guestid = Opts::get_option('guestid');
my @runonce;
if (Opts::get_option('runonce')) {
@runonce = split(',', Opts::get_option('runonce'));
}
if ( ( $guestid eq "windows7Server64Guest" ) || ( $guestid eq "winLonghornGu
est" ) ){
$licensekey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
} elsif ( ( $guestid eq "windows7_64Guest" ) || ( $guestid eq "windows7_32Gu
est" ) ) {
$licensekey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX";
}
my $customization_sysprep;
my @ifconfig;
my $iface_ip_settings;
my $iface_settings;
my $iface_fixed_ip;
my $customization_name;
# Identify OS
if ( ( $guestid eq "windows7_64Guest" ) || ( $guestid eq "windows7_32Gue
st" ) || ( $guestid eq "windows7Server64Guest" ) || ( $guestid eq "winLonghornGu
est" ) ){
#########################################
# Create Windows customizationimization #
#########################################
my $customization_domain_admin_pwd = CustomizationPassword->new(
plainText => $pl
aintextpassword,
value => $domain
userpassword
);
my $customization_identification = CustomizationIdentification->
new(
domainAdmin => $
domainuser,
domainAdminPassw
ord => $customization_domain_admin_pwd,
joinDomain => $d
omain
);
my $customization_gui_unattended;
my $customization_local_admin_pwd;
if (Opts::get_option('localadminpwd')) {
$customization_local_admin_pwd = CustomizationPassword->new(
plainText => $plaintextpassword,
value => $localadminpwd
);
$customization_gui_unattended = CustomizationGuiUnattended->new(
autoLogon => $autologon,
autoLogonCount => $autologoncount,
password => $customization_local_admin_pwd,
timeZone => $timezone
);
} else {
$customization_gui_unattended = CustomizationGuiUnattended->new(
autoLogon => $autologon,
autoLogonCount => $autologoncount,
timeZone => $timezone,
password => Cust
omizationPassword->new(
plainText => "true",
value => $hudsoncred
),
);
}
my $customization_runonce;
if (Opts::get_option('runonce')) {
$customization_runonce = CustomizationGuiRunOnce->new(
commandList => \
@runonce
);
}
$customization_name = CustomizationFixedName->new(
name => $clone_name
);
my $customization_user_data = CustomizationUserData->new(
computerName => $customization_name,
fullName => $fullname,
orgName => $orgname,
productId => $li
censekey
);
$customization_sysprep = CustomizationSysprep->new(
guiUnattended => $customization_gui_unattended,
identification => $customization_identification,
userData => $customization_user_data
);
} elsif ( $guestid eq "rhel5_64Guest" ) {
#######################################
# Create Linux customizationimization #
#######################################
$customization_name = CustomizationFixedName->new(name => $clone
_name);
$customization_sysprep = CustomizationLinuxPrep->new(
domain => $domai
n,
hostName => $cus
tomization_name,
timeZone => $tim
ezone
);
} else {
die "Error: Unrecognized Operating System Type.\n $guestid \n";
}
#######################################
# IP stuff #
#######################################
my $customization_global_ip_settings = CustomizationGlobalIPSettings->ne
w();
$customization_global_ip_settings->{'dnsServerList'} = \@dnsservers;
my $numOfipaddresses = @ipaddresses;
my $numOfnetmasks = @netmasks;
if ( $numOfipaddresses == $numOfnetmasks ) {
my $counter = 0;
while ($counter < $numOfipaddresses ) {
$iface_fixed_ip = CustomizationFixedIp->new(
ipAddress => $ip
addresses[$counter]
);
$iface_ip_settings = CustomizationIPSettings->new(
dnsDomain => $dn
sdomain,
dnsServerList =>
\@dnsservers,
ip => $iface_fix
ed_ip,
gateway => \@gat
eway,
primaryWINS => $
winsservers[0],
secondaryWINS =>
$winsservers[1],
# netBIOS => "",
subnetMask => $n
etmasks[$counter]
);
$iface_settings = CustomizationAdapterMapping->new(
adapter => $ifac
e_ip_settings
);
if ($counter == 0) {
@ifconfig = $iface_settings;
} else {
push (@ifconfig, $iface_settings);
}
$counter++;
}
} else {
die "Error: Number of ipaddresses must match number of netmasks
specified. \n"
}
my $customization_spec = CustomizationSpec->new(
# encryptionKey => "",
identity => $customization_sysprep,
globalIPSettings => $customization_global_ip_settings,
nicSettingMap => \@ifconfig
);
return $customization_spec;
}
# Gets the config_spec for customizing the memory, number of cpu's
# and returns the spec
sub get_config_spec() {
my %args = @_;
my $net_dev_key = $args{'network_dev_key'};
my $network = "VM_NET_vlan149";
my $nic_poweron = 1;
my $nic_allow_guest_control = 1;
# my $memory = "6144";
# my $cpus = "1";
my $memory = Opts::get_option('memory');
my $cpus = Opts::get_option('cpus');
my $guestid = Opts::get_option('guestid');
my $vmname = Opts::get_option('vmname_destination');
# Find dvportgroup
my $network_view = Vim::find_entity_view(
view_type => 'Network',
filter => { 'name' => $network },
);
# New object which defines network backing for a virtual Ethernet card
my $virtual_device_backing_info = VirtualEthernetCardNetworkBackingInfo-
>new(
network => $network_view,
deviceName => $network);
# New object which contains information about connectable virtual device
s
my $vdev_connect_info = VirtualDeviceConnectInfo->new(
startConnected => $nic_poweron,
allowGuestControl => $ni
c_allow_guest_control,
connected => '1');
# New object which define virtual device
my $network_device = VirtualE1000->new(
key => $net_dev_key,
backing => $virtual_device_backing_info,
connectable => $vdev_connect_info);
# New object which encapsulates change specifications for an individual
virtual device
my @device_config_spec = VirtualDeviceConfigSpec->new(
operation => VirtualDeviceConfigSpecOperation->new('edit'),
device => $network_device);
# New object which encapsulates configuration settings when creating or
reconfiguring a virtual machine
my $vm_config_spec = VirtualMachineConfigSpec->new(
name => $vmname,
memoryMB => $memory,
numCPUs => $cpus,
deviceChange => \@device_config_spec,);

return $vm_config_spec;
}
sub find_snapshot_name {
my ($tree, $name) = @_;
my $ref = undef;
my $count = 0;
foreach my $node (@$tree) {
if ($node->name eq $name) {
$ref = $node;
$count++;
}
my ($subRef, $subCount) = find_snapshot_name($node->childSnapsho
tList, $name);
$count = $count + $subCount;
$ref = $subRef if ($subCount);
}
return ($ref, $count);
}
sub get_disksize {
my $disksize = 4194304;
my $parser = XML::LibXML->new();

eval {
my $tree = $parser->parse_file(Opts::get_option('filename'));
my $root = $tree->getDocumentElement;
my @cspec = $root->findnodes('Virtual-Machine-Spec');
foreach (@cspec) {
$disksize = $_->findvalue('Disksize');
}
};

return $disksize;
}
sub get_resource_pool() {
my $resourcepool = Opts::get_option('resourcepool');
my $resourpoolView = Vim::find_entity_view(view_type => 'ResourcePool',
filter =>{ 'name'=> $resourcepool});
unless($resourpoolView) { Util::disconnect(); die "Resource pool \"$reso
urcepool\" not found.\n";}
return $resourpoolView;
}
sub find_disk {
my %args = @_;
my $vm = $args{vm};
my $name = $args{fileName};
my $devices = $vm->config->hardware->device;
foreach my $device(@$devices) {
if($device->isa('VirtualDisk')) {
return $device;
}
}
}
# check missing values of mandatory fields
sub check_missing_value {
my $valid= 1;
my $filename = Opts::get_option('filename');
my $parser = XML::LibXML->new();
my $tree = $parser->parse_file($filename);
my $root = $tree->getDocumentElement;
my @cust_spec = $root->findnodes('Customization-Spec');
my $total = @cust_spec;
if (!$cust_spec[0]->findvalue('Auto-Logon')) {
Util::trace(0,"\nERROR in '$filename':\n autologon value missing
");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Virtual-Machine-Name')) {
Util::trace(0,"\nERROR in '$filename':\n computername value miss
ing ");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Timezone')) {
Util::trace(0,"\nERROR in '$filename':\n timezone value missing
");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Domain')) {
Util::trace(0,"\nERROR in '$filename':\n domain value missing ")
;
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Domain-User-Name')) {
Util::trace(0,"\nERROR in '$filename':\n domain_user_name value
missing ");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Domain-User-Password')) {
Util::trace(0,"\nERROR in '$filename':\n domain_user_password va
lue missing ");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Full-Name')) {
Util::trace(0,"\nERROR in '$filename':\n fullname value missing
");
$valid = 0;
}
if (!$cust_spec[0]->findvalue('Orgnization-Name')) {
Util::trace(0,"\nERROR in '$filename':\n Orgnization name value
missing ");
$valid = 0;
}
return $valid;
}
sub validate {
my $valid= 1;
if ((Opts::get_option('customize_vm') eq "yes")
|| (Opts::get_option('customize_guest')
eq "yes")) {
$valid = check_missing_value();
}
if (Opts::option_is_set('customize_vm')) {
if ((Opts::get_option('customize_vm') ne "yes")
&& (Opts::get_option('customize_vm') ne "no")) {
Util::trace(0,"\nMust specify 'yes' or 'no' for customiz
e_vm option");
$valid = 0;
}
}
if (Opts::option_is_set('customize_guest')) {
if ((Opts::get_option('customize_guest') ne "yes")
&& (Opts::get_option('customize_guest') ne "no")
) {
Util::trace(0,"\nMust specify 'yes' or 'no' for customiz
e_guest option");
$valid = 0;
}
}
return $valid;
}
__END__
=head1 NAME
deployVMLinked.pl - Perform clone operation on virtual machine and
customize operation on both virtual machine and the guest.
=head1 SYNOPSIS
deployVMLinked.pl [options]
=head1 DESCRIPTION
VI Perl command-line utility allows you to clone a virtual machine. You
can customize the virtual machine or the guest operating system as part
of the clone operation.
=head1 OPTIONS
=head2 GENERAL OPTIONS
=over
=item B<vmhost>
Required. Name of the host containing the virtual machine.
=item B<vmname>
Required. Name of the virtual machine whose clone is to be created.
=item B<vmname_destination>
Required. Name of the clone virtual machine which will be created.
=item B<datastore>
Optional. Name of a data center. If none is given, the script uses the default d
ata center.
=back
=head2 CUSTOMIZE GUEST OPTIONS
=over
=item B<customize_guest>
Required. Customize guest is used to customize the network settings of the guest
operating system. Options are Yes/No.
=item B<filename>
Required. It is the name of the file in which values of parameters to be
customized is written e.g. --filename clone_vm.xml.
=item B<schema>
Required. It is the name of the schema which validates the filename.
=back
=head2 CUSTOMIZE VM OPTIONS
=over
=item B<customize_vm>
Required. customize_vm is used to customize the virtual machine settings
like disksize, memory. If yes is written it will be customized.
=item B<filename>
Required. It is the name of the file in which values of parameters to be
customized is written e.g. --filename clone_vm.xml.
=item B<schema>
Required. It is the name of the schema which validates the filename.
=back
=head2 INPUT PARAMETERS
=head3 GUEST CUSTOMIZATION
The parameters for customizing the guest os are specified in an XML
file. The structure of the input XML file is:
<Specification>
<Customization-Spec>
</Customization-Spec>
</Specification>
Following are the input parameters:
=over
=item B<Auto-Logon>
Required. Flag to specify whether auto logon should be enabled or disabled.
=item B<Virtual-Machine-Name>
Required. Name of the virtual machine to be created.
=item B<Timezone>
Required. Time zone property of guest OS.
=item B<Domain>
Required. The domain that the virtual machine should join.
=item B<Domain-User-Name>
Required. The domain user account used for authentication.
=item B<Domain-User-Password>
Required. The password for the domain user account used for authentication.
=item B<Full-Name>
Required. User's full name.
=item B<Orgnization-Name>
Required. User's organization.
=back
=head3 VIRTUAL MACHINE CUSTOMIZATION
The parameters for customizing the virtual machine are specified in an XML
file. The structure of the input XML file is:
<Specification>
<Config-Spec-Spec>
<!--Several parameters like Guest-Id, Memory, Disksize, Number-of-CPUS et
c-->
</Config-Spec>
</Specification>
Following are the input parameters:
=over
=item B<Guest-Id>
Required. Short guest operating system identifier.
=item B<Memory>
Required. Size of a virtual machine's memory, in MB.
=item B<Number-of-CPUS>
Required. Number of virtual processors in a virtual machine.
=back
See the B<vmcreate.pl> page for an example of a virtual machine XML file.
=head1 EXAMPLES
Making a clone without any customization:
perl deployVMLinked.pl --username username --password mypassword
--vmhost <hostname/ipaddress> --vmname DVM1 --vmname_destinatio
n DVM99
--url https://<ipaddress>:<port>/sdk/webService
If datastore is given:
perl deployVMLinked.pl --username username --password mypassword
--vmhost <hostname/ipaddress> --vmname DVM1 --vmname_destinatio
n DVM99
--url https://<ipaddress>:<port>/sdk/webService --datastore sto
rage1
Making a clone and customizing the VM:
perl deployVMLinked.pl --username myusername --password mypassword
--vmhost <hostname/ipaddress> --vmname DVM1 --vmname_destinatio
n Clone_VM
--url https://<ipaddress>:<port>/sdk/webService --customize_vm
yes
--filename clone_vm.xml --schema clone_schema.xsd
Making a clone and customizing the guestOS:
perl deployVMLinked.pl --username myuser --password mypassword --operation clon
e
--vmhost <hostname/ipaddress> --vmname DVM1 --vmname_destinatio
n DVM99
--url https://<ipaddress>:<port>/sdk/webService --customize_gue
st yes
--filename clone_vm.xml --schema clone_schema.xsd
Making a clone and customizing both guestos and VM:
perl deployVMLinked.pl --username myuser --password mypassword
--vmhost <hostname/ipaddress> --vmname DVM1 --vmname_destinatio
n DVM99
--url https://<ipaddress>:<port>/sdk/webService --customize_gue
st yes
--customize_vm yes --filename clone_vm.xml --schema clone_schem
a.xsd
All the parameters which are to be customized are written in the deployVMLinked.
xml file.
=head1 SUPPORTED PLATFORMS
All operations supported on VirtualCenter 2.0.1 or later.
To perform the clone operation, you must connect to a VirtualCenter server.

Vous aimerez peut-être aussi