Class: Docker::Swarm::Service
- Inherits:
-
Object
- Object
- Docker::Swarm::Service
- Defined in:
- lib/docker/swarm/service.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
include Docker::Base.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(hash, connection) ⇒ Service
constructor
A new instance of Service.
- #remove(opts = {}) ⇒ Object
- #scale(count) ⇒ Object
- #update(opts) ⇒ Object
Constructor Details
#initialize(hash, connection) ⇒ Service
Returns a new instance of Service.
7 8 9 10 |
# File 'lib/docker/swarm/service.rb', line 7 def initialize(hash, connection) @connection = connection @hash = hash end |
Instance Attribute Details
#hash ⇒ Object (readonly)
include Docker::Base
5 6 7 |
# File 'lib/docker/swarm/service.rb', line 5 def hash @hash end |
Class Method Details
.create(opts = {}, conn = Docker.connection) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/docker/swarm/service.rb', line 33 def self.create(opts = {}, conn = Docker.connection) query = {} response = conn.post('/services/create', query, :body => opts.to_json) info = JSON.parse(response) service_id = info['ID'] return self.find(service_id, conn) end |
.find(id, conn = Docker.connection) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/docker/swarm/service.rb', line 41 def self.find(id, conn = Docker.connection) query = {} opts = {} response = conn.get("/services/#{id}", query, :body => opts.to_json) hash = JSON.parse(response) return Docker::Swarm::Service.new(hash, conn) end |
Instance Method Details
#id ⇒ Object
12 13 14 |
# File 'lib/docker/swarm/service.rb', line 12 def id() return @hash['ID'] end |
#remove(opts = {}) ⇒ Object
16 17 18 19 |
# File 'lib/docker/swarm/service.rb', line 16 def remove(opts = {}) query = {} @connection.delete("/services/#{self.id}", query, :body => opts.to_json) end |
#scale(count) ⇒ Object
28 29 30 31 |
# File 'lib/docker/swarm/service.rb', line 28 def scale(count) @hash['Spec']['Mode']['Replicated']['Replicas'] = count self.update(@hash['Spec']) end |
#update(opts) ⇒ Object
21 22 23 24 25 |
# File 'lib/docker/swarm/service.rb', line 21 def update(opts) query = {} version = @hash['Version']['Index'] response = @connection.post("/services/#{self.id}/update?version=#{version}", query, :body => opts.to_json) end |