Class: Yast::NetworkConfigClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetworkConfigClass
- Defined in:
- library/network/src/modules/NetworkConfig.rb
Instance Method Summary collapse
-
#Export ⇒ Object
Export data.
-
#Import(settings) ⇒ Object
Import data.
- #main ⇒ Object
-
#Modified ⇒ Object
Data was modified?.
-
#Read ⇒ Object
Read all network settings from the SCR.
-
#ReadConfig(config) ⇒ Object
Read sysconfig file.
-
#Write ⇒ Object
Update the SCR according to network settings.
-
#WriteConfig(config, data) ⇒ Object
Write sysconfig file.
Instance Method Details
#Export ⇒ Object
Export data
189 190 191 |
# File 'library/network/src/modules/NetworkConfig.rb', line 189 def Export Builtins.eval("config" => @Config, "dhcp" => @DHCP) end |
#Import(settings) ⇒ Object
Import data
176 177 178 179 180 181 182 183 184 185 |
# File 'library/network/src/modules/NetworkConfig.rb', line 176 def Import(settings) settings = deep_copy(settings) @Config = Builtins.eval(Ops.get_map(settings, "config", {})) @DHCP = Builtins.eval(Ops.get_map(settings, "dhcp", {})) @Orig_Config = nil @Orig_DHCP = nil true end |
#main ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'library/network/src/modules/NetworkConfig.rb', line 36 def main Yast.import "String" # Basic network settings (/etc/sysconfig/network/config) @Config = {} # DHCP settings (/etc/sysconfig/network/dhcp) @DHCP = {} # Basic network settings @Orig_Config = nil # DHCP settings @Orig_DHCP = nil #-------------- # PRIVATE DATA # True if data are already read @initialized = false end |
#Modified ⇒ Object
Data was modified?
137 138 139 140 141 |
# File 'library/network/src/modules/NetworkConfig.rb', line 137 def Modified ret = @DHCP != @Orig_DHCP || @Config != @Orig_Config Builtins.y2debug("ret=%1", ret) ret end |
#Read ⇒ Object
Read all network settings from the SCR
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'library/network/src/modules/NetworkConfig.rb', line 145 def Read return true if @initialized == true @Config = ReadConfig(path(".sysconfig.network.config")) @DHCP = ReadConfig(path(".sysconfig.network.dhcp")) @Orig_Config = Builtins.eval(@Config) @Orig_DHCP = Builtins.eval(@DHCP) @initialized = true true end |
#ReadConfig(config) ⇒ Object
Read sysconfig file. Uses metadata to distinguish between booleans, integers, and strings
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'library/network/src/modules/NetworkConfig.rb', line 62 def ReadConfig(config) Builtins.y2debug("config=%1", config) return {} if config.nil? ret = {} vars = SCR.Dir(config) vars = [] if vars.nil? Builtins.maplist(vars) do |var| varpath = Builtins.add(config, var) comment = Convert.to_string(SCR.Read(Builtins.add(varpath, "comment"))) if Builtins.regexpmatch( comment, Ops.add(Ops.add("^.*## Type:[ \t]*([", String.CLower), "]*).*$") ) comment = Builtins.regexpsub( comment, Ops.add(Ops.add("^.*## Type:[ \t]*([", String.CLower), "]*).*$"), "\\1" ) end val = Convert.to_string(SCR.Read(varpath)) Builtins.y2debug("%1[%2]=%3", var, comment, val) if !val.nil? if comment == "yesno" || val == "yes" || val == "no" Ops.set(ret, var, val == "yes") elsif comment == "integer" Ops.set(ret, var, Builtins.tointeger(val)) if val != "" else Ops.set(ret, var, val) end end end ret = {} if ret.nil? Builtins.y2debug("ret=%1", ret) deep_copy(ret) end |
#Write ⇒ Object
Update the SCR according to network settings
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'library/network/src/modules/NetworkConfig.rb', line 160 def Write Builtins.y2milestone("Writing configuration") if !Modified() Builtins.y2milestone("No changes to NetworkConfig -> nothing to write") return true end WriteConfig(path(".sysconfig.network.dhcp"), @DHCP) WriteConfig(path(".sysconfig.network.config"), @Config) true end |
#WriteConfig(config, data) ⇒ Object
Write sysconfig file
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'library/network/src/modules/NetworkConfig.rb', line 104 def WriteConfig(config, data) data = deep_copy(data) Builtins.y2debug("config=%1", config) Builtins.y2debug("data=%1", data) return false if config.nil? || data.nil? changed = false Builtins.maplist( Convert.convert(data, from: "map", to: "map <string, any>") ) do |var, val| oldval = Convert.to_string(SCR.Read(Builtins.add(config, var))) newval = if Ops.is_boolean?(val) Convert.to_boolean(val) ? "yes" : "no" else Builtins.sformat("%1", val) end if oldval.nil? || oldval != newval SCR.Write(Builtins.add(config, var), newval) changed = true end end SCR.Write(config, nil) if changed == true Builtins.y2debug("changed=%1", changed) true end |