Method: Pec::CLI#up

Defined in:
lib/pec/cli.rb

#up(host_name = nil) ⇒ Object



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
# File 'lib/pec/cli.rb', line 13

def up(host_name = nil)
  Pec.configure.each do |host|
    next if host_name && host.name != host_name
    Pec.init_yao(host.tenant)

    server = Yao::Server.list_detail.find {|s|s.name == host.name}
    if server
      Pec::Logger.notice "already exists: #{host.name}"
      next
    end
    Pec::Logger.info "make start #{host.name}"

    attribute = { name: host.name}
    host.keys.each do |k|
      Pec::Handler.constants.each do |c|
        if Object.const_get("Pec::Handler::#{c}").kind == k
          attribute.deep_merge!(Object.const_get("Pec::Handler::#{c}").build(host))
        end
      end
    end
    attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]

    Yao::Server.create(attribute)
    Pec::Logger.info "create success! #{host.name}"
  end
  rescue => e
    print_exception(e)
end