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 +4 -4
- data/lib/docker/swarm/swarm.rb +32 -9
- data/lib/docker/swarm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b90891a651e044750fc2bc7b1956679634db08
|
4
|
+
data.tar.gz: 7fd85045899307db8a32fb3d94654167f4ba8ef2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4083515f3553d91273ea6e8f0b3959f71996529f9ab3340fd8f6e756677bf6cca787748e9491ec5b2e778d17e89b48ca1bc7a8c50b778e7b492f8bce6f119b17
|
7
|
+
data.tar.gz: a0e8a29a37b6eabc9c42e5963db95de9568cc2070b6c6e9fc00c008eb973d81ee38383ab2308873b6187af16076f49f32d1e1f37b8b6ad11c952ad0f0c17974d
|
data/lib/docker/swarm/swarm.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
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
|
135
|
+
def nodes
|
122
136
|
opts = {}
|
123
137
|
query = {}
|
124
|
-
response =
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/docker/swarm/version.rb
CHANGED