Change in vdsm[master]: netinfo: Determine bootproto without ifcfg files

osvoboda at redhat.com osvoboda at redhat.com
Thu Jan 9 14:47:08 UTC 2014


Ondřej Svoboda has uploaded a new change for review.

Change subject: netinfo: Determine bootproto without ifcfg files
......................................................................

netinfo: Determine bootproto without ifcfg files

This is an initial take with comments on IPv4/6 and completeness.

Change-Id: I5fbc48a0adf5f40120a72ec2c4cc2fc80b7226b8
Bug-Url: https://bugzilla.redhat.com/??????
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M lib/vdsm/netinfo.py
1 file changed, 47 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/98/23098/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 6d0c5ff..2ea3236 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -40,7 +40,7 @@
 from .ipwrapper import routeShowAllDefaultGateways
 from . import libvirtconnection
 from .ipwrapper import linkShowDev
-from .utils import anyFnmatch
+from .utils import anyFnmatch, pgrep, getCmdArgs
 from .netconfpersistence import RunningConfig
 
 
@@ -447,6 +447,44 @@
         raise NotImplementedError
 
 
+def getBootProtocolDynamic(iface):
+    logging.info('Looking for DHCP client for %s.', iface)
+
+    for pid in pgrep('dhclient'):
+        if iface in getCmdArgs(pid):
+            logging.info('Found dhclient running for %s.', iface)
+            return 'dhcp'
+
+    for pid in pgrep('dhcpcd'):
+        if iface in getCmdArgs(pid):
+            logging.info('Found dhcpcd running for %s.', iface)
+            return 'dhcp'
+
+    # To do/consider (optimization and edge (?) cases):
+    #
+    # There are a bunch of "network managers" around but all of them
+    #   hopefully only use either dhclient or dhcpcd
+    #   => not worth asking them or is NetworkManager so widespread?
+    #
+    # Walk the process list only once for all interfaces
+    #
+    # Treat IPv4 and IPv6 independently
+    #
+    # Fall back to getBootProtocol?
+    #
+    # Try harder (how much?) in cases a device name is not explicitly specified
+    #   on command line / or DHCP client already gone but its lease still valid
+    # This possibly includes: defaulting to all interfaces; dhcpcd's globbing;
+    #   explicit/implicit configuration files (of different nature, indeed)
+    #
+    # A last resort: lease files created by daemons _somewhere_
+
+    logging.info('No DHCP client found for %s. '
+                 'Please file a bug if it was configured using DHCP.', iface)
+
+    return 'none'
+
+
 def permAddr():
     paddr = {}
     for b in bondings():
@@ -480,6 +518,7 @@
                      'gateway': getgateway(gateways, iface),
                      'ipv6addrs': ipv6addrs,
                      'ipv6gateway': ipv6routes.get(iface, '::'),
+                     'bootproto4': getBootProtocolDynamic(iface),
                      'mtu': str(getMtu(iface))})
         if qosInbound:
             data['qosInbound'] = qosInbound
@@ -527,6 +566,7 @@
     return {'addr': ipv4addr,
             'cfg': getIfaceCfg(dev),
             'ipv6addrs': ipv6addrs,
+            'bootproto4': getBootProtocolDynamic(dev),
             'mtu': str(getMtu(dev)),
             'netmask': ipv4netmask}
 
@@ -538,6 +578,12 @@
     ipv6routes = getIPv6Routes()
     paddr = permAddr()
 
+    # To do:
+    #
+    # Determine if interfaces were configured using DHCP in a single loop
+    #   over processes run from here / a run over interfaces when resorting
+    #   to lease files
+
     for net, netAttr in networks().iteritems():
         try:
             d['networks'][net] = _getNetInfo(netAttr.get('iface', net),


-- 
To view, visit http://gerrit.ovirt.org/23098
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5fbc48a0adf5f40120a72ec2c4cc2fc80b7226b8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list