[virt-tools-list] [PATCH 3/4] IPv6 support v2: update the virt-manager-tui
Gene Czarcinski
gene at czarc.net
Fri Mar 29 18:38:30 UTC 2013
This patch updates the tui python to use ipaddr
from python-ipaddr rather than IPy.py. This patch
removes all IPy dependency.
This patch works under RELEASE-0.9.4-1 but tui is
broken under branch gtk3.2. Applying patch anyway
and then will worry about it working later.
Signed-off-by: Gene Czarcinski <gene at czarc.net>
---
virtManagerTui/addnetwork.py | 10 ++++-----
virtManagerTui/listnetworks.py | 15 +++++++++-----
virtManagerTui/networkconfig.py | 45 +++++++++++++++++++++++++----------------
3 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/virtManagerTui/addnetwork.py b/virtManagerTui/addnetwork.py
index c6b0bf0..3e4ff36 100644
--- a/virtManagerTui/addnetwork.py
+++ b/virtManagerTui/addnetwork.py
@@ -21,7 +21,7 @@ from snack import Entry
from snack import Label
from snack import RadioBar
-from IPy import IP
+import ipaddr
import logging
import re
@@ -91,8 +91,8 @@ class AddNetworkConfigScreen(VmmTuiConfigScreen):
elif page is DHCP_RANGE_PAGE:
try:
if len(self.__start_address.value()) > 0 and len(self.__end_address.value()) > 0:
- start = IP(self.__start_address.value(), )
- end = IP(self.__end_address.value())
+ start = ipaddr.IPNetwork(self.__start_address.value(), )
+ end = ipaddr.IPNetwork(self.__end_address.value())
if not self.__config.is_bad_address(start) and not self.__config.is_bad_address(end):
return True
else:
@@ -202,8 +202,8 @@ class AddNetworkConfigScreen(VmmTuiConfigScreen):
self.__end_address = Entry(15, self.__config.get_ipv4_end_address())
fields = []
fields.append(("Select the DHCP range", None))
- fields.append(("Start", self.__start_address))
- fields.append(("End", self.__end_address))
+ fields.append(("Start", self.__start_address.network))
+ fields.append(("End", self.__end_address.network))
return [Label("Selecting The DHCP Range"),
self.create_grid_from_fields(fields),
Label("TIP: Unless you wish to reserve some addresses to allow static network"),
diff --git a/virtManagerTui/listnetworks.py b/virtManagerTui/listnetworks.py
index 5590c0a..4c2f7a6 100644
--- a/virtManagerTui/listnetworks.py
+++ b/virtManagerTui/listnetworks.py
@@ -18,6 +18,7 @@
from snack import Label
from networklistconfigscreen import NetworkListConfigScreen
+import ipaddr
LIST_PAGE = 1
DETAILS_PAGE = 2
@@ -43,6 +44,11 @@ class ListNetworksConfigScreen(NetworkListConfigScreen):
network = self.get_selected_network()
fields = []
+ result = network.get_ipv4_network()
+ netaddr = result[0]
+ dhcp = result[1]
+ route = result[2]
+
fields.append(("Basic details", None))
fields.append(("Name", network.get_name()))
fields.append(("Device", network.get_bridge_device()))
@@ -51,12 +57,11 @@ class ListNetworksConfigScreen(NetworkListConfigScreen):
fields.append(("Autostart", "On Boot" if network.get_autostart() else "Never"))
fields.append(("IPv4 configuration", None))
- fields.append(("Network", network.get_ipv4_network().strNormal()))
+ fields.append(("Network", str(netaddr)))
- if network.get_ipv4_dhcp_range() is not None:
- (dhcp_start, dhcp_end) = network.get_ipv4_dhcp_range()
- dhcp_start = dhcp_start.strNormal()
- dhcp_end = dhcp_end.strNormal()
+ if dhcp is not None:
+ dhcp_start = str(dhcp[0])
+ dhcp_end = str(dhcp[1])
else:
dhcp_start = "Disabled"
dhcp_end = "Disabled"
diff --git a/virtManagerTui/networkconfig.py b/virtManagerTui/networkconfig.py
index 09f038a..3ece1cd 100644
--- a/virtManagerTui/networkconfig.py
+++ b/virtManagerTui/networkconfig.py
@@ -16,7 +16,7 @@
# MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html.
-from IPy import IP
+import ipaddr
class NetworkConfig:
def __init__(self):
@@ -35,37 +35,48 @@ class NetworkConfig:
return self.__name
def set_ipv4_address(self, address):
- self.__ipv4_address = IP(address)
- start = int(self.__ipv4_address.len() / 2)
- end = self.__ipv4_address.len() - 2
- self.__ipv4_start = str(self.__ipv4_address[start])
- self.__ipv4_end = str(self.__ipv4_address[end])
+ self.__ipv4_address = ipaddr.IPNetwork(address)
+ start = int(self.__ipv4_address.numhosts / 2)
+ end = self.__ipv4_address.numhosts - 2
+ self.__ipv4_start = self.__ipv4_address.network + start
+ self.__ipv4_end = self.__ipv4_address.network + end
def get_ipv4_address(self):
- return self.__ipv4_address.strNormal()
+ return self.__ipv4_address
def get_ipv4_address_raw(self):
return self.__ipv4_address
def get_ipv4_netmask(self):
- return self.__ipv4_address.netmask().strNormal()
+ return self.__ipv4_address.netmask
def get_ipv4_broadcast(self):
- return self.__ipv4_address.broadcast().strNormal()
+ return self.__ipv4_address.broadcast
def get_ipv4_gateway(self):
- return str(self.__ipv4_address[1])
+ return self.__ipv4_address.network + 1
def get_ipv4_max_addresses(self):
- return self.__ipv4_address.len()
+ return self.__ipv4_address.numhosts
def get_ipv4_network_type(self):
- return self.__ipv4_address.iptype()
-
- def is_public_ipv4_network(self):
- if self.__ipv4_address.iptype() is "PUBLIC":
- return True
- return False
+ if self.__ipv4_address.is_private:
+ return "PRIVATE"
+ if self.__ipv4_address.is_reserved:
+ return "RESERVED"
+ return "OTHER"
+
+#FIXME ??
+#def is_public_ipv4_network(self):
+# if self.__ipv4_address.is_private
+# return False
+# if self.__ipv4_address.is_loopback
+# return False
+# if self.__ipv4_address.is_multicast
+# return False
+# if self.__ipv4_address.is_reserved
+# return False
+# return True
def set_ipv4_start_address(self, address):
self.__ipv4_start = address
--
1.8.1.4
More information about the virt-tools-list
mailing list