Class: Conjure::Service::ContainerSet

Inherits:
Object
  • Object
show all
Defined in:
lib/conjure/service/docker_host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ContainerSet

Returns a new instance of ContainerSet.



207
208
209
# File 'lib/conjure/service/docker_host.rb', line 207

def initialize(options)
  self.host = options[:host]
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



205
206
207
# File 'lib/conjure/service/docker_host.rb', line 205

def host
  @host
end

Instance Method Details

#destroy_all(options) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/conjure/service/docker_host.rb', line 226

def destroy_all(options)
  while container = find(:image_name => options[:image_name]) do
    Log.info "[docker] Stopping #{options[:image_name]}"
    host.command "stop #{container.id}"
    host.command "rm #{container.id}"
  end
end

#destroy_all_stoppedObject



219
220
221
222
223
224
# File 'lib/conjure/service/docker_host.rb', line 219

def destroy_all_stopped
  all_ids = host.command("ps -a -q").split("\n").map(&:strip)
  running_ids = host.command("ps -q").split("\n").map(&:strip)
  stopped_ids = all_ids - running_ids
  host.command "rm #{stopped_ids.join ' '}"
end

#find(options) ⇒ Object



211
212
213
214
215
216
217
# File 'lib/conjure/service/docker_host.rb', line 211

def find(options)
  image_name = options[:image_name].clone
  image_name << ":" unless image_name.include? ":"
  id = host.command("ps | grep #{image_name} ; true").strip.split("\n").first.to_s[0..11]
  id = nil if id == ""
  Container.new(:host => host, :id => id) if id
end