Skip to content

Commit

Permalink
Merge pull request #18103 from fdupont-redhat/conversion_host_hostnam…
Browse files Browse the repository at this point in the history
…e_as_ipaddress

Conversion Host - Try hostname for SSH and fix MiqSshUtil args
  • Loading branch information
agrare committed Oct 17, 2018
2 parents 89a1ebf + 1de3f2d commit 84a80a0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/models/conversion_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ConversionHost < ApplicationRecord
has_many :service_template_transformation_plan_tasks, :dependent => :nullify
has_many :active_tasks, -> { where(:state => 'active') }, :class_name => ServiceTemplateTransformationPlanTask, :inverse_of => :conversion_host
delegate :ext_management_system, :to => :resource, :allow_nil => true
delegate :hostname, :to => :resource, :allow_nil => true

# To be eligible, a conversion host must have the following properties
# - A transport mechanism is configured for source (set by 3rd party)
Expand Down Expand Up @@ -39,7 +40,8 @@ def ipaddress(family = 'ipv4')
end

def run_conversion(conversion_options)
connect_ssh { |ssu| ssu.shell_exec('/usr/bin/virt-v2v-wrapper.py', nil, nil, conversion_options.to_json) }
result = connect_ssh { |ssu| ssu.shell_exec('/usr/bin/virt-v2v-wrapper.py', nil, nil, conversion_options.to_json) }
JSON.parse(result)
rescue => e
raise "Starting conversion failed on '#{resource.name}' with [#{e.class}: #{e}]"
end
Expand Down Expand Up @@ -121,7 +123,7 @@ def check_resource_credentials_openstack

def connect_ssh
require 'MiqSshUtil'
MiqSshUtil.shell_with_su(miq_ssh_util_args) do |ssu, _shell|
MiqSshUtil.shell_with_su(*miq_ssh_util_args) do |ssu, _shell|
yield(ssu)
end
rescue Exception => e
Expand All @@ -134,15 +136,15 @@ def miq_ssh_util_args
end

def miq_ssh_util_args_manageiq_providers_redhat_inframanager_host
[ ipaddress, resource.authentication_userid, resource.authentication_password, nil, nil ]
[hostname || ipaddress, resource.authentication_userid, resource.authentication_password, nil, nil]
end

def miq_ssh_util_args_manageiq_providers_openstack_cloudmanager_vm
authentication = resource.ext_management_system.authentications
.where(:authtype => 'ssh_keypair')
.where.not(:userid => nil, :auth_key => nil)
.first
[ ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }]
[hostname || ipaddress, authentication.userid, nil, nil, nil, { :key_data => authentication.auth_key, :passwordless_sudo => true }]
end

def ansible_playbook(playbook, extra_vars, connection)
Expand Down

0 comments on commit 84a80a0

Please sign in to comment.