Class: CFA::RoutesFile
- Inherits:
-
Object
- Object
- CFA::RoutesFile
- Defined in:
- src/lib/cfa/routes_file.rb
Overview
This class represents a file containing a set of routes
Constant Summary collapse
- DEFAULT_ROUTES_FILE =
"/etc/sysconfig/network/routes".freeze
- SYSCONFIG_NETWORK_DIR =
"/etc/sysconfig/network".freeze
Instance Attribute Summary collapse
-
#file_path ⇒ String
readonly
File path.
-
#routes ⇒ Array<Route>
Routes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file_path = DEFAULT_ROUTES_FILE) ⇒ RoutesFile
constructor
A new instance of RoutesFile.
-
#load ⇒ Array<Hash<String, String>>
Loads routes from system.
-
#remove ⇒ Object
Removes the file.
-
#save ⇒ Boolean
Writes configured routes.
Constructor Details
#initialize(file_path = DEFAULT_ROUTES_FILE) ⇒ RoutesFile
Returns a new instance of RoutesFile.
58 59 60 61 |
# File 'src/lib/cfa/routes_file.rb', line 58 def initialize(file_path = DEFAULT_ROUTES_FILE) @register_agent = file_path != DEFAULT_ROUTES_FILE @file_path = file_path end |
Instance Attribute Details
#file_path ⇒ String (readonly)
Returns File path.
47 48 49 |
# File 'src/lib/cfa/routes_file.rb', line 47 def file_path @file_path end |
#routes ⇒ Array<Route>
Returns Routes.
44 45 46 |
# File 'src/lib/cfa/routes_file.rb', line 44 def routes @routes end |
Class Method Details
.find(interface) ⇒ Object
51 52 53 54 |
# File 'src/lib/cfa/routes_file.rb', line 51 def find(interface) file_path = File.join(SYSCONFIG_NETWORK_DIR, "ifroute-#{interface}") new(file_path) end |
Instance Method Details
#load ⇒ Array<Hash<String, String>>
Loads routes from system
68 69 70 71 72 |
# File 'src/lib/cfa/routes_file.rb', line 68 def load entries = with_registered_ifroute_agent(file_path) { |a| Yast::SCR.Read(a) } entries = entries ? normalize_entries(entries.uniq) : [] @routes = entries.map { |r| serializer.from_hash(r) } end |
#remove ⇒ Object
Removes the file
91 92 93 94 95 |
# File 'src/lib/cfa/routes_file.rb', line 91 def remove return unless Yast::FileUtils.Exists(file_path) Yast::SCR.Execute(Yast::Path.new(".target.remove"), file_path) end |
#save ⇒ Boolean
Writes configured routes
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'src/lib/cfa/routes_file.rb', line 77 def save # create if not exists, otherwise backup if Yast::FileUtils.Exists(file_path) Yast::Execute.on_target("/bin/cp", file_path, file_path + ".YaST2save") end with_registered_ifroute_agent(file_path) do |scr| # work around bnc#19476 Yast::SCR.Write(Yast::Path.new(".target.string"), file_path, "") Yast::SCR.Write(scr, routes.map { |r| serializer.to_hash(r) }) end end |