diff --git a/app/models/conversion_host.rb b/app/models/conversion_host.rb index 99cc9bfb60c..371e68793d9 100644 --- a/app/models/conversion_host.rb +++ b/app/models/conversion_host.rb @@ -280,31 +280,19 @@ 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 + host = hostname || ipaddress authentication = find_credentials - [hostname || ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] + case authentication.type + when 'AuthPrivateKey', 'AuthToken' + [host, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }] + when 'AuthUseridPassword' + [host, 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