[virt-tools-list] [PATCH 4/4] Added pause domain to VMM TUI.
Darryl L. Pierce
dpierce at redhat.com
Mon May 23 21:47:23 UTC 2011
---
src/virtManagerTui/nodemenu.py | 12 ++++--
src/virtManagerTui/pausedomain.py | 69 ++++++++++++++++++++++++++++++++++++
src/virtManagerTui/removedomain.py | 6 ++--
src/virtManagerTui/setup.py | 1 +
4 files changed, 81 insertions(+), 7 deletions(-)
create mode 100644 src/virtManagerTui/pausedomain.py
diff --git a/src/virtManagerTui/nodemenu.py b/src/virtManagerTui/nodemenu.py
index f213e09..8314123 100644
--- a/src/virtManagerTui/nodemenu.py
+++ b/src/virtManagerTui/nodemenu.py
@@ -24,6 +24,7 @@ from configscreen import ConfigScreen
from adddomain import AddDomain
from startdomain import StartDomain
from stopdomain import StopDomain
+from pausedomain import PauseDomain
from removedomain import RemoveDomain
from listdomains import ListDomains
from migratedomain import MigrateDomain
@@ -35,10 +36,11 @@ import logging
ADD_DOMAIN = 1
START_DOMAIN = 2
STOP_DOMAIN = 3
-REMOVE_DOMAIN = 4
-LIST_DOMAINS = 5
-MIGRATE_DOMAIN = 6
-CREATE_USER = 7
+PAUSE_DOMAIN = 4
+REMOVE_DOMAIN = 5
+LIST_DOMAINS = 6
+MIGRATE_DOMAIN = 7
+CREATE_USER = 8
class NodeMenuScreen(MenuScreen):
def __init__(self):
@@ -48,6 +50,7 @@ class NodeMenuScreen(MenuScreen):
return (("Add A Virtual Machine", ADD_DOMAIN),
("Start A Virtual Machine", START_DOMAIN),
("Stop A Virtual Machine", STOP_DOMAIN),
+ ("Pause A Virtual Machine", PAUSE_DOMAIN),
("Remove A Virtual Machine", REMOVE_DOMAIN),
("List All Virtual Machines", LIST_DOMAINS),
("Migrate Virtual Machine", MIGRATE_DOMAIN),
@@ -57,6 +60,7 @@ class NodeMenuScreen(MenuScreen):
if item is ADD_DOMAIN: AddDomain()
elif item is START_DOMAIN: StartDomain()
elif item is STOP_DOMAIN: StopDomain()
+ elif item is PAUSE_DOMAIN: PauseDomain()
elif item is REMOVE_DOMAIN: RemoveDomain()
elif item is LIST_DOMAINS: ListDomains()
elif item is MIGRATE_DOMAIN: MigrateDomain()
diff --git a/src/virtManagerTui/pausedomain.py b/src/virtManagerTui/pausedomain.py
new file mode 100644
index 0000000..007339f
--- /dev/null
+++ b/src/virtManagerTui/pausedomain.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# pausedomain.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.
+
+from snack import *
+from configscreen import *
+
+class PauseDomainConfigScreen(DomainListConfigScreen):
+ LIST_PAGE = 1
+ STOP_PAGE = 2
+
+ def __init__(self):
+ DomainListConfigScreen.__init__(self, "Pause A Domain")
+
+ def get_elements_for_page(self, screen, page):
+ if page is self.LIST_PAGE:
+ return self.get_domain_list_page(screen, defined = False)
+ elif page is self.STOP_PAGE:
+ return self.get_stop_page(screen)
+
+ def page_has_next(self, page):
+ if page is self.LIST_PAGE: return self.has_selectable_domains()
+ return False
+
+ def page_has_back(self, page):
+ if page is self.STOP_PAGE: return True
+ return False
+
+ def validate_input(self, page, errors):
+ if page is self.LIST_PAGE:
+ if self.get_selected_domain() is not None:
+ domain = self.get_selected_domain()
+ try:
+ if domain.is_pauseable():
+ domain.suspend()
+ return True
+ else:
+ errors.append("%s is not in a pauseable state: state=%s" % (domain.get_name(), domain.run_status()))
+ except Exception, error:
+ errors.append("There was an error pausing the domain: %s" % domain)
+ errors.append(str(error))
+ else:
+ errors.append("You must first select a domain to stop.")
+ return False
+
+ def get_stop_page(self, screen):
+ grid = Grid(1, 1)
+ grid.setField(Label("%s was successfully paused." % self.get_selected_domain().get_name()), 0, 0)
+ return [grid]
+
+def PauseDomain():
+ screen = PauseDomainConfigScreen()
+ screen.start()
diff --git a/src/virtManagerTui/removedomain.py b/src/virtManagerTui/removedomain.py
index 28fe8e9..e4b6417 100644
--- a/src/virtManagerTui/removedomain.py
+++ b/src/virtManagerTui/removedomain.py
@@ -58,7 +58,7 @@ class RemoveDomainConfigScreen(DomainListConfigScreen):
if self.__confirm_remove.value():
domain = self.get_selected_domain()
try:
- self.get_libvirt().undefine_domain(domain)
+ domain.delete()
return True
except Exception, error:
errors.append("Failed to remove %s." % domain)
@@ -68,14 +68,14 @@ class RemoveDomainConfigScreen(DomainListConfigScreen):
return False
def get_confirm_page(self, screen):
- self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 0)
+ self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain().get_name(), 0)
grid = Grid(1, 1)
grid.setField(self.__confirm_remove, 0, 0)
return [grid]
def get_remove_page(self, screen):
grid = Grid(1, 1)
- grid.setField(Label("%s has been removed." % self.get_selected_domain()), 0, 0)
+ grid.setField(Label("%s has been removed." % self.get_selected_domain().get_name()), 0, 0)
return [grid]
def RemoveDomain():
diff --git a/src/virtManagerTui/setup.py b/src/virtManagerTui/setup.py
index fd01c07..5c2d418 100644
--- a/src/virtManagerTui/setup.py
+++ b/src/virtManagerTui/setup.py
@@ -28,6 +28,7 @@ setup(name = "nodeadmin",
'addvm = nodeadmin.adddomain:AddDomain',
'startvm = nodeadmin.startdomain:StartDomain',
'stopvm = nodeadmin.stopdomain:StopDomain',
+ 'pausevm = nodeadmin.pausdomain:PauseDomain',
'rmvm = nodeadmin.removedomain:RemoveDomain',
'migratevm = nodeadmin.migratedomain:MigradeDomain',
'createuser = nodeadmin.createuser:CreateUser',
--
1.7.4.4
More information about the virt-tools-list
mailing list