diff --git a/core/src/com/cloud/storage/SnapshotVO.java b/core/src/com/cloud/storage/SnapshotVO.java index 171f7496e29..6038d81c1c3 100644 --- a/core/src/com/cloud/storage/SnapshotVO.java +++ b/core/src/com/cloud/storage/SnapshotVO.java @@ -52,7 +52,10 @@ public class SnapshotVO implements Snapshot { long domainId; @Column(name="volume_id") - Long volumeId; + Long volumeId; + + @Column(name="disk_offering_id") + Long diskOfferingId; @Expose @Column(name="path") @@ -94,11 +97,12 @@ public class SnapshotVO implements Snapshot { public SnapshotVO() { } - public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) { + public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) { this.dataCenterId = dcId; this.accountId = accountId; this.domainId = domainId; - this.volumeId = volumeId; + this.volumeId = volumeId; + this.diskOfferingId = diskOfferingId; this.path = path; this.name = name; this.snapshotType = snapshotType; @@ -132,6 +136,10 @@ public class SnapshotVO implements Snapshot { return volumeId; } + public long getDiskOfferingId() { + return diskOfferingId; + } + public void setVolumeId(Long volumeId) { this.volumeId = volumeId; } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index ea0e894693b..c45f51d66c6 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1395,7 +1395,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag throw new InvalidParameterValueException("Either disk Offering Id or snapshot Id must be passed whilst creating volume"); } - if (cmd.getSnapshotId() == null) { + if (cmd.getSnapshotId() == null) {// create a new volume zoneId = cmd.getZoneId(); if ((zoneId == null)) { throw new InvalidParameterValueException("Missing parameter, zoneid must be specified."); @@ -1441,15 +1441,15 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes } - } else { + } else { // create volume from snapshot Long snapshotId = cmd.getSnapshotId(); SnapshotVO snapshotCheck = _snapshotDao.findById(snapshotId); - diskOfferingId = cmd.getDiskOfferingId(); + diskOfferingId = (cmd.getDiskOfferingId() != null) ? cmd.getDiskOfferingId() : snapshotCheck.getDiskOfferingId(); if (snapshotCheck == null) { throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId); } zoneId = snapshotCheck.getDataCenterId(); - size = snapshotCheck.getSize(); //we maintain size from org vol ; disk offering is used for tags purposes + size = snapshotCheck.getSize(); //; disk offering is used for tags purposes if (account != null) { if (isAdmin(account.getType())) { diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index c4a9af769ec..b08a758b1ed 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -1191,7 +1191,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma // user Type snapshotType = getSnapshotType(policyId); HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId); - SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), null, snapshotName, + SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), null, snapshotName, (short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType); return _snapshotDao.persist(snapshotVO); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index b99663e672e..4272bc14892 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -401,6 +401,7 @@ CREATE TABLE `cloud`.`snapshots` ( `account_id` bigint unsigned NOT NULL COMMENT 'owner. foreign key to account table', `domain_id` bigint unsigned NOT NULL COMMENT 'the domain that the owner belongs to', `volume_id` bigint unsigned NOT NULL COMMENT 'volume it belongs to. foreign key to volume table', + `disk_offering_id` bigint unsigned NOT NULL COMMENT , `status` varchar(32) COMMENT 'snapshot creation status', `path` varchar(255) COMMENT 'Path', `name` varchar(255) NOT NULL COMMENT 'snapshot name',