Module: SSHClient
- Defined in:
- lib/rbbt/workflow/remote/ssh/get.rb
Class Method Summary collapse
- .clean(url) ⇒ Object
- .get_json(url, params) ⇒ Object
- .get_raw(url, params) ⇒ Object
- .parse_url(url) ⇒ Object
- .path_script(path) ⇒ Object
- .post_job(url, inputs, input_types, jobname = nil) ⇒ Object
- .run(server, script) ⇒ Object
- .run_job(url, inputs, input_types, jobname = nil) ⇒ Object
- .run_log(server, script) ⇒ Object
Class Method Details
.clean(url) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 136 def self.clean(url) server, path = parse_url(url) script = path_script(path) script +=<<-EOF job.clean EOF self.run(server, script) end |
.get_json(url, params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 68 def self.get_json(url, params) server, path = parse_url(url) script = path_script(path) script +=<<-EOF puts res.to_json EOF JSON.parse(self.run(server, script)) end |
.get_raw(url, params) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 79 def self.get_raw(url, params) server, path = parse_url(url) script = path_script(path) script +=<<-EOF puts res EOF self.run(server, script) end |
.parse_url(url) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 12 def self.parse_url(url) m = url.match(/ssh:\/\/([^:]+):(.*)/) server = m.captures[0] path = m.captures[1] [server, path] end |
.path_script(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 19 def self.path_script(path) workflow, task, job, *rest = path.split("/") script =<<-EOF require 'rbbt/workflow' wf = Workflow.require_workflow "#{workflow}" EOF case task when nil script +=<<-EOF task_info = {} wf.tasks.keys.each do |task| task_info[task] = wf.task_info(task) end res = task_info EOF when 'documentation' script +=<<-EOF res = documentation = wf.documentation EOF else if job.nil? script +=<<-EOF task = '#{task}' res = task_info = wf.task_info(task) EOF else case rest.first when nil script +=<<-EOF task = '#{task}' jobname = '#{job}' res = job = wf.fast_load_id(File.join(task, jobname)) EOF when "info" script +=<<-EOF task = '#{task}' jobname = '#{job}' job = wf.fast_load_id(File.join(task, jobname)) res = job_info = job.info EOF else raise "Unkown path: #{[path, rest].inspect}" end end end end |
.post_job(url, inputs, input_types, jobname = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 90 def self.post_job(url, inputs, input_types, jobname = nil) server, path = parse_url(url) script = path_script(path) id = "inputs-" << rand(100000).to_s CMD.cmd("ssh '#{server}' mkdir -p .rbbt/tmp/tmp-ssh_job_inputs/ ", :in => script).read TmpFile.with_file do |dir| if Step.save_inputs(inputs, input_types, dir) CMD.cmd("scp -r '#{dir}' .rbbt/tmp/tmp-ssh_job_inputs/#{id}") end end script +=<<-EOF jobname = #{jobname.nil? ? 'nil' : "'#{jobname}'"} path = '.rbbt/tmp/tmp-ssh_job_inputs/#{id}' job_inputs = Workflow.load_inputs(path, task_info[:inputs], task_info[:input_types]) job = wf.job(task, jobname, job_inputs) Log.severity = 10 job.fork puts job.name EOF self.run(server, script) end |
.run(server, script) ⇒ Object
2 3 4 5 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 2 def self.run(server, script) Log.debug "Run ssh script in #{server}:\n#{script}" CMD.cmd("ssh '#{server}' ruby ", :in => script).read.strip end |
.run_job(url, inputs, input_types, jobname = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/rbbt/workflow/remote/ssh/get.rb', line 114 def self.run_job(url, inputs, input_types, jobname = nil) server, path = parse_url(url) script = path_script(path) id = "inputs-" << rand(100000).to_s CMD.cmd("ssh '#{server}' mkdir -p .rbbt/tmp/tmp-ssh_job_inputs/ ", :in => script).read TmpFile.with_file do |dir| if Step.save_inputs(inputs, input_types, dir) CMD.cmd("scp -r '#{dir}' .rbbt/tmp/tmp-ssh_job_inputs/#{id}") end end script +=<<-EOF jobname = #{jobname.nil? ? 'nil' : "'#{jobname}'"} path = '.rbbt/tmp/tmp-ssh_job_inputs/#{id}' job_inputs = Workflow.load_inputs(path, task_info[:inputs], task_info[:input_types]) job = wf.job(task, jobname, job_inputs) job.run EOF self.run_log(server, script) end |