Class: CFA::NmConnection
- Inherits:
-
BaseModel
- Object
- BaseModel
- CFA::NmConnection
- Defined in:
- src/lib/cfa/nm_connection.rb
Overview
Class to handle NetworkManager connection configuration files
Constant Summary collapse
- KNOWN_SECTIONS =
[ "bond", "bridge", "connection", "ethernet", "ethernet_s390_options", "ipv4", "ipv6", "vlan", "wifi", "wifi_security" ].freeze
Instance Attribute Summary collapse
-
#file_path ⇒ String
readonly
File path.
Class Method Summary collapse
-
.for(conn) ⇒ NmConnection
Returns the file corresponding to a connection.
Instance Method Summary collapse
-
#add_collection(section, name, values) ⇒ Object
Sets an array's property under an specific section.
-
#exist? ⇒ Boolean
Determines whether the file exist.
-
#initialize(path, file_handler: nil) ⇒ NmConnection
constructor
Constructor.
-
#section_for(name) ⇒ AugeasTree
Returns the augeas tree for the given section.
Constructor Details
#initialize(path, file_handler: nil) ⇒ NmConnection
Constructor
75 76 77 |
# File 'src/lib/cfa/nm_connection.rb', line 75 def initialize(path, file_handler: nil) super(AugeasParser.new("NetworkManager.lns"), path, file_handler: file_handler) end |
Instance Attribute Details
#file_path ⇒ String (readonly)
Returns File path.
41 42 43 |
# File 'src/lib/cfa/nm_connection.rb', line 41 def file_path @file_path end |
Class Method Details
.for(conn) ⇒ NmConnection
Returns the file corresponding to a connection
48 49 50 51 |
# File 'src/lib/cfa/nm_connection.rb', line 48 def for(conn) path = SYSTEM_CONNECTIONS_PATH.join(file_basename_for(conn)).sub_ext(FILE_EXT) new(path) end |
Instance Method Details
#add_collection(section, name, values) ⇒ Object
Sets an array's property under an specific section
Array properties are written as a numbered variable. This method takes care of numbering them according to the variable name.
109 110 111 112 113 114 115 |
# File 'src/lib/cfa/nm_connection.rb', line 109 def add_collection(section, name, values) section = section_for(section) values.each_with_index do |ip, index| section["#{name}#{index + 1}"] = ip end end |
#exist? ⇒ Boolean
Determines whether the file exist
120 121 122 |
# File 'src/lib/cfa/nm_connection.rb', line 120 def exist? ::File.exist?(::File.join(Yast::WFM.scr_root, file_path)) end |
#section_for(name) ⇒ AugeasTree
Returns the augeas tree for the given section
If the given section does not exist, it returns an empty one
85 86 87 88 89 90 |
# File 'src/lib/cfa/nm_connection.rb', line 85 def section_for(name) sname = name.gsub("_", "-") return data[sname] if data[sname] data[sname] ||= CFA::AugeasTree.new end |