@@ -4171,7 +4171,9 @@ private List<CheckedReservation> reserveStorageResourcesForVm(Account owner, Lon
41714171 CheckedReservation additionalPrimaryStorageReservation = diskOfferingId != null ? new CheckedReservation (owner , ResourceType .primary_storage , additionalResourceLimitStorageTags , size , reservationDao , resourceLimitService ) : null ;
41724172 checkedReservations .add (additionalPrimaryStorageReservation );
41734173
4174- } else if (dataDiskOfferingsInfo != null ) {
4174+ }
4175+
4176+ if (dataDiskOfferingsInfo != null ) {
41754177 for (DiskOfferingInfo diskOfferingInfo : dataDiskOfferingsInfo ) {
41764178 DiskOffering diskOffering = diskOfferingInfo .getDiskOffering ();
41774179 List <String > additionalResourceLimitStorageTagsForDataDisk = getResourceLimitStorageTags (diskOfferingInfo .getDiskOffering ().getId ());
@@ -9024,6 +9026,16 @@ public boolean unmanageUserVM(Long vmId) {
90249026 return true ;
90259027 }
90269028
9029+ private void updateDetailsWithRootDiskAttributes (Map <String , String > details , DiskOfferingInfo rootDiskOfferingInfo ) {
9030+ details .put (VmDetailConstants .ROOT_DISK_SIZE , rootDiskOfferingInfo .getSize ().toString ());
9031+ if (rootDiskOfferingInfo .getMinIops () != null ) {
9032+ details .put (MIN_IOPS , rootDiskOfferingInfo .getMinIops ().toString ());
9033+ }
9034+ if (rootDiskOfferingInfo .getMaxIops () != null ) {
9035+ details .put (MAX_IOPS , rootDiskOfferingInfo .getMaxIops ().toString ());
9036+ }
9037+ }
9038+
90279039 @ Override
90289040 public UserVm allocateVMFromBackup (CreateVMFromBackupCmd cmd ) throws InsufficientCapacityException , ResourceAllocationException , ResourceUnavailableException {
90299041 //Verify that all objects exist before passing them to the service
@@ -9046,6 +9058,26 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
90469058
90479059 verifyDetails (cmd .getDetails ());
90489060
9061+ VMInstanceVO backupVm = _vmInstanceDao .findByIdIncludingRemoved (backup .getVmId ());
9062+ HypervisorType hypervisorType = backupVm .getHypervisorType ();
9063+
9064+ Long templateId ;
9065+ if (cmd .getTemplateId () != null ) {
9066+ templateId = cmd .getTemplateId ();
9067+ } else {
9068+ templateId = backupVm .getTemplateId ();
9069+ }
9070+
9071+ VirtualMachineTemplate template = _templateDao .findById (templateId );
9072+ if (template == null ) {
9073+ throw new InvalidParameterValueException ("Unable to use template " + templateId );
9074+ }
9075+ Boolean isIso = template .getFormat ().equals (ImageFormat .ISO );
9076+
9077+ if (template .isDeployAsIs ()) {
9078+ throw new InvalidParameterValueException ("Deploy as is template not supported" );
9079+ }
9080+
90499081 Long serviceOfferingId = cmd .getServiceOfferingId ();
90509082 ServiceOffering serviceOffering ;
90519083 if (serviceOfferingId != null ) {
@@ -9064,16 +9096,37 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
90649096 }
90659097 }
90669098
9099+ Long diskOfferingId = cmd .getDiskOfferingId ();
9100+ if (diskOfferingId != null ) {
9101+ if (!isIso ) {
9102+ throw new InvalidParameterValueException (ApiConstants .DISK_OFFERING_ID + " parameter is supported for creating instance from backup only for ISO. For creating VMs with templates, please use the parameter " + ApiConstants .DATADISKS_DETAILS );
9103+ }
9104+ DiskOffering diskOffering = _entityMgr .findById (DiskOffering .class , diskOfferingId );
9105+ if (diskOffering == null ) {
9106+ throw new InvalidParameterValueException ("Unable to find disk offering " + diskOfferingId );
9107+ }
9108+ if (diskOffering .isComputeOnly ()) {
9109+ throw new InvalidParameterValueException (String .format ("The disk offering %s provided is directly mapped to a service offering, please provide an individual disk offering" , diskOffering ));
9110+ }
9111+ }
9112+
90679113 Long overrideDiskOfferingId = cmd .getOverrideDiskOfferingId ();
9068- if (overrideDiskOfferingId == null ) {
9114+
9115+ if (isIso && diskOfferingId == null ) {
9116+ DiskOfferingInfo rootDiskOfferingInfo = backupManager .getRootDiskOfferingInfoFromBackup (backup );
9117+ if (rootDiskOfferingInfo == null ) {
9118+ throw new CloudRuntimeException ("Unable to find root disk offering with the uuid stored in backup. Please specify a valid root disk offering id while creating instance" );
9119+ }
9120+ diskOfferingId = rootDiskOfferingInfo .getDiskOffering ().getId ();
9121+ updateDetailsWithRootDiskAttributes (cmd .getDetails (), rootDiskOfferingInfo );
9122+ }
9123+
9124+ if (!isIso && overrideDiskOfferingId == null ) {
90699125 DiskOfferingInfo rootDiskOfferingInfo = backupManager .getRootDiskOfferingInfoFromBackup (backup );
90709126 if (rootDiskOfferingInfo != null &&
90719127 serviceOffering .getDiskOfferingId () != rootDiskOfferingInfo .getDiskOffering ().getId ()) {
90729128 overrideDiskOfferingId = rootDiskOfferingInfo .getDiskOffering ().getId ();
9073- Map <String , String > details = cmd .getDetails ();
9074- details .put (VmDetailConstants .ROOT_DISK_SIZE , rootDiskOfferingInfo .getSize ().toString ());
9075- details .put (MIN_IOPS , rootDiskOfferingInfo .getSize ().toString ());
9076- details .put (MAX_IOPS , rootDiskOfferingInfo .getSize ().toString ());
9129+ updateDetailsWithRootDiskAttributes (cmd .getDetails (), rootDiskOfferingInfo );
90779130 }
90789131 }
90799132
@@ -9093,32 +9146,6 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
90939146 }
90949147 }
90959148
9096- Long templateId = cmd .getTemplateId ();
9097- VirtualMachineTemplate template ;
9098- if (templateId != null ) {
9099- template = _templateDao .findById (templateId );
9100- if (template == null ) {
9101- throw new InvalidParameterValueException ("Unable to use template " + templateId );
9102- }
9103- } else {
9104- String templateUuid = backup .getDetail (ApiConstants .TEMPLATE_ID );
9105- if (templateUuid == null ) {
9106- throw new CloudRuntimeException ("Backup doesn't contain template uuid. Please specify a valid template id while creating instance" );
9107- }
9108- template = _templateDao .findByUuid (templateUuid );
9109- if (template == null ) {
9110- throw new CloudRuntimeException ("Unable to find template with the uuid stored in backup. Please specify a valid template id while creating the instance" );
9111- }
9112- }
9113-
9114- if (template .isDeployAsIs ()) {
9115- throw new InvalidParameterValueException ("Deploy as is template not supported" );
9116- }
9117-
9118- if (cmd .getDiskOfferingId () != null ) {
9119- throw new InvalidParameterValueException (ApiConstants .DISK_OFFERING_ID + " parameter is not supported for creating instance from backup. Please use the parameter " + ApiConstants .DATADISKS_DETAILS );
9120- }
9121-
91229149 List <DiskOfferingInfo > dataDiskOfferingsInfo = cmd .getDataDiskOfferingsInfo ();
91239150 if (dataDiskOfferingsInfo != null ) {
91249151 backupManager .updateDiskOfferingSizeFromBackup (dataDiskOfferingsInfo , backup );
@@ -9177,25 +9204,25 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
91779204 if (networkIds != null ) {
91789205 throw new InvalidParameterValueException ("Can't specify network Ids in Basic zone" );
91799206 } else {
9180- vm = createBasicSecurityGroupVirtualMachine (zone , serviceOffering , template , getSecurityGroupIdList (cmd , zone , template , owner ), owner , name , displayName , null ,
9181- size , dataDiskOfferingsInfo , null , cmd . getHypervisor () , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null , cmd .getAffinityGroupIdList (),
9207+ vm = createBasicSecurityGroupVirtualMachine (zone , serviceOffering , template , getSecurityGroupIdList (cmd , zone , template , owner ), owner , name , displayName , diskOfferingId ,
9208+ size , dataDiskOfferingsInfo , null , hypervisorType , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null , cmd .getAffinityGroupIdList (),
91829209 cmd .getDetails (), cmd .getCustomId (), cmd .getDhcpOptionsMap (),
91839210 dataDiskTemplateToDiskOfferingMap , userVmOVFProperties , false , overrideDiskOfferingId );
91849211 }
91859212 } else {
91869213 if (_networkModel .checkSecurityGroupSupportForNetwork (owner , zone , networkIds ,
91879214 cmd .getSecurityGroupIdList ())) {
91889215 vm = createAdvancedSecurityGroupVirtualMachine (zone , serviceOffering , template , networkIds , getSecurityGroupIdList (cmd , zone , template , owner ), owner , name ,
9189- displayName , null , size , dataDiskOfferingsInfo , null , cmd . getHypervisor () , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null ,
9216+ displayName , diskOfferingId , size , dataDiskOfferingsInfo , null , hypervisorType , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null ,
91909217 cmd .getAffinityGroupIdList (), cmd .getDetails (), cmd .getCustomId (), cmd .getDhcpOptionsMap (),
91919218 dataDiskTemplateToDiskOfferingMap , userVmOVFProperties , false , overrideDiskOfferingId , null );
91929219
91939220 } else {
91949221 if (cmd .getSecurityGroupIdList () != null && !cmd .getSecurityGroupIdList ().isEmpty ()) {
91959222 throw new InvalidParameterValueException ("Can't create vm with security groups; security group feature is not enabled per zone" );
91969223 }
9197- vm = createAdvancedVirtualMachine (zone , serviceOffering , template , networkIds , owner , name , displayName , null , size , dataDiskOfferingsInfo , null ,
9198- cmd . getHypervisor () , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null , cmd .getAffinityGroupIdList (), cmd .getDetails (),
9224+ vm = createAdvancedVirtualMachine (zone , serviceOffering , template , networkIds , owner , name , displayName , diskOfferingId , size , dataDiskOfferingsInfo , null ,
9225+ hypervisorType , cmd .getHttpMethod (), null , null , null , sshKeyPairs , ipToNetworkMap , addrs , null , null , cmd .getAffinityGroupIdList (), cmd .getDetails (),
91999226 cmd .getCustomId (), cmd .getDhcpOptionsMap (), dataDiskTemplateToDiskOfferingMap , userVmOVFProperties , false , null , overrideDiskOfferingId );
92009227 }
92019228 }
0 commit comments