docker-swarm-sdk 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 166f2d37a054fea0b51d90d32f48cdace6ccd133
4
- data.tar.gz: 990589c2d8478c55dcb45ca6d868f034ceeb94f6
3
+ metadata.gz: '0788875137185f4cd9dc756a4f5472c88b6c095c'
4
+ data.tar.gz: b8cf6d7b1ea314c346e27481abc87de47839ba74
5
5
  SHA512:
6
- metadata.gz: 4bafe8fd12192bb44d9d1074f08b385d1c38cf93583f5fed4f698021e1d1c3096d1ea5e262242173cf2ee2f0e09aef61345f2123aec78591f8b79008c22369ec
7
- data.tar.gz: 271c2ea0d98e7a9ebe679b94f79f623bc691b08bb80e390949852ce834523d0f9f283bbb09acc7d51d5b563f27766cd37b8384e5e5899f95521c113b484b5b22
6
+ metadata.gz: 7f036700557339985b766a4f75fff68ed0133efaf89329d1dddaf4f7c13e5739a08cfba2e57e8f9b91b225047c2733cbb111c8029a8f330f0980190b83263abb
7
+ data.tar.gz: 7e618fffef5ed3b5b966274732524e8da14a423dc7ac1670976f5fb63e93f6875b25b7a59c898d39b6713e26151873618962b0c7cf6a6d65c7d5f150613fa94e
data/README.md CHANGED
@@ -19,9 +19,6 @@ Sample Usage
19
19
  # Make a connection to the Swarm manager's API. (Assumes port 2375 exposed for API)
20
20
  master_connection = Docker::Swarm::Connection.new('http://10.20.30.1:2375')
21
21
 
22
- # If swarm on the swarm master and using socket:
23
- master_connection = Docker::Swarm::Connection.new('unix:///var/run/docker.sock')
24
-
25
22
  # Manager node intializes swarm
26
23
  swarm_init_options = { "ListenAddr" => "0.0.0.0:2377" }
27
24
  swarm = Docker::Swarm::Swarm.init(swarm_init_options, master_connection)
@@ -93,7 +90,7 @@ tasks = swarm.tasks()
93
90
 
94
91
  # Scale up or down the number of replicas on a service
95
92
  service.scale(20)
96
-
93
+
97
94
  # Worker leaves the swarm - no forcing
98
95
  swarm.leave(worker_node, node)
99
96
 
@@ -1,14 +1,14 @@
1
1
  require 'docker-api'
2
- require 'active_support'
3
2
 
4
3
  class Docker::Swarm::Service
4
+ #include Docker::Base
5
5
  attr_reader :hash
6
6
 
7
7
  def initialize(swarm, hash)
8
8
  @swarm = swarm
9
9
  @hash = hash
10
10
  end
11
-
11
+
12
12
  def name()
13
13
  @hash['Spec']['Name']
14
14
  end
@@ -16,13 +16,13 @@ class Docker::Swarm::Service
16
16
  def id()
17
17
  return @hash['ID']
18
18
  end
19
-
19
+
20
20
  def reload()
21
21
  s = @swarm.find_service(id())
22
22
  @hash = s.hash
23
23
  return self
24
24
  end
25
-
25
+
26
26
  def network_ids
27
27
  network_ids = []
28
28
  if (@hash['Endpoint']['VirtualIPs'])
@@ -32,23 +32,16 @@ class Docker::Swarm::Service
32
32
  end
33
33
  return network_ids
34
34
  end
35
-
35
+
36
36
  def remove(opts = {})
37
37
  query = {}
38
38
  @swarm.connection.delete("/services/#{self.id}", query, :body => opts.to_json)
39
39
  end
40
-
41
- def update(options = {})
42
- specs = @hash['Spec'].deep_merge(options)
40
+
41
+ def update(opts)
43
42
  query = {}
44
43
  version = @hash['Version']['Index']
45
- response = @swarm.connection.post("/services/#{self.id}/update?version=#{version}", query, :body => specs.to_json)
46
- end
47
-
48
- def restart
49
- options = {}
50
- options['TaskTemplate'] = {'ForceUpdate' => 1}
51
- update(options)
44
+ response = @swarm.connection.post("/services/#{self.id}/update?version=#{version}", query, :body => opts.to_json)
52
45
  end
53
46
 
54
47
  def scale(count)
@@ -56,10 +49,6 @@ class Docker::Swarm::Service
56
49
  self.update(@hash['Spec'])
57
50
  end
58
51
 
59
- def replicas
60
- @hash['Spec']['Mode']['Replicated']['Replicas']
61
- end
62
-
63
52
  def self.DEFAULT_OPTIONS
64
53
  default_service_create_options = {
65
54
  "Name" => "<<Required>>",
@@ -84,7 +73,7 @@ class Docker::Swarm::Service
84
73
  },
85
74
  "Reservations" => {
86
75
  # "NanoCPUs" => ?
87
- # MemoryBytes =>
76
+ # MemoryBytes =>
88
77
  }
89
78
  },
90
79
  "RestartPolicy" => {
@@ -118,4 +107,6 @@ class Docker::Swarm::Service
118
107
  }
119
108
  return default_service_create_options
120
109
  end
121
- end
110
+
111
+
112
+ end
@@ -8,8 +8,8 @@ class Docker::Swarm::Swarm
8
8
  attr_reader :node_ip, :manager_ip, :worker_join_token, :manager_join_token, :id, :hash, :node_hash
9
9
 
10
10
  def store_manager(manager_connection, listen_address_and_port)
11
- node = nodes.find {|n|
12
- (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true) && (n.hash['ManagerStatus']['Addr'] == listen_address_and_port)
11
+ node = nodes.find {|n|
12
+ (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true) && (n.hash['ManagerStatus']['Addr'] == listen_address_and_port)
13
13
  }
14
14
  raise "Node not found for: #{listen_address}" if (!node)
15
15
  @node_hash[node.id] = {hash: node.hash, connection: manager_connection}
@@ -18,7 +18,7 @@ class Docker::Swarm::Swarm
18
18
  def update_data(hash)
19
19
  @hash = hash
20
20
  end
21
-
21
+
22
22
  def socket_connection(node_connection)
23
23
  node_connection.url.include?('unix:///')
24
24
  end
@@ -32,7 +32,7 @@ class Docker::Swarm::Swarm
32
32
  node_ip = node_connection.url.split("//").last.split(":").first
33
33
  manager_ip = self.connection.url.split("//").last.split(":").first
34
34
  end
35
-
35
+
36
36
  join_options = {
37
37
  "ListenAddr" => "#{listen_address}",
38
38
  "AdvertiseAddr" => "#{node_ip}:2377",
@@ -62,11 +62,11 @@ class Docker::Swarm::Swarm
62
62
  def join_worker(node_connection, listen_address = "0.0.0.0:2377")
63
63
  join(node_connection, @node_ip, @manager_ip, @worker_join_token)
64
64
  end
65
-
65
+
66
66
  def join_manager(node_connection, listen_address = "0.0.0.0:2377")
67
67
  join(node_connection, @node_ip, @manager_ip, @manager_join_token, listen_address)
68
68
  end
69
-
69
+
70
70
  def connection
71
71
  @node_hash.keys.each do |node_id|
72
72
  node_info = @node_hash[node_id]
@@ -81,7 +81,7 @@ class Docker::Swarm::Swarm
81
81
  services().each do |service|
82
82
  service.remove()
83
83
  end
84
-
84
+
85
85
  worker_nodes.each do |node|
86
86
  leave(node, true)
87
87
  end
@@ -89,7 +89,7 @@ class Docker::Swarm::Swarm
89
89
  leave(node, true)
90
90
  end
91
91
  end
92
-
92
+
93
93
  def tasks
94
94
  items = []
95
95
  query = {}
@@ -109,11 +109,11 @@ class Docker::Swarm::Swarm
109
109
  Docker::Swarm::Swarm.leave(force, node_info[:connection])
110
110
  end
111
111
  end
112
-
112
+
113
113
  def remove_node(worker_node)
114
114
  Swarm::Node.remove(worker_node.id, self.connection)
115
115
  end
116
-
116
+
117
117
  def manager_nodes
118
118
  return nodes.select { |node| node.role == :manager} || []
119
119
  end
@@ -121,7 +121,7 @@ class Docker::Swarm::Swarm
121
121
  def worker_nodes
122
122
  return nodes.select { |node| node.role == :worker} || []
123
123
  end
124
-
124
+
125
125
  def networks
126
126
  all_networks = []
127
127
  response = connection.get("/networks", {}, full_response: true)
@@ -135,7 +135,7 @@ class Docker::Swarm::Swarm
135
135
  end
136
136
  return all_networks
137
137
  end
138
-
138
+
139
139
  def create_network(options)
140
140
  response = connection.post('/networks/create', {}, body: options.to_json, expects: [200, 201, 500], full_response: true)
141
141
  if (response.status <= 201)
@@ -148,11 +148,11 @@ class Docker::Swarm::Swarm
148
148
  raise "Error creating network: HTTP-#{response.status} - #{response.body}"
149
149
  end
150
150
  end
151
-
151
+
152
152
  def create_network_overlay(network_name)
153
153
  subnet_16_parts = [10, 10, 0, 0]
154
154
  max_vxlanid = 200
155
-
155
+
156
156
  # Sometimes nodes have leftover networks not on other nodes, that have subnets that can't be duplicated in
157
157
  # the new overlay network.
158
158
  nodes.each do |node|
@@ -165,7 +165,7 @@ class Docker::Swarm::Swarm
165
165
  end
166
166
  end
167
167
  end
168
-
168
+
169
169
  # Make sure our new network doesn't duplicate subnet of other network.
170
170
  if (network.hash['IPAM']) && (network.hash['IPAM']['Config'])
171
171
  network.hash['IPAM']['Config'].each do |subnet_config|
@@ -189,7 +189,7 @@ class Docker::Swarm::Swarm
189
189
  end
190
190
  end
191
191
  end
192
-
192
+
193
193
 
194
194
  options = {
195
195
  "Name" => network_name,
@@ -218,7 +218,7 @@ class Docker::Swarm::Swarm
218
218
  }
219
219
  create_network(options)
220
220
  end
221
-
221
+
222
222
  # Return all of the Nodes.
223
223
  def nodes
224
224
  opts = {}
@@ -249,7 +249,7 @@ class Docker::Swarm::Swarm
249
249
  end
250
250
  return nil
251
251
  end
252
-
252
+
253
253
  def find_service(id)
254
254
  query = {}
255
255
  opts = {}
@@ -257,14 +257,14 @@ class Docker::Swarm::Swarm
257
257
  hash = JSON.parse(response)
258
258
  return Docker::Swarm::Service.new(self, hash)
259
259
  end
260
-
260
+
261
261
  def find_service_by_name(name)
262
262
  services.each do |service|
263
263
  return service if (service.name == name)
264
264
  end
265
265
  return nil
266
266
  end
267
-
267
+
268
268
  def services
269
269
  items = []
270
270
  query = {}
@@ -276,18 +276,17 @@ class Docker::Swarm::Swarm
276
276
  end
277
277
  return items
278
278
  end
279
-
280
-
279
+
280
+
281
281
  # Initialize Swarm
282
282
  def self.init(opts, connection)
283
283
  query = {}
284
284
  resp = connection.post('/swarm/init', query, :body => opts.to_json, full_response: true, expects: [200, 404, 406, 500])
285
285
  if (resp.status == 200)
286
286
  swarm = Docker::Swarm::Swarm.swarm(opts, connection)
287
- manager_node = swarm.nodes.find {|n|
288
- (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true)
287
+ manager_node = swarm.nodes.find {|n|
288
+ (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true)
289
289
  }
290
- byebug
291
290
  listen_address = manager_node.hash['ManagerStatus']['Addr']
292
291
  swarm.store_manager(connection, listen_address)
293
292
  return swarm
@@ -297,14 +296,14 @@ class Docker::Swarm::Swarm
297
296
  end
298
297
 
299
298
  # docker swarm join-token -q worker
300
- def self.swarm(connection, options = {})
299
+ def self.swarm(options, connection)
301
300
  query = {}
302
301
  resp = connection.get('/swarm', query, :body => options.to_json, expects: [200, 404, 406], full_response: true)
303
302
  if (resp.status == 406) || (resp.status == 404)
304
303
  return nil
305
304
  elsif (resp.status == 200)
306
305
  hash = JSON.parse(resp.body)
307
- swarm = self.find_swarm_for_id(hash['ID'])
306
+ swarm = self.find_swarm_for_id(hash['ID'])
308
307
  if (swarm)
309
308
  swarm.update_data(hash)
310
309
  else
@@ -314,7 +313,7 @@ class Docker::Swarm::Swarm
314
313
  raise "Bad response: #{resp.status} #{resp.body}"
315
314
  end
316
315
  end
317
-
316
+
318
317
  def self.leave(force, connection)
319
318
  query = {}
320
319
  query['force'] = force
@@ -323,39 +322,39 @@ class Docker::Swarm::Swarm
323
322
  raise "Error leaving: #{response.body} HTTP-#{response.status}"
324
323
  end
325
324
  end
326
-
325
+
327
326
  def self.find(connection, options = {})
328
327
  query = {}
329
328
  response = connection.get('/swarm', query, expects: [200, 404, 406], full_response: true)
330
329
  if (response.status == 200)
331
330
  hash = JSON.parse(response.body)
332
- swarm = self.find_swarm_for_id(hash['ID'])
331
+ swarm = self.find_swarm_for_id(hash['ID'])
333
332
  if (swarm)
334
333
  swarm.update_data(hash)
335
334
  else
336
335
  swarm = Docker::Swarm::Swarm.new(hash, connection, options)
337
336
  end
338
- manager_node = swarm.nodes.find {|n|
339
- (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true)
337
+ manager_node = swarm.nodes.find {|n|
338
+ (n.hash['ManagerStatus']) && (n.hash['ManagerStatus']['Leader'] == true)
340
339
  }
341
340
  listen_address = manager_node.hash['ManagerStatus']['Addr']
342
341
  swarm.store_manager(connection, listen_address)
343
342
  return swarm
344
343
  elsif (response.status > 200)
345
344
  return nil
346
- else
345
+ else
347
346
  raise "Error finding swarm: HTTP-#{response.status} #{response.body}"
348
347
  end
349
348
  end
350
-
351
-
349
+
350
+
352
351
  private
353
352
  @@swarms = {}
354
-
353
+
355
354
  def self.find_swarm_for_id(swarm_id)
356
355
  return @@swarms[swarm_id]
357
356
  end
358
-
357
+
359
358
  def initialize(hash, manager_connection = nil, options = {})
360
359
  @hash = hash
361
360
  @id = hash['ID']
@@ -367,8 +366,8 @@ class Docker::Swarm::Swarm
367
366
  @manager_connection = manager_connection
368
367
  @@swarms[@id] = self
369
368
  end
370
-
371
-
372
-
369
+
370
+
371
+
373
372
 
374
373
  end
@@ -7,19 +7,19 @@ class Docker::Swarm::Task
7
7
  @hash = hash
8
8
  @swarm = swarm
9
9
  end
10
-
11
- def id
10
+
11
+ def id
12
12
  return @hash['ID']
13
13
  end
14
-
14
+
15
15
  def image
16
16
  return @hash['Spec']['ContainerSpec']['Image']
17
17
  end
18
-
18
+
19
19
  def service_id
20
20
  @hash['ServiceID']
21
21
  end
22
-
22
+
23
23
  def service
24
24
  return @swarm.services.find { |service|
25
25
  self.service_id == service.id
@@ -29,27 +29,19 @@ class Docker::Swarm::Task
29
29
  def node_id
30
30
  @hash['NodeID']
31
31
  end
32
-
32
+
33
33
  def node
34
34
  return @swarm.nodes.find {|n| n.id == self.node_id}
35
35
  end
36
-
36
+
37
37
  def created_at
38
38
  return DateTime.parse(@hash.first['CreatedAt'])
39
39
  end
40
-
40
+
41
41
  def status
42
42
  @hash['Status']['State'].to_sym
43
43
  end
44
44
 
45
- def status_timestamp
46
- return DateTime.parse(@hash['Status']['Timestamp'])
47
- end
48
-
49
- def status_message
50
- @hash['Status']['Message']
51
- end
52
-
53
45
  def networks
54
46
  all_networks = @swarm.networks
55
47
  nets = []
@@ -1,7 +1,7 @@
1
1
  module Docker
2
2
  module Swarm
3
- # The version of this gem.
4
- VERSION = '1.2.5'
3
+ # The version of the docker-api gem.
4
+ VERSION = '1.2.6'
5
5
 
6
6
  # The version of the compatible Docker remote API.
7
7
  API_VERSION = '1.24'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-swarm-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -52,34 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.2.0
55
- - !ruby/object:Gem::Dependency
56
- name: activesupport
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '5.0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '5.0'
69
- - !ruby/object:Gem::Dependency
70
- name: byebug
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '6.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '6.0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: rake
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -205,5 +177,5 @@ rubyforge_project:
205
177
  rubygems_version: 2.6.12
206
178
  signing_key:
207
179
  specification_version: 4
208
- summary: Ruby API for Docker Swarm
180
+ summary: Ruby SDK for Docker Swarm API
209
181
  test_files: []