Skip to content

Commit 30484fb

Browse files
committed
CLOUDSTACK-3706:[Object_Store_Refactor] Failed to create template from
stopped guest vm's root disk.
1 parent 4ee6a6d commit 30484fb

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe
202202
templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
203203
if (this.getDataStore().getRole() == DataStoreRole.Image) {
204204
VMTemplateVO templateVO = this.imageDao.findById(this.getId());
205-
templateVO.setFormat(newTemplate.getFormat());
205+
if (newTemplate.getFormat() != null) {
206+
templateVO.setFormat(newTemplate.getFormat());
207+
}
206208
templateVO.setSize(newTemplate.getSize());
207209
this.imageDao.update(templateVO.getId(), templateVO);
208210
}

‎services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,21 @@ protected Answer copyFromNfsToS3(CopyCommand cmd) {
737737

738738
final String bucket = s3.getBucketName();
739739
File srcFile = _storage.getFile(templatePath);
740+
// guard the case where templatePath does not have file extension, since we are not completely sure
741+
// about hypervisor, so we check each extension
740742
if (!srcFile.exists()) {
741743
srcFile = _storage.getFile(templatePath + ".qcow2");
742744
if (!srcFile.exists()) {
743-
return new CopyCmdAnswer("Can't find src file:" + templatePath);
745+
srcFile = _storage.getFile(templatePath + ".vhd");
746+
if (!srcFile.exists()) {
747+
srcFile = _storage.getFile(templatePath + ".ova");
748+
if (!srcFile.exists()) {
749+
return new CopyCmdAnswer("Can't find src file:" + templatePath);
750+
}
751+
}
744752
}
745753
}
746-
ImageFormat format = this.getTemplateFormat(templatePath);
754+
ImageFormat format = this.getTemplateFormat(srcFile.getName());
747755
String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
748756
putFile(s3, srcFile, bucket, key);
749757

@@ -1386,7 +1394,7 @@ Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
13861394

13871395
private Answer execute(ListTemplateCommand cmd) {
13881396
if (!_inSystemVM) {
1389-
return new ListTemplateAnswer(null, null);
1397+
return new ListTemplateAnswer(null, null);
13901398
}
13911399

13921400
DataStoreTO store = cmd.getDataStore();

0 commit comments

Comments
 (0)