Skip to content

Commit

Permalink
Add methods for provider mapping supportability in ExtManagementSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
lpichler committed Nov 13, 2020
1 parent d5ec820 commit 3a7f053
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/models/provider_tag_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 3a7f053

Please sign in to comment.