From 9dbbf275bf2be67c3999129c6d63e5a28fa679a3 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 30 Sep 2019 20:16:22 -0400 Subject: [PATCH] Add verify_credentials and params_for_create Add a method to return the parameters required to add an SCVMM provider and a method to verity credentials with those parameters. --- .../providers/microsoft/infra_manager.rb | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/app/models/manageiq/providers/microsoft/infra_manager.rb b/app/models/manageiq/providers/microsoft/infra_manager.rb index cef0cce..dbc7891 100644 --- a/app/models/manageiq/providers/microsoft/infra_manager.rb +++ b/app/models/manageiq/providers/microsoft/infra_manager.rb @@ -20,6 +20,51 @@ def self.description @description ||= "Microsoft System Center VMM".freeze end + def self.params_for_create + @params_for_create ||= { + :title => "Configure #{description}", + :fields => [ + { + :component => "text-field", + :name => "endpoints.default.server", + :label => "Server Hostname/IP Address", + :isRequired => true, + :validate => [{:type => "required-validator"}] + }, + { + :component => "text-field", + :name => "endpoints.default.username", + :label => "Username", + :isRequired => true, + :validate => [{:type => "required-validator"}] + }, + { + :component => "text-field", + :name => "endpoints.default.password", + :label => "Password", + :type => "password", + :isRequired => true, + :validate => [{:type => "required-validator"}] + }, + { + :component => "text-field", + :name => "endpoints.default.port", + :label => "Port", + :type => "numberic", + } + ] + }.freeze + end + + def self.verify_credentials(args) + default_endpoint = args.dig("endpoints", "default") + username, password, server, port = default_endpoint&.values_at("username", "password", "server", "port") + connect_params = build_connect_params(:user => username, :password => password, :hostname => server, :port => port) + + raw_connect(connect_params, validate = true) + true + end + def self.raw_connect(connect_params, validate = false) require 'winrm'