Skip to content

Commit cd27202

Browse files
committed
bug 8216: create volume from snapshot can take a disk_offering_id, if disk_offering_id is not specified, use the one from original volume
status 8216: resolved fixed
1 parent 8571d04 commit cd27202

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎core/src/com/cloud/storage/SnapshotVO.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public class SnapshotVO implements Snapshot {
5252
long domainId;
5353

5454
@Column(name="volume_id")
55-
Long volumeId;
55+
Long volumeId;
56+
57+
@Column(name="disk_offering_id")
58+
Long diskOfferingId;
5659

5760
@Expose
5861
@Column(name="path")
@@ -94,11 +97,12 @@ public class SnapshotVO implements Snapshot {
9497

9598
public SnapshotVO() { }
9699

97-
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) {
100+
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) {
98101
this.dataCenterId = dcId;
99102
this.accountId = accountId;
100103
this.domainId = domainId;
101-
this.volumeId = volumeId;
104+
this.volumeId = volumeId;
105+
this.diskOfferingId = diskOfferingId;
102106
this.path = path;
103107
this.name = name;
104108
this.snapshotType = snapshotType;
@@ -132,6 +136,10 @@ public long getVolumeId() {
132136
return volumeId;
133137
}
134138

139+
public long getDiskOfferingId() {
140+
return diskOfferingId;
141+
}
142+
135143
public void setVolumeId(Long volumeId) {
136144
this.volumeId = volumeId;
137145
}

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
13951395
throw new InvalidParameterValueException("Either disk Offering Id or snapshot Id must be passed whilst creating volume");
13961396
}
13971397

1398-
if (cmd.getSnapshotId() == null) {
1398+
if (cmd.getSnapshotId() == null) {// create a new volume
13991399
zoneId = cmd.getZoneId();
14001400
if ((zoneId == null)) {
14011401
throw new InvalidParameterValueException("Missing parameter, zoneid must be specified.");
@@ -1441,15 +1441,15 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
14411441
}
14421442
size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes
14431443
}
1444-
} else {
1444+
} else { // create volume from snapshot
14451445
Long snapshotId = cmd.getSnapshotId();
14461446
SnapshotVO snapshotCheck = _snapshotDao.findById(snapshotId);
1447-
diskOfferingId = cmd.getDiskOfferingId();
1447+
diskOfferingId = (cmd.getDiskOfferingId() != null) ? cmd.getDiskOfferingId() : snapshotCheck.getDiskOfferingId();
14481448
if (snapshotCheck == null) {
14491449
throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId);
14501450
}
14511451
zoneId = snapshotCheck.getDataCenterId();
1452-
size = snapshotCheck.getSize(); //we maintain size from org vol ; disk offering is used for tags purposes
1452+
size = snapshotCheck.getSize(); //; disk offering is used for tags purposes
14531453

14541454
if (account != null) {
14551455
if (isAdmin(account.getType())) {

‎server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ public SnapshotVO allocSnapshot(CreateSnapshotCmd cmd) {
11911191
// user
11921192
Type snapshotType = getSnapshotType(policyId);
11931193
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
1194-
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), null, snapshotName,
1194+
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), null, snapshotName,
11951195
(short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType);
11961196
return _snapshotDao.persist(snapshotVO);
11971197
}

‎setup/db/create-schema.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ CREATE TABLE `cloud`.`snapshots` (
401401
`account_id` bigint unsigned NOT NULL COMMENT 'owner. foreign key to account table',
402402
`domain_id` bigint unsigned NOT NULL COMMENT 'the domain that the owner belongs to',
403403
`volume_id` bigint unsigned NOT NULL COMMENT 'volume it belongs to. foreign key to volume table',
404+
`disk_offering_id` bigint unsigned NOT NULL COMMENT ,
404405
`status` varchar(32) COMMENT 'snapshot creation status',
405406
`path` varchar(255) COMMENT 'Path',
406407
`name` varchar(255) NOT NULL COMMENT 'snapshot name',

0 commit comments

Comments
 (0)