WS: import ovf and ignore HardDiskImage fails

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
derDaywalker
Posts: 3
Joined: 8. Nov 2013, 16:46

WS: import ovf and ignore HardDiskImage fails

Post by derDaywalker »

Hi everyone

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();
}
This is my test output:

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: []
I don't get any error messages neither inside java nor from vboxwebsrv.


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]
Maybe someone can help and give me a hint. This would be great! :D

Thx and regards!
Dennis
Last edited by derDaywalker on 8. Nov 2013, 18:11, edited 1 time in total.
derDaywalker
Posts: 3
Joined: 8. Nov 2013, 16:46

Re: WS: import ovf and ignore HardDiskImage fails

Post by derDaywalker »

Hmm, maybe it's not possible / allowed to ignore the DiskImage?!?
Because if I enter the following command into the terminal (unit 12 is the Hard disk image):

Code: Select all

vboxmanage import test.ovf --vsys 0 --unit 12 --ignore
I get the following error:

Code: Select all

0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Appliance import failed
VBoxManage: error: Internal inconsistency looking up disk image 'vmdisk1'
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Appliance, interface IAppliance
VBoxManage: error: Context: "int handleImportAppliance(HandlerArg*)" at line 779 of file VBoxManageAppliance.cpp
But the question remains, why I don't get any error messages / exceptions :?
And why is it possible to disable this item at all?

Quote from API:
You can only disable items of the types HardDiskControllerIDE, HardDiskControllerSATA, HardDiskControllerSCSI, HardDiskImage, .....
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: WS: import ovf and ignore HardDiskImage fails

Post by noteirak »

You don't get any error because you don't check for them. You are given an IProgress object, but you don't check the return code, or any error message inside it.
You should!

Check the IProgress methods in the SDK, you'll see what you are missing.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
derDaywalker
Posts: 3
Joined: 8. Nov 2013, 16:46

Re: WS: import ovf and ignore HardDiskImage fails

Post by derDaywalker »

Hi noteirak

Thx for this hint. I didn't know that. Now I'm aware of that and I will check for errors now. Thx!
Post Reply