[node-patches] Change in ovirt-node[master]: network: Fetch default gateway from NM if possible

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Feb 6 09:06:14 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: network: Fetch default gateway from NM if possible
......................................................................

network: Fetch default gateway from NM if possible

Change-Id: I9f529d8d9def57aabdaa32d48eb0b76a361a9a4f
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/utils/network.py
1 file changed, 22 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/88/11788/1

diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index 10b2516..fdadf54 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -405,6 +405,11 @@
     def default(self):
         """Return the default gw of the system
         """
+        if _nm_client:
+            return self._default_nm()
+        return self._default_fallback()
+
+    def _default_fallback(self):
         # Fallback
         gw = None
         cmd = "ip route list"
@@ -414,8 +419,25 @@
                 gw = token[2]
         return gw
 
+    def _default_nm(self):
+        active_connections = _nm_client.get_active_connections()
+        default_connection = [c for c in active_connections
+                              if c.get_default()][0]
+        ip4_config = default_connection.get_ip4_config()
+        ip4_gateway = ip4_config.get_addresses()[0].get_gateway()
+        return _nm_address_to_str(socket.AF_INET, ip4_gateway)
+
 
 def _nm_address_to_str(family, ipaddr):
+    """Convert the binary representation of NMs IPaddresse into its textual
+    representation
+
+    Args:
+        family: socket.AF_INET or socket.F_INET6
+        ipaddr: The binary (long) representation of the IP
+    Returns:
+        Textual representation of the binary IP Addr
+    """
     if family == socket.AF_INET:
         packed = struct.pack('L', ipaddr)
     elif family == socket.AF_INET6:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f529d8d9def57aabdaa32d48eb0b76a361a9a4f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list