From 7cd6c40acdce971688278f7bbde4f0724734418a Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 10 May 2011 16:08:49 +0000 Subject: [PATCH] Implement chvm cdrom and eject for VMware git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9548 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/esx.pm | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/esx.pm b/xCAT-server/lib/xcat/plugins/esx.pm index cb0b9da7d..4620ed2e4 100644 --- a/xCAT-server/lib/xcat/plugins/esx.pm +++ b/xCAT-server/lib/xcat/plugins/esx.pm @@ -678,12 +678,16 @@ sub chvm { xCAT::SvrUtils::sendmsg([1,"Could not parse options, ".shift()], $output_handler); }; my @otherparams; + my $cdrom; + my $eject; my $rc = GetOptions( "d=s" => \@deregister, "p=s" => \@purge, "a=s" => \@add, "o=s" => \@otherparams, "resize=s%" => \%resize, + "optical|cdrom|c=s" => \$cdrom, + "eject" => \$eject, "cpus=s" => \$cpuCount, "mem=s" => \$memory ); @@ -802,6 +806,57 @@ sub chvm { push @devChanges, create_storage_devs($node,$hyphash{$hyp}->{datastoremap},$addSizes,$scsiCont,$scsiUnit,$ideCont,$ideUnit,$devices,idefull=>$idefull,scsifull=>$scsifull); } + if ($cdrom or $eject) { + my $opticalbackingif; + my $opticalconnectable; + if ($cdrom) { + my $storageurl; + if ($cdrom =~ m!://!) { + $storageurl=$cdrom; + $storageurl =~ s!/[^/]*\z!!; + unless (validate_datastore_prereqs([],$hyp,{$storageurl=>[$node]})) { + xCAT::SvrUtils::sendmsg([1,"Unable to find/mount datastore holding $cdrom"], $output_handler,$node); + return; + } + $cdrom =~ s!.*/!!; + } else { + $storageurl = $tablecfg{vm}->{$node}->[0]->{storage}; + $storageurl =~ s/=.*//; + $storageurl =~ s/.*,//; + $storageurl =~ s/\/\z//; + } + $opticalbackingif = VirtualCdromIsoBackingInfo->new( fileName => "[".$hyphash{$hyp}->{datastoremap}->{$storageurl}."] $cdrom"); + $opticalconnectable = VirtualDeviceConnectInfo->new(startConnected=>1,allowGuestControl=>1,connected=>1); + } elsif ($eject) { + $opticalbackingif=VirtualCdromRemoteAtapiBackingInfo->new(deviceName=>""); + $opticalconnectable=VirtualDeviceConnectInfo->new(startConnected=>0,allowGuestControl=>1,connected=>0); + } + my $oldcd; + foreach my $dev (@$devices) { + if ($dev->deviceInfo->label eq "CD/DVD drive 1") { + $oldcd=$dev; + last; + } + } + unless ($oldcd) { + if ($cdrom) { + xCAT::SvrUtils::sendmsg([1,"Unable to find Optical drive in VM to insert ISO image"], $output_handler,$node); + } else { + xCAT::SvrUtils::sendmsg([1,"Unable to find Optical drive in VM to perform eject"], $output_handler,$node); + } + return; + } + my $newDevice = VirtualCdrom->new(backing => $opticalbackingif, + key=>$oldcd->key, + controllerKey=>201, + unitNumber=>0, + connectable=>$opticalconnectable, + ); + push @devChanges, VirtualDeviceConfigSpec->new( + device => $newDevice, + operation => VirtualDeviceConfigSpecOperation->new('edit')); + + } if(%resize) { while( my ($key, $value) = each(%resize) ) { my @drives = split(/,/, $key);