Bugzilla – Attachment 520659 Details for
Bug 798348
No network without networkmanager
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Forgot Password
[patch]
yast2: prototype patch to use network.service instead NETWORKMANAGER
yast2-2.23.18.diff (text/plain), 6.39 KB, created by
Marius Tomaschewski
on 2013-01-17 15:49:42 UTC
(
hide
)
Description:
yast2: prototype patch to use network.service instead NETWORKMANAGER
Filename:
MIME Type:
Creator:
Marius Tomaschewski
Created:
2013-01-17 15:49:42 UTC
Size:
6.39 KB
patch
obsolete
>--- library/network/src/NetworkService.ycp >+++ library/network/src/NetworkService.ycp 2013/01/17 15:32:31 >@@ -27,8 +27,21 @@ you may find current contact information > * > * $Id$ > * >- * This module used to switch between rcnetwork and rcnetworkmanager. >- * Now the master switch is /etc/sysconfig/network/config:NETWORKMANAGER >+ * This module used to switch between /etc/init.d/network providing >+ * LSB network.service and the NetworkManager.service (or another), >+ * which installs a network.service alias link. >+ * >+ * The service name installing the network.sevice is visible in the >+ * "Id" systemctl property: >+ * >+ * # systemctl --no-pager -p Id show network.service >+ * Id=network.service >+ * # systemctl --force enable NetworkManager.service >+ * # systemctl --no-pager -p Id show network.service >+ * Id=NetworkManager.service >+ * >+ * The network.service alias link obsoletes the old master switch in >+ * /etc/sysconfig/network/config:NETWORKMANAGER (until openSUSE-12.2). > */ > > { >@@ -50,20 +63,59 @@ global void Read (); > boolean initialized = false; > > /** >+ * current network service id name >+ */ >+string cur_service_id_name = ""; >+ >+/** >+ * the new network service id name >+ */ >+string new_service_id_name = ""; >+ >+/** >+ * Path to the systemctl command >+ */ >+string systemctl = "/bin/systemctl"; >+ >+/** >+ * Helper to run systemctl actions >+ */ >+integer RunSystemCtl (string service, string action) { >+ string cmd = sformat ("%1 %2 %3.service", systemctl, action, service); >+ map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, cmd, $[ "TERM" : "raw"]); >+ y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret); >+ return ret["exit"]:-1; >+} >+ >+/** >+ * Whether a network service change were requested >+ */ >+global boolean Modified () { >+ boolean ret = false; >+ Read(); >+ if (new_service_id_name != cur_service_id_name) >+ { >+ ret = true; >+ } >+ y2debug("NetworkService::Modified(%1, %2) => %3", >+ cur_service_id_name, new_service_id_name, ret); >+ return ret; >+} >+ >+/** > * Whether use NetworkManager or ifup > */ > global boolean IsManaged () { > Read (); >- return NetworkConfig::Config["NETWORKMANAGER"]:false; >- >+ return new_service_id_name != "network"; > } > > /** > * @param m whether networkmanager will be used > */ > global void SetManaged (boolean m) { >- NetworkConfig::Config["NETWORKMANAGER"] = m; >- initialized = true; >+ Read (); >+ new_service_id_name = m ? "NetworkManager" : "network"; > } > > /** >@@ -72,8 +124,10 @@ global void SetManaged (boolean m) { > global void Read () { > if (!initialized) > { >- NetworkConfig::Read (); >- boolean nm = NetworkConfig::Config["NETWORKMANAGER"]:false; >+ cur_service_id_name = Service::GetServiceId("network"); >+ new_service_id_name = cur_service_id_name; >+ >+ boolean nm = new_service_id_name != "network"; > y2milestone ("NetworkManager: %1", nm); > } > initialized = true; >@@ -98,25 +152,70 @@ boolean RunScript (string script, string > return SCR::Execute (.target.bash, cmd) == 0; > } > >+void EnableDisableNow() { >+ if (Modified()) { >+ /* Stop should be called before ... >+ RunSystemCtl(cur_service_id_name, "kill"); >+ */ >+ if (new_service_id_name == "network") { >+ RunSystemCtl(cur_service_id_name, "disable"); >+ } else { >+ RunSystemCtl(new_service_id_name, "--force enable"); >+ } >+ cur_service_id_name = Service::GetServiceId("network"); >+ new_service_id_name = cur_service_id_name; >+ } >+} >+ >+/** >+ * Reports if network _service_ is active or not. >+ * It does not report if network is connected. >+ */ >+global boolean isActive() >+{ >+ return RunSystemCtl ("network", "is-active") == 0; >+} >+ > /** >- * Starts and stops the appropriate services. >+ * This is an old, confusing name for ReloadOrRestart() now > */ > global void StartStop () { >- if (Service::Status ("network") == 0) >- { >- RunScript ("network", "reload"); >- } >- else >- { >+ ReloadOrRestart(); >+} >+ >+/** >+ * Reload or restars the network service. >+ */ >+global void ReloadOrRestart () { >+ if (isActive()) { >+ if (Modified()) { >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); >+ } else { >+ RunSystemCtl ("network", "reload-or-try-restart"); >+ } >+ } else { > // #148263 > // Because rcnetwork really handles two different things in one script > // (ifup and NM), it could happen that "start" would shut down an > // interface. Instead, it tells the user to use "restart". > // So we do it always, it does not hurt if the net was stopped. >- RunScript ("network", "restart"); >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); > } > } > >+/** >+ * Restarts the network service >+ */ >+global void Restart () { >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); >+} >+ > /* > * Variable remembers that the question has been asked during this run already. > * It avoids useless questions over and over again. >--- library/runlevel/src/Service.ycp >+++ library/runlevel/src/Service.ycp 2013/01/17 15:06:11 >@@ -123,6 +123,50 @@ define boolean checkExists (string name) > } > > /** >+ * Get complete systemd unit id >+ * @param name name or alias of the unit >+ * @return (resolved) unit Id >+ */ >+global string GetUnitId(string unit) >+{ >+ string cmd = sformat ("%1 --no-pager -p Id show %2", invoker, unit); >+ map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, >+ cmd, $[ "TERM" : "raw"]); >+ if (ret["exit"]:-1 != 0) { >+ y2error (_("Unable to query '%1' unit Id\nCommand returned: %2\n"), >+ unit, ret); >+ return nil; >+ } >+ >+ /* extract first line */ >+ integer end = findfirstof (ret["stdout"]:"", "\r\n"); >+ string out = substring(ret["stdout"]:"", 0, end != nil ? end : 0); >+ >+ /* extract key anv value */ >+ list tmp = splitstring (out, "="); >+ if (size(tmp) != 2 || (tmp[0]:"") != "Id" || (tmp[1]:"") == "") { >+ y2error (_("Unable to parse '%1' unit Id query output: '%2'\n"), >+ unit, out); >+ return nil; >+ } >+ >+ return tmp[1]:""; >+} >+ >+global string GetServiceId(string name) >+{ >+ string id = GetUnitId(sformat("%1.service", name)); >+ if (id == nil) >+ return nil; >+ >+ /* return without .service */ >+ integer pos = search(id, ".service"); >+ if (pos <= 0) >+ return nil; >+ return substring(id, 0, pos); >+} >+ >+/** > * Get service info without peeking if service runs. > * @param name name of the service > * @return Service information or empty map ($[])
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 798348
:
520129
|
520659
|
520661
|
520665
|
520666
|
521559
|
521560
|
528381