[PATCH 07/17] Replace getActiveNetDevs() using new nm module
Radek Vykydal
rvykydal at redhat.com
Fri Feb 8 14:04:23 UTC 2013
---
pyanaconda/kickstart.py | 2 +-
pyanaconda/network.py | 36 +++---------------------------------
pyanaconda/ui/gui/spokes/network.py | 5 +++--
3 files changed, 7 insertions(+), 36 deletions(-)
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 3b8f924..9864a8e 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -542,7 +542,7 @@ class Iscsi(commands.iscsi.F17_Iscsi):
tg = commands.iscsi.F17_Iscsi.parse(self, args)
if tg.iface:
- active_ifaces = network.getActiveNetDevs()
+ active_ifaces = nm.nm_activated_devices()
if tg.iface not in active_ifaces:
raise KickstartValueError, formatErrorMsg(self.lineno, msg="network interface %s required by iscsi %s target is not up" % (tg.iface, tg.target))
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 6498039..1d779ba 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -271,7 +271,7 @@ def sanityCheckHostname(hostname):
# Return a list of IP addresses for all active devices.
def getIPs():
ips = []
- for devname in getActiveNetDevs():
+ for devname in nm.nm_activated_devices():
try:
ips += (getIPAddresses(devname, version=4) +
getIPAddresses(devname, version=6))
@@ -317,7 +317,7 @@ def getHostname():
hn = None
# First address (we prefer ipv4) of last device (as it used to be) wins
- for dev in getActiveNetDevs():
+ for dev in nm.nm_activated_devices():
addrs = (getIPAddresses(dev, version=4) +
getIPAddresses(dev, version=6))
for ipaddr in addrs:
@@ -355,36 +355,6 @@ def hasActiveNetDev():
except:
return flags.testing
-# Return a list of device names (e.g., eth0) for all active devices.
-# Returning a list here even though we will almost always have one
-# device. NM uses lists throughout its D-Bus communication, so trying
-# to follow suit here. Also, if this uses a list now, we can think
-# about multihomed hosts during installation later.
-def getActiveNetDevs():
- active_devs = set()
-
- bus = dbus.SystemBus()
- nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH)
- nm_props_iface = dbus.Interface(nm, DBUS_PROPS_IFACE)
-
- active_connections = nm_props_iface.Get(NM_MANAGER_IFACE, "ActiveConnections")
-
- for connection in active_connections:
- active_connection = bus.get_object(NM_SERVICE, connection)
- active_connection_props_iface = dbus.Interface(active_connection, DBUS_PROPS_IFACE)
- devices = active_connection_props_iface.Get(NM_ACTIVE_CONNECTION_IFACE, 'Devices')
-
- for device_path in devices:
- device = bus.get_object(NM_SERVICE, device_path)
- device_props_iface = dbus.Interface(device, DBUS_PROPS_IFACE)
-
- interface_name = device_props_iface.Get(NM_DEVICE_IFACE, 'Interface')
- active_devs.add(interface_name)
-
- ret = list(active_devs)
- ret.sort()
- return ret
-
def logIfcfgFile(path, message=""):
content = ""
if os.access(path, os.R_OK):
@@ -985,7 +955,7 @@ def get_device_name(devspec):
elif hasActiveNetDev():
# device activated in stage 1 by network kickstart command
msg = "first active device"
- devname = getActiveNetDevs()[0]
+ devname = nm.nm_activated_devices()[0]
else:
msg = "first device found"
devname = min(devices)
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 8d3ac0d..2c3ca5c 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -42,7 +42,8 @@ from pyanaconda.ui.gui.categories.software import SoftwareCategory
from pyanaconda.ui.gui.hubs.summary import SummaryHub
from pyanaconda.ui.gui.utils import gtk_call_once
-from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, getActiveNetDevs, logIfcfgFiles, update_hostname_data, sanityCheckHostname, getHostname, DEFAULT_HOSTNAME
+from pyanaconda.network import NetworkDevice, netscriptsDir, kickstartNetworkData, logIfcfgFiles, update_hostname_data, sanityCheckHostname, getHostname, DEFAULT_HOSTNAME
+from pyanaconda.nm import nm_activated_devices
from gi.repository import GLib, GObject, Pango, Gio, NetworkManager, NMClient
import dbus
@@ -1173,7 +1174,7 @@ def getKSNetworkData(device):
log.debug("getKSNetworkData %s: %s" % (ifcfg_suffix, e))
return None
retval = kickstartNetworkData(ifcfg=device_cfg)
- if device.get_iface() in getActiveNetDevs():
+ if device.get_iface() in nm_activated_devices():
retval.activate = True
return retval
--
1.7.11.7
More information about the anaconda-patches
mailing list