Class: Yast::NetworkServiceClass
- Inherits:
-
Module
- Object
- Module
- Yast::NetworkServiceClass
- Includes:
- Logger
- Defined in:
- library/network/src/modules/NetworkService.rb
Constant Summary collapse
- BACKENDS =
network backend identification to service name mapping
{ # <internal-id> <service name> netconfig: "network", network_manager: "NetworkManager", wicked: "wicked" }.freeze
- BACKEND_PKG_NAMES =
network backend identification to its rpm package name mapping
{ # <internal-id> <service name> netconfig: "sysconfig-network", network_manager: "NetworkManager", wicked: "wicked" }.freeze
- DEFAULT_BACKEND =
:wicked
Instance Attribute Summary collapse
-
#cached_name ⇒ Object
Replies with currently selected network service name.
-
#current_name ⇒ Object
return [String, nil] current network backend identification, nil is valid value for "no service selected / running".
Instance Method Summary collapse
-
#backend_available?(backend) ⇒ Boolean
(also: #is_backend_available)
Checks if given network backend is available in the system.
-
#backend_in_use ⇒ Symbol?
Determines which backend is in use based on the network service.
-
#ConfirmNetworkManager ⇒ Boolean
Opens up a continue/cancel confirmation popup in the case when NetworkManager is enabled.
-
#disable ⇒ Object
disables network service completely.
- #disabled? ⇒ Boolean (also: #is_disabled)
-
#EnableDisableNow(force: false) ⇒ Object
Helper to apply a change of the network service enabling the service selected and taking care of disabling the current one in case of modified.
-
#IsActive ⇒ Object
Reports if network service is active or not.
- #isNetworkRunning ⇒ Object
-
#isNetworkv4Running ⇒ Object
test for IPv4.
-
#isNetworkv6Running ⇒ Object
test for IPv6.
- #main ⇒ Object
-
#Modified ⇒ Object
Whether a network service change were requested.
- #netconfig? ⇒ Boolean (also: #is_netconfig)
-
#network_manager? ⇒ Boolean
(also: #is_network_manager)
Checks if configuration is managed by NetworkManager.
-
#Read ⇒ Object
Initialize module data.
-
#ReloadOrRestart ⇒ Object
Reload or restars the network service.
- #reset! ⇒ Object
-
#Restart ⇒ Object
Restarts the network service.
- #run_wicked(*params) ⇒ Object
-
#RunningNetworkPopup ⇒ Object
If there is network running, return true.
-
#RunSystemCtl(service, action, force: false) ⇒ Object
Helper to run systemctl actions.
-
#StartStop ⇒ Object
This is an old, confusing name for ReloadOrRestart() now.
-
#use(name) ⇒ Object
Choose the given backend as the one to be used.
- #use_netconfig ⇒ Object
- #use_network_manager ⇒ Object
- #use_wicked ⇒ Object
- #wicked? ⇒ Boolean (also: #is_wicked)
Instance Attribute Details
#cached_name ⇒ Object
Replies with currently selected network service name
Currently known backends:
- :network_manager - not supported by YaST
- :netconfig - supported
- :wicked - supported (via its backward compatibility to ifup)
402 403 404 405 |
# File 'library/network/src/modules/NetworkService.rb', line 402 def cached_name Read() @cached_name end |
#current_name ⇒ Object
return [String, nil] current network backend identification, nil is valid value for "no service selected / running"
49 50 51 |
# File 'library/network/src/modules/NetworkService.rb', line 49 def current_name @current_name end |
Instance Method Details
#backend_available?(backend) ⇒ Boolean Also known as: is_backend_available
Checks if given network backend is available in the system
126 127 128 |
# File 'library/network/src/modules/NetworkService.rb', line 126 def backend_available?(backend) Package.Installed(BACKEND_PKG_NAMES[backend], target: :system) end |
#backend_in_use ⇒ Symbol?
Determines which backend is in use based on the network service. In an (auto)installation it returns the default backend except if systemd is running (live) where the systemd service can be checked.
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'library/network/src/modules/NetworkService.rb', line 208 def backend_in_use backend = nil if Stage.initial && !Systemd.Running backend = DEFAULT_BACKEND log.info "Running in installer/AutoYaST, use default: #{backend}" else service = Yast2::Systemd::Service.find("network") backend = BACKENDS.invert[service.name] if service end backend end |
#ConfirmNetworkManager ⇒ Boolean
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.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'library/network/src/modules/NetworkService.rb', line 307 def ConfirmNetworkManager return true 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 cont end |
#disable ⇒ Object
disables network service completely
195 196 197 198 199 200 201 |
# File 'library/network/src/modules/NetworkService.rb', line 195 def disable @cached_name = nil stop_service(@current_name) disable_service(@current_name) Read() end |
#disabled? ⇒ Boolean Also known as: is_disabled
154 155 156 |
# File 'library/network/src/modules/NetworkService.rb', line 154 def disabled? cached_service?(nil) end |
#EnableDisableNow(force: false) ⇒ Object
Helper to apply a change of the network service enabling the service selected and taking care of disabling the current one in case of modified.
TODO: this method could take care of disabling all the services except the one selected in order to prevent that multiple backends are enabled at the same time.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'library/network/src/modules/NetworkService.rb', line 248 def EnableDisableNow(force: false) return unless force || Modified() if current_name && Modified() stop_service(current_name) disable_service(current_name) end enable_service(cached_name) if cached_name @initialized = false Read() nil end |
#IsActive ⇒ Object
Reports if network service is active or not. It does not report if network is connected.
267 268 269 |
# File 'library/network/src/modules/NetworkService.rb', line 267 def IsActive RunSystemCtl("network", "is-active") == 0 end |
#isNetworkRunning ⇒ Object
328 329 330 |
# File 'library/network/src/modules/NetworkService.rb', line 328 def isNetworkRunning isNetworkv4Running || isNetworkv6Running end |
#isNetworkv4Running ⇒ Object
test for IPv4
333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'library/network/src/modules/NetworkService.rb', line 333 def isNetworkv4Running net = SCR.Execute( path(".target.bash"), "/bin/ip addr | /usr/bin/grep -v '127.0.0\\|inet6' | /usr/bin/grep -c inet" ) if net == 0 Builtins.y2milestone("IPv4 network is running ...") true else Builtins.y2milestone("IPv4 network is not running ...") false end end |
#isNetworkv6Running ⇒ Object
test for IPv6
348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'library/network/src/modules/NetworkService.rb', line 348 def isNetworkv6Running net = SCR.Execute( path(".target.bash"), "/bin/ip addr | /usr/bin/grep -v 'inet6 ::1\\|inet6 fe80' | /usr/bin/grep -c inet6" ) if net == 0 Builtins.y2milestone("IPv6 network is running ...") true else Builtins.y2milestone("IPv6 network is not running ...") false end end |
#main ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'library/network/src/modules/NetworkService.rb', line 73 def main Yast.import "NetworkConfig" Yast.import "Popup" Yast.import "Mode" Yast.import "Stage" Yast.import "Package" Yast.import "Systemd" 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 |
#Modified ⇒ Object
Whether a network service change were requested
120 121 122 123 |
# File 'library/network/src/modules/NetworkService.rb', line 120 def Modified Read() @cached_name != @current_name end |
#netconfig? ⇒ Boolean Also known as: is_netconfig
142 143 144 |
# File 'library/network/src/modules/NetworkService.rb', line 142 def netconfig? cached_service?(:netconfig) end |
#network_manager? ⇒ Boolean Also known as: is_network_manager
Checks if configuration is managed by NetworkManager
136 137 138 |
# File 'library/network/src/modules/NetworkService.rb', line 136 def network_manager? cached_service?(:network_manager) end |
#Read ⇒ Object
Initialize module data
223 224 225 226 227 228 229 230 231 232 |
# File 'library/network/src/modules/NetworkService.rb', line 223 def Read return if @initialized @cached_name = @current_name = backend_in_use log.info "Current backend: #{@current_name}" @initialized = true nil end |
#ReloadOrRestart ⇒ Object
Reload or restars the network service.
272 273 274 275 276 277 278 279 280 |
# File 'library/network/src/modules/NetworkService.rb', line 272 def ReloadOrRestart if Stage.initial # 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 |
#reset! ⇒ Object
234 235 236 237 238 |
# File 'library/network/src/modules/NetworkService.rb', line 234 def reset! @initialized = false @current_name = nil @cached_name = nil end |
#Restart ⇒ Object
Restarts the network service
283 284 285 286 287 288 289 290 291 |
# File 'library/network/src/modules/NetworkService.rb', line 283 def Restart if Stage.initial wicked_restart else systemctl_restart end nil end |
#run_wicked(*params) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'library/network/src/modules/NetworkService.rb', line 108 def run_wicked(*params) cmd = "/usr/sbin/wicked #{params.map(&:shellescape).join(" ")}" ret = SCR.Execute( path(".target.bash"), cmd ) Builtins.y2milestone("run_wicked: #{cmd} -> #{ret}") end |
#RunningNetworkPopup ⇒ Object
If there is network running, return true. Otherwise show error popup depending on Stage and return false
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'library/network/src/modules/NetworkService.rb', line 366 def RunningNetworkPopup network_running = isNetworkRunning log.info "RunningNetworkPopup #{network_running}" return true if network_running error_text = if Stage.initial _( "No running network detected.\n" \ "Restart installation and configure network in Linuxrc\n" \ "or continue without network." ) else _( "No running network detected.\n" \ "Configure network with YaST or Network Manager plug-in\n" \ "and start this module again\n" \ "or continue without network." ) end ret = Popup.ContinueCancel(error_text) log.error "Network not runing!" ret end |
#RunSystemCtl(service, action, force: false) ⇒ Object
Helper to run systemctl actions
96 97 98 99 100 101 102 103 104 105 106 |
# File 'library/network/src/modules/NetworkService.rb', line 96 def RunSystemCtl(service, action, force: false) raise ArgumentError, "No network service defined." if service.nil? cmd = "/usr/bin/systemctl "\ "#{force ? "--force" : ""} " \ "#{action.shellescape} " \ "#{service.shellescape}.service" ret = SCR.Execute(path(".target.bash_output"), cmd, "TERM" => "raw") Builtins.y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret) Ops.get_integer(ret, "exit", -1) end |
#StartStop ⇒ Object
This is an old, confusing name for ReloadOrRestart() now
294 295 296 297 298 |
# File 'library/network/src/modules/NetworkService.rb', line 294 def StartStop ReloadOrRestart() nil end |
#use(name) ⇒ Object
Choose the given backend as the one to be used
164 165 166 167 168 169 170 171 |
# File 'library/network/src/modules/NetworkService.rb', line 164 def use(name) return false unless BACKENDS.key?(name) Read() @cached_name = name true end |
#use_netconfig ⇒ Object
180 181 182 183 184 185 |
# File 'library/network/src/modules/NetworkService.rb', line 180 def use_netconfig Read() @cached_name = :netconfig nil end |
#use_network_manager ⇒ Object
173 174 175 176 177 178 |
# File 'library/network/src/modules/NetworkService.rb', line 173 def use_network_manager Read() @cached_name = :network_manager nil end |
#use_wicked ⇒ Object
187 188 189 190 191 192 |
# File 'library/network/src/modules/NetworkService.rb', line 187 def use_wicked Read() @cached_name = :wicked nil end |
#wicked? ⇒ Boolean Also known as: is_wicked
148 149 150 |
# File 'library/network/src/modules/NetworkService.rb', line 148 def wicked? cached_service?(:wicked) end |