Class: Pec::Configure::Host

Inherits:
Object show all
Defined in:
lib/pec/configure/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Host

Returns a new instance of Host.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pec/configure/host.rb', line 5

def initialize(config)
  check_format(config)
  append_network(config[1])
  @name           = config[0];
  @image          = config[1]["image"];
  @flavor         = config[1]["flavor"];
  @security_group = config[1]["security_group"];
  @user_data      = config[1]["user_data"];
  @templates      = config[1]["templates"]
  @tenant         = config[1]["tenant"]
end

Instance Attribute Details

#flavor ⇒ Object (readonly)

Returns the value of attribute flavor.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def flavor
  @flavor
end

#image ⇒ Object (readonly)

Returns the value of attribute image.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def image
  @image
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def name
  @name
end

#networks ⇒ Object (readonly)

Returns the value of attribute networks.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def networks
  @networks
end

#security_group ⇒ Object (readonly)

Returns the value of attribute security_group.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def security_group
  @security_group
end

#templates ⇒ Object (readonly)

Returns the value of attribute templates.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def templates
  @templates
end

#tenant ⇒ Object (readonly)

Returns the value of attribute tenant.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def tenant
  @tenant
end

#user_data ⇒ Object (readonly)

Returns the value of attribute user_data.



4
5
6
# File 'lib/pec/configure/host.rb', line 4

def user_data
  @user_data
end

Instance Method Details

#append_network(config) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pec/configure/host.rb', line 17

def append_network(config)
  @networks ||= []
  config["networks"].each do |net|
    raise(Pec::Errors::Ethernet, "please! network interface format is Array") unless net.kind_of?(Array)

    if ethernet = Pec::Configure::Ethernet.new(config, net)
      @networks << ethernet
    end

  end if config["networks"]
end

#check_format(config) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
# File 'lib/pec/configure/host.rb', line 29

def check_format(config)
  err = %w(image flavor tenant).find {|r| !config[1].key?(r) || config[1][r].nil? }
  raise(Pec::Errors::Host,"skip! #{config[0]}: #{err} is required!") unless  err.nil?

  err = %w(security_group templates).find {|r| config[1].key?(r) && !config[1][r].kind_of?(Array) }
  raise(Pec::Errors::Host,"#{config[0]}: please! #{err} format is Array!") unless err.nil?
  true
end