Hi all,
another question came up today.
I have to create a vm and add a floppy drive. Sometimes the floppy drive should be backed by an Image, sometimes not. I could create two VirtualFloppy Objects, depending on having an image or not.
This blows up my code, so it would be nice to add the backing to the objects afterwards if needed.
In my opinion the code should look roughly like this, but this throws an error: Can't modify non-lvalue subroutine call at....
sub getFloppy{
my $image =$_[0];
my $virFloppy = VirtualFloppy->new( connectable => VirtualDeviceConnectInfo->new(allowGuestControl => 'false',
startConnected => 'true',
connected => 'true'),
controllerKey => 400,
key => 8000,
);
if($image){
$virFloppy->backing=VirtualFloppyImageBackingInfo->new(fileName => $image);
}
return $virFloppy
}
Any ideas?
Thanks, Chris
Floppies eh? ![]()
You should be able to change the backing, you'll just have to build them properly. In your code below, you'll have to use ->{} accessor to replace the backing object:
my $virFloppy = new VirtualFloppy
(
connectable => new VirtualDeviceConnectInfo
(
allowGuestControl => 'false',
startConnected => 'true',
connected => 'true'
),
controllerKey => 400,
key => 8000,
);
if ($image)
{
$virFloppy->{'backing'} = new VirtualFloppyImageBackingInfo(fileName => $image);
}
return $virFloppy
Didn't test your floppy use case, but I've done similar logic like this for other backing types (network, disk, etc)
Thanks stumpr! ![]()
The floppy is needed for an automated installation.
Chris
