Skip to content

Commit b72a409

Browse files
committed
add/remove service constraints
1 parent d16ba72 commit b72a409

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

tasks/service_scale.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"description": "Scale one replicated service",
43
"input_method": "stdin",

tasks/service_update.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
"image": {
1010
"description": "The new image to use for the service",
1111
"type": "String[1]"
12+
},
13+
"constraint_add": {
14+
"description": "Add or update a service constraint (selector==value, selector!=value)",
15+
"type": "Optional[Array]"
16+
},
17+
"constraint_rm": {
18+
"description": "Remove a service constraint if exists.",
19+
"type": "Optional[Array]"
1220
}
1321
}
1422
}

tasks/service_update.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@
55
require 'open3'
66
require 'puppet'
77

8-
def service_update(image, service)
8+
def service_update(image, service, constraint_add, constraint_rm)
99
cmd_string = 'docker service update'
1010
cmd_string += " --image #{image}" unless image.nil?
11+
12+
if constraint_add.is_a? Array
13+
constraint_add.each do |param|
14+
cmd_string += " --constraint-add #{param}"
15+
end
16+
end
17+
18+
if constraint_rm.is_a? Array
19+
constraint_rm.each do |param|
20+
cmd_string += " --constraint-rm #{param}"
21+
end
22+
end
23+
1124
cmd_string += " #{service}" unless service.nil?
1225

1326
stdout, stderr, status = Open3.capture3(cmd_string)
@@ -18,9 +31,11 @@ def service_update(image, service)
1831
params = JSON.parse(STDIN.read)
1932
image = params['image']
2033
service = params['service']
34+
constraint_add = params['constraint_add']
35+
constraint_rm = params['constraint_rm']
2136

2237
begin
23-
result = service_update(image, service)
38+
result = service_update(image, service, constraint_add, constraint_rm)
2439
puts result
2540
exit 0
2641
rescue Puppet::Error => e

tasks/swarm_init.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"description": "Initializes a swarm",
43
"input_method": "stdin",

tasks/swarm_join.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"description": "Join a swarm",
43
"input_method": "stdin",

tasks/swarm_leave.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"description": "Leave a swarm",
43
"input_method": "stdin",

tasks/swarm_token.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"description": "Gets the swarm token from the master",
43
"input_method": "stdin",

0 commit comments

Comments
 (0)