File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "description" : " Updates an existing service." ,
3+ "input_method" : " stdin" ,
4+ "parameters" : {
5+ "service" : {
6+ "description" : " The service to update" ,
7+ "type" : " String[1]"
8+ },
9+ "image" : {
10+ "description" : " The new image to use for the service" ,
11+ "type" : " String[1]"
12+ }
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ #!/opt/puppetlabs/puppet/bin/ruby
2+ require 'json'
3+ require 'open3'
4+ require 'puppet'
5+
6+ def swarm_update ( image , service )
7+ cmd_string = "docker service update"
8+ cmd_string << " --image #{ image } " unless image . nil?
9+ cmd_string << " #{ service } " unless service . nil?
10+
11+ stdout , stderr , status = Open3 . capture3 ( cmd_string )
12+ raise Puppet ::Error , ( "stderr: '#{ stderr } '" ) if status != 0
13+ stdout . strip
14+ end
15+
16+ params = JSON . parse ( STDIN . read )
17+ image = params [ 'image' ]
18+ service = params [ 'service' ]
19+
20+ begin
21+ result = swarm_update ( image , service )
22+ puts result
23+ exit 0
24+ rescue Puppet ::Error => e
25+ puts ( { status : 'failure' , error : e . message } )
26+ exit 1
27+ end
You can’t perform that action at this time.
0 commit comments