class Machine
A class that handles the ssh conection and parameters to a single machine
Attributes
host[RW]
keys[RW]
num_workers[RW]
port[RW]
user[RW]
Public Class Methods
get_all(path_to_env)
click to toggle source
# File lib/machine.rb, line 11 def self.get_all(path_to_env) config = YAML.load_file(File.join(path_to_env, 'config.yaml')) default = config['default'] machines = config['clients'].map { |machine| default.merge(machine) } machines.map { |m| Machine.new(m) } end
new(params)
click to toggle source
# File lib/machine.rb, line 6 def initialize(params) @host, @user, @keys = params['host'], params['user'], params['keys'] @num_workers, @port = params['num_workers'], params['port'] end
Public Instance Methods
log(tag, text)
click to toggle source
# File lib/machine.rb, line 41 def log(tag, text) puts "[#@host,#{Time.now},#{tag}]: #{text}" end
scp(local_path, remote_path)
click to toggle source
# File lib/machine.rb, line 32 def scp(local_path, remote_path) raise "file not found: #{local_path}" unless File.exists?(local_path) Net::SCP.upload!(@host, @user, local_path, remote_path, ssh: to_ssh_args, recursive: true) #doesn't change the name of the last folder in local path to remote_path... end
scp_r(remote_path, local_path)
click to toggle source
# File lib/machine.rb, line 37 def scp_r(remote_path, local_path) Net::SCP.download!(@host, @user, remote_path, local_path, ssh: to_ssh_args, recursive: true) end
ssh(cmd)
click to toggle source
# File lib/machine.rb, line 24 def ssh(cmd) Net::SSH.start(@host, @user, to_ssh_args) do |ssh| res = OpenStruct.new(stdout: '', stderr: '') ssh.exec!(cmd) { |_channel, stream, data| res[stream] << data } return res end end
to_ssh_args()
click to toggle source
# File lib/machine.rb, line 18 def to_ssh_args args = { user: @user, port: @port, keys: @keys, keys_only: true } args[:number_of_password_prompts] = 0 args end