@@ -2075,6 +2075,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
20752075
20762076 // Check disable threshold for cluster is not crossed
20772077 HostVO host = _hostDao .findById (vmInstance .getHostId ());
2078+ _hostDao .loadDetails (host );
20782079 if (_capacityMgr .checkIfClusterCrossesThreshold (host .getClusterId (), cpuDiff , memoryDiff )) {
20792080 throw new CloudRuntimeException (String .format ("Unable to scale %s due to insufficient resources." , vmInstance .toString ()));
20802081 }
@@ -2087,12 +2088,14 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
20872088 _resourceLimitMgr .updateVmResourceCountForServiceOfferingChange (caller .getAccountId (), vmInstance .isDisplay (),
20882089 (long ) currentCpu , (long ) newCpu , (long ) currentMemory , (long ) newMemory ,
20892090 currentServiceOffering , newServiceOffering , template );
2090- // #1 Check existing host has capacity
2091+
2092+ // #1 Check existing host has capacity & and the correct tags
20912093 if (!excludes .shouldAvoid (ApiDBUtils .findHostById (vmInstance .getHostId ()))) {
20922094 existingHostHasCapacity = _capacityMgr .checkIfHostHasCpuCapability (vmInstance .getHostId (), newCpu , newSpeed )
20932095 && _capacityMgr .checkIfHostHasCapacity (vmInstance .getHostId (), cpuDiff , ByteScaleUtils .mebibytesToBytes (memoryDiff ), false ,
20942096 _capacityMgr .getClusterOverProvisioningFactor (host .getClusterId (), Capacity .CAPACITY_TYPE_CPU ),
2095- _capacityMgr .getClusterOverProvisioningFactor (host .getClusterId (), Capacity .CAPACITY_TYPE_MEMORY ), false );
2097+ _capacityMgr .getClusterOverProvisioningFactor (host .getClusterId (), Capacity .CAPACITY_TYPE_MEMORY ), false )
2098+ && checkEnforceStrictHostTagCheck (vmInstance , host );
20962099 excludes .addHost (vmInstance .getHostId ());
20972100 }
20982101
@@ -5490,7 +5493,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
54905493 if (destinationHost != null ) {
54915494 logger .debug ("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM" );
54925495 _hostDao .loadHostTags (destinationHost );
5493- checkEnforceStrictHostTagCheck (vm , destinationHost );
5496+ validateStrictHostTagCheck (vm , destinationHost );
54945497
54955498 final ServiceOfferingVO offering = serviceOfferingDao .findById (vm .getId (), vm .getServiceOfferingId ());
54965499 Pair <Boolean , Boolean > cpuCapabilityAndCapacity = _capacityMgr .checkIfHostHasCpuCapabilityAndCapacity (destinationHost , offering , false );
@@ -6705,16 +6708,26 @@ private DeployDestination chooseVmMigrationDestination(VMInstanceVO vm, Host src
67056708 }
67066709 }
67076710
6708- protected void checkEnforceStrictHostTagCheck (VMInstanceVO vm , HostVO host ) {
6711+ protected boolean checkEnforceStrictHostTagCheck (VMInstanceVO vm , HostVO host ) {
67096712 ServiceOffering serviceOffering = serviceOfferingDao .findByIdIncludingRemoved (vm .getServiceOfferingId ());
67106713 VirtualMachineTemplate template = _templateDao .findByIdIncludingRemoved (vm .getTemplateId ());
6714+ return checkEnforceStrictHostTagCheck (host , serviceOffering , template );
6715+ }
67116716
6717+ private boolean checkEnforceStrictHostTagCheck (HostVO host , ServiceOffering serviceOffering , VirtualMachineTemplate template ) {
67126718 Set <String > strictHostTags = UserVmManager .getStrictHostTags ();
6713- if (!host .checkHostServiceOfferingAndTemplateTags (serviceOffering , template , strictHostTags )) {
6714- s_logger .error (String .format (
6715- "Cannot deploy VM: %s to host : %s due to tag mismatch." +
6716- " strictHosts: %s serviceOffering tags: %s, template tags: %s" ,
6717- vm , host , strictHostTags , serviceOffering .getHostTag (), template .getTemplateTag ()));
6719+ return host .checkHostServiceOfferingAndTemplateTags (serviceOffering , template , strictHostTags );
6720+ }
6721+
6722+ protected void validateStrictHostTagCheck (VMInstanceVO vm , HostVO host ) {
6723+ ServiceOffering serviceOffering = serviceOfferingDao .findByIdIncludingRemoved (vm .getServiceOfferingId ());
6724+ VirtualMachineTemplate template = _templateDao .findByIdIncludingRemoved (vm .getTemplateId ());
6725+
6726+ if (!checkEnforceStrictHostTagCheck (host , serviceOffering , template )) {
6727+ Set <String > missingTags = host .getHostServiceOfferingAndTemplateMissingTags (serviceOffering , template , UserVmManager .getStrictHostTags ());
6728+ logger .error ("Cannot deploy VM: {} to host : {} due to tag mismatch. host tags: {}, " +
6729+ "strict host tags: {} serviceOffering tags: {}, template tags: {}, missing tags: {}" ,
6730+ vm , host , host .getHostTags (), UserVmManager .getStrictHostTags (), serviceOffering .getHostTag (), template .getTemplateTag (), missingTags );
67186731 throw new InvalidParameterValueException (String .format ("Cannot deploy VM, destination host: %s " +
67196732 "is not compatible for the VM" , host .getName ()));
67206733 }
@@ -6747,7 +6760,7 @@ private DeployDestination checkVmMigrationDestination(VMInstanceVO vm, Host srcH
67476760
67486761 HostVO destinationHostVO = _hostDao .findById (destinationHost .getId ());
67496762 _hostDao .loadHostTags (destinationHostVO );
6750- checkEnforceStrictHostTagCheck (vm , destinationHostVO );
6763+ validateStrictHostTagCheck (vm , destinationHostVO );
67516764
67526765 checkHostsDedication (vm , srcHost .getId (), destinationHost .getId ());
67536766
0 commit comments