docker-swarm-api 1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7be7483768fca3556ef820aede393f082ea9112d
4
- data.tar.gz: 46d6a6c0831df578aef01dd6ced0c6d38f79ef84
3
+ metadata.gz: f0b90891a651e044750fc2bc7b1956679634db08
4
+ data.tar.gz: 7fd85045899307db8a32fb3d94654167f4ba8ef2
5
5
  SHA512:
6
- metadata.gz: da9b11be6fb1cd7dd935e04779cc7f4c05fb05ee48def067d4f7d64017f1278483106a5e0ee984a7ab50897197821da4af0b9090d7808800ed092c2f784602d6
7
- data.tar.gz: e231e65865010eea0be3b362a50a9d3ba28825aeda8d269eb84b67a99c18dca93aa9fcf52d8544f5ae1caf5ee955679e47d8ab21343e92cafcbc1aafc4ad8aec
6
+ metadata.gz: 4083515f3553d91273ea6e8f0b3959f71996529f9ab3340fd8f6e756677bf6cca787748e9491ec5b2e778d17e89b48ca1bc7a8c50b778e7b492f8bce6f119b17
7
+ data.tar.gz: a0e8a29a37b6eabc9c42e5963db95de9568cc2070b6c6e9fc00c008eb973d81ee38383ab2308873b6187af16076f49f32d1e1f37b8b6ad11c952ad0f0c17974d
@@ -5,16 +5,30 @@ class Docker::Swarm::Swarm
5
5
  include Docker
6
6
  attr_reader :worker_join_token, :manager_join_token, :id, :hash, :node_hash
7
7
 
8
- def initialize(hash, manager_connection)
8
+ def initialize(hash, manager_connection, options = {})
9
9
  @hash = hash
10
10
  # @manager_connection = manager_connection
11
11
  @id = hash['ID']
12
12
  @worker_join_token = hash['JoinTokens']['Worker']
13
13
  @manager_join_token = hash['JoinTokens']['Manager']
14
14
  @node_hash = {}
15
- nodes(manager_connection).each do |node|
16
- # Resolv::DNS.new.getaddress("devlog")
17
- @node_hash[node.id] = {hash: node.hash, connection: manager_connection}
15
+ @manager_connection = manager_connection
16
+ nodes.each do |node|
17
+ node_connection = nil
18
+ docker_port = options[:docker_api_port] || 2375
19
+ if (node.hash['ManagerStatus'])
20
+ ip_address = node.hash['ManagerStatus']['Addr'].split(":").first
21
+ manager_ip_address = @manager_connection.url.split('//').last.split(':').first
22
+ if (ip_address == manager_ip_address)
23
+ node.connection = @manager_connection
24
+ else
25
+ node.connection = Docker::Swarm::Connection.new("tcp://#{ip_address}:#{docker_port}")
26
+ end
27
+ else
28
+ ip_address = Resolv::DNS.new.getaddress(node.host_name())
29
+ node.connection = Docker::Swarm::Connection.new("tcp://#{ip_address}:#{docker_port}")
30
+ end
31
+ @node_hash[node.id] = {hash: node.hash, connection: node.connection}
18
32
 
19
33
  end
20
34
  end
@@ -118,15 +132,16 @@ class Docker::Swarm::Swarm
118
132
  end
119
133
 
120
134
  # Return all of the Nodes.
121
- def nodes(conn = self.connection)
135
+ def nodes
122
136
  opts = {}
123
137
  query = {}
124
- response = conn.get('/nodes', query, :body => opts.to_json, expects: [200, 406], full_response: true)
138
+ response = self.connection.get('/nodes', query, :body => opts.to_json, expects: [200, 406], full_response: true)
125
139
  if (response.status == 200)
126
140
  hashes = JSON.parse(response.body)
127
141
  nodes = []
128
142
  hashes.each do |node_hash|
129
- nodes << Docker::Swarm::Node.new(self, node_hash)
143
+ node = Docker::Swarm::Node.new(self, node_hash)
144
+ nodes << node
130
145
  end
131
146
  return nodes || []
132
147
  else
@@ -161,6 +176,11 @@ class Docker::Swarm::Swarm
161
176
  end
162
177
  return items
163
178
  end
179
+
180
+ def discover_nodes
181
+ # {discover_nodes: true, worker_docker_port: 2375}
182
+
183
+ end
164
184
 
165
185
  # Initialize Swarm
166
186
  def self.init(opts, connection)
@@ -192,11 +212,14 @@ class Docker::Swarm::Swarm
192
212
  end
193
213
  end
194
214
 
195
- def self.find(connection)
215
+ def self.find(connection, options = {})
196
216
  query = {}
197
217
  response = connection.get('/swarm', query, expects: [200, 406], full_response: true)
198
218
  if (response.status == 200)
199
- return Docker::Swarm::Swarm.new(JSON.parse(response.body), connection)
219
+ swarm = Docker::Swarm::Swarm.new(JSON.parse(response.body), connection, options)
220
+ return swarm
221
+ else
222
+ raise "Error finding swarm: HTTP-#{response.status} #{response.body}"
200
223
  end
201
224
  end
202
225
 
@@ -1,7 +1,7 @@
1
1
  module Docker
2
2
  module Swarm
3
3
  # The version of the docker-api gem.
4
- VERSION = '1.2'
4
+ VERSION = '1.2.1'
5
5
 
6
6
  # The version of the compatible Docker remote API.
7
7
  API_VERSION = '1.24'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-swarm-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore / Rogue Wave Software