Joey Boggs
2011-Aug-03 18:38 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 | 46 +++++++++++++++++++++++++++++++++------- scripts/ovirtfunctions.py | 22 +++++++++++-------- 3 files changed, 53 insertions(+), 18 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..8c6c8af 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,8 @@ class NodeConfigScreen(): for key in sorted(self.network_status.iterkeys()): if key.startswith("br"): parent_dev = key[+2:] - del self.network_status[parent_dev] + if self.network_status.has_key(parent_dev): + del self.network_status[parent_dev] 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 +604,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 +979,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..6ef27d3 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 = "ip addr show dev %s | awk '$1==\"inet6\" && $4==\"global\" { print $2 }'" % interface 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 - + ipv6_addr = inet6_lookup.stdout.read().strip() + 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
Maybe Matching 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