Class: MescalCli::Cli
- Inherits:
-
Object
- Object
- MescalCli::Cli
- Defined in:
- lib/mescal-cli/cli.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Cli
constructor
A new instance of Cli.
- #list ⇒ Object
- #run ⇒ Object
- #run! ⇒ Object
- #ssh ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(config) ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 11 12 13 14 |
# File 'lib/mescal-cli/cli.rb', line 6 def initialize(config) @mode = ARGV.first usage and System.exit(1) unless !!@mode @config = config @client = Client.new(config['mescal']) @image = config['image'] @cmd = ARGV[1] || config['cmd'] @sshCmd = config['sshCmd'] end |
Instance Method Details
#list ⇒ Object
28 29 30 |
# File 'lib/mescal-cli/cli.rb', line 28 def list tp Task.list(@client), {id: {width: 48}}, :image, :cmd, :state end |
#run ⇒ Object
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 |
# File 'lib/mescal-cli/cli.rb', line 32 def run puts "Sending task to Mescal..." task = Task.create(@client, @image, @cmd) run = true threads = [] pailer_started = false while(run) do sleep(2) state = task.state task.update! if state != task.state puts "State: #{task.state}" if task.state != "TASK_PENDING" && !pailer_started pailer_started = true ["stdout", "stderr"].each do |std| threads << Thread.new { Pailer.new(task, @config['mescal'], std).run! } end end end run = !task.done? end sleep(10) threads.each { |t| t.kill } end |
#run! ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mescal-cli/cli.rb', line 20 def run! case @mode when "run" then run when "ssh" then ssh when "list" then list end end |
#ssh ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mescal-cli/cli.rb', line 58 def ssh task = Task.create(@client, @image, @sshCmd) run = true while(run) do sleep(2) state = task.state task.update! if state != task.state if task.state != "TASK_PENDING" Ssh.new(task).run! end end run = !task.done? end end |
#usage ⇒ Object
16 17 18 |
# File 'lib/mescal-cli/cli.rb', line 16 def usage puts "mescal [run|ssh]" end |