Merge branch 'master' into qeng-7604_add_jobid_to_delete

This commit is contained in:
Brian Cain 2020-01-28 13:40:53 -08:00 committed by GitHub
commit 5dbe19e10b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 6 deletions

View file

@ -91,7 +91,7 @@ class Service
STDERR.puts 'Could not get token... requesting vm without a token anyway...'
end
end
Ssh.ssh(verbose, host_os, token_value, url)
Ssh.ssh(verbose, self, host_os, token_value)
end
def pretty_print_running(verbose, hostnames = [])

View file

@ -14,21 +14,27 @@ class Ssh
nil
end
def self.ssh(verbose, host_os, token, url)
def self.command_string(verbose, service, host_os, use_token)
ssh_path = which('ssh')
raise 'Could not determine path to ssh' unless ssh_path
os_types = {}
os_types[host_os] = 1
response = Pooler.retrieve(verbose, os_types, token, url)
raise "Could not get vm from vmpooler:\n #{response}" unless response['ok']
response = service.retrieve(verbose, os_types, use_token)
raise "Could not get vm from #{service.type}:\n #{response}" unless response['ok']
user = /win/.match?(host_os) ? 'Administrator' : 'root'
hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
cmd = "#{ssh_path} #{user}@#{hostname}"
hostname = response[host_os]['hostname']
hostname = response[host_os]['hostname'][0] if response[host_os]['hostname'].is_a?(Array)
hostname = "#{hostname}.#{response['domain']}" unless hostname.end_with?('puppetlabs.net')
"#{ssh_path} #{user}@#{hostname}"
end
def self.ssh(verbose, service, host_os, use_token)
cmd = command_string(verbose, service, host_os, use_token)
# TODO: Should this respect more ssh settings? Can it be configured
# by users ssh config and does this respect those settings?
Kernel.exec(cmd)