mirror of https://github.com/apache/cloudstack.git
Bug 8830 - Return parent template ID from templates created off of a snapshot
Changes: - Added a new column `source_template_id` to vm_template table to carry the parent/source template ID from which the tempalte was created - Added the column in db upgrade 224 to 225 - Changed code to save the source_template_id if there is one associated to the volume/ volume from which the snapshot was taken - API response returns the sourcetemplateid field, if set, in all template usecases.
This commit is contained in:
parent
b6364627a3
commit
b2b01bfcd2
|
|
@ -110,6 +110,9 @@ public class TemplateResponse extends BaseResponse {
|
|||
@SerializedName("checksum") @Param(description="checksum of the template")
|
||||
private String checksum;
|
||||
|
||||
@SerializedName("sourcetemplateid") @Param(description="the template ID of the parent template if present")
|
||||
private Long sourcetemplateId;
|
||||
|
||||
public Long getObjectId() {
|
||||
return getId();
|
||||
}
|
||||
|
|
@ -336,5 +339,13 @@ public class TemplateResponse extends BaseResponse {
|
|||
|
||||
public void setChecksum(String checksum) {
|
||||
this.checksum = checksum;
|
||||
}
|
||||
}
|
||||
|
||||
public Long getSourceTemplateId() {
|
||||
return sourcetemplateId;
|
||||
}
|
||||
|
||||
public void setSourceTemplateId(Long sourcetemplateId) {
|
||||
this.sourcetemplateId = sourcetemplateId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,4 +83,6 @@ public interface VirtualMachineTemplate extends ControlledEntity {
|
|||
String getUrl();
|
||||
|
||||
String getChecksum();
|
||||
|
||||
Long getSourceTemplateId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,10 @@ public class VMTemplateVO implements VirtualMachineTemplate {
|
|||
@Column(name="extractable")
|
||||
private boolean extractable = true;
|
||||
|
||||
@Override
|
||||
@Column(name="source_template_id")
|
||||
private Long sourceTemplateId;
|
||||
|
||||
@Override
|
||||
public String getUniqueName() {
|
||||
return uniqueName;
|
||||
}
|
||||
|
|
@ -355,6 +358,15 @@ public class VMTemplateVO implements VirtualMachineTemplate {
|
|||
public void setExtractable(boolean extractable) {
|
||||
this.extractable = extractable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSourceTemplateId() {
|
||||
return sourceTemplateId;
|
||||
}
|
||||
|
||||
public void setSourceTemplateId(Long sourceTemplateId) {
|
||||
this.sourceTemplateId = sourceTemplateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainId() {
|
||||
|
|
|
|||
|
|
@ -1519,7 +1519,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
|
||||
templateResponse.setChecksum(template.getChecksum());
|
||||
|
||||
templateResponse.setSourceTemplateId(template.getSourceTemplateId());
|
||||
|
||||
templateResponse.setObjectName("template");
|
||||
responses.add(templateResponse);
|
||||
}
|
||||
|
|
@ -1580,7 +1581,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
templateResponse.setHypervisor(template.getHypervisorType().toString());
|
||||
templateResponse.setObjectName("template");
|
||||
templateResponse.setChecksum(template.getChecksum());
|
||||
|
||||
templateResponse.setSourceTemplateId(template.getSourceTemplateId());
|
||||
|
||||
responses.add(templateResponse);
|
||||
}
|
||||
response.setResponses(responses);
|
||||
|
|
@ -1741,6 +1743,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
templateResponse.setPasswordEnabled(template.getEnablePassword());
|
||||
templateResponse.setZoneId(destZoneId);
|
||||
templateResponse.setZoneName(ApiDBUtils.findZoneById(destZoneId).getName());
|
||||
templateResponse.setSourceTemplateId(template.getSourceTemplateId());
|
||||
|
||||
GuestOS os = ApiDBUtils.findGuestOSById(template.getGuestOSId());
|
||||
if (os != null) {
|
||||
|
|
@ -1942,6 +1945,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
response.setZoneName(zone.getName());
|
||||
}
|
||||
|
||||
response.setSourceTemplateId(template.getSourceTemplateId());
|
||||
|
||||
response.setObjectName("template");
|
||||
return response;
|
||||
|
||||
|
|
|
|||
|
|
@ -1374,12 +1374,20 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
Long nextTemplateId = _templateDao.getNextInSequence(Long.class, "id");
|
||||
String description = cmd.getDisplayText();
|
||||
boolean isExtractable = false;
|
||||
Long sourceTemplateId = null;
|
||||
if (volume != null) {
|
||||
VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
|
||||
isExtractable = template != null && template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
|
||||
sourceTemplateId = template.getId();
|
||||
}
|
||||
privateTemplate = new VMTemplateVO(nextTemplateId, uniqueName, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, null, requiresHvmValue, bitsValue, accountId,
|
||||
null, description, passwordEnabledValue, guestOS.getId(), true, hyperType);
|
||||
if(sourceTemplateId != null){
|
||||
if(s_logger.isDebugEnabled()){
|
||||
s_logger.debug("This template is getting created from other template, setting source template Id to: "+sourceTemplateId);
|
||||
}
|
||||
}
|
||||
privateTemplate.setSourceTemplateId(sourceTemplateId);
|
||||
|
||||
VMTemplateVO template = _templateDao.persist(privateTemplate);
|
||||
// Increment the number of templates
|
||||
|
|
@ -1954,7 +1962,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
@Override
|
||||
public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner,
|
||||
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Host destinationHost)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<NetworkVO> networkList = new ArrayList<NetworkVO>();
|
||||
|
|
@ -2052,7 +2060,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
@Override
|
||||
public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Host destinationHost)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<NetworkVO> networkList = new ArrayList<NetworkVO>();
|
||||
|
|
@ -2397,7 +2405,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
protected UserVm startVirtualMachine(DeployVMCmd cmd, Map<VirtualMachineProfile.Param, Object> additonalParams) throws ResourceUnavailableException, InsufficientCapacityException,
|
||||
ConcurrentOperationException {
|
||||
ConcurrentOperationException {
|
||||
long vmId = cmd.getEntityId();
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
_vmDao.loadDetails(vm);
|
||||
|
|
@ -2955,7 +2963,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
|
||||
@Override
|
||||
public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException,
|
||||
ResourceAllocationException {
|
||||
ResourceAllocationException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -785,6 +785,7 @@ CREATE TABLE `cloud`.`vm_template` (
|
|||
`cross_zones` int(1) unsigned NOT NULL default 0 COMMENT 'Make this template available in all zones',
|
||||
`extractable` int(1) unsigned NOT NULL default 0 COMMENT 'Is this template extractable',
|
||||
`hypervisor_type` varchar(32) COMMENT 'hypervisor that the template is belonged to',
|
||||
`source_template_id` bigint unsigned COMMENT 'Id of the original template, if this template is created from snapshot',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,3 +43,5 @@ ALTER TABLE `cloud`.`security_ingress_rule` DROP COLUMN `allowed_sec_grp_acct`;
|
|||
|
||||
ALTER TABLE `cloud`.`data_center` ADD COLUMN `zone_token` varchar(255);
|
||||
ALTER TABLE `cloud`.`data_center` ADD INDEX `i_data_center__zone_token`(`zone_token`);
|
||||
|
||||
ALTER TABLE `cloud`.`vm_template` ADD COLUMN `source_template_id` bigint unsigned COMMENT 'Id of the original template, if this template is created from snapshot';
|
||||
|
|
|
|||
Loading…
Reference in New Issue