@@ -521,11 +521,7 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
521521 private Pair <UnmanagedInstanceTO .Disk , List <UnmanagedInstanceTO .Disk >> getRootAndDataDisks (List <UnmanagedInstanceTO .Disk > disks , final Map <String , Long > dataDiskOfferingMap ) {
522522 UnmanagedInstanceTO .Disk rootDisk = null ;
523523 List <UnmanagedInstanceTO .Disk > dataDisks = new ArrayList <>();
524- //ToDo: fix cdrom
525- if (disks .size () == 2 ) {
526- rootDisk = disks .get (0 );
527- return new Pair <>(rootDisk , dataDisks );
528- }
524+
529525 Set <String > callerDiskIds = dataDiskOfferingMap .keySet ();
530526 if (callerDiskIds .size () != disks .size () - 1 ) {
531527 String msg = String .format ("VM has total %d disks for which %d disk offering mappings provided. %d disks need a disk offering for import" , disks .size (), callerDiskIds .size (), disks .size ()-1 );
@@ -1653,6 +1649,17 @@ private UserVm importExternalKvmVirtualMachine(final UnmanagedInstanceTO unmanag
16531649 String rootVolumeName = String .format ("ROOT-%s" , userVm .getId ());
16541650 DiskProfile diskProfile = volumeManager .allocateRawVolume (Volume .Type .ROOT , rootVolumeName , diskOffering , null , null , null , userVm , template , owner , null );
16551651
1652+ DiskProfile [] dataDiskProfiles = new DiskProfile [dataDisks .size ()];
1653+ int diskSeq = 0 ;
1654+ for (UnmanagedInstanceTO .Disk disk : dataDisks ) {
1655+ if (disk .getCapacity () == null || disk .getCapacity () == 0 ) {
1656+ throw new InvalidParameterValueException (String .format ("Disk ID: %s size is invalid" , disk .getDiskId ()));
1657+ }
1658+ DiskOffering offering = diskOfferingDao .findById (dataDiskOfferingMap .get (disk .getDiskId ()));
1659+ DiskProfile dataDiskProfile = volumeManager .allocateRawVolume (Volume .Type .DATADISK , String .format ("DATA-%d-%s" , userVm .getId (), disk .getDiskId ()), offering , null , null , null , userVm , template , owner , null );
1660+ dataDiskProfiles [diskSeq ++] = dataDiskProfile ;
1661+ }
1662+
16561663 final VirtualMachineProfile profile = new VirtualMachineProfileImpl (userVm , template , serviceOffering , owner , null );
16571664 DeploymentPlanner .ExcludeList excludeList = new DeploymentPlanner .ExcludeList ();
16581665 final DataCenterDeployment plan = new DataCenterDeployment (zone .getId (), null , null , null , null , null );
@@ -1678,12 +1685,10 @@ private UserVm importExternalKvmVirtualMachine(final UnmanagedInstanceTO unmanag
16781685 template , null , remoteUrl , username , password , tmpPath , diskProfile ));
16791686
16801687 long deviceId = 1L ;
1688+ diskSeq = 0 ;
16811689 for (UnmanagedInstanceTO .Disk disk : dataDisks ) {
1682- if (disk .getCapacity () == null || disk .getCapacity () == 0 ) {
1683- throw new InvalidParameterValueException (String .format ("Disk ID: %s size is invalid" , disk .getDiskId ()));
1684- }
1690+ DiskProfile dataDiskProfile = dataDiskProfiles [diskSeq ++];
16851691 DiskOffering offering = diskOfferingDao .findById (dataDiskOfferingMap .get (disk .getDiskId ()));
1686- DiskProfile dataDiskProfile = volumeManager .allocateRawVolume (Volume .Type .DATADISK , String .format ("DATA-%d-%s" ), offering , null , null , null , userVm , template , owner , null );
16871692
16881693 diskProfileStoragePoolList .add (importExternalDisk (disk , userVm , dest , offering , Volume .Type .DATADISK ,
16891694 template , deviceId , remoteUrl , username , password , tmpPath , dataDiskProfile ));
0 commit comments