Class: Yast::NetworkConfigClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetworkConfigClass
- Defined in:
- ../../src/modules/NetworkConfig.rb
Instance Method Summary (collapse)
-
- (Object) Export
Export data.
-
- (Object) Import(settings)
Import data.
- - (Object) main
-
- (Object) Modified
Data was modified?.
-
- (Object) Read
Read all network settings from the SCR.
-
- (Object) ReadConfig(config)
Read sysconfig file.
-
- (Object) Write
Update the SCR according to network settings.
-
- (Object) WriteConfig(config, data)
Write sysconfig file.
Instance Method Details
- (Object) Export
Export data
195 196 197 |
# File '../../src/modules/NetworkConfig.rb', line 195 def Export Builtins.eval({ "config" => @Config, "dhcp" => @DHCP }) end |
- (Object) Import(settings)
Import data
182 183 184 185 186 187 188 189 190 191 |
# File '../../src/modules/NetworkConfig.rb', line 182 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 |
- (Object) main
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File '../../src/modules/NetworkConfig.rb', line 38 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 |
- (Object) Modified
Data was modified?
143 144 145 146 147 |
# File '../../src/modules/NetworkConfig.rb', line 143 def Modified ret = @DHCP != @Orig_DHCP || @Config != @Orig_Config Builtins.y2debug("ret=%1", ret) ret end |
- (Object) Read
Read all network settings from the SCR
151 152 153 154 155 156 157 158 159 160 161 162 |
# File '../../src/modules/NetworkConfig.rb', line 151 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 |
- (Object) ReadConfig(config)
Read sysconfig file. Uses metadata to distinguish between booleans, integers, and strings
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 99 100 |
# File '../../src/modules/NetworkConfig.rb', line 65 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 |
- (Object) Write
Update the SCR according to network settings
166 167 168 169 170 171 172 173 174 175 176 177 |
# File '../../src/modules/NetworkConfig.rb', line 166 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 |
- (Object) WriteConfig(config, data)
Write sysconfig file
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 131 132 133 134 135 136 |
# File '../../src/modules/NetworkConfig.rb', line 106 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 vars = SCR.Dir(config) vars = [] if vars == 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) newval = Convert.to_boolean(val) ? "yes" : "no" else newval = 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 |