Class: Pec::Director::MakeDirector

Inherits:
Object
  • Object
show all
Defined in:
lib/pec/director/make_director.rb

Instance Method Summary collapse

Instance Method Details

#do_it?(host) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/pec/director/make_director.rb', line 9

def do_it?(host)
  true
end

#err_message(e, host) ⇒ Object



29
30
31
32
# File 'lib/pec/director/make_director.rb', line 29

def err_message(e, host)
    puts e.to_s.magenta
    puts "can't create server:#{host.name}".magenta if host
end

#execute!(host) ⇒ Object



4
5
6
7
# File 'lib/pec/director/make_director.rb', line 4

def execute!(host)
  Pec::Resource.set_tenant(host.tenant)
  make(host)
end

#make(host) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pec/director/make_director.rb', line 13

def make(host)
  if Pec::Compute::Server.exists?(host.name)
    puts "skip create server! name:#{host.name} is exists!".yellow
    return true
  end

  ports      = Pec::Director::Helper.ports_assign(host)
  flavor_ref = Pec::Compute::Flavor.get_ref(host.flavor)
  image_ref  = Pec::Compute::Image.get_ref(host.image)
  options    = { "user_data" => Pec::Configure::UserData.make(host, ports) }

  options.merge!(Pec::Director::Helper.get_nics(ports))

  Pec::Compute::Server.create(host.name, image_ref, flavor_ref, options)
end