[virt-tools-list] [PATCH 2/9] Updated definenet.py to look more like VMM GUI.

Darryl L. Pierce dpierce at redhat.com
Fri Jul 15 14:02:19 UTC 2011


From: "Darryl L. Pierce" <dpierce at redhat.com>

---
 src/virtManagerTui/definenet.py |  152 +++++++++++++++++---------------------
 1 files changed, 68 insertions(+), 84 deletions(-)

diff --git a/src/virtManagerTui/definenet.py b/src/virtManagerTui/definenet.py
index 12dbaad..890874c 100644
--- a/src/virtManagerTui/definenet.py
+++ b/src/virtManagerTui/definenet.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.
 
-import snack
+from snack import Checkbox, Entry, Grid, Label
 from IPy import IP
 import logging
 import re
@@ -159,75 +159,75 @@ class DefineNetworkConfigScreen(VmmTuiConfigScreen):
 
     def get_network_name_page(self, screen):
         ignore = screen
-        self.__name = snack.Entry(50, self.__config.get_name())
-        grid = snack.Grid(2, 1)
-        grid.setField(snack.Label("Network Name:"), 0, 0)
+        self.__name = Entry(50, self.__config.get_name())
+        grid = Grid(2, 1)
+        grid.setField(Label("Network Name:"), 0, 0)
         grid.setField(self.__name, 1, 0)
-        return [snack.Label("Please choose a name for your virtual network"),
+        return [Label("Please choose a name for your virtual network"),
                 grid]
 
     def get_ipv4_address_page(self, screen):
         ignore = screen
-        self.__ipv4_address = snack.Entry(18, self.__config.get_ipv4_address())
-        grid = snack.Grid(2, 1)
-        grid.setField(snack.Label("Network:"), 0, 0, anchorRight=1)
-        grid.setField(self.__ipv4_address, 1, 0, anchorLeft=1)
-        return [snack.Label("You will need to choose an IPv4 address space for the virtual network:"),
+        self.__ipv4_address = Entry(18, self.__config.get_ipv4_address())
+        grid = Grid(2, 1)
+        grid.setField(Label("Network:"), 0, 0, anchorRight = 1)
+        grid.setField(self.__ipv4_address, 1, 0, anchorLeft = 1)
+        return [Label("You will need to choose an IPv4 address space for the virtual network:"),
                 grid,
-                snack.Label("HINT: The network should be chosen from"),
-                snack.Label("one of the IPv4 private address ranges;"),
-                snack.Label("e.g., 10.0.0.0/8, 172.168.0.0/12, 192.168.0.0/16")]
+                Label("HINT: The network should be chosen from"),
+                Label("one of the IPv4 private address ranges;"),
+                Label("e.g., 10.0.0.0/8, 172.168.0.0/12, 192.168.0.0/16")]
 
     def get_network_details_page(self, screen):
         ignore = screen
-        grid = snack.Grid(2, 6)
-        grid.setField(snack.Label("Network:"), 0, 0, anchorRight=1)
-        grid.setField(snack.Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft=1)
-        grid.setField(snack.Label("Netmask:"), 0, 1, anchorRight=1)
-        grid.setField(snack.Label(self.__config.get_ipv4_netmask()), 1, 1, anchorLeft=1)
-        grid.setField(snack.Label("Broadcast:"), 0, 2, anchorRight=1)
-        grid.setField(snack.Label(self.__config.get_ipv4_broadcast()), 1, 2, anchorLeft=1)
-        grid.setField(snack.Label("Gateway:"), 0, 3, anchorRight=1)
-        grid.setField(snack.Label(self.__config.get_ipv4_gateway()), 1, 3, anchorLeft=1)
-        grid.setField(snack.Label("Size:"), 0, 4, anchorRight=1)
-        grid.setField(snack.Label("%d addresses" % self.__config.get_ipv4_max_addresses()), 1, 4, anchorLeft=1)
-        grid.setField(snack.Label("Type:"), 0, 5, anchorRight=1)
-        grid.setField(snack.Label(self.__config.get_ipv4_network_type()), 1, 5, anchorLeft=1)
-        return [snack.Label("Network Details"),
+        grid = Grid(2, 6)
+        grid.setField(Label("Network:"), 0, 0, anchorRight = 1)
+        grid.setField(Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft = 1)
+        grid.setField(Label("Netmask:"), 0, 1, anchorRight = 1)
+        grid.setField(Label(self.__config.get_ipv4_netmask()), 1, 1, anchorLeft = 1)
+        grid.setField(Label("Broadcast:"), 0, 2, anchorRight = 1)
+        grid.setField(Label(self.__config.get_ipv4_broadcast()), 1, 2, anchorLeft = 1)
+        grid.setField(Label("Gateway:"), 0, 3, anchorRight = 1)
+        grid.setField(Label(self.__config.get_ipv4_gateway()), 1, 3, anchorLeft = 1)
+        grid.setField(Label("Size:"), 0, 4, anchorRight = 1)
+        grid.setField(Label("%d addresses" % self.__config.get_ipv4_max_addresses()), 1, 4, anchorLeft = 1)
+        grid.setField(Label("Type:"), 0, 5, anchorRight = 1)
+        grid.setField(Label(self.__config.get_ipv4_network_type()), 1, 5, anchorLeft = 1)
+        return [Label("Network Details"),
                 grid]
 
     def get_public_network_alert_page(self, screen):
         ignore = screen
-        grid = snack.Grid(1, 2)
-        grid.setField(snack.Label("The network should normally use a private IPv4 address."), 0, 0, anchorLeft=1)
-        grid.setField(snack.Label("Use this non-private address anyway?"), 0, 1, anchorLeft=1)
-        return [snack.Label("Check Network Address"),
+        grid = Grid(1, 2)
+        grid.setField(Label("The network should normally use a private IPv4 address."), 0, 0, anchorLeft = 1)
+        grid.setField(Label("Use this non-private address anyway?"), 0, 1, anchorLeft = 1)
+        return [Label("Check Network Address"),
                 grid]
 
     def get_dhcp_range_page(self, screen):
         ignore = screen
-        self.__start_address = snack.Entry(15, self.__config.get_ipv4_start_address())
-        self.__end_address   = snack.Entry(15, self.__config.get_ipv4_end_address())
-        grid = snack.Grid(2, 2)
-        grid.setField(snack.Label("Start:"), 0, 0, anchorRight=1)
-        grid.setField(self.__start_address, 1, 0, anchorLeft=1)
-        grid.setField(snack.Label("End:"), 0, 1, anchorRight=1)
-        grid.setField(self.__end_address, 1, 1, anchorLeft=1)
-        return [snack.Label("Selecting The DHCP Range"),
+        self.__start_address = Entry(15, self.__config.get_ipv4_start_address())
+        self.__end_address   = Entry(15, self.__config.get_ipv4_end_address())
+        grid = Grid(2, 2)
+        grid.setField(Label("Start:"), 0, 0, anchorRight = 1)
+        grid.setField(self.__start_address, 1, 0, anchorLeft = 1)
+        grid.setField(Label("End:"), 0, 1, anchorRight = 1)
+        grid.setField(self.__end_address, 1, 1, anchorLeft = 1)
+        return [Label("Selecting The DHCP Range"),
                 grid,
-                snack.Label("TIP: Unless you wish to reserve some addresses to allow static network"),
-                snack.Label("configuration in virtual machines, these paraemters can be left with"),
-                snack.Label("their default values.")]
+                Label("TIP: Unless you wish to reserve some addresses to allow static network"),
+                Label("configuration in virtual machines, these paraemters can be left with"),
+                Label("their default values.")]
 
     def get_network_type_page(self, screen):
         ignore = screen
-        self.__isolated_network = snack.Checkbox("Isolated virtual network",
+        self.__isolated_network = Checkbox("Isolated virtual network",
                                            self.__config.is_isolated_network())
-        grid = snack.Grid(1, 3)
-        grid.setField(snack.Label("Please indicate whether this virtual network should be"), 0, 0, anchorLeft=1)
-        grid.setField(snack.Label("connected to the physical network."), 0, 1, anchorLeft=1)
+        grid = Grid(1, 3)
+        grid.setField(Label("Please indicate whether this virtual network should be"), 0, 0, anchorLeft = 1)
+        grid.setField(Label("connected to the physical network."), 0, 1, anchorLeft = 1)
         grid.setField(self.__isolated_network, 0, 2)
-        return [snack.Label("Connecting To Physical Network"),
+        return [Label("Connecting To Physical Network"),
                 grid]
 
     def get_select_physical_network_page(self, screen):
@@ -236,49 +236,33 @@ class DefineNetworkConfigScreen(VmmTuiConfigScreen):
         devices.append(["NAT to any physical device", "", self.__config.get_physical_device() == ""])
         for device in self.get_hal().list_network_devices():
             devices.append(["NAT to physical device %s" % device, device, self.__config.get_physical_device() == device])
-        self.__physical_devices = snack.RadioBar(screen, (devices))
-        grid = snack.Grid(1, 2)
-        grid.setField(snack.Label("Forward to physical network:"), 0, 0)
+        self.__physical_devices = RadioBar(screen, (devices))
+        grid = Grid(1, 2)
+        grid.setField(Label("Forward to physical network:"), 0, 0)
         grid.setField(self.__physical_devices, 0, 1)
-        return [snack.Label("Connecting To Physical Network"),
+        return [Label("Connecting To Physical Network"),
                 grid]
 
     def get_summary_page(self, screen):
         ignore = screen
-        grid1 = snack.Grid(2, 1)
-        grid1.setField(snack.Label("Network name:"), 0, 0, anchorRight=1)
-        grid1.setField(snack.Label(self.__config.get_name()), 1, 0, anchorLeft=1)
+        fields = []
+        fields.append(("Summary", None))
+        fields.append(("Network name", self.__config.get_name()))
+        fields.append(("IPv4 network", None))
+        fields.append(("Network", self.__config.get_ipv4_address()))
+        fields.append(("Gateway", self.__config.get_ipv4_gateway()))
+        fields.append(("Netmask", self.__config.get_ipv4_netmask()))
+        fields.append(("DHCP", None))
+        fields.append(("Start address", self.__config.get_ipv4_start_address()))
+        fields.append(("End address", self.__config.get_ipv4_end_address()))
+        fields.append(("Forwarding", None))
+        forwarding = "Isolated virtual network"
+        if not self.__config.is_isolated_network():
+            forwarding = "NAT to %s" % self.__config.get_physical_device_text()
+        fields.append(("Connectivity", forwarding))
 
-        grid2 = snack.Grid(2, 3)
-        grid2.setField(snack.Label("Network:"), 0, 0, anchorRight=1)
-        grid2.setField(snack.Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft=1)
-        grid2.setField(snack.Label("Gateway:"), 0, 1, anchorRight=1)
-        grid2.setField(snack.Label(self.__config.get_ipv4_gateway()), 1, 1, anchorLeft=1)
-        grid2.setField(snack.Label("Netmask:"), 0, 2, anchorRight=1)
-        grid2.setField(snack.Label(self.__config.get_ipv4_netmask()), 1, 2, anchorLeft=1)
-
-        grid3 = snack.Grid(2, 2)
-        grid3.setField(snack.Label("Start address:"), 0, 0, anchorRight=1)
-        grid3.setField(snack.Label(self.__config.get_ipv4_start_address()), 1, 0, anchorLeft=1)
-        grid3.setField(snack.Label("End address:"), 0, 1, anchorRight=1)
-        grid3.setField(snack.Label(self.__config.get_ipv4_end_address()), 1, 1, anchorLeft=1)
-
-        grid4 = snack.Grid(2, 1)
-        grid4.setField(snack.Label("Connectivity:"), 0, 0, anchorRight=1)
-        if self.__config.is_isolated_network():
-            grid4.setField(snack.Label("Isolated virtual network"), 1, 0, anchorLeft=1)
-        else:
-            grid4.setField(snack.Label("NAT to %s" % self.__config.get_physical_device_text()), 1, 0, anchorLeft=1)
-
-        return [snack.Label("Ready To Create Network"),
-                snack.Label("Summary"),
-                grid1,
-                snack.Label("IPv4 Network"),
-                grid2,
-                snack.Label("DHCP"),
-                grid3,
-                snack.Label("Forwarding"),
-                grid4]
+        return [Label("Ready To Create Network"),
+                self.create_grid_from_fields(fields)]
 
 def DefineNetwork():
     screen = DefineNetworkConfigScreen()
-- 
1.7.6




More information about the virt-tools-list mailing list