@@ -343,7 +343,11 @@ public UserVmResponse importUnmanagedInstance(ImportUnmanageInstanceCmd cmd) {
343343 null , caller , true , null , owner .getAccountId (), userId ,
344344 serviceOffering , diskOffering , null , null , hostName ,
345345 cluster .getHypervisorType (), new HashMap <>(), powerState );
346- if (userVm != null ) {
346+ } catch (InsufficientCapacityException ice ) {
347+ throw new ServerApiException (ApiErrorCode .INSUFFICIENT_CAPACITY_ERROR , ice .getMessage ());
348+ }
349+ if (userVm != null ) {
350+ try {
347351 ingestDisk (rootDisk , userVm , diskOffering , Volume .Type .ROOT , String .format ("ROOT-%d" , userVm .getId ()), rootDiskSize , template , owner , null );
348352 Set <String > disks = dataDiskOfferingMap .keySet ();
349353 for (String diskId : disks ) {
@@ -354,7 +358,11 @@ public UserVmResponse importUnmanagedInstance(ImportUnmanageInstanceCmd cmd) {
354358 }
355359 }
356360 }
361+ } catch (Exception e ) {
362+ throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , String .format ("Failed to import volumes while ingesting vm: %s. %s" , instanceName , e .getMessage ()));
363+ }
357364
365+ try {
358366 Set <String > nics = nicNetworkMap .keySet ();
359367 int i = 0 ;
360368 for (String nicId : nics ) {
@@ -367,9 +375,9 @@ public UserVmResponse importUnmanagedInstance(ImportUnmanageInstanceCmd cmd) {
367375 }
368376 i ++;
369377 }
378+ } catch (Exception e ) {
379+ throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , String .format ("Failed to import NICs while ingesting vm: %s. %s" , instanceName , e .getMessage ()));
370380 }
371- } catch (InsufficientCapacityException ice ) {
372- throw new ServerApiException (ApiErrorCode .INSUFFICIENT_CAPACITY_ERROR , ice .getMessage ());
373381 }
374382 break ;
375383 }
0 commit comments