Class: Pec::Configure::Ethernet
- Inherits:
-
Object
- Object
- Pec::Configure::Ethernet
- Defined in:
- lib/pec/configure/ethernet.rb
Instance Attribute Summary collapse
-
#bootproto ⇒ Object
readonly
Returns the value of attribute bootproto.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .check_network_key(name, config) ⇒ Object
- .check_require_key(name, config) ⇒ Object
- .load(name, config) ⇒ Object
Instance Method Summary collapse
- #find_port(ports) ⇒ Object
-
#initialize(config) ⇒ Ethernet
constructor
A new instance of Ethernet.
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 end |
Class Method Details
.check_network_key(name, config) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pec/configure/ethernet.rb', line 28 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") end true end |
.check_require_key(name, config) ⇒ Object
23 24 25 26 |
# File 'lib/pec/configure/ethernet.rb', line 23 def check_require_key(name, config) raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto is required!") if config[1]["bootproto"].nil? true end |
.load(name, config) ⇒ Object
19 20 21 |
# File 'lib/pec/configure/ethernet.rb', line 19 def load(name, config) self.new(config) if check_require_key(name, config) && check_network_key(name, config) end |
Instance Method Details
#find_port(ports) ⇒ Object
14 15 16 |
# File 'lib/pec/configure/ethernet.rb', line 14 def find_port(ports) ports.find { |p| p.device_name == @name } end |