From b1235ac0eefb36aa5d1b6bed704b714a8464480b Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 2 Oct 2019 16:09:29 -0400 Subject: [PATCH 1/2] Add methods for for provider creation pluggable UI Add a method indicating the properties required to create a Kubevirt provider and implement the common self.verify_credentials interface method. https://github.com/ManageIQ/manageiq/issues/18818 --- .../providers/kubevirt/infra_manager.rb | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/kubevirt/infra_manager.rb b/app/models/manageiq/providers/kubevirt/infra_manager.rb index 340ceb8..f6b4359 100644 --- a/app/models/manageiq/providers/kubevirt/infra_manager.rb +++ b/app/models/manageiq/providers/kubevirt/infra_manager.rb @@ -53,6 +53,54 @@ def self.description @description ||= ManageIQ::Providers::Kubevirt::Constants::PRODUCT end + def self.params_for_create + @params_for_create ||= { + :title => "Configure #{description}", + :fields => [ + { + :component => "text-field", + :name => "endpoints.default.server", + :label => "Hostname", + :isRequired => true, + :validate => [{:type => "required-validator"}] + }, + { + :component => "text-field", + :name => "endpoints.default.port", + :type => "number", + :isRequired => true, + :validate => [ + { + :type => "required-validator" + }, + { + :type => "validatorTypes.MIN_NUMBER_VALUE", + :includeThreshold => true, + :value => 1 + }, + { + :type => "validatorTypes.MAX_NUMBER_VALUE", + :includeThreshold => true, + :value => 65535 + } + ] + }, + { + :component => "text-field", + :name => "endpoints.default.token", + :label => "Token", + :type => "password", + :isRequired => true, + :validate => [{:type => "required-validator"}] + } + ] + }.freeze + end + + def self.verify_credentials(args) + !!raw_connect(args.dig("endpoints", "default")&.values_at("server", "port", "token")&.symbolize_keys) + end + # # This method from the dialog that adds a provider, to verify the connection details and the # credentials. @@ -70,7 +118,7 @@ def self.raw_connect(opts) connection = Connection.new( :host => opts[:server], :port => opts[:port], - :token => opts[:token], + :token => MiqPassword.try_decrypt(opts[:token]), ) # Verify that the connection works: From 8f7439dd93dec39f5762e82063604ca73112d7a9 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 7 Oct 2019 12:37:36 -0400 Subject: [PATCH 2/2] Remove documented arguments that aren't used --- app/models/manageiq/providers/kubevirt/infra_manager.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/models/manageiq/providers/kubevirt/infra_manager.rb b/app/models/manageiq/providers/kubevirt/infra_manager.rb index f6b4359..2557436 100644 --- a/app/models/manageiq/providers/kubevirt/infra_manager.rb +++ b/app/models/manageiq/providers/kubevirt/infra_manager.rb @@ -81,7 +81,7 @@ def self.params_for_create { :type => "validatorTypes.MAX_NUMBER_VALUE", :includeThreshold => true, - :value => 65535 + :value => 65_535 } ] }, @@ -98,7 +98,7 @@ def self.params_for_create end def self.verify_credentials(args) - !!raw_connect(args.dig("endpoints", "default")&.values_at("server", "port", "token")&.symbolize_keys) + !!raw_connect(args.dig("endpoints", "default")&.slice("server", "port", "token")&.symbolize_keys) end # @@ -109,16 +109,13 @@ def self.verify_credentials(args) # @option opts [String] :server The Kubernetes API server host name or IP address. # @option opts [Integer] :port The Kubernetes API port number. # @option opts [String] :token The Kubernetes authentication token. - # @option opts [Integer] :verify_ssl Integer indicating if the Kubernetes API server certificate - # should be verified. - # @option opts [Integer] :ca_certs Trusted CA certificates, in PEM format. # def self.raw_connect(opts) # Create the connection: connection = Connection.new( :host => opts[:server], :port => opts[:port], - :token => MiqPassword.try_decrypt(opts[:token]), + :token => MiqPassword.try_decrypt(opts[:token]) ) # Verify that the connection works: