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
This commit is contained in:
jbjohnso 2011-05-10 16:08:49 +00:00
parent a4dd8b7b22
commit 7cd6c40acd

View File

@ -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);