diff --git a/engine/schema/src/com/cloud/storage/VolumeVO.java b/engine/schema/src/com/cloud/storage/VolumeVO.java index 1445e99d727..bbecf0346c3 100755 --- a/engine/schema/src/com/cloud/storage/VolumeVO.java +++ b/engine/schema/src/com/cloud/storage/VolumeVO.java @@ -152,6 +152,9 @@ public class VolumeVO implements Volume { @Column(name = "vm_snapshot_chain_size") private Long vmSnapshotChainSize; + + @Column(name = "iso_id") + private long isoId; @Transient // @Column(name="reservation") @@ -561,4 +564,12 @@ public class VolumeVO implements Volume { public Long getVmSnapshotChainSize(){ return this.vmSnapshotChainSize; } + + public Long getIsoId() { + return this.isoId; + } + + public void setIsoId(long isoId) { + this.isoId =isoId; + } } diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java index 13ddbab12ee..d95a8149fe1 100644 --- a/server/src/com/cloud/storage/VolumeManager.java +++ b/server/src/com/cloud/storage/VolumeManager.java @@ -77,7 +77,7 @@ public interface VolumeManager extends VolumeApiService { void destroyVolume(VolumeVO volume); - DiskProfile allocateRawVolume(Type type, String name, DiskOfferingVO offering, Long size, VMInstanceVO vm, Account owner); + DiskProfile allocateRawVolume(Type type, String name, DiskOfferingVO offering, Long size, VMInstanceVO vm, VMTemplateVO template, Account owner); @Override Volume attachVolumeToVM(AttachVolumeCmd command); diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index 393904e59c2..36bc1037e89 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -31,6 +31,13 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.utils.DateUtil; +import com.cloud.utils.EnumUtils; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.Pair; +import com.cloud.utils.UriUtils; +import com.cloud.utils.db.SearchCriteria; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -1380,7 +1387,8 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @Override public DiskProfile allocateRawVolume(Type type, - String name, DiskOfferingVO offering, Long size, VMInstanceVO vm, Account owner) { + String name, DiskOfferingVO offering, Long size, VMInstanceVO vm, VMTemplateVO template, Account owner) { + Long isoId=null; if (size == null) { size = offering.getDiskSize(); } else { @@ -1398,6 +1406,9 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } else { vol.setDeviceId(1l); } + if (template.getFormat() == ImageFormat.ISO) { + vol.setIsoId(template.getId()); + } vol.setFormat(getSupportedImageFormatForCluster(vm.getHypervisorType())); vol = _volsDao.persist(vol); diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index d26ebe25d04..5a9f5d9aef2 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1376,6 +1376,22 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, this._tmpltZoneDao.persist(templateZone); privateTemplate = this._tmpltDao.findById(templateId); + if (snapshotId != null) { + //getting the prent volume + long parentVolumeId=_snapshotDao.findById(snapshotId).getVolumeId(); + VolumeVO parentVolume = _volumeDao.findById(parentVolumeId); + if (parentVolume.getIsoId() != null) { + privateTemplate.setSourceTemplateId(parentVolume.getIsoId()); + _tmpltDao.update(privateTemplate.getId(), privateTemplate); + } + } + else if (volumeId != null) { + VolumeVO parentVolume = _volumeDao.findById(volumeId); + if (parentVolume.getIsoId() != null) { + privateTemplate.setSourceTemplateId(parentVolume.getIsoId()); + _tmpltDao.update(privateTemplate.getId(), privateTemplate); + } + } TemplateDataStoreVO srcTmpltStore = this._tmplStoreDao.findByStoreTemplate(store.getId(), templateId); UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(), zoneId, privateTemplate.getId(), privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(), srcTmpltStore.getPhysicalSize(), privateTemplate.getSize()); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 08bca43e733..b54d1feade5 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -372,7 +372,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (template.getFormat() == ImageFormat.ISO) { - volumeMgr.allocateRawVolume(Type.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vm, owner); + volumeMgr.allocateRawVolume(Type.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), vm, template, owner); } else if (template.getFormat() == ImageFormat.BAREMETAL) { // Do nothing } else { @@ -380,7 +380,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } for (Pair offering : dataDiskOfferings) { - volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, owner); + volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, template, owner); } txn.commit(); diff --git a/setup/db/db/schema-307to410.sql b/setup/db/db/schema-307to410.sql index be6c17da148..af296abbe25 100644 --- a/setup/db/db/schema-307to410.sql +++ b/setup/db/db/schema-307to410.sql @@ -1572,3 +1572,4 @@ ALTER TABLE `cloud_usage`.`usage_storage` CHANGE COLUMN `virtual_size` `virtual_ ALTER TABLE `cloud_usage`.`cloud_usage` CHANGE COLUMN `virtual_size` `virtual_size1` bigint unsigned; ALTER TABLE `cloud`.`network_offerings` CHANGE COLUMN `concurrent_connections` `concurrent_connections1` int(10) unsigned COMMENT 'Load Balancer(haproxy) maximum number of concurrent connections(global max)'; +ALTER TABLE `cloud`.`volumes` DROP COLUMN `iso_id`; \ No newline at end of file diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 657d947dd71..07f227fc40f 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -1788,7 +1788,7 @@ CREATE VIEW `cloud`.`volume_view` AS left join `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id left join - `cloud`.`vm_template` ON volumes.template_id = vm_template.id + `cloud`.`vm_template` ON volumes.template_id = vm_template.id OR volumes.iso_id = vm_template.id left join `cloud`.`resource_tags` ON resource_tags.resource_id = volumes.id and resource_tags.resource_type = 'Volume' @@ -2220,6 +2220,7 @@ CREATE TABLE `cloud_usage`.`usage_vmsnapshot` ( ) ENGINE=InnoDB CHARSET=utf8; ALTER TABLE volumes ADD COLUMN vm_snapshot_chain_size bigint(20) unsigned; +ALTER TABLE volumes ADD COLUMN iso_id bigint(20) unsigned; INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'healthcheck.update.interval', '600', 'Time Interval to fetch the LB health check states (in sec)'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Snapshots', 'DEFAULT', 'SnapshotManager', 'KVM.snapshot.enabled', 'false', 'whether snapshot is enabled for KVM hosts');