Class: Annex::Provision
Instance Method Summary collapse
Methods inherited from Command
Constructor Details
This class inherits a constructor from Annex::Command
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/annex/provision.rb', line 7 def execute if !role && !environment @env.info("Sorry, you must include the role and the environment when provisioning", :error) return end begin # Try to determine the environment write_environment which = servers.select do |server| name_tag = server.["Name"] name_tag = name_tag.gsub(/-i-[0-9a-f]+$/, '') rescue '' choose = server.state == "running" choose = choose && name_tag =~ /^#{role}/ if role choose = choose && name_tag =~ /#{environment}$/ if environment choose end msg = "We have #{which.length} servers" msg << " for the #{role} role" msg << " in the environment #{environment}" @env.info(msg, :info) count = @env.config['roles'][role]['count'] @env.info("We should have #{count}", :info) # Try to be graceful Thread.abort_on_exception = false threads = [] # For each server we do have, update which.each do |server| threads << update(server, @env.config['users']['update']) unless ENV['SKIP_UPDATE'] end # For each server we need, bootstrap (count - which.length).times do image = @env.config['roles'][role]['image'] kind = @env.config['amazon']['images'][image] threads << bootstrap(connection, kind['image_id'], kind['flavor_id'], kind['az_id'], @env.config['users']['bootstrap']) end threads.each do |thr| thr.join unless ENV['SYNC'] end ensure cleanup_environment end end |