@@ -268,6 +268,9 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
268268 Pair <String , String > templateInfo = VmwareStorageLayoutHelper .decodeTemplateRelativePathAndNameFromUrl (secondaryStorageUrl , templateUrl , template .getName ());
269269
270270 VmwareContext context = hostService .getServiceContext (cmd );
271+ if (context == null ) {
272+ return new CopyCmdAnswer ("Failed to create a Vmware context, check the management server logs or the ssvm log for details" );
273+ }
271274
272275 try {
273276 VmwareHypervisorHost hyperHost = hostService .getHyperHost (context , cmd );
@@ -286,7 +289,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
286289
287290 if (managed ) {
288291 morDs = prepareManagedDatastore (context , hyperHost , managedStoragePoolName , storageHost , storagePort ,
289- chapInitiatorUsername , chapInitiatorSecret , chapTargetUsername , chapTargetSecret );
292+ chapInitiatorUsername , chapInitiatorSecret , chapTargetUsername , chapTargetSecret );
290293 }
291294 else {
292295 morDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , storageUuid );
@@ -303,9 +306,9 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
303306 vmMo .unregisterVm ();
304307
305308 String [] vmwareLayoutFilePair = VmwareStorageLayoutHelper .getVmdkFilePairDatastorePath (dsMo , managedStoragePoolRootVolumeName ,
306- managedStoragePoolRootVolumeName , VmwareStorageLayoutType .VMWARE , false );
309+ managedStoragePoolRootVolumeName , VmwareStorageLayoutType .VMWARE , false );
307310 String [] legacyCloudStackLayoutFilePair = VmwareStorageLayoutHelper .getVmdkFilePairDatastorePath (dsMo , null ,
308- managedStoragePoolRootVolumeName , VmwareStorageLayoutType .CLOUDSTACK_LEGACY , false );
311+ managedStoragePoolRootVolumeName , VmwareStorageLayoutType .CLOUDSTACK_LEGACY , false );
309312
310313 dsMo .moveDatastoreFile (vmwareLayoutFilePair [0 ], dcMo .getMor (), dsMo .getMor (), legacyCloudStackLayoutFilePair [0 ], dcMo .getMor (), true );
311314 dsMo .moveDatastoreFile (vmwareLayoutFilePair [1 ], dcMo .getMor (), dsMo .getMor (), legacyCloudStackLayoutFilePair [1 ], dcMo .getMor (), true );
@@ -1294,9 +1297,9 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean
12941297 Map <String , String > details = disk .getDetails ();
12951298
12961299 morDs = prepareManagedStorage (context , hyperHost , iScsiName , storageHost , storagePort , null ,
1297- details .get (DiskTO .CHAP_INITIATOR_USERNAME ), details .get (DiskTO .CHAP_INITIATOR_SECRET ),
1298- details .get (DiskTO .CHAP_TARGET_USERNAME ), details .get (DiskTO .CHAP_TARGET_SECRET ),
1299- volumeTO .getSize (), cmd );
1300+ details .get (DiskTO .CHAP_INITIATOR_USERNAME ), details .get (DiskTO .CHAP_INITIATOR_SECRET ),
1301+ details .get (DiskTO .CHAP_TARGET_USERNAME ), details .get (DiskTO .CHAP_TARGET_SECRET ),
1302+ volumeTO .getSize (), cmd );
13001303 }
13011304 else {
13021305 morDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , isManaged ? VmwareResource .getDatastoreName (iScsiName ) : primaryStore .getUuid ());
@@ -1573,7 +1576,7 @@ public Answer deleteVolume(DeleteCommand cmd) {
15731576 }
15741577
15751578 ManagedObjectReference morDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost ,
1576- isManaged ? managedDatastoreName : store .getUuid ());
1579+ isManaged ? managedDatastoreName : store .getUuid ());
15771580
15781581 if (morDs == null ) {
15791582 String msg = "Unable to find datastore based on volume mount point " + store .getUuid ();
@@ -1982,7 +1985,7 @@ public ManagedObjectReference prepareManagedStorage(VmwareContext context, Vmwar
19821985 String storageHost , int storagePort , String volumeName , String chapInitiatorUsername , String chapInitiatorSecret ,
19831986 String chapTargetUsername , String chapTargetSecret , long size , Command cmd ) throws Exception {
19841987 ManagedObjectReference morDs = prepareManagedDatastore (context , hyperHost , iScsiName , storageHost , storagePort ,
1985- chapInitiatorUsername , chapInitiatorSecret , chapTargetUsername , chapTargetSecret );
1988+ chapInitiatorUsername , chapInitiatorSecret , chapTargetUsername , chapTargetSecret );
19861989
19871990 DatastoreMO dsMo = new DatastoreMO (hostService .getServiceContext (null ), morDs );
19881991
0 commit comments