Class: Armada::Clean::Containers

Inherits:
Object
  • Object
show all
Defined in:
lib/armada/clean/containers.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Containers

Returns a new instance of Containers.



4
5
6
7
8
# File 'lib/armada/clean/containers.rb', line 4

def initialize(options)
  @hosts   = options[:hosts]
  @force   = options[:force]
  @options = options
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/armada/clean/containers.rb', line 10

def run
  Armada.ui.info "******* DRY RUN *******" unless @force
  @hosts.each_in_parallel do |host|
    docker_host = Armada::Host.create(host, @options)
    docker_host.get_all_containers.each do |container|
      running = container.json["State"]["Running"]
      paused = container.json["State"]["Paused"]
      unless running || paused
        begin
          Armada.ui.info "#{docker_host.host} -- #{container.json["Name"]} with id [#{container.id[0..11]}]"
          container.remove if @force
        rescue Exception => e
          Armada.ui.error "#{docker_host.host} -- unable to remove container #{container.json["Name"]} with id [#{container.id[0..11]}] because of the following error - #{e.message}"
        end
      end
    end
  end
end