Joey Boggs
2011-Aug-03 01:14 UTC
[Ovirt-devel] [PATCH] display ipv6 address in networking details page, also fix ipv6 netmask configurations
rhbz#698650
Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
scripts/network.py | 3 +-
scripts/ovirt-config-setup.py | 48 ++++++++++++++++++++++++++++++++++------
scripts/ovirtfunctions.py | 20 ++++++++++------
3 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/scripts/network.py b/scripts/network.py
index ccc4bd8..f51ee7c 100644
--- a/scripts/network.py
+++ b/scripts/network.py
@@ -85,9 +85,10 @@ class Network:
self.BR_CONFIG += "set %s/DHCPV6C yes\n" % BR_ROOT
elif OVIRT_VARS["OVIRT_IPV6"] == "static":
self.BR_CONFIG += "set %s/IPV6INIT yes\n" % BR_ROOT
- self.BR_CONFIG += "set %s/IPV6ADDR %s\n" % (BR_ROOT,
OVIRT_VARS["OVIRT_IPV6_ADDRESS"])
+ self.BR_CONFIG += "set %s/IPV6ADDR %s/%s\n" %
(BR_ROOT, OVIRT_VARS["OVIRT_IPV6_ADDRESS"],
OVIRT_VARS["OVIRT_IPV6_NETMASK"])
self.BR_CONFIG += "set %s/IPV6_AUTOCONF no\n" %
BR_ROOT
self.BR_CONFIG += "set %s/IPV6FORWARDING no\n" %
BR_ROOT
+ self.BR_CONFIG += "set %s/IPV6_DEFAULTGW %s\n" %
(BR_ROOT, OVIRT_VARS["OVIRT_IPV6_GATEWAY"])
else:
self.BR_CONFIG += "set %s/IPV6INIT no\n" % BR_ROOT
self.BR_CONFIG += "set %s/IPV6_AUTOCONF no\n" % BR_ROOT
diff --git a/scripts/ovirt-config-setup.py b/scripts/ovirt-config-setup.py
index 0de6c2e..8a81feb 100755
--- a/scripts/ovirt-config-setup.py
+++ b/scripts/ovirt-config-setup.py
@@ -399,12 +399,15 @@ class NodeConfigScreen():
def ipv6_netmask_callback(self):
warn = 0
if not self.ipv6_netdevmask.value() is None and not
self.ipv6_netdevmask.value() == "":
- if not is_valid_ipv6(self.ipv6_netdevmask.value()):
- warn = 1
+ try:
+ if not int(self.ipv6_netdevmask.value()) in range(1,128):
+ warn = 1
+ except:
+ warn = 1
if warn == 1:
self.screen.setColor("BUTTON", "black",
"red")
self.screen.setColor("ACTBUTTON", "blue",
"white")
- ButtonChoiceWindow(self.screen, "Network",
"Invalid IP Address", buttons = ['Ok'])
+ ButtonChoiceWindow(self.screen, "Network",
"Invalid IPv6 Netmask", buttons = ['Ok'])
self.ipv6_netdevmask.set("")
self.reset_screen_colors()
return
@@ -566,9 +569,9 @@ class NodeConfigScreen():
if not interface == "lo":
if has_ip_address(interface) or
get_ipv6_address(interface):
ipv4_address = get_ip_address(interface)
- if get_ipv6_address(interface):
- ipv6_address = get_ipv6_address(interface)
- else:
+ try:
+ ipv6_address, netmask =
get_ipv6_address(interface)
+ except:
ipv6_address = ""
self.network_status[interface] =
(ipv4_address,ipv6_address)
except:
@@ -577,7 +580,10 @@ class NodeConfigScreen():
for key in sorted(self.network_status.iterkeys()):
if key.startswith("br"):
parent_dev = key[+2:]
- del self.network_status[parent_dev]
+ try:
+ del self.network_status[parent_dev]
+ except:
+ pass
for key in sorted(self.network_status.iterkeys()):
ipv4_addr, ipv6_addr = self.network_status[key]
cmd =
"/files/etc/sysconfig/network-scripts/ifcfg-%s/BOOTPROTO" % str(key)
@@ -600,7 +606,7 @@ class NodeConfigScreen():
if ipv6_addr != "":
status_text += "%1s: %5s %14s \nIPv6:
%1s\n\n" %
(key.strip(),dev_bootproto.strip(),ipv4_addr.strip(),ipv6_addr.strip())
else:
- status_text += "%1s: %5s %14s \n\n" %
(key.strip(),dev_bootproto.strip(),ipv4_addr.strip(),ipv6_addr.strip())
+ status_text += "%1s: %5s %14s \n\n" %
(key.strip(),dev_bootproto.strip(),ipv4_addr.strip())
status_text.strip()
networking = TextboxReflowed(32, status_text, maxHeight=10)
networking.setText(status_text)
@@ -975,6 +981,32 @@ class NodeConfigScreen():
self.ipv6_netdevmask.setCallback(self.ipv6_netmask_callback)
self.ipv6_netdevgateway = Entry(39, "", scroll = 0)
self.ipv6_netdevgateway.setCallback(self.ipv6_gateway_callback)
+ if "OVIRT_IPV6_ADDRESS" in OVIRT_VARS:
+
self.ipv6_netdevip.set(OVIRT_VARS["OVIRT_IPV6_ADDRESS"])
+ else:
+ try:
+ current_ip, current_netmask =
get_ipv6_address(self.nic_lb.current())
+ except:
+ current_ip = ""
+ current_netmask = ""
+ if current_ip == "":
+ try:
+ current_ip, current_netmask =
get_ipv6_address("br" + self.nic_lb.current())
+ except:
+ pass
+ if current_ip != "":
+ self.ipv6_netdevip.set(current_ip)
+ if "OVIRT_IPV6_NETMASK" in OVIRT_VARS:
+
self.ipv6_netdevmask.set(OVIRT_VARS["OVIRT_IPV6_NETMASK"])
+ else:
+ if current_ip != "":
+ self.ipv6_netdevmask.set(current_netmask)
+ if "OVIRT_IPV6_GATEWAY" in OVIRT_VARS:
+
self.ipv6_netdevgateway.set(OVIRT_VARS["OVIRT_IPV6_GATEWAY"])
+ else:
+ current_gateway = get_ipv6_gateway(self.nic_lb.current())
+ if current_gateway == "":
+ current_gateway = get_gateway("br" +
self.nic_lb.current())
ipv6_grid = Grid (5,4)
ipv6_grid.setField(Label("IP Address: "), 0, 1, anchorLeft
= 1)
ipv6_grid.setField(Label("Netmask: "), 0, 2, anchorLeft =
1)
diff --git a/scripts/ovirtfunctions.py b/scripts/ovirtfunctions.py
index 271b16b..8c7bea5 100644
--- a/scripts/ovirtfunctions.py
+++ b/scripts/ovirtfunctions.py
@@ -854,18 +854,22 @@ def get_gateway(ifname):
return result
def get_ipv6_address(interface):
- inet6_lookup_cmd = 'ifconfig ' + interface + ' |grep inet6|grep
-v Global|awk {\'print $3\'}'
+ inet6_lookup_cmd = 'ifconfig ' + interface + ' |grep inet6|grep
Global|awk {\'print $3\'}'
inet6_lookup = subprocess.Popen(inet6_lookup_cmd, shell=True, stdout=PIPE,
stderr=STDOUT)
ipv6_addr = inet6_lookup.stdout.read()
-
- if "/" in ipv6_addr:
- while not ipv6_addr.endswith("/"):
- ipv6_addr = ipv6_addr[:-1]
- ipv6_addr = ipv6_addr.strip("/")
- return ipv6_addr
-
+ try:
+ ip, netmask = ipv6_addr.split("/")
+ return (ip,netmask)
+ except:
+ log("unable to determine ip/netmask from: " + ipv6_addr)
return False
+def get_ipv6_gateway(ifname):
+ cmd = "ip route list dev "+ ifname + " | awk '
/^default/ {print $3}'"
+ result = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+ result = result.stdout.read().strip()
+ return result
+
def has_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
--
1.7.5.4
Alan Pevec
2011-Aug-03 09:07 UTC
[Ovirt-devel] [PATCH] display ipv6 address in networking details page, also fix ipv6 netmask configurations
subject is too long - 1. line should be 50 chars or less, put detailed description in 3. and following lines http://spheredev.org/wiki/Git_for_the_lazy#Writing_good_commit_messages> - ? ? ? ? ? ? ? ?self.BR_CONFIG += "set %s/IPV6ADDR %s\n" % (BR_ROOT, OVIRT_VARS["OVIRT_IPV6_ADDRESS"]) > + ? ? ? ? ? ? ? ?self.BR_CONFIG += "set %s/IPV6ADDR %s/%s\n" % (BR_ROOT, OVIRT_VARS["OVIRT_IPV6_ADDRESS"], OVIRT_VARS["OVIRT_IPV6_NETMASK"])While at it, this whole section could be made more readable by using multi-line string: map=OVIRT_VARS.copy() map["BR_ROOT"]=BR_ROOT self.BR_CONFIG = """ set %(BR_ROOT)s/IPV6ADDR %(OVIRT_IPV6_ADDRESS)s/%(OVIRT_IPV6_NETMASK)s set %(BR_ROOT)s/IPV6_AUTOCONF no set %(BR_ROOT)s/IPV6FORWARDING no set %(BR_ROOT)s/IPV6_DEFAULTGW %(OVIRT_IPV6_GATEWAY)s """ % map> ? ? ? ? ? ? ? ? for key in sorted(self.network_status.iterkeys()): > ? ? ? ? ? ? ? ? ? ? if key.startswith("br"): > ? ? ? ? ? ? ? ? ? ? ? ? parent_dev = key[+2:] > - ? ? ? ? ? ? ? ? ? ? ? ?del self.network_status[parent_dev] > + ? ? ? ? ? ? ? ? ? ? ? ?try: > + ? ? ? ? ? ? ? ? ? ? ? ? ? ?del self.network_status[parent_dev] > + ? ? ? ? ? ? ? ? ? ? ? ?except: > + ? ? ? ? ? ? ? ? ? ? ? ? ? ?passWhy not network_status.pop(parent_dev) ?> ?def get_ipv6_address(interface): > - ? ?inet6_lookup_cmd = 'ifconfig ' + interface + ' |grep inet6|grep -v Global|awk {\'print $3\'}' > + ? ?inet6_lookup_cmd = 'ifconfig ' + interface + ' |grep inet6|grep Global|awk {\'print $3\'}'Better use ip command, ifconfig is obsolete: inet6_lookup_cmd = "ip addr show dev %s | awk '$1==\"inet6\" && $4==\"global\" { print $2 }'" % interface BTW, a general note, when parsing command output you must ensure locale but in case of ovirt/rhevh that's fixed in the image. Best would be to replace it with python-only code, there's http://pypi.python.org/pypi/netifaces - it's in F16 so we could have a look at it. Alan
Seemingly Similar Threads
- [PATCH] display ipv6 address in networking details page, also fix ipv6 netmask configurations.
- [PATCH] fix ipv6 switch to disabled
- [PATCH] map nics-> bridges correctly in network pages, when cancelling nic configuration return to network page
- [PATCH] fix ipv4 static/dhcp/disabled networking changes
- [PATCH node] add network.py script