Class: Docker::Swarm::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/swarm/task.rb

Overview

This class represents a Docker Swarm Node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(swarm, hash) ⇒ Task

Returns a new instance of Task.



6
7
8
9
# File 'lib/docker/swarm/task.rb', line 6

def initialize(swarm, hash)
  @hash = hash
  @swarm = swarm
end

Instance Attribute Details

#hashObject (readonly)

include Docker::Base



4
5
6
# File 'lib/docker/swarm/task.rb', line 4

def hash
  @hash
end

Instance Method Details

#created_atObject



37
38
39
# File 'lib/docker/swarm/task.rb', line 37

def created_at
  return DateTime.parse(@hash.first['CreatedAt'])
end

#idObject



11
12
13
# File 'lib/docker/swarm/task.rb', line 11

def id
  return @hash['ID']
end

#imageObject



15
16
17
# File 'lib/docker/swarm/task.rb', line 15

def image
  return @hash['Spec']['ContainerSpec']['Image']
end

#networksObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/docker/swarm/task.rb', line 53

def networks
  all_networks = @swarm.networks
  nets = []
  self.hash['NetworksAttachments'].each do |net_hash|
    hash = net_hash['Network']
    network_id = hash['ID']
    nets << all_networks.find {|net| net.id == network_id}
  end
  return nets
end

#nodeObject



33
34
35
# File 'lib/docker/swarm/task.rb', line 33

def node
  return @swarm.nodes.find {|n| n.id == self.node_id}
end

#node_idObject



29
30
31
# File 'lib/docker/swarm/task.rb', line 29

def node_id
  @hash['NodeID']
end

#serviceObject



23
24
25
26
27
# File 'lib/docker/swarm/task.rb', line 23

def service
  return @swarm.services.find { |service|
    self.service_id == service.id
  }
end

#service_idObject



19
20
21
# File 'lib/docker/swarm/task.rb', line 19

def service_id
  @hash['ServiceID']
end

#statusObject



41
42
43
# File 'lib/docker/swarm/task.rb', line 41

def status
  @hash['Status']['State'].to_sym
end

#status_messageObject



49
50
51
# File 'lib/docker/swarm/task.rb', line 49

def status_message
  @hash['Status']['Message']
end

#status_timestampObject



45
46
47
# File 'lib/docker/swarm/task.rb', line 45

def status_timestamp
  return DateTime.parse(@hash['Status']['Timestamp'])
end