-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from khaefeli/tasks
Add new Docker Swarm Tasks (node ls, rm, update; service scale)
- Loading branch information
Showing
8 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
{ | ||
"description": "List nodes in the swarm", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"filter": { | ||
"description": "Filter output based on conditions provided", | ||
"type": "Optional[String[1]]" | ||
}, | ||
"quiet": { | ||
"description": "Only display IDs", | ||
"type": "Optional[Boolean]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def node_ls(filter, quiet) | ||
cmd_string = 'docker node ls' | ||
cmd_string += " --filter=#{filter}" unless filter.nil? | ||
cmd_string += ' --quiet' unless quiet.nil? | ||
|
||
stdout, stderr, status = Open3.capture3(cmd_string) | ||
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 | ||
stdout.strip | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
filter = params['filter'] | ||
quiet = params['quiet'] | ||
|
||
begin | ||
result = node_ls(filter, quiet) | ||
puts result | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts(status: 'failure', error: e.message) | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
{ | ||
"description": "Update a node", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"force": { | ||
"description": "Force remove a node from the swarm", | ||
"type": "Optional[Boolean]" | ||
}, | ||
"node": { | ||
"description": "Hostname or ID of the node in the swarm", | ||
"type": "String[1]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def node_rm(force, node) | ||
cmd_string = 'docker node rm' | ||
cmd_string += ' --force' unless force.nil? | ||
cmd_string += " #{node}" unless node.nil? | ||
|
||
stdout, stderr, status = Open3.capture3(cmd_string) | ||
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 | ||
stdout.strip | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
force = params['force'] | ||
node = params['node'] | ||
|
||
begin | ||
result = node_rm(force, node) | ||
puts result | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts(status: 'failure', error: e.message) | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
{ | ||
"description": "Update a node", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"availability": { | ||
"description": "Availability of the node", | ||
"type": "Optional[Enum['active', 'pause', 'drain']]" | ||
}, | ||
"role": { | ||
"description": "Role of the node", | ||
"type": "Optional[Enum['manager', 'worker']]" | ||
}, | ||
"node": { | ||
"description": "Hostname or ID of the node in the swarm", | ||
"type": "String[1]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def node_update(availability, role, node) | ||
cmd_string = 'docker node update' | ||
cmd_string += " --availability #{availability}" unless availability.nil? | ||
cmd_string += " --role #{role}" unless role.nil? | ||
cmd_string += " #{node}" unless node.nil? | ||
|
||
stdout, stderr, status = Open3.capture3(cmd_string) | ||
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 | ||
stdout.strip | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
availability = params['availability'] | ||
role = params['role'] | ||
node = params['node'] | ||
|
||
begin | ||
result = node_update(availability, role, node) | ||
puts result | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts(status: 'failure', error: e.message) | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
{ | ||
"description": "Scale one replicated service", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"service": { | ||
"description": "Name or ID of the service", | ||
"type": "String[1]" | ||
}, | ||
"scale": { | ||
"description": "Number of replicas", | ||
"type": "Integer" | ||
}, | ||
"detatch": { | ||
"description": "Exit immediately instead of waiting for the service to converge", | ||
"type": "Optional[Boolean]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def service_scale(service, scale, detach) | ||
cmd_string = 'docker service scale' | ||
cmd_string += " #{service}" unless service.nil? | ||
cmd_string += "=#{scale}" unless scale.nil? | ||
cmd_string += ' -d' unless detach.nil? | ||
|
||
stdout, stderr, status = Open3.capture3(cmd_string) | ||
raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 | ||
stdout.strip | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
service = params['service'] | ||
scale = params['scale'] | ||
detach = params['detach'] | ||
|
||
begin | ||
result = service_scale(service, scale, detach) | ||
puts result | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts(status: 'failure', error: e.message) | ||
exit 1 | ||
end |