class Docker::Swarm::Service
Attributes
hash[R]
include Docker::Base
Public Class Methods
DEFAULT_OPTIONS()
click to toggle source
# File lib/docker/swarm/service.rb, line 52 def self.DEFAULT_OPTIONS default_service_create_options = { "Name" => "<<Required>>", "TaskTemplate" => { "ContainerSpec" => { "Image" => "<<Required>>", "Mounts" => [], "User" => "root" }, "Env" => [], "LogDriver" => { "Name" => "json-file", "Options" => { "max-file" => "3", "max-size" => "10M" } }, "Placement" => {}, "Resources" => { "Limits" => { "MemoryBytes" => 104857600 }, "Reservations" => { # "NanoCPUs" => ? # MemoryBytes => } }, "RestartPolicy" => { "Condition" => "on-failure", "Delay" => 1, "MaxAttempts" => 3 } }, # End of TaskTemplate "Mode" => { "Replicated" => { "Replicas" => 1 } }, "UpdateConfig" => { "Delay" => 2, "Parallelism" => 2, "FailureAction" => "pause" }, "EndpointSpec" => { "Ports" => [ { # "Protocol" => "http", # "PublishedPort" => 2881, # "TargetPort" => 2881 } ] }, "Labels" => { "foo" => "bar" } } return default_service_create_options end
new(swarm, hash)
click to toggle source
# File lib/docker/swarm/service.rb, line 7 def initialize(swarm, hash) @swarm = swarm @hash = hash end
Public Instance Methods
id()
click to toggle source
# File lib/docker/swarm/service.rb, line 16 def id() return @hash['ID'] end
name()
click to toggle source
# File lib/docker/swarm/service.rb, line 12 def name() @hash['Spec']['Name'] end
network_ids()
click to toggle source
# File lib/docker/swarm/service.rb, line 26 def network_ids network_ids = [] if (@hash['Endpoint']['VirtualIPs']) @hash['Endpoint']['VirtualIPs'].each do |network_info| network_ids << network_info['NetworkID'] end end return network_ids end
reload()
click to toggle source
# File lib/docker/swarm/service.rb, line 20 def reload() s = @swarm.find_service(id()) @hash = s.hash return self end
remove(opts = {})
click to toggle source
# File lib/docker/swarm/service.rb, line 36 def remove(opts = {}) query = {} @swarm.connection.delete("/services/#{self.id}", query, :body => opts.to_json) end
scale(count)
click to toggle source
# File lib/docker/swarm/service.rb, line 47 def scale(count) @hash['Spec']['Mode']['Replicated']['Replicas'] = count self.update(@hash['Spec']) end
update(opts)
click to toggle source
# File lib/docker/swarm/service.rb, line 41 def update(opts) query = {} version = @hash['Version']['Index'] response = @swarm.connection.post("/services/#{self.id}/update?version=#{version}", query, :body => opts.to_json) end