@@ -1847,20 +1847,31 @@ public HashMap<Long, List<VmDiskStatsEntry>> getVmDiskStatistics(long hostId, St
18471847 public boolean upgradeVirtualMachine (Long vmId , Long newServiceOfferingId , Map <String , String > customParameters ) throws ResourceUnavailableException ,
18481848 ConcurrentOperationException , ManagementServerException , VirtualMachineMigrationException {
18491849
1850- // Verify input parameters
18511850 VMInstanceVO vmInstance = _vmInstanceDao .findById (vmId );
18521851 Account caller = CallContext .current ().getCallingAccount ();
18531852 _accountMgr .checkAccess (caller , null , true , vmInstance );
1854- if (vmInstance != null ) {
1855- if (vmInstance .getState ().equals (State .Stopped )) {
1856- upgradeStoppedVirtualMachine (vmId , newServiceOfferingId , customParameters );
1857- return true ;
1858- }
1859- if (vmInstance .getState ().equals (State .Running )) {
1860- return upgradeRunningVirtualMachine (vmId , newServiceOfferingId , customParameters );
1853+ if (vmInstance == null ) {
1854+ s_logger .error (String .format ("VM instance with id [%s] is null, it is not possible to upgrade a null VM." , vmId ));
1855+ return false ;
1856+ }
1857+
1858+ if (State .Stopped .equals (vmInstance .getState ())) {
1859+ upgradeStoppedVirtualMachine (vmId , newServiceOfferingId , customParameters );
1860+ return true ;
1861+ }
1862+
1863+ if (State .Running .equals (vmInstance .getState ())) {
1864+ ServiceOfferingVO newServiceOfferingVO = _serviceOfferingDao .findById (newServiceOfferingId );
1865+ HostVO instanceHost = _hostDao .findById (vmInstance .getHostId ());
1866+ _hostDao .loadHostTags (instanceHost );
1867+
1868+ if (!instanceHost .checkHostServiceOfferingTags (newServiceOfferingVO )) {
1869+ s_logger .error (String .format ("Cannot upgrade VM [%s] as the new service offering [%s] does not have the required host tags %s." , vmInstance , newServiceOfferingVO ,
1870+ instanceHost .getHostTags ()));
1871+ return false ;
18611872 }
18621873 }
1863- return false ;
1874+ return upgradeRunningVirtualMachine ( vmId , newServiceOfferingId , customParameters ) ;
18641875 }
18651876
18661877 private boolean upgradeRunningVirtualMachine (Long vmId , Long newServiceOfferingId , Map <String , String > customParameters ) throws ResourceUnavailableException ,
0 commit comments