@@ -182,7 +182,7 @@ private String getOVFFilePath(String srcOVAFileName) {
182182 return null ;
183183 }
184184
185- private VirtualMachineMO copyTemplateFromSecondaryToPrimary (VmwareHypervisorHost hyperHost , DatastoreMO datastoreMo , String secondaryStorageUrl ,
185+ private Pair < VirtualMachineMO , Long > copyTemplateFromSecondaryToPrimary (VmwareHypervisorHost hyperHost , DatastoreMO datastoreMo , String secondaryStorageUrl ,
186186 String templatePathAtSecondaryStorage , String templateName , String templateUuid , boolean createSnapshot , Integer nfsVersion ) throws Exception {
187187
188188 s_logger .info ("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
@@ -229,6 +229,12 @@ private VirtualMachineMO copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost
229229 throw new Exception (msg );
230230 }
231231
232+ OVAProcessor processor = new OVAProcessor ();
233+ Map <String , Object > params = new HashMap <String , Object >();
234+ params .put (StorageLayer .InstanceConfigKey , _storage );
235+ processor .configure ("OVA Processor" , params );
236+ long virtualSize = processor .getTemplateVirtualSize (secondaryMountPoint + "/" + templatePathAtSecondaryStorage , templateName );
237+
232238 if (createSnapshot ) {
233239 if (vmMo .createSnapshot ("cloud.template.base" , "Base snapshot" , false , false )) {
234240 // the same template may be deployed with multiple copies at per-datastore per-host basis,
@@ -246,7 +252,7 @@ private VirtualMachineMO copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost
246252 }
247253 }
248254
249- return vmMo ;
255+ return new Pair < VirtualMachineMO , Long >( vmMo , new Long ( virtualSize )) ;
250256 }
251257
252258 @ Override
@@ -322,6 +328,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
322328 DatacenterMO dcMo = new DatacenterMO (context , hyperHost .getHyperHostDatacenter ());
323329 VirtualMachineMO templateMo = VmwareHelper .pickOneVmOnRunningHost (dcMo .findVmByNameAndLabel (templateUuidName ), true );
324330 DatastoreMO dsMo = null ;
331+ Pair <VirtualMachineMO , Long > vmInfo = null ;
325332
326333 if (templateMo == null ) {
327334 if (s_logger .isInfoEnabled ()) {
@@ -343,9 +350,10 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
343350 dsMo = new DatastoreMO (context , morDs );
344351
345352 if (managed ) {
346- VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
353+ vmInfo = copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
347354 managedStoragePoolRootVolumeName , false , _nfsVersion );
348355
356+ VirtualMachineMO vmMo = vmInfo .first ();
349357 vmMo .unregisterVm ();
350358
351359 String [] vmwareLayoutFilePair = VmwareStorageLayoutHelper .getVmdkFilePairDatastorePath (dsMo , managedStoragePoolRootVolumeName ,
@@ -360,7 +368,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
360368 dsMo .deleteFolder (folderToDelete , dcMo .getMor ());
361369 }
362370 else {
363- copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
371+ vmInfo = copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
364372 templateUuidName , true , _nfsVersion );
365373 }
366374 } else {
@@ -378,7 +386,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
378386 else {
379387 newTemplate .setPath (templateUuidName );
380388 }
381- newTemplate .setSize (new Long ( 0 )); // TODO: replace 0 with correct template physical_size.
389+ newTemplate .setSize (( vmInfo != null )? vmInfo . second () : new Long ( 0 ));
382390
383391 return new CopyCmdAnswer (newTemplate );
384392 } catch (Throwable e ) {
0 commit comments