I'm using the newest 4.3.2 sdk and virtualbox and i'm trying to import a ovf file via vboxwebsrv.
I have two goals:
1.) Change the vmname
2.) Ignore the HardDiskImage (an image will be attached after the machine is registered)
ATM I can read the ovf file and interpret it correctly, but I can't import it to virtualbox if I "ignore" the HardDiskImage.
Here is my code:
Code: Select all
try {
generator = new Random();
vmname = String.valueOf(Math.abs(generator.nextInt()));
VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
mgr.connect("127.0.0.1:18083/", "", "");
IVirtualBox box = mgr.getVBox();
IAppliance importOvf = box.createAppliance();
IProgress p = importOvf.read(inputOvf.getAbsolutePath());
p.waitForCompletion(-1);
importOvf.interpret();
System.out.println("warnings: " + importOvf.getWarnings());
List<IVirtualSystemDescription> sysDescription = importOvf.getVirtualSystemDescriptions();
Holder<List<VirtualSystemDescriptionType>> aType = new Holder<List<VirtualSystemDescriptionType>>();
Holder<List<String>> aRefs = new Holder<List<String>>();
Holder<List<String>> aOvfValues = new Holder<List<String>>();
Holder<List<String>> aVBoxValues = new Holder<List<String>>();
Holder<List<String>> aExtraConfigValues = new Holder<List<String>>();
sysDescription.get(0).getDescription(aType, aRefs, aOvfValues, aVBoxValues, aExtraConfigValues);
System.out.println("get machines: " + importOvf.getMachines());
System.out.println("aType value: " + aType.value);
System.out.println("aRefs value: " + aRefs.value);
System.out.println("aOvfValues value: " + aOvfValues.value);
System.out.println("aVBoxValues value: " + aVBoxValues.value);
System.out.println("aExtraConfigValues value: " + aExtraConfigValues.value);
List<Boolean> options = new ArrayList<Boolean>() ;
Iterator listIter = aRefs.value.iterator();
int i = 0;
while(listIter.hasNext()){
switch (aType.value.get(i)) {
case HardDiskImage:
options.add(false);
break;
case Name:
options.add(true);
aVBoxValues.value.set(i, vmname);
break;
default:
options.add(true);
break;
}
i++;
listIter.next();
}
System.out.println("options: " + options);
sysDescription.get(0).setFinalValues(options, aVBoxValues.value, aExtraConfigValues.value);
sysDescription.get(0).getDescription(aType, aRefs, aOvfValues, aVBoxValues, aExtraConfigValues);
System.out.println("aType value: " + aType.value);
System.out.println("aRefs value: " + aRefs.value);
System.out.println("aOvfValues value: " + aOvfValues.value);
System.out.println("aVBoxValues value: " + aVBoxValues.value);
System.out.println("aExtraConfigValues value: " + aExtraConfigValues.value);
List<ImportOptions> mac_options = new ArrayList<ImportOptions>();
mac_options.add(ImportOptions.KeepAllMACs);
IProgress importProgress = importOvf.importMachines(mac_options);
importProgress.waitForCompletion(-1);
System.out.println("get machines: " + importOvf.getMachines());
mgr.disconnect();
} catch (VBoxException e) {
System.out.println("Cause: " + e.getCause());
e.printStackTrace();
}
Code: Select all
warnings: []
get machines: []
aType value: [OS, Name, CPU, Memory, SoundCard, USBController, NetworkAdapter, NetworkAdapter, CDROM, HardDiskControllerIDE, HardDiskControllerIDE, HardDiskControllerSATA, HardDiskImage]
aRefs value: [, , , , , , , , , 3, 4, 5, vmdisk1]
aOvfValues value: [95, TestName, 2, 2147483648, , , NAT, NAT, , PIIX4, PIIX4, AHCI, test-disk1.vmdk]
aVBoxValues value: [Debian, TestName, 2, 2048, 0, , 3, 3, , PIIX4, PIIX4, AHCI, /home/dennis/VirtualBox VMs/test/test-disk1.vmdk]
aExtraConfigValues value: [, , , , , , slot=0;type=NAT, slot=1;type=NAT, , , , , controller=11;channel=0]
options: [true, true, true, true, true, true, true, true, true, true, true, true, false]
aType value: [OS, Name, CPU, Memory, SoundCard, USBController, NetworkAdapter, NetworkAdapter, CDROM, HardDiskControllerIDE, HardDiskControllerIDE, HardDiskControllerSATA, Ignore]
aRefs value: [, , , , , , , , , 3, 4, 5, vmdisk1]
aOvfValues value: [95, TestName, 2, 2147483648, , , NAT, NAT, , PIIX4, PIIX4, AHCI, test-disk1.vmdk]
aVBoxValues value: [Debian, 1466652333, 2, 2048, 0, , 3, 3, , PIIX4, PIIX4, AHCI, /home/dennis/VirtualBox VMs/test/test-disk1.vmdk]
aExtraConfigValues value: [, , , , , , slot=0;type=NAT, slot=1;type=NAT, , , , , controller=11;channel=0]
get machines: []
But if I leave HardDiskImage "untouched" (uncomment HardDiskImage-case) and only change the name, then it works and I get:
Code: Select all
...
options: [true, true, true, true, true, true, true, true, true, true, true, true, true]
aType value: [OS, Name, CPU, Memory, SoundCard, USBController, NetworkAdapter, NetworkAdapter, CDROM, HardDiskControllerIDE, HardDiskControllerIDE, HardDiskControllerSATA, HardDiskImage]
aRefs value: [, , , , , , , , , 3, 4, 5, vmdisk1]
aOvfValues value: [95, TestName, 2, 2147483648, , , NAT, NAT, , PIIX4, PIIX4, AHCI, test-disk1.vmdk]
aVBoxValues value: [Debian, 1728574243, 2, 2048, 0, , 3, 3, , PIIX4, PIIX4, AHCI, /home/dennis/VirtualBox VMs/test/test-disk1.vmdk]
aExtraConfigValues value: [, , , , , , slot=0;type=NAT, slot=1;type=NAT, , , , , controller=11;channel=0]
get machines: [e3b53b94-648b-4ddd-af5d-3285840629e6]
Thx and regards!
Dennis