2395
2400
if (FAILED(rc)) throw rc;
2396
2401
stack.fSessionOpen = true;
2398
/* Iterate over all given disk images */
2399
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2400
for (itHD = avsdeHDs.begin();
2401
itHD != avsdeHDs.end();
2403
ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
2404
std::set<RTCString> disksResolvedNames;
2406
while(oit != stack.mapDisks.end())
2404
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2406
// vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
2407
// in the virtual system's disks map under that ID and also in the global images map
2408
ovf::VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
2409
// and find the disk from the OVF's disk list
2410
ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
2411
if ( (itVirtualDisk == vsysThis.mapVirtualDisks.end())
2412
|| (itDiskImage == stack.mapDisks.end())
2414
throw setError(E_FAIL,
2415
tr("Internal inconsistency looking up disk image '%s'"),
2416
vsdeHD->strRef.c_str());
2418
const ovf::DiskImage &ovfDiskImage = itDiskImage->second;
2419
const ovf::VirtualDisk &ovfVdisk = itVirtualDisk->second;
2408
if (RTPathHaveExt(oit->second.strHref.c_str()))
2410
/* Figure out which format the user have. */
2411
char *pszExt = RTPathExt(oit->second.strHref.c_str());
2412
/* Get the system properties. */
2413
SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
2414
ComObjPtr<MediumFormat> trgFormat = pSysProps->mediumFormatFromExtension(&pszExt[1]);
2415
if (trgFormat.isNull())
2422
ovf::DiskImage diCurrent = oit->second;
2423
ovf::VirtualDisksMap::const_iterator itVDisk = vsysThis.mapVirtualDisks.begin();
2425
VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
2429
* Iterate over all given disk images of the virtual system
2430
* disks description. We need to find the target disk path,
2431
* which could be changed by the user.
2435
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2436
for (itHD = avsdeHDs.begin();
2437
itHD != avsdeHDs.end();
2440
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2441
if (vsdeHD->strRef == diCurrent.strDiskId)
2443
vsdeTargetHD = vsdeHD;
2448
throw setError(E_FAIL,
2449
tr("Internal inconsistency looking up disk image '%s'"),
2450
diCurrent.strHref.c_str());
2452
//diCurrent.strDiskId contains the disk identifier (e.g. "vmdisk1"), which should exist
2453
//in the virtual system's disks map under that ID and also in the global images map
2454
itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId);
2455
if (itVDisk == vsysThis.mapVirtualDisks.end())
2456
throw setError(E_FAIL,
2457
tr("Internal inconsistency looking up disk image '%s'"),
2458
diCurrent.strHref.c_str());
2461
if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, "Appliance::IOTar", strlen("Appliance::IOTar")) == 0)
2463
/* It means that we possibly have imported the storage earlier on the previous loop steps*/
2464
std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref);
2465
if (h != disksResolvedNames.end())
2467
/* Yes, disk name was found, we can skip it*/
2472
RTCString availableImage(diCurrent.strHref);
2476
* The preliminary check availability of the image
2477
* This step is useful if image is placed in the OVA (TAR) package
2481
RTTAR tar = (RTTAR)pStorage->pVDImageIfaces->pvUser;
2482
char *pszFilename = 0;
2484
int vrc = RTTarCurrentFile(tar, &pszFilename);
2486
if (RT_FAILURE(vrc))
2488
throw setError(VBOX_E_FILE_ERROR,
2489
tr("Could not open the current file in the archive (%Rrc)"), vrc);
2493
availableImage = pszFilename;
2495
/* current opened file isn't the same as passed one */
2496
if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0)
2500
* availableImage contains the disk file reference (e.g. "disk1.vmdk"), which should exist
2501
* in the global images map.
2502
* And find the disk from the OVF's disk list
2506
ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin();
2507
while (++itDiskImage != stack.mapDisks.end())
2509
if (itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0)
2512
if (itDiskImage == stack.mapDisks.end())
2514
throw setError(E_FAIL,
2515
tr("Internal inconsistency looking up disk image '%s'"),
2516
availableImage.c_str());
2519
/* replace with a new found disk image */
2520
diCurrent = *(&itDiskImage->second);
2525
* Again iterate over all given disk images of the virtual system
2526
* disks description using the found disk image
2530
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2531
for (itHD = avsdeHDs.begin();
2532
itHD != avsdeHDs.end();
2535
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2536
if (vsdeHD->strRef == diCurrent.strDiskId)
2538
vsdeTargetHD = vsdeHD;
2543
throw setError(E_FAIL,
2544
tr("Internal inconsistency looking up disk image '%s'"),
2545
diCurrent.strHref.c_str());
2547
itVDisk = vsysThis.mapVirtualDisks.find(diCurrent.strDiskId);
2548
if (itVDisk == vsysThis.mapVirtualDisks.end())
2549
throw setError(E_FAIL,
2550
tr("Internal inconsistency looking up disk image '%s'"),
2551
diCurrent.strHref.c_str());
2562
/* just continue with normal files*/
2566
disksResolvedNames.insert(diCurrent.strHref);
2568
const ovf::VirtualDisk &ovfVdisk = itVDisk->second;
2421
2570
ComObjPtr<Medium> pTargetHD;
2422
importOneDiskImage(ovfDiskImage,
2423
vsdeHD->strVboxCurrent,
2571
importOneDiskImage(diCurrent,
2572
vsdeTargetHD->strVboxCurrent,
2672
2824
if (cHardDisks != avsdeHDs.size())
2673
2825
fRepairDuplicate = false;
2675
// for each storage controller...
2676
for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin();
2677
sit != config.storageMachine.llStorageControllers.end();
2828
ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
2829
std::set<RTCString> disksResolvedNames;
2831
while(oit != stack.mapDisks.end())
2680
settings::StorageController &sc = *sit;
2682
// find the OVF virtual system description entry for this storage controller
2683
switch (sc.storageBus)
2685
case StorageBus_SATA:
2687
case StorageBus_SCSI:
2689
case StorageBus_IDE:
2691
case StorageBus_SAS:
2695
// for each medium attachment to this controller...
2696
for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
2697
dit != sc.llAttachedDevices.end();
2700
settings::AttachedDevice &d = *dit;
2702
if (d.uuid.isEmpty())
2703
// empty DVD and floppy media
2706
// When repairing a broken VirtualBox xml config section (written
2707
// by VirtualBox versions earlier than 3.2.10) assume the disks
2708
// show up in the same order as in the OVF description.
2709
if (fRepairDuplicate)
2711
VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt;
2712
ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
2713
if (itDiskImage != stack.mapDisks.end())
2715
const ovf::DiskImage &di = itDiskImage->second;
2716
d.uuid = Guid(di.uuidVbox);
2721
// convert the Guid to string
2722
Utf8Str strUuid = d.uuid.toString();
2724
// there must be an image in the OVF disk structs with the same UUID
2725
bool fFound = false;
2726
for (ovf::DiskImagesMap::const_iterator oit = stack.mapDisks.begin();
2727
oit != stack.mapDisks.end();
2730
const ovf::DiskImage &di = oit->second;
2732
if (di.uuidVbox == strUuid)
2734
VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
2736
/* Iterate over all given disk images of the virtual system
2737
* disks description. We need to find the target disk path,
2738
* which could be changed by the user. */
2739
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2740
for (itHD = avsdeHDs.begin();
2741
itHD != avsdeHDs.end();
2744
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2745
if (vsdeHD->strRef == oit->first)
2747
vsdeTargetHD = vsdeHD;
2752
throw setError(E_FAIL,
2753
tr("Internal inconsistency looking up disk image '%s'"),
2754
oit->first.c_str());
2758
* step 3: import disk
2761
ComObjPtr<Medium> pTargetHD;
2762
importOneDiskImage(di,
2763
vsdeTargetHD->strVboxCurrent,
2769
// ... and replace the old UUID in the machine config with the one of
2770
// the imported disk that was just created
2772
rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
2773
if (FAILED(rc)) throw rc;
2833
ovf::DiskImage diCurrent = oit->second;
2835
VirtualSystemDescriptionEntry *vsdeTargetHD = 0;
2838
/* Iterate over all given disk images of the virtual system
2839
* disks description. We need to find the target disk path,
2840
* which could be changed by the user. */
2841
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2842
for (itHD = avsdeHDs.begin();
2843
itHD != avsdeHDs.end();
2846
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2847
if (vsdeHD->strRef == oit->first)
2849
vsdeTargetHD = vsdeHD;
2782
// no disk with such a UUID found:
2784
2854
throw setError(E_FAIL,
2785
tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s but the OVF describes no such image"),
2787
} // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin();
2788
} // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin();
2855
tr("Internal inconsistency looking up disk image '%s'"),
2856
oit->first.c_str());
2861
* The preliminary check availability of the image
2862
* This step is useful if image is placed in the OVA (TAR) package
2866
if (strncmp(pStorage->pVDImageIfaces->pszInterfaceName, "Appliance::IOTar", strlen("Appliance::IOTar")) == 0)
2868
std::set<RTCString>::const_iterator h = disksResolvedNames.find(diCurrent.strHref);
2869
if (h != disksResolvedNames.end())
2871
/* Yes, disk name was found, we can skip it*/
2876
RTCString availableImage(diCurrent.strHref);
2878
RTTAR tar = (RTTAR)pStorage->pVDImageIfaces->pvUser;
2879
char *pszFilename = 0;
2881
int vrc = RTTarCurrentFile(tar, &pszFilename);
2883
if (RT_FAILURE(vrc))
2885
throw setError(VBOX_E_FILE_ERROR,
2886
tr("Could not open the current file in the archive (%Rrc)"), vrc);
2890
availableImage = pszFilename;
2892
/* current opened file isn't the same as passed one */
2893
if(availableImage.compare(diCurrent.strHref, Utf8Str::CaseInsensitive) != 0)
2895
// availableImage contains the disk identifier (e.g. "vmdisk1"), which should exist
2896
// in the virtual system's disks map under that ID and also in the global images map
2897
// and find the disk from the OVF's disk list
2898
ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.begin();
2899
while (++itDiskImage != stack.mapDisks.end())
2901
if(itDiskImage->second.strHref.compare(availableImage, Utf8Str::CaseInsensitive) == 0 )
2904
if (itDiskImage == stack.mapDisks.end())
2906
throw setError(E_FAIL,
2907
tr("Internal inconsistency looking up disk image '%s'"),
2908
availableImage.c_str());
2911
/* replace with a new found disk image */
2912
diCurrent = *(&itDiskImage->second);
2914
/* Again iterate over all given disk images of the virtual system
2915
* disks description using the found disk image
2917
list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
2918
for (itHD = avsdeHDs.begin();
2919
itHD != avsdeHDs.end();
2922
VirtualSystemDescriptionEntry *vsdeHD = *itHD;
2923
if (vsdeHD->strRef == diCurrent.strDiskId)
2925
vsdeTargetHD = vsdeHD;
2930
throw setError(E_FAIL,
2931
tr("Internal inconsistency looking up disk image '%s'"),
2932
diCurrent.strHref.c_str());
2942
/* just continue with normal files*/
2946
/* Important! to store disk name for the next checks */
2947
disksResolvedNames.insert(diCurrent.strHref);
2949
// there must be an image in the OVF disk structs with the same UUID
2950
bool fFound = false;
2953
// for each storage controller...
2954
for (settings::StorageControllersList::iterator sit = config.storageMachine.llStorageControllers.begin();
2955
sit != config.storageMachine.llStorageControllers.end();
2958
settings::StorageController &sc = *sit;
2960
// find the OVF virtual system description entry for this storage controller
2961
switch (sc.storageBus)
2963
case StorageBus_SATA:
2965
case StorageBus_SCSI:
2967
case StorageBus_IDE:
2969
case StorageBus_SAS:
2973
// for each medium attachment to this controller...
2974
for (settings::AttachedDevicesList::iterator dit = sc.llAttachedDevices.begin();
2975
dit != sc.llAttachedDevices.end();
2978
settings::AttachedDevice &d = *dit;
2980
if (d.uuid.isEmpty())
2981
// empty DVD and floppy media
2984
// When repairing a broken VirtualBox xml config section (written
2985
// by VirtualBox versions earlier than 3.2.10) assume the disks
2986
// show up in the same order as in the OVF description.
2987
if (fRepairDuplicate)
2989
VirtualSystemDescriptionEntry *vsdeHD = *avsdeHDsIt;
2990
ovf::DiskImagesMap::const_iterator itDiskImage = stack.mapDisks.find(vsdeHD->strRef);
2991
if (itDiskImage != stack.mapDisks.end())
2993
const ovf::DiskImage &di = itDiskImage->second;
2994
d.uuid = Guid(di.uuidVbox);
2999
// convert the Guid to string
3000
strUuid = d.uuid.toString();
3001
if (diCurrent.uuidVbox != strUuid)
3007
* step 3: import disk
3010
ComObjPtr<Medium> pTargetHD;
3011
importOneDiskImage(diCurrent,
3012
vsdeTargetHD->strVboxCurrent,
3018
// ... and replace the old UUID in the machine config with the one of
3019
// the imported disk that was just created
3021
rc = pTargetHD->COMGETTER(Id)(hdId.asOutParam());
3022
if (FAILED(rc)) throw rc;
3028
} // for (settings::AttachedDevicesList::const_iterator dit = sc.llAttachedDevices.begin();
3029
} // for (settings::StorageControllersList::const_iterator sit = config.storageMachine.llStorageControllers.begin();
3030
// no disk with such a UUID found:
3032
throw setError(E_FAIL,
3033
tr("<vbox:Machine> element in OVF contains a medium attachment for the disk image %s but the OVF describes no such image"),
3035
}// while(oit != stack.mapDisks.end())
2792
3038
* step 4): create the machine and have it import the config