Class: Yast::NetworkServiceClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetworkServiceClass
- Defined in:
- ../../src/modules/NetworkService.rb
Constant Summary
- BACKENDS =
network backend identification to service name mapping
{ # <internal-id> <service name> :netconfig => "network", :network_manager => "NetworkManager", :wicked => "wicked" }
- BACKEND_PKG_NAMES =
network backend identification to its rpm package name mapping
{ # <internal-id> <service name> :netconfig => "sysconfig-network", :network_manager => "NetworkManager", :wicked => "wicked" }
- SYSTEMCTL =
"/bin/systemctl"
- WICKED =
"/usr/sbin/wicked"
Instance Method Summary (collapse)
-
- (Boolean) backend_available?(backend)
(also: #is_backend_available)
Checks if given network backend is available in the system.
-
- (Boolean) ConfirmNetworkManager
Opens up a continue/cancel confirmation popup in the case when NetworkManager is enabled.
-
- (Object) EnableDisableNow
Helper to apply a change of the network service.
-
- (Object) IsActive
Reports if network service is active or not.
-
- (Object) isNetworkRunning
test for IPv4.
-
- (Object) isNetworkv6Running
test for IPv6.
- - (Object) main
-
- (Object) Modified
Whether a network service change were requested.
- - (Boolean) netconfig? (also: #is_netconfig)
-
- (Boolean) network_manager?
(also: #is_network_manager)
Checks if configuration is managed by NetworkManager.
-
- (Object) Read
Initialize module data.
-
- (Object) ReloadOrRestart
Reload or restars the network service.
-
- (Object) Restart
Restarts the network service.
- - (Object) run_wicked(*params)
-
- (Object) RunningNetworkPopup
If there is network running, return true.
-
- (Object) RunScript(script, action)
Run /etc/init.d script with specified action.
-
- (Object) RunSystemCtl(service, action)
Helper to run systemctl actions.
-
- (Object) StartStop
This is an old, confusing name for ReloadOrRestart() now.
- - (Object) use_netconfig
- - (Object) use_network_manager
- - (Object) use_wicked
- - (Boolean) wicked? (also: #is_wicked)
Instance Method Details
- (Boolean) backend_available?(backend) Also known as: is_backend_available
Checks if given network backend is available in the system
122 123 124 |
# File '../../src/modules/NetworkService.rb', line 122 def backend_available?(backend) PackageSystem.Installed( BACKEND_PKG_NAMES[backend]) end |
- (Boolean) ConfirmNetworkManager
Opens up a continue/cancel confirmation popup in the case when NetworkManager is enabled. User is informed that continuing the configuration may produce undefined results. If NetworkManager is not used, silently returns true.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File '../../src/modules/NetworkService.rb', line 276 def ConfirmNetworkManager if !@already_asked_for_NetworkManager && network_manager? # TRANSLATORS: pop-up question when reading the service configuration cont = Popup.ContinueCancel( _( "Your network interfaces are currently controlled by NetworkManager\n" + "but the service to configure might not work well with it.\n" + "\n" + "Really continue?" ) ) Builtins.y2milestone( "Network is controlled by NetworkManager, user decided %1...", cont ? "to continue" : "not to continue" ) @already_asked_for_NetworkManager = true return cont else return true end end |
- (Object) EnableDisableNow
Helper to apply a change of the network service
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File '../../src/modules/NetworkService.rb', line 205 def EnableDisableNow if Modified() # Stop should be called before, but when the service # were not correctly started until now, stop may have # no effect. # So let's kill all processes in the network service # cgroup to make sure e.g. dhcp clients are stopped. @initialized = false RunSystemCtl( BACKENDS[ @current_name], "kill") case @cached_name when :network_manager, :wicked RunSystemCtl( BACKENDS[ @cached_name], "--force enable") when :netconfig RunSystemCtl( BACKENDS[ @current_name], "disable") # Workaround for bug #61055: Builtins.y2milestone("Enabling service %1", "network") cmd = "cd /; /sbin/insserv -d /etc/init.d/network" SCR.Execute(path(".target.bash"), cmd) end Read() end nil end |
- (Object) IsActive
Reports if network service is active or not. It does not report if network is connected.
236 237 238 |
# File '../../src/modules/NetworkService.rb', line 236 def IsActive RunSystemCtl("network", "is-active") == 0 end |
- (Object) isNetworkRunning
test for IPv4
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File '../../src/modules/NetworkService.rb', line 301 def isNetworkRunning net = Convert.to_integer( SCR.Execute( path(".target.bash"), "ip addr|grep -v '127.0.0\\|inet6'|grep -c inet" ) ) if net == 0 Builtins.y2milestone("Network is running ...") return true else Builtins.y2milestone("Network is not running ...") return false end end |
- (Object) isNetworkv6Running
test for IPv6
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File '../../src/modules/NetworkService.rb', line 317 def isNetworkv6Running net = Convert.to_integer( SCR.Execute( path(".target.bash"), "ip addr|grep -v 'inet6 ::1\\|inet6 fe80'|grep -c inet6" ) ) if net == 0 Builtins.y2milestone("Network is running ...") return true else Builtins.y2milestone("Network is not running ...") return false end end |
- (Object) main
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File '../../src/modules/NetworkService.rb', line 74 def main Yast.import "Service" Yast.import "NetworkConfig" Yast.import "Popup" Yast.import "Mode" Yast.import "PackageSystem" textdomain "base" # if false, read needs to do work @initialized = false # Variable remembers that the question has been asked during this run already. # It avoids useless questions over and over again. @already_asked_for_NetworkManager = false end |
- (Object) Modified
Whether a network service change were requested
116 117 118 119 |
# File '../../src/modules/NetworkService.rb', line 116 def Modified Read() @cached_name != @current_name end |
- (Boolean) netconfig? Also known as: is_netconfig
138 139 140 |
# File '../../src/modules/NetworkService.rb', line 138 def netconfig? cached_name == :netconfig end |
- (Boolean) network_manager? Also known as: is_network_manager
Checks if configuration is managed by NetworkManager
132 133 134 |
# File '../../src/modules/NetworkService.rb', line 132 def network_manager? cached_name == :network_manager end |
- (Object) Read
Initialize module data
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File '../../src/modules/NetworkService.rb', line 172 def Read if !@initialized case Service.GetServiceId("network") when "network" @current_name = :netconfig when "NetworkManager" @current_name = :network_manager when "wicked" @current_name = :wicked end @cached_name = @current_name Builtins.y2milestone("Current backend: #{@current_name}") end @initialized = true nil end |
- (Object) ReloadOrRestart
Reload or restars the network service.
241 242 243 244 245 246 247 248 249 |
# File '../../src/modules/NetworkService.rb', line 241 def ReloadOrRestart if Mode.installation # inst-sys is not running systemd nor sysV init, so systemctl call # is not available and service has to be restarted directly wicked_restart else systemctl_reload_restart end end |
- (Object) Restart
Restarts the network service
252 253 254 255 256 257 258 259 260 |
# File '../../src/modules/NetworkService.rb', line 252 def Restart if Mode.installation wicked_restart else systemctl_restart end nil end |
- (Object) run_wicked(*params)
104 105 106 107 108 109 110 111 112 |
# File '../../src/modules/NetworkService.rb', line 104 def run_wicked(*params) cmd = "#{WICKED} #{params.join(" ")}" ret = SCR.Execute( path(".target.bash"), cmd ) Builtins.y2milestone("run_wicked: #{cmd} -> #{ret}") end |
- (Object) RunningNetworkPopup
If there is network running, return true. Otherwise show error popup depending on Mode and return false
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File '../../src/modules/NetworkService.rb', line 336 def RunningNetworkPopup Builtins.y2internal("RunningNetworkPopup %1", isNetworkRunning) if isNetworkRunning return true else error_text = Builtins.sformat( "%1\n%2 %3", _("No running network detected."), Mode.installation ? _("Restart installation and configure network in Linuxrc") : _( "Configure network with YaST or Network Manager plug-in\nand start this module again" ), _("or continue without network.") ) Popup.ContinueCancel(error_text) Builtins.y2error("Network not runing!") return false end end |
- (Object) RunScript(script, action)
Run /etc/init.d script with specified action
196 197 198 199 200 201 202 |
# File '../../src/modules/NetworkService.rb', line 196 def RunScript(script, action) return true if script == "" Builtins.y2milestone("rc%1 %2", script, action) # Workaround for bug #61055: cmd = Builtins.sformat("cd /; /etc/init.d/%1 %2", script, action) SCR.Execute(path(".target.bash"), cmd) == 0 end |
- (Object) RunSystemCtl(service, action)
Helper to run systemctl actions
93 94 95 96 97 98 99 100 101 102 |
# File '../../src/modules/NetworkService.rb', line 93 def RunSystemCtl(service, action) cmd = Builtins.sformat("%1 %2 %3.service", SYSTEMCTL, action, service) ret = Convert.convert( SCR.Execute(path(".target.bash_output"), cmd, { "TERM" => "raw" }), :from => "any", :to => "map <string, any>" ) Builtins.y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret) Ops.get_integer(ret, "exit", -1) end |
- (Object) StartStop
This is an old, confusing name for ReloadOrRestart() now
263 264 265 266 267 |
# File '../../src/modules/NetworkService.rb', line 263 def StartStop ReloadOrRestart() nil end |
- (Object) use_netconfig
157 158 159 160 161 162 |
# File '../../src/modules/NetworkService.rb', line 157 def use_netconfig Read() @cached_name = :netconfig nil end |
- (Object) use_network_manager
150 151 152 153 154 155 |
# File '../../src/modules/NetworkService.rb', line 150 def use_network_manager Read() @cached_name = :network_manager nil end |
- (Object) use_wicked
164 165 166 167 168 169 |
# File '../../src/modules/NetworkService.rb', line 164 def use_wicked Read() @cached_name = :wicked nil end |
- (Boolean) wicked? Also known as: is_wicked
144 145 146 |
# File '../../src/modules/NetworkService.rb', line 144 def wicked? cached_name == :wicked end |