Class: Simp::Cli::Config::Item::NetworkInterface

Inherits:
Simp::Cli::Config::Item show all
Defined in:
lib/simp/cli/config/item/network_interface.rb

Instance Attribute Summary

Attributes inherited from Simp::Cli::Config::Item

#allow_user_apply, #config_items, #description, #die_on_apply_fail, #fact, #fail_on_missing_answer, #key, #next_items_tree, #silent, #skip_apply, #skip_query, #skip_yaml, #value

Instance Method Summary collapse

Methods inherited from Simp::Cli::Config::Item

#apply, #default_value, #highline_question_type, #next_items, #os_value, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_extras, #query_status, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s

Constructor Details

#initializeNetworkInterface

Returns a new instance of NetworkInterface.



10
11
12
13
14
# File 'lib/simp/cli/config/item/network_interface.rb', line 10

def initialize
  super
  @key         = 'network::interface'
  @description = 'The network interface to use to connect to the network.'
end

Instance Method Details

#acceptable_valuesObject

helper method; provides a list of available NICs



37
38
39
# File 'lib/simp/cli/config/item/network_interface.rb', line 37

def acceptable_values
  Facter.value('interfaces').split(',').delete_if{|x| x == 'lo'}.sort
end

#not_valid_messageObject



32
33
34
# File 'lib/simp/cli/config/item/network_interface.rb', line 32

def not_valid_message
  "Acceptable values: \n" + acceptable_values.map{ |x| "  #{x}" }.join("\n")
end

try to guess which NIC is likely to be used TODO IDEA: also use Facter to prefer NICs that already have IPs



18
19
20
21
22
23
24
25
26
# File 'lib/simp/cli/config/item/network_interface.rb', line 18

def recommended_value
  devices = acceptable_values
  (
   devices.select{|x|  x.match(/^br/)}.first  ||
   devices.select{|x|  x.match(/^eth/)}.first ||
   devices.select{|x| x.match(/^em/)}.first   ||
   devices.first
  )
end

#validate(x) ⇒ Object



28
29
30
# File 'lib/simp/cli/config/item/network_interface.rb', line 28

def validate( x )
  acceptable_values.include?( x )
end