From c9f1679fb28bf3b6bec435e48bf16b16f692d6cd Mon Sep 17 00:00:00 2001 From: Libor Pichler Date: Wed, 4 Nov 2020 13:59:56 +0100 Subject: [PATCH] Add methods for provider mapping supportability in ExtManagementSystem --- app/models/ext_management_system.rb | 12 ++++++++++++ app/models/mixins/supports_feature_mixin.rb | 1 + app/models/provider_tag_mapping.rb | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/ext_management_system.rb b/app/models/ext_management_system.rb index 8df699f5a8b2..2c14b59ec558 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 6730b85073c1..8f799e0541ff 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -98,6 +98,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,