@@ -1964,9 +1964,9 @@ public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId, Map<S
19641964 HostVO instanceHost = _hostDao .findById (vmInstance .getHostId ());
19651965 _hostDao .loadHostTags (instanceHost );
19661966
1967- if (!instanceHost .checkHostServiceOfferingAndTemplateTags (newServiceOfferingVO , template )) {
1968- logger .error (String .format ("Cannot upgrade VM [%s] as the new service offering [%s] does not have the required host tags %s." , vmInstance , newServiceOfferingVO ,
1969- instanceHost .getHostTags ()));
1967+ if (!instanceHost .checkHostServiceOfferingAndTemplateTags (newServiceOfferingVO , template , UserVmManager . getStrictHostTags () )) {
1968+ logger .error (String .format ("Cannot upgrade VM [%s] as the new service offering [%s] does not have the required host tags %s." ,
1969+ vmInstance , newServiceOfferingVO , instanceHost .getHostTags ()));
19701970 return false ;
19711971 }
19721972 }
@@ -5484,11 +5484,14 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
54845484 boolean isRootAdmin = _accountService .isRootAdmin (callerAccount .getId ());
54855485 Pod destinationPod = getDestinationPod (podId , isRootAdmin );
54865486 Cluster destinationCluster = getDestinationCluster (clusterId , isRootAdmin );
5487- Host destinationHost = getDestinationHost (hostId , isRootAdmin , isExplicitHost );
5487+ HostVO destinationHost = getDestinationHost (hostId , isRootAdmin , isExplicitHost );
54885488 DataCenterDeployment plan = null ;
54895489 boolean deployOnGivenHost = false ;
54905490 if (destinationHost != null ) {
54915491 logger .debug ("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM" );
5492+ _hostDao .loadHostTags (destinationHost );
5493+ checkEnforceStrictHostTagCheck (vm , destinationHost );
5494+
54925495 final ServiceOfferingVO offering = serviceOfferingDao .findById (vm .getId (), vm .getServiceOfferingId ());
54935496 Pair <Boolean , Boolean > cpuCapabilityAndCapacity = _capacityMgr .checkIfHostHasCpuCapabilityAndCapacity (destinationHost , offering , false );
54945497 if (!cpuCapabilityAndCapacity .first () || !cpuCapabilityAndCapacity .second ()) {
@@ -5659,8 +5662,8 @@ private Cluster getDestinationCluster(Long clusterId, boolean isRootAdmin) {
56595662 return destinationCluster ;
56605663 }
56615664
5662- private Host getDestinationHost (Long hostId , boolean isRootAdmin , boolean isExplicitHost ) {
5663- Host destinationHost = null ;
5665+ private HostVO getDestinationHost (Long hostId , boolean isRootAdmin , boolean isExplicitHost ) {
5666+ HostVO destinationHost = null ;
56645667 if (hostId != null ) {
56655668 if (isExplicitHost && !isRootAdmin ) {
56665669 throw new PermissionDeniedException (
@@ -6702,6 +6705,21 @@ private DeployDestination chooseVmMigrationDestination(VMInstanceVO vm, Host src
67026705 }
67036706 }
67046707
6708+ protected void checkEnforceStrictHostTagCheck (VMInstanceVO vm , HostVO host ) {
6709+ ServiceOffering serviceOffering = serviceOfferingDao .findByIdIncludingRemoved (vm .getServiceOfferingId ());
6710+ VirtualMachineTemplate template = _templateDao .findByIdIncludingRemoved (vm .getTemplateId ());
6711+
6712+ 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 ()));
6718+ throw new InvalidParameterValueException (String .format ("Cannot deploy VM, destination host: %s " +
6719+ "is not compatible for the VM" , host .getName ()));
6720+ }
6721+ }
6722+
67056723 private DeployDestination checkVmMigrationDestination (VMInstanceVO vm , Host srcHost , Host destinationHost ) throws VirtualMachineMigrationException {
67066724 if (destinationHost == null ) {
67076725 return null ;
@@ -6727,6 +6745,10 @@ private DeployDestination checkVmMigrationDestination(VMInstanceVO vm, Host srcH
67276745 throw new CloudRuntimeException ("Cannot migrate VM, VM is DPDK enabled VM but destination host is not DPDK enabled" );
67286746 }
67296747
6748+ HostVO destinationHostVO = _hostDao .findById (destinationHost .getId ());
6749+ _hostDao .loadHostTags (destinationHostVO );
6750+ checkEnforceStrictHostTagCheck (vm , destinationHostVO );
6751+
67306752 checkHostsDedication (vm , srcHost .getId (), destinationHost .getId ());
67316753
67326754 // call to core process
@@ -6736,7 +6758,6 @@ private DeployDestination checkVmMigrationDestination(VMInstanceVO vm, Host srcH
67366758 DeployDestination dest = new DeployDestination (dcVO , pod , cluster , destinationHost );
67376759
67386760 // check max guest vm limit for the destinationHost
6739- HostVO destinationHostVO = _hostDao .findById (destinationHost .getId ());
67406761 if (_capacityMgr .checkIfHostReachMaxGuestLimit (destinationHostVO )) {
67416762 if (logger .isDebugEnabled ()) {
67426763 logger .debug ("Host name: " + destinationHost .getName () + ", hostId: " + destinationHost .getId ()
@@ -8395,7 +8416,8 @@ public String getConfigComponentName() {
83958416 public ConfigKey <?>[] getConfigKeys () {
83968417 return new ConfigKey <?>[] {EnableDynamicallyScaleVm , AllowDiskOfferingChangeDuringScaleVm , AllowUserExpungeRecoverVm , VmIpFetchWaitInterval , VmIpFetchTrialMax ,
83978418 VmIpFetchThreadPoolMax , VmIpFetchTaskWorkers , AllowDeployVmIfGivenHostFails , EnableAdditionalVmConfig , DisplayVMOVFProperties ,
8398- KvmAdditionalConfigAllowList , XenServerAdditionalConfigAllowList , VmwareAdditionalConfigAllowList , DestroyRootVolumeOnVmDestruction };
8419+ KvmAdditionalConfigAllowList , XenServerAdditionalConfigAllowList , VmwareAdditionalConfigAllowList , DestroyRootVolumeOnVmDestruction ,
8420+ EnforceStrictResourceLimitHostTagCheck , StrictHostTags };
83998421 }
84008422
84018423 @ Override
0 commit comments