Class: Pec::Director

Inherits:
Object show all
Defined in:
lib/pec/director.rb,
lib/pec/director/helper.rb,
lib/pec/director/make_director.rb,
lib/pec/director/destroy_director.rb,
lib/pec/director/vm_status_director.rb

Defined Under Namespace

Classes: DestroyDirector, Helper, MakeDirector, VmStatusDirector

Class Method Summary collapse

Class Method Details

.assign_director(action, options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pec/director.rb', line 26

def assign_director(action, options)
  case
  when action == "make"
    Pec::Director::MakeDirector.new
  when action == "destroy"
    Pec::Director::DestroyDirector.new(options)
  when action == "vm_status"
    Pec::Director::VmStatusDirector.new
  else
    raise
  end
end

.config_load_err_message(e) ⇒ Object



43
44
45
46
# File 'lib/pec/director.rb', line 43

def config_load_err_message(e)
  puts e
  puts "can't load configfile".magenta
end

.err_message(e) ⇒ Object



39
40
41
# File 'lib/pec/director.rb', line 39

def err_message(e)
  puts e.to_s.magenta
end

.excon_err_message(e) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/pec/director.rb', line 48

def excon_err_message(e)
  if e.response
    JSON.parse(e.response[:body]).each { |e,m| puts "#{e}:#{m["message"]}".magenta }
  else
    puts e
  end
end

.execute(action, host_name, options = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pec/director.rb', line 5

def execute(action, host_name, options=nil)
  config = Pec::Configure.new("Pec.yaml")
  director = assign_director(action, options)
  config.filter_by_host(host_name).each do |host|
    begin
      director.execute!(host) if director.do_it?(host)
    rescue Pec::Errors::Error => e
      director.err_message(e, host)
    rescue Excon::Errors::Error => e
      excon_err_message(e)
    end
  end if config

  rescue Pec::Errors::Configure => e
    config_load_err_message(e)
  rescue Pec::Errors::Error => e
    err_message(e)
  rescue Errno::ENOENT => e
    err_message(e)
end