Sandro Bonazzola has uploaded a new change for review.

Change subject: ux: provide default gw for pingable address.
......................................................................

ux: provide default gw for pingable address.

Change-Id: Id73ecc9d929e0afe9c62773975c9564b35c38da7
Bug-Url: https://bugzilla.redhat.com/1044920
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M src/plugins/ovirt-hosted-engine-setup/network/gateway.py
1 file changed, 23 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/94/22594/1

diff --git a/src/plugins/ovirt-hosted-engine-setup/network/gateway.py 
b/src/plugins/ovirt-hosted-engine-setup/network/gateway.py
index c2e26df..565b8f1 100644
--- a/src/plugins/ovirt-hosted-engine-setup/network/gateway.py
+++ b/src/plugins/ovirt-hosted-engine-setup/network/gateway.py
@@ -24,6 +24,8 @@
 
 
 import gettext
+import socket
+import struct
 
 
 from otopi import util
@@ -41,6 +43,8 @@
     """
     gateway configuration plugin.
     """
+    ROUTE_DESTINATION = 1
+    ROUTE_GW = 2
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
@@ -61,6 +65,22 @@
         except RuntimeError:
             pingable = False
         return pingable
+
+    def _get_default_gw(self):
+        gateway = None
+        with open('/proc/net/route', 'r') as f:
+            lines = f.read().splitlines()
+            for line in lines:
+                data = line.split()
+                if data[self.ROUTE_DESTINATION] == '00000000':
+                    gateway = socket.inet_ntoa(
+                        struct.pack(
+                            'I',
+                            int(data[self.ROUTE_GW], 16)
+                        )
+                    )
+                    break
+        return gateway
 
     @plugin.event(
         stage=plugin.Stages.STAGE_INIT,
@@ -99,10 +119,12 @@
                 ] = self.dialog.queryString(
                     name='OVEHOSTED_GATEWAY',
                     note=_(
-                        'Please indicate a pingable gateway IP address: '
+                        'Please indicate a pingable gateway IP address '
+                        '[@DEFAULT@]: '
                     ),
                     prompt=True,
                     caseSensitive=True,
+                    default=self._get_default_gw(),
                 )
             valid = self._check_gw_pingable(
                 self.environment[


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id73ecc9d929e0afe9c62773975c9564b35c38da7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to