Class: MescalCli::Task
- Inherits:
-
Object
- Object
- MescalCli::Task
- Defined in:
- lib/mescal-cli/task.rb
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#slave_id ⇒ Object
readonly
Returns the value of attribute slave_id.
-
#state ⇒ Object
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(client, id, image, cmd) ⇒ Task
constructor
A new instance of Task.
- #slave_ip ⇒ Object
- #ssh_port ⇒ Object
- #to_s ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(client, id, image, cmd) ⇒ Task
Returns a new instance of Task.
31 32 33 |
# File 'lib/mescal-cli/task.rb', line 31 def initialize(client, id, image, cmd) @client, @id, @image, @cmd = client, id, image, cmd end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
3 4 5 |
# File 'lib/mescal-cli/task.rb', line 3 def cmd @cmd end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/mescal-cli/task.rb', line 3 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
3 4 5 |
# File 'lib/mescal-cli/task.rb', line 3 def image @image end |
#slave_id ⇒ Object (readonly)
Returns the value of attribute slave_id.
3 4 5 |
# File 'lib/mescal-cli/task.rb', line 3 def slave_id @slave_id end |
#state ⇒ Object
Returns the value of attribute state.
4 5 6 |
# File 'lib/mescal-cli/task.rb', line 4 def state @state end |
Class Method Details
.create(client, image, cmd, cpus, mem) ⇒ Object
6 7 8 9 10 |
# File 'lib/mescal-cli/task.rb', line 6 def self.create(client, image, cmd, cpus, mem) resp = client.task.create(image, cmd, cpus, mem) obj = MultiJson.load(resp) Task.new(client, obj['id'], image, cmd) end |
.kill(client, id) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/mescal-cli/task.rb', line 22 def self.kill(client, id) resp = client.task.kill(id) rescue nil if(resp && obj = MultiJson.load(resp)) obj['id'] else nil end end |
Instance Method Details
#done? ⇒ Boolean
43 44 45 |
# File 'lib/mescal-cli/task.rb', line 43 def done? ['TASK_FINISHED', 'TASK_LOST', 'TASK_FAILED'].include?(@state) end |
#slave_ip ⇒ Object
47 48 49 50 51 |
# File 'lib/mescal-cli/task.rb', line 47 def slave_ip resp = @client.slave.get(@slave_id) obj = MultiJson.load(resp) obj['hostname'] end |
#ssh_port ⇒ Object
53 54 55 |
# File 'lib/mescal-cli/task.rb', line 53 def ssh_port @ports.find { |p| p[0] == 22 }[1] end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/mescal-cli/task.rb', line 57 def to_s "#{@id} #{@image} #{@cmd}" end |
#update! ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/mescal-cli/task.rb', line 35 def update! resp = @client.task.get(@id) obj = MultiJson.load(resp) @state = obj['state'] @slave_id = obj['slaveId'] @ports = obj['ports'] end |