@@ -142,7 +142,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
142142 DataTO destData = cmd .getDestTO ();
143143 TemplateObjectTO template = (TemplateObjectTO )srcData ;
144144 DataStoreTO imageStore = template .getDataStore ();
145- VolumeObjectTO volume = (VolumeObjectTO )destData ;
145+ TemplateObjectTO volume = (TemplateObjectTO )destData ;
146146 PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volume .getDataStore ();
147147
148148 if (!(imageStore instanceof NfsTO )) {
@@ -195,10 +195,10 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
195195 KVMPhysicalDisk primaryVol = storagePoolMgr .copyPhysicalDisk (
196196 tmplVol , UUID .randomUUID ().toString (), primaryPool );
197197
198- VolumeObjectTO newVol = new VolumeObjectTO ();
199- newVol .setPath (primaryVol .getName ());
200- newVol . setSize ( primaryVol . getSize () );
201- return new CopyCmdAnswer (newVol );
198+ TemplateObjectTO newTemplate = new TemplateObjectTO ();
199+ newTemplate .setPath (primaryVol .getName ());
200+ newTemplate . setFormat ( ImageFormat . QCOW2 );
201+ return new CopyCmdAnswer (newTemplate );
202202 } catch (CloudRuntimeException e ) {
203203 return new CopyCmdAnswer (e .toString ());
204204 } finally {
@@ -273,14 +273,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
273273 primaryPool = storagePoolMgr .getStoragePool (primaryStore .getPoolType (),
274274 primaryStore .getUuid ());
275275
276- String templatePath = null ;
277- if (imageStore instanceof NfsTO ) {
278- NfsTO nfsImageStore = (NfsTO )imageStore ;
279- templatePath = nfsImageStore .getUrl ();
280- } else {
281- s_logger .debug ("Failed to create volume: " );
282- return new CopyCmdAnswer ("Unsupported protocol" );
283- }
276+ String templatePath = template .getPath ();
284277
285278 if (primaryPool .getType () == StoragePoolType .CLVM ) {
286279 vol = templateToPrimaryDownload (templatePath , primaryPool );
@@ -321,9 +314,9 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
321314 DataTO srcData = cmd .getSrcTO ();
322315 DataTO destData = cmd .getDestTO ();
323316 int wait = cmd .getWait ();
324- TemplateObjectTO template = (TemplateObjectTO )srcData ;
317+ TemplateObjectTO template = (TemplateObjectTO )destData ;
325318 DataStoreTO imageStore = template .getDataStore ();
326- VolumeObjectTO volume = (VolumeObjectTO )destData ;
319+ VolumeObjectTO volume = (VolumeObjectTO )srcData ;
327320 PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volume .getDataStore ();
328321
329322 if (!(imageStore instanceof NfsTO )) {
@@ -425,7 +418,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
425418 loc .save ();
426419
427420 TemplateObjectTO newTemplate = new TemplateObjectTO ();
428- newTemplate .setPath (templateFolder + templateName + ".qcow2" );
421+ newTemplate .setPath (templateFolder + File . separator + templateName + ".qcow2" );
429422 return new CopyCmdAnswer (newTemplate );
430423 } catch (Exception e ) {
431424 s_logger .debug ("Failed to create template from volume: " + e .toString ());
@@ -783,8 +776,9 @@ public Answer createVolume(CreateObjectCommand cmd) {
783776
784777 @ Override
785778 public Answer createSnapshot (CreateObjectCommand cmd ) {
786- VolumeObjectTO volume = (VolumeObjectTO )cmd .getData ();
787- PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volume .getDataStore ();
779+ SnapshotObjectTO snapshotTO = (SnapshotObjectTO )cmd .getData ();
780+ PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )snapshotTO .getDataStore ();
781+ VolumeObjectTO volume = snapshotTO .getVolume ();
788782 String snapshotName = UUID .randomUUID ().toString ();
789783 String vmName = volume .getVmName ();
790784 try {
0 commit comments