Class: Conjure::Service::ContainerSet
- Inherits:
-
Object
- Object
- Conjure::Service::ContainerSet
- Defined in:
- lib/conjure/service/docker_host.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
- #destroy_all(options) ⇒ Object
- #destroy_all_stopped ⇒ Object
- #find(options) ⇒ Object
-
#initialize(options) ⇒ ContainerSet
constructor
A new instance of ContainerSet.
Constructor Details
#initialize(options) ⇒ ContainerSet
Returns a new instance of ContainerSet.
213 214 215 |
# File 'lib/conjure/service/docker_host.rb', line 213 def initialize() self.host = [:host] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
211 212 213 |
# File 'lib/conjure/service/docker_host.rb', line 211 def host @host end |
Instance Method Details
#destroy_all(options) ⇒ Object
232 233 234 235 236 237 238 |
# File 'lib/conjure/service/docker_host.rb', line 232 def destroy_all() while container = find(:image_name => [:image_name]) do Log.info "[docker] Stopping #{[:image_name]}" host.command "stop #{container.id}" host.command "rm #{container.id}" end end |
#destroy_all_stopped ⇒ Object
225 226 227 228 229 230 |
# File 'lib/conjure/service/docker_host.rb', line 225 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
217 218 219 220 221 222 223 |
# File 'lib/conjure/service/docker_host.rb', line 217 def find() image_name = [: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 |