Class: Docker::Swarm::Node
- Inherits:
-
Object
- Object
- Docker::Swarm::Node
- Defined in:
- lib/docker/swarm/node.rb
Overview
This class represents a Docker Swarm Node.
Constant Summary collapse
- AVAILABILITY =
{ active: "active", drain: "drain" }
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
include Docker::Base.
Class Method Summary collapse
-
.all(opts = {}, conn = Docker.connection) ⇒ Object
Return all of the Nodes.
Instance Method Summary collapse
- #activate ⇒ Object
- #availability ⇒ Object
- #change_availability(availability) ⇒ Object
- #drain ⇒ Object
- #host_name ⇒ Object
- #id ⇒ Object
-
#initialize(hash, connection) ⇒ Node
constructor
A new instance of Node.
- #role ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(hash, connection) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 |
# File 'lib/docker/swarm/node.rb', line 10 def initialize(hash, connection) @hash = hash @connection = connection hash['Description']['Hostname'] end |
Instance Attribute Details
#hash ⇒ Object (readonly)
include Docker::Base
4 5 6 |
# File 'lib/docker/swarm/node.rb', line 4 def hash @hash end |
Class Method Details
.all(opts = {}, conn = Docker.connection) ⇒ Object
Return all of the Nodes.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/docker/swarm/node.rb', line 58 def self.all(opts = {}, conn = Docker.connection) raise "opts needs to be hash" if (opts.class != Hash) query = {} resp = conn.get('/nodes', query, :body => opts.to_json) hashes = JSON.parse(resp) nodes = [] hashes.each do |node_hash| nodes << Docker::Swarm::Node.new(node_hash, conn) end return nodes end |
Instance Method Details
#activate ⇒ Object
46 47 48 |
# File 'lib/docker/swarm/node.rb', line 46 def activate change_availability(:active) end |
#availability ⇒ Object
34 35 36 |
# File 'lib/docker/swarm/node.rb', line 34 def availability return @hash['Spec']['Availability'].to_sym end |
#change_availability(availability) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/docker/swarm/node.rb', line 50 def change_availability(availability) raise "Bad availability param: #{availability}" if (!AVAILABILITY[availability]) @hash['Spec']['Availability'] = AVAILABILITY[availability] query = {version: @hash['Version']['Index']} response = @connection.post("/nodes/#{self.id}/update", query, :body => @hash['Spec'].to_json) end |
#drain ⇒ Object
42 43 44 |
# File 'lib/docker/swarm/node.rb', line 42 def drain change_availability(:drain) end |
#host_name ⇒ Object
20 21 22 |
# File 'lib/docker/swarm/node.rb', line 20 def host_name return @hash['Description']['Hostname'] end |
#id ⇒ Object
16 17 18 |
# File 'lib/docker/swarm/node.rb', line 16 def id return @hash['ID'] end |
#role ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/docker/swarm/node.rb', line 24 def role if (@hash['Spec']['Role'] == "worker") return :worker elsif (@hash['Spec']['Role'] == "manager") return :manager else raise "Couldn't determine machine role from spec: #{@hash['Spec']}" end end |
#status ⇒ Object
38 39 40 |
# File 'lib/docker/swarm/node.rb', line 38 def status return @hash['Status']['State'] end |