Class: Docker::Swarm::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/swarm/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#hashObject (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

#idObject



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