From 8820df110ad2dfe6908f78c164e41ce09feecd00 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Thu, 23 May 2019 14:48:22 -0400 Subject: [PATCH 1/3] Allow ssh auth for RHV --- app/models/conversion_host.rb | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index 99cc9bfb60c..fb678c7670a 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -280,31 +280,18 @@ def connect_ssh raise e end - # Collect appropriate authentication information based on the resource type. - #-- - # TODO: This should be handled by a ConversionHost subclass within each supported provider. + # Collect appropriate authentication information based on the authentication type. # def miq_ssh_util_args - send("miq_ssh_util_args_#{resource.type.gsub('::', '_').downcase}") - end - - # For the Redhat provider, use the userid and password associated directly with the resource. - #-- - # TODO: Move this to ManageIQ::Providers::Redhat::InfraManager::ConversionHost - # - def miq_ssh_util_args_manageiq_providers_redhat_inframanager_host - authentication = find_credentials - [hostname || ipaddress, authentication.userid, authentication.password, nil, nil] - end - - # For the OpenStack provider, use the first authentication containing an ssh keypair that has - # both a userid and auth key. - #-- - # TODO: Move this to ManageIQ::Providers::OpenStack::CloudManager::ConversionHost - # - def miq_ssh_util_args_manageiq_providers_openstack_cloudmanager_vm authentication = find_credentials - [hostname || ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] + case authentication.type + when 'AuthPrivateKey', 'AuthToken' + return [hostname || ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] + when 'AuthUseridPassword' + return [hostname || ipaddress, authentication.userid, authentication.password, nil, nil] + else + raise 'Unsupported authentication type: #{authentication.type}' + end end # Run the specified ansible playbook using the ansible-playbook command. The From 018b67cbf440c256b351f6d4f2d8a6682598d133 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Thu, 23 May 2019 15:08:51 -0400 Subject: [PATCH 2/3] Move common code out of case statement. Remove returns --- app/models/conversion_host.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index fb678c7670a..c1fa5242c5e 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -283,12 +283,13 @@ def connect_ssh # Collect appropriate authentication information based on the authentication type. # def miq_ssh_util_args + host = hostname || ipaddress authentication = find_credentials case authentication.type when 'AuthPrivateKey', 'AuthToken' - return [hostname || ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] + [host, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] when 'AuthUseridPassword' - return [hostname || ipaddress, authentication.userid, authentication.password, nil, nil] + [host, authentication.userid, authentication.password, nil, nil] else raise 'Unsupported authentication type: #{authentication.type}' end From 988d3cf3688fea45da8c388ad38ccd82eb61ae41 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Thu, 23 May 2019 15:10:04 -0400 Subject: [PATCH 3/3] Use double-quotes for string interpolation --- app/models/conversion_host.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index c1fa5242c5e..371e68793d9 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -291,7 +291,7 @@ def miq_ssh_util_args when 'AuthUseridPassword' [host, authentication.userid, authentication.password, nil, nil] else - raise 'Unsupported authentication type: #{authentication.type}' + raise "Unsupported authentication type: #{authentication.type}" end end