Class: Simp::Cli::Config::Item::NetworkConf
- Inherits:
-
ActionItem
- Object
- Simp::Cli::Config::Item
- ActionItem
- Simp::Cli::Config::Item::NetworkConf
- Defined in:
- lib/simp/cli/config/item/network_conf.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
- #apply ⇒ Object
- #format_puppet_array(v) ⇒ Object
-
#initialize ⇒ NetworkConf
constructor
A new instance of NetworkConf.
Methods inherited from ActionItem
Methods included from SafeApplying
Methods inherited from Simp::Cli::Config::Item
#default_value, #highline_question_type, #next_items, #not_valid_message, #os_value, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_extras, #query_status, #recommended_value, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s, #validate
Constructor Details
#initialize ⇒ NetworkConf
Returns a new instance of NetworkConf.
9 10 11 12 13 14 |
# File 'lib/simp/cli/config/item/network_conf.rb', line 9 def initialize super @key = 'network::conf' @description = 'action item; configures network interfaces' @die_on_apply_fail = true end |
Instance Method Details
#apply ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/simp/cli/config/item/network_conf.rb', line 16 def apply ci = {} cmd = nil dhcp = @config_items.fetch( 'dhcp' ).value # BOOTPROTO=none is valid to spec; BOOTPROTO=static isn't bootproto = (dhcp == 'static') ? 'none' : dhcp interface = @config_items.fetch( 'network::interface' ).value # apply the interface useing the SIMP classes # NOTE: the "FACTER_ipaddress=XXX" helps puppet avoid a fatal error that # occurs in the core ipaddress fact on offline systems. cmd = %Q@FACTER_ipaddress=XXX puppet apply -e "network::add_eth{'#{interface}': bootproto => '#{bootproto}', onboot => 'yes'@ if bootproto == 'none' ipaddress = @config_items.fetch( 'ipaddress' ).value hostname = @config_items.fetch( 'hostname' ).value netmask = @config_items.fetch( 'netmask' ).value gateway = @config_items.fetch( 'gateway' ).value dns_search = @config_items.fetch( 'dns::search' ).value dns_servers = @config_items.fetch( 'dns::servers').value resolv_domain = hostname.split('.')[1..-1].join('.') cmd += %Q{, } cmd += %Q@ipaddr => '#{ipaddress}', @ cmd += %Q@netmask => '#{netmask}', @ cmd += %Q@gateway => '#{gateway}' } @ cmd += %Q@class{ 'simplib::resolv': @ cmd += %Q@resolv_domain => '#{resolv_domain}', @ cmd += %Q@nameservers => #{ format_puppet_array( dns_servers ) }, @ cmd += %Q@search => #{ format_puppet_array( dns_search ) }, @ cmd += %Q@named_autoconf => false, @ end cmd += %Q@}"@ # TODO: maybe good ideas # - set $::domain with FACTER_domain= # - set comon::resolv{ named_autofonf => false puts cmd unless @silent %x{#{cmd}} end |
#format_puppet_array(v) ⇒ Object
58 59 60 61 |
# File 'lib/simp/cli/config/item/network_conf.rb', line 58 def format_puppet_array v v = [v] if v.kind_of? String "['#{v.join "','"}']" end |