Class: Algo::Docker::Service

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

Defined Under Namespace

Classes: Spec

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, hash) ⇒ Service

Returns a new instance of Service.



12
13
14
15
# File 'lib/algo/docker/service.rb', line 12

def initialize conn, hash
  super(conn, hash)
  @spec = nil
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



10
11
12
# File 'lib/algo/docker/service.rb', line 10

def spec
  @spec
end

Class Method Details

.all(conn = Docker.connection) ⇒ Object



75
76
77
78
# File 'lib/algo/docker/service.rb', line 75

def self.all(conn=Docker.connection)
  hashes = conn.get('/services')
  hashes.map{ |h| new(conn, h) }
end

.create(init_spec, conn = Docker.connection) ⇒ Object



61
62
63
# File 'lib/algo/docker/service.rb', line 61

def self.create(init_spec, conn=Docker.connection)
  new(conn, conn.post('/services/create', nil, body: JSON.generate(init_spec)))
end

.find(id_or_name, conn = Docker.connection) ⇒ Object



57
58
59
# File 'lib/algo/docker/service.rb', line 57

def self.find(id_or_name, conn=Docker.connection)
  new(conn, conn.get("/services/#{id_or_name}"))
end

.remove(id_or_name, conn = Docker.connection) ⇒ Object



65
66
67
# File 'lib/algo/docker/service.rb', line 65

def self.remove(id_or_name, conn=Docker.connection)
  conn.delete("/services/#{id_or_name}")
end

.update(id_or_name, version, next_spec, conn = Docker.connection) ⇒ Object



69
70
71
72
73
# File 'lib/algo/docker/service.rb', line 69

def self.update(id_or_name, version, next_spec, conn=Docker.connection)
  conn.post("/services/#{id_or_name}/update",
            { version: version },
            body: JSON.generate(next_spec))
end

Instance Method Details

#infoObject



17
18
19
20
# File 'lib/algo/docker/service.rb', line 17

def info
  @info = Docker::Service.find(@info["Id"]).info if @info["Spec"].blank?
  @info
end

#inspectObject



44
45
46
# File 'lib/algo/docker/service.rb', line 44

def inspect
  "<Algo::Docker::Service name=#{spec.name}>"
end

#raw_specObject



40
41
42
# File 'lib/algo/docker/service.rb', line 40

def raw_spec
  info["Spec"]
end

#removeObject



48
49
50
# File 'lib/algo/docker/service.rb', line 48

def remove
  self.class.remove info['Id']
end

#update(next_spec) ⇒ Object



52
53
54
55
# File 'lib/algo/docker/service.rb', line 52

def update next_spec
  self.class.update info['Id'], info['Version']['Index'], next_spec
  @info = self.class.find(@info["Id"]).info
end