diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 1e50725bbbc0..17955efbecbb 100644 --- a/app/models/ext_management_system.rb +++ b/app/models/ext_management_system.rb @@ -50,6 +50,18 @@ def self.supported_for_catalog? catalog_types.present? end + def self.label_mapping_classes + supported_subclasses.select(&:supports_label_mapping?) + end + + def self.label_mapping_prefixes + label_mapping_classes.map(&:label_mapping_prefix).uniq + end + + def self.entities_for_label_mapping + label_mapping_classes.reduce({}) { |all_mappings, klass| all_mappings.merge(klass.entities_for_label_mapping) } + end + def self.provider_create_params supported_types_for_create.each_with_object({}) do |ems_type, create_params| create_params[ems_type.name] = ems_type.params_for_create if ems_type.respond_to?(:params_for_create) diff --git a/app/models/mixins/supports_feature_mixin.rb b/app/models/mixins/supports_feature_mixin.rb index 7b1cef4ef2d3..2c7ef7b51356 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -101,6 +101,7 @@ module SupportsFeatureMixin :launch_html5_console => 'Launch HTML5 Console', :launch_vmrc_console => 'Launch VMRC Console', :launch_native_console => 'Launch Native Console', + :label_mapping => 'Label Mapping', :admin_ui => 'Open Admin UI for a Provider', :live_migrate => 'Live Migration', :warm_migrate => 'Warm Migration', diff --git a/app/models/provider_tag_mapping.rb b/app/models/provider_tag_mapping.rb index 42697b2398a9..b1eb0635421e 100644 --- a/app/models/provider_tag_mapping.rb +++ b/app/models/provider_tag_mapping.rb @@ -22,7 +22,7 @@ class ProviderTagMapping < ApplicationRecord require_nested :Mapper - TAG_PREFIXES = %w(amazon azure kubernetes ibm openstack vmware).map { |name| "/managed/#{name}:" }.freeze + TAG_PREFIXES = ExtManagementSystem.label_mapping_prefixes.map { |name| "/managed/#{name}:" }.freeze validate :validate_tag_prefix # Return ProviderTagMapping::Mapper instance that holds all current mappings, diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index c3d6d6b03c77..ff625b0242d7 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -1,4 +1,24 @@ RSpec.describe ExtManagementSystem do + SUPPORTED_MAPPING_ENTITIES = { + "ContainerGroup" => "ContainerGroup", + "ContainerProject" => "ContainerProject", + "ContainerNode" => "ContainerNode", + "ContainerReplicator" => "ContainerReplicator", + "ContainerRoute" => "ContainerRoute", + "ContainerService" => "ContainerService", + "ContainerBuild" => "ContainerBuild", + "VmVmware" => "ManageIQ::Providers::Vmware::InfraManager::Vm", + "Vm" => "ManageIQ::Providers::Amazon::CloudManager::Vm", + "Image" => "ManageIQ::Providers::Amazon::CloudManager::Template", + "VmAzure" => "ManageIQ::Providers::Azure::CloudManager::Vm", + "VmIBM" => "ManageIQ::Providers::IbmCloud::VPC::CloudManager::Vm", + "VmOpenstack" => "ManageIQ::Providers::Openstack::CloudManager::Vm" + }.freeze + + it "supports label mapping for provider subclasses" do + expect(SUPPORTED_MAPPING_ENTITIES).to eq(ExtManagementSystem.entities_for_label_mapping) + end + subject { FactoryBot.create(:ext_management_system) } include_examples "AggregationMixin"