[virt-tools-list] [PATCH 04/10] Created the new base config screen class for working with virtual networks.

Darryl L. Pierce dpierce at redhat.com
Wed Jul 13 19:06:34 UTC 2011


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

---
 src/virtManagerTui/networklistconfigscreen.py |   61 +++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 src/virtManagerTui/networklistconfigscreen.py

diff --git a/src/virtManagerTui/networklistconfigscreen.py b/src/virtManagerTui/networklistconfigscreen.py
new file mode 100644
index 0000000..4496dbe
--- /dev/null
+++ b/src/virtManagerTui/networklistconfigscreen.py
@@ -0,0 +1,61 @@
+# networklistconfigscreen.py - Copyright (C) 2011 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# 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 vmmconfigscreen import VmmTuiConfigScreen
+
+from halworker import HALWorker
+from libvirtworker import LibvirtWorker, VirtManagerConfig
+import traceback
+
+class NetworkListConfigScreen(VmmTuiConfigScreen):
+    '''Provides a base class for all config screens that require a network list.'''
+
+    def __init__(self, title):
+        VmmTuiConfigScreen.__init__(self, title)
+        self.__has_networks = None
+        self.__network_list = None
+
+    def get_network_list_page(self, screen, defined=True, started=True):
+        ignore = screen
+        uuids = self.get_libvirt().list_networks(defined, started)
+        result = None
+
+        if len(uuids) > 0:
+            self.__has_networks = True
+            self.__network_list = snack.Listbox(0)
+            for uuid in uuids:
+                network = self.get_libvirt().get_network(uuid)
+                self.__network_list.append(uuid, network.get_name())
+            result = self.__network_list
+        else:
+            self.__has_networks = False
+            result = snack.Label("There are no networks available.")
+        grid = snack.Grid(1, 1)
+        grid.setField(result, 0, 0)
+        return [snack.Label("Network List"),
+                grid]
+
+    def get_selected_network(self):
+        uuid = self.__network_list.current()
+        return self.get_libvirt().get_network(uuid)
+
+    def has_selectable_networks(self):
+        return self.__has_networks
+
-- 
1.7.6




More information about the virt-tools-list mailing list