Class: Pec::Configure::Ethernet

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Ethernet

Returns a new instance of Ethernet.



5
6
7
8
9
10
11
12
# File 'lib/pec/configure/ethernet.rb', line 5

def initialize(config)
  @name = config[0];
  @bootproto = config[1]["bootproto"];
  @ip_address = config[1]["ip_address"];
  @options = config[1].select do |k,v|
    { k => v } if k != "bootproto" && k != "ip_address"
  end
end

Instance Attribute Details

#bootproto ⇒ Object (readonly)

Returns the value of attribute bootproto.



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

def bootproto
  @bootproto
end

#ip_address ⇒ Object (readonly)

Returns the value of attribute ip_address.



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

def ip_address
  @ip_address
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.check_network_key(name, config) ⇒ Object



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

def check_network_key(name, config)
  net = config[1]
  case
  when (net["bootproto"] == "static" && net["ip_address"].nil?)
    raise(Pec::Errors::Ethernet, "skip! #{name}: ip_address is required by bootproto static")
  when (!net["bootproto"] == "static" && !net["bootproto"] == "dhcp")
    raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto set the value dhcp or static")
  when (!net["bootproto"] == "static" && !net["bootproto"] == "dhcp")
    raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto set the value dhcp or static")
  end
  true
end

.check_require_key(name, config) ⇒ Object



19
20
21
22
23
# File 'lib/pec/configure/ethernet.rb', line 19

def check_require_key(name, config)
  err = %w(bootproto).find {|k| !config[1].key?(k)}
  raise(Pec::Errors::Ethernet, "skip! #{name}: #{err} is required!") unless err.nil?
  true
end

.load(name, config) ⇒ Object



15
16
17
# File 'lib/pec/configure/ethernet.rb', line 15

def load(name, config)
  self.new(config) if check_require_key(name, config) && check_network_key(name, config)
end