@@ -896,6 +896,7 @@ private UserVm migrateImportedVM(HostVO sourceHost, VirtualMachineTemplate templ
896896 if (!hostSupportsServiceOffering (sourceHost , serviceOffering )) {
897897 LOGGER .debug (String .format ("VM %s needs to be migrated" , vm .getUuid ()));
898898 final VirtualMachineProfile profile = new VirtualMachineProfileImpl (vm , template , serviceOffering , owner , null );
899+ profile .setServiceOffering (serviceOfferingDao .findByIdIncludingRemoved (vm .getId (), serviceOffering .getId ()));
899900 DeploymentPlanner .ExcludeList excludeList = new DeploymentPlanner .ExcludeList ();
900901 excludeList .addHost (sourceHost .getId ());
901902 final DataCenterDeployment plan = new DataCenterDeployment (sourceHost .getDataCenterId (), sourceHost .getPodId (), sourceHost .getClusterId (), null , null , null );
@@ -1083,7 +1084,7 @@ private UserVm importVirtualMachineInternal(final UnmanagedInstanceTO unmanagedI
10831084 internalCSName = instanceName ;
10841085 }
10851086 Map <String , String > allDetails = new HashMap <>(details );
1086- if (validatedServiceOffering .isDynamic ()) {
1087+ if (! validatedServiceOffering .isDynamic ()) {
10871088 allDetails .put (VmDetailConstants .CPU_NUMBER , String .valueOf (validatedServiceOffering .getCpu ()));
10881089 allDetails .put (VmDetailConstants .MEMORY , String .valueOf (validatedServiceOffering .getRamSize ()));
10891090 if (serviceOffering .getSpeed () == null ) {
@@ -2131,7 +2132,7 @@ private UserVm importExternalKvmVirtualMachine(final UnmanagedInstanceTO unmanag
21312132 UserVm userVm = null ;
21322133
21332134 Map <String , String > allDetails = new HashMap <>(details );
2134- if (serviceOffering .isDynamic ()) {
2135+ if (! serviceOffering .isDynamic ()) {
21352136 allDetails .put (VmDetailConstants .CPU_NUMBER , String .valueOf (serviceOffering .getCpu ()));
21362137 allDetails .put (VmDetailConstants .MEMORY , String .valueOf (serviceOffering .getRamSize ()));
21372138 allDetails .put (VmDetailConstants .CPU_SPEED , String .valueOf (serviceOffering .getSpeed ()));
@@ -2189,6 +2190,8 @@ private UserVm importExternalKvmVirtualMachine(final UnmanagedInstanceTO unmanag
21892190 }
21902191
21912192 final VirtualMachineProfile profile = new VirtualMachineProfileImpl (userVm , template , serviceOffering , owner , null );
2193+ ServiceOfferingVO dummyOffering = serviceOfferingDao .findByIdIncludingRemoved (userVm .getId (), serviceOffering .getId ());
2194+ profile .setServiceOffering (dummyOffering );
21922195 DeploymentPlanner .ExcludeList excludeList = new DeploymentPlanner .ExcludeList ();
21932196 final DataCenterDeployment plan = new DataCenterDeployment (zone .getId (), null , null , null , null , null );
21942197 DeployDestination dest = null ;
@@ -2240,7 +2243,7 @@ private UserVm importExternalKvmVirtualMachine(final UnmanagedInstanceTO unmanag
22402243 cleanupFailedImportVM (userVm );
22412244 throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , String .format ("Failed to import NICs while importing vm: %s. %s" , instanceName , StringUtils .defaultString (e .getMessage ())));
22422245 }
2243- publishVMUsageUpdateResourceCount (userVm , serviceOffering );
2246+ publishVMUsageUpdateResourceCount (userVm , dummyOffering );
22442247 return userVm ;
22452248 }
22462249
@@ -2252,7 +2255,7 @@ private UserVm importKvmVirtualMachineFromDisk(final ImportSource importSource,
22522255 UserVm userVm = null ;
22532256
22542257 Map <String , String > allDetails = new HashMap <>(details );
2255- if (serviceOffering .isDynamic ()) {
2258+ if (! serviceOffering .isDynamic ()) {
22562259 allDetails .put (VmDetailConstants .CPU_NUMBER , String .valueOf (serviceOffering .getCpu ()));
22572260 allDetails .put (VmDetailConstants .MEMORY , String .valueOf (serviceOffering .getRamSize ()));
22582261 allDetails .put (VmDetailConstants .CPU_SPEED , String .valueOf (serviceOffering .getSpeed ()));
@@ -2323,6 +2326,8 @@ private UserVm importKvmVirtualMachineFromDisk(final ImportSource importSource,
23232326 DiskProfile diskProfile = volumeManager .allocateRawVolume (Volume .Type .ROOT , rootVolumeName , diskOffering , null , null , null , userVm , template , owner , null );
23242327
23252328 final VirtualMachineProfile profile = new VirtualMachineProfileImpl (userVm , template , serviceOffering , owner , null );
2329+ ServiceOfferingVO dummyOffering = serviceOfferingDao .findByIdIncludingRemoved (userVm .getId (), serviceOffering .getId ());
2330+ profile .setServiceOffering (dummyOffering );
23262331 DeploymentPlanner .ExcludeList excludeList = new DeploymentPlanner .ExcludeList ();
23272332 final DataCenterDeployment plan = new DataCenterDeployment (zone .getId (), null , null , hostId , poolId , null );
23282333 DeployDestination dest = null ;
@@ -2374,7 +2379,7 @@ private UserVm importKvmVirtualMachineFromDisk(final ImportSource importSource,
23742379 throw new ServerApiException (ApiErrorCode .INTERNAL_ERROR , String .format ("Failed to import volumes while importing vm: %s. %s" , instanceName , StringUtils .defaultString (e .getMessage ())));
23752380 }
23762381 networkOrchestrationService .importNic (macAddress ,0 ,network , true , userVm , requestedIpPair , zone , true );
2377- publishVMUsageUpdateResourceCount (userVm , serviceOffering );
2382+ publishVMUsageUpdateResourceCount (userVm , dummyOffering );
23782383 return userVm ;
23792384 }
23802385
0 commit comments