Darryl L. Pierce
2009-Oct-21 19:48 UTC
[Ovirt-devel] [PATCH node] Renamed files and menu items for node administration:
define domain -> add virtual machine (addvm) undefine domain -> remove virtual machine (rmvm) create domain -> start virtual machine (startvm) destroy domain -> stop virtual machine (stopvm) list domains -> list virtual machiens (listvms) Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- Makefile.am | 8 +- nodeadmin/adddomain.py | 470 +++++++++++++++++++++++++++++++++++++++++++ nodeadmin/createdomain.py | 65 ------ nodeadmin/definedomain.py | 470 ------------------------------------------- nodeadmin/destroydomain.py | 66 ------ nodeadmin/listdomains.py | 4 +- nodeadmin/nodemenu.py | 42 ++-- nodeadmin/removedomain.py | 83 ++++++++ nodeadmin/setup.py.in | 10 +- nodeadmin/startdomain.py | 65 ++++++ nodeadmin/stopdomain.py | 66 ++++++ nodeadmin/undefinedomain.py | 83 -------- ovirt-node.spec.in | 18 +- 13 files changed, 725 insertions(+), 725 deletions(-) create mode 100755 nodeadmin/adddomain.py delete mode 100755 nodeadmin/createdomain.py delete mode 100755 nodeadmin/definedomain.py delete mode 100755 nodeadmin/destroydomain.py create mode 100755 nodeadmin/removedomain.py create mode 100755 nodeadmin/startdomain.py create mode 100755 nodeadmin/stopdomain.py delete mode 100755 nodeadmin/undefinedomain.py diff --git a/Makefile.am b/Makefile.am index abb7c33..3ce24c1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,10 +27,10 @@ EXTRA_DIST = \ images/grub-splash.xpm.gz \ images/syslinux-vesa-splash.jpg \ nodeadmin/__init__.py \ + nodeadmin/adddomain.py \ nodeadmin/configscreen.py \ nodeadmin/createnetwork.py \ nodeadmin/createuser.py \ - nodeadmin/destroydomain.py \ nodeadmin/destroynetwork.py \ nodeadmin/halworker.py \ nodeadmin/libvirtworker.py \ @@ -39,10 +39,10 @@ EXTRA_DIST = \ nodeadmin/menuscreen.py \ nodeadmin/netmenu.py \ nodeadmin/nodemenu.py \ - nodeadmin/undefinedomain.py \ + nodeadmin/removedomain.py \ nodeadmin/undefinenetwork.py \ - nodeadmin/createdomain.py \ - nodeadmin/definedomain.py \ + nodeadmin/startdomain.py \ + nodeadmin/stopdomain.py \ nodeadmin/definenet.py \ nodeadmin/domainconfig.py \ nodeadmin/networkconfig.py \ diff --git a/nodeadmin/adddomain.py b/nodeadmin/adddomain.py new file mode 100755 index 0000000..70a2011 --- /dev/null +++ b/nodeadmin/adddomain.py @@ -0,0 +1,470 @@ +#!/usr/bin/env python +# +# adddomain.py - Copyright (C) 2009 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 * +import os +from domainconfig import DomainConfig +from configscreen import ConfigScreen +import urlgrabber.progress as progress +import utils +import logging + +from virtinst import * + +VM_DETAILS_PAGE = 1 +LOCAL_INSTALL_PAGE = 2 +SELECT_CDROM_PAGE = 3 +SELECT_ISO_PAGE = 4 +NETWORK_INSTALL_PAGE = 10 +OS_TYPE_PAGE = 11 +OS_VARIANT_PAGE = 12 +RAM_CPU_PAGE = 13 +ENABLE_STORAGE_PAGE = 14 +LOCAL_STORAGE_PAGE = 15 +MANAGED_STORAGE_PAGE = 16 +BRIDGE_PAGE = 17 +VIRT_DETAILS_PAGE = 18 +CONFIRM_PAGE = 19 + +LOCATION="location" +KICKSTART="kickstart" +KERNELOPTS="kernel.options" +OS_TYPE="os.type" +OS_VARIANT="os.variant" +MEMORY="memory" +CPUS="cpus" + +class DummyMeter(progress.BaseMeter): + def _do_start(self, now = None): + logging.info("Starting...") + + def _do_end(self, amount_read, now = None): + logging.info("Ending: read=%d" % amount_read) + + def _do_update(self, amount_read, now = None): + logging.info("Update: read=%d" % amount_read) + +class DomainConfigScreen(ConfigScreen): + def __init__(self): + ConfigScreen.__init__(self, "Create A New Virtual Machine") + self.__config = DomainConfig() + self.__config.set_architecture(self.get_libvirt().get_default_architecture()) + self.__config.set_virt_type(self.get_libvirt().get_default_virt_type()) + + def get_elements_for_page(self, screen, page): + if page == VM_DETAILS_PAGE: return self.get_vm_details_page(screen) + elif page == LOCAL_INSTALL_PAGE: return self.get_local_install_page(screen) + elif page == SELECT_CDROM_PAGE: return self.get_select_cdrom_page(screen) + elif page == SELECT_ISO_PAGE: return self.get_select_iso_page(screen) + elif page == NETWORK_INSTALL_PAGE: return self.get_network_install_page(screen) + elif page == OS_TYPE_PAGE: return self.get_os_type_page(screen) + elif page == OS_VARIANT_PAGE: return self.get_os_variant_page(screen) + elif page == RAM_CPU_PAGE: return self.get_ram_and_cpu_page(screen) + elif page == ENABLE_STORAGE_PAGE: return self.get_enable_storage_page(screen) + elif page == LOCAL_STORAGE_PAGE: return self.get_local_storage_page(screen) + elif page == MANAGED_STORAGE_PAGE: return self.get_managed_storage_page(screen) + elif page == BRIDGE_PAGE: return self.get_bridge_page(screen) + elif page == VIRT_DETAILS_PAGE: return self.get_virt_details_page(screen) + elif page == CONFIRM_PAGE: return self.get_confirm_page(screen) + return [] + + def validate_input(self, page, errors): + if page == VM_DETAILS_PAGE: + if len(self.__guest_name.value()) > 0: + if self.get_libvirt().domain_exists(self.__guest_name.value()): + errors.append("Guest name '%s' is already in use." % self.__guest_name.value()) + else: + return True + else: + errors.append("Guest name must be a string between 0 and 50 characters.") + elif page == LOCAL_INSTALL_PAGE: + if self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM: + return True + elif self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_ISO: + return True + elif page == SELECT_CDROM_PAGE: + if self.__install_media.getSelection() != None: + if len(self.get_hal().list_installable_volumes()) == 0: + errors.append("No installable media is available.") + else: + return True + else: + errors.append("You must select an install media.") + elif page == SELECT_ISO_PAGE: + if len(self.__iso_path.value()) > 0: + if os.path.exists(self.__iso_path.value()): + if os.path.isfile(self.__iso_path.value()): + return True + else: + errors.append("%s is not a file." % self.__iso_path.value()) + else: + errors.append("No such install media exists:") + errors.append(self.__iso_path.value()) + else: + errors.append("An install media selection is required.") + elif page == NETWORK_INSTALL_PAGE: + if len(self.__install_url.value()) > 0: + return True + else: + errors.append("An install tree is required.") + elif page == OS_TYPE_PAGE: return True + elif page == OS_VARIANT_PAGE: return True + elif page == RAM_CPU_PAGE: + if (len(self.__memory.value()) > 0 and len(self.__cpus.value()) > 0) \ + and (int(self.__memory.value()) > 0 and int(self.__cpus.value()) > 0): + return True + else: + if len(self.__memory.value()) == 0: + errors.append("A value must be entered for memory.") + elif int(self.__memory.value()) <= 0: + errors.append("A positive integer value must be entered for memory.") + if len(self.__cpus.value()) == 0: + errors.append("A value must be entered for CPUs.") + elif int(self.__cpus.value()) <= 0: + errors.append("A positive integer value must be entered for memory.") + elif page == ENABLE_STORAGE_PAGE: return True + elif page == LOCAL_STORAGE_PAGE: + if len(self.__storage_size.value()) > 0: + if float(self.__storage_size.value()) > 0: + return True + else: + errors.append("A positive value must be entered for the storage size.") + else: + errors.append("A value must be entered for the storage size.") + elif page == MANAGED_STORAGE_PAGE: + if self.__existing_storage.getSelection() is not None: + return True + else: + errors.append("Please select a storage volume.") + elif page == BRIDGE_PAGE: + if self.__network_bridges.getSelection() != None: + if len(self.__mac_address.value()) > 0: + # TODO: regex check the format + return True + else: + errors.append("MAC address must be supplied.") + else: + errors.append("A network bridge must be selected.") + elif page == VIRT_DETAILS_PAGE: + if self.__virt_types.getSelection() != None and self.__architectures.getSelection() != None: + return True + if self.__virt_types.getSelection() is None: + errors.append("Please select a virtualization type.") + if self.__architectures.getSelection() is None: + errors.append("Please selection an architecture.") + elif page == CONFIRM_PAGE: return True + return False + + def process_input(self, page): + if page == VM_DETAILS_PAGE: + self.__config.set_guest_name(self.__guest_name.value()) + self.__config.set_install_type(self.__install_type.getSelection()) + elif page == LOCAL_INSTALL_PAGE: + self.__config.set_use_cdrom_source(self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM) + elif page == SELECT_CDROM_PAGE: + self.__config.set_install_media(self.__install_media.getSelection()) + elif page == SELECT_ISO_PAGE: + self.__config.set_iso_path(self.__iso_path.value()) + elif page == NETWORK_INSTALL_PAGE: + self.__config.set_install_url(self.__install_url.value()) + self.__config.set_kickstart_url(self.__kickstart_url.value()) + self.__config.set_kernel_options(self.__kernel_options.value()) + elif page == OS_TYPE_PAGE: + self.__config.set_os_type(self.__os_types.getSelection()) + elif page == OS_VARIANT_PAGE: + self.__config.set_os_variant(self.__os_variants.getSelection()) + elif page == RAM_CPU_PAGE: + self.__config.set_memory(int(self.__memory.value())) + self.__config.set_cpus(int(self.__cpus.value())) + elif page == ENABLE_STORAGE_PAGE: + self.__config.set_enable_storage(self.__enable_storage.value()) + if self.__storage_type.getSelection() == DomainConfig.NEW_STORAGE: + self.__config.set_use_local_storage(True) + elif self.__storage_type.getSelection() == DomainConfig.EXISTING_STORAGE: + self.__config.set_use_local_storage(False) + elif page == LOCAL_STORAGE_PAGE: + self.__config.set_storage_size(float(self.__storage_size.value())) + self.__config.set_allocate_storage(self.__allocate_storage.value()) + elif page == MANAGED_STORAGE_PAGE: + self.__config.set_use_local_storage(False) + self.__config.set_existing_storage(self.__existing_storage.getSelection()) + self.__config.set_storage_size(self.get_libvirt().get_storage_size(self.__existing_storage.getSelection())) + elif page == BRIDGE_PAGE: + self.__config.set_network_bridge(self.__network_bridges.getSelection()) + elif page == VIRT_DETAILS_PAGE: + self.__config.set_virt_type(self.__virt_types.getSelection()) + self.__config.set_architecture(self.__architectures.getSelection()) + elif page == CONFIRM_PAGE: + self.get_libvirt().define_domain(self.__config, DummyMeter()) + self.set_finished() + + def get_back_page(self, page): + result = page + if page == OS_TYPE_PAGE: + install_type = self.__config.get_install_type() + if install_type == DomainConfig.LOCAL_INSTALL: + if self.__config.get_use_cdrom_source(): + result = SELECT_CDROM_PAGE + else: + result = SELECT_ISO_PAGE + elif install_type == DomainConfig.NETWORK_INSTALL: + result = NETWORK_INSTALL_PAGE + elif install_type == DomainConfig.PXE_INSTALL: + result = VM_DETAILS_PAGE + elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: + result = ENABLE_STORAGE_PAGE + elif page == NETWORK_INSTALL_PAGE: + result = VM_DETAILS_PAGE + elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: + result = LOCAL_INSTALL_PAGE + elif page == BRIDGE_PAGE: + if self.__config.get_use_local_storage(): + result = LOCAL_STORAGE_PAGE + else: + result = MANAGED_STORAGE_PAGE + else: + if page > 1: result = page - 1 + return result + + def get_next_page(self, page): + result = page + if page == VM_DETAILS_PAGE: + install_type = self.__config.get_install_type() + if install_type == DomainConfig.LOCAL_INSTALL: + result = LOCAL_INSTALL_PAGE + elif install_type == DomainConfig.NETWORK_INSTALL: + result = NETWORK_INSTALL_PAGE + elif install_type == DomainConfig.PXE_INSTALL: + result = OS_TYPE_PAGE + elif page == LOCAL_INSTALL_PAGE: + if self.__config.get_use_cdrom_source(): + result = SELECT_CDROM_PAGE + else: + result = SELECT_ISO_PAGE + elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: + result = OS_TYPE_PAGE + elif page == NETWORK_INSTALL_PAGE: + result = OS_TYPE_PAGE + elif page == ENABLE_STORAGE_PAGE: + result = BRIDGE_PAGE + if self.__config.get_enable_storage(): + if self.__config.get_use_local_storage(): + result = LOCAL_STORAGE_PAGE + else: + result = MANAGED_STORAGE_PAGE + elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: + result = BRIDGE_PAGE + else: + result = page + 1 + return result + + def page_has_finish(self, page): + if page == CONFIRM_PAGE: return True + return False + + def page_has_next(self, page): + if page < CONFIRM_PAGE: + return True + + def get_vm_details_page(self, screen): + self.__guest_name = Entry(50, self.__config.get_guest_name()) + self.__install_type = RadioBar(screen, (("Local install media (ISO image or CDROM)", + DomainConfig.LOCAL_INSTALL, + self.__config.is_install_type(DomainConfig.LOCAL_INSTALL)), + ("Network Install (HTTP, FTP, or NFS)", + DomainConfig.NETWORK_INSTALL, + self.__config.is_install_type(DomainConfig.NETWORK_INSTALL)), + ("Network Boot (PXE)", + DomainConfig.PXE_INSTALL, + self.__config.is_install_type(DomainConfig.PXE_INSTALL)))) + grid = Grid(2,3) + grid.setField(Label("Name:"), 0, 0, anchorRight = 1) + grid.setField(self.__guest_name, 1, 0, anchorLeft = 1) + grid.setField(Label("Choose how you would like to install the operating system"), 1, 1, + anchorLeft = 1, anchorTop = 1) + grid.setField(self.__install_type, 1, 2, anchorLeft = 1) + return [Label("Enter your machine details"), + grid] + + def get_local_install_page(self, screen): + self.__install_source = RadioBar(screen, (("Use CDROM or DVD", + DomainConfig.INSTALL_SOURCE_CDROM, + self.__config.get_use_cdrom_source()), + ("Use ISO image", + DomainConfig.INSTALL_SOURCE_ISO, + self.__config.get_use_cdrom_source() is False))) + grid = Grid(1,1) + grid.setField(self.__install_source, 0, 0, anchorLeft = 1) + return [Label("Locate your install media"), + grid] + + def get_select_cdrom_page(self, screen): + drives = [] + media = self.get_hal().list_installable_volumes() + for drive in media.keys(): + drives.append([media[drive], drive, self.__config.is_install_media(drive)]) + self.__install_media = RadioBar(screen, (drives)) + grid = Grid(1, 1) + grid.setField(self.__install_media, 0, 0) + return [Label("Select the install media"), + grid] + + def get_select_iso_page(self, screen): + self.__iso_path = Entry(50, self.__config.get_iso_path()) + grid = Grid(1, 2) + grid.setField(Label("Enter ISO path:"), 0, 0, anchorLeft = 1) + grid.setField(self.__iso_path, 0, 1, anchorLeft = 1) + return [Label("Enter the full path to an install ISO"), + grid] + + def get_network_install_page(self, screen): + self.__install_url = Entry(50, self.__config.get_install_url()) + self.__kickstart_url = Entry(50, self.__config.get_kickstart_url()) + self.__kernel_options = Entry(50, self.__config.get_kernel_options()) + grid = Grid(2,3) + grid.setField(Label("URL:"), 0, 0, anchorRight = 1) + grid.setField(self.__install_url, 1, 0, anchorLeft = 1) + grid.setField(Label("Kickstart URL:"), 0, 1, anchorRight = 1) + grid.setField(self.__kickstart_url, 1, 1, anchorLeft = 1) + grid.setField(Label("Kernel Options:"), 0, 2, anchorRight = 1) + grid.setField(self.__kernel_options, 1, 2, anchorLeft = 1) + return [Label("Provide the operating system URL"), + grid] + + def get_os_type_page(self, screen): + types = [] + for type in Guest.list_os_types(): + types.append([Guest.get_os_type_label(type), type, self.__config.is_os_type(type)]) + self.__os_types = RadioBar(screen, types) + grid = Grid(1, 1) + grid.setField(self.__os_types, 0, 0, anchorLeft = 1) + return [Label("Choose the operating system type"), + grid] + + def get_os_variant_page(self, screen): + variants = [] + type = self.__config.get_os_type() + for variant in Guest.list_os_variants(type): + variants.append([Guest.get_os_variant_label(type, variant), variant, self.__config.is_os_variant(variant)]) + self.__os_variants = RadioBar(screen, variants) + grid = Grid(1, 1) + grid.setField(self.__os_variants, 0, 0, anchorLeft = 1) + return [Label("Choose the operating system version"), + grid] + + def get_ram_and_cpu_page(self, screen): + self.__memory = Entry(10, str(self.__config.get_memory())) + self.__cpus = Entry(10, str(self.__config.get_cpus())) + grid = Grid(2,2) + grid.setField(Label("Memory (RAM):"), 0, 0, anchorRight = 1) + grid.setField(self.__memory, 1, 0, anchorLeft = 1) + grid.setField(Label("CPUs:"), 0, 1, anchorRight = 1) + grid.setField(self.__cpus, 1, 1, anchorLeft = 1) + return [Label("Choose memory and CPU settings"), + grid] + + def get_enable_storage_page(self, screen): + self.__enable_storage = Checkbox("Enable storage for this virtual machine", self.__config.get_enable_storage()) + self.__storage_type = RadioBar(screen,((["Create a disk image on the computer's hard disk", + DomainConfig.NEW_STORAGE, + self.__config.get_use_local_storage()]), + (["Select managed or other existing storage", + DomainConfig.EXISTING_STORAGE, + self.__config.get_use_local_storage() is False]))) + grid = Grid(1,2) + grid.setField(self.__enable_storage, 0, 0, anchorLeft = 1) + grid.setField(self.__storage_type, 0, 1, anchorLeft = 1) + return [Label("Configure storage"), + grid] + + def get_local_storage_page(self, screen): + self.__storage_size = Entry(6, str(self.__config.get_storage_size())) + self.__allocate_storage = Checkbox("Allocate entire disk now", self.__config.get_allocate_storage()) + grid = Grid(2, 2) + grid.setField(self.__allocate_storage, 0, 0, growx = 1, anchorLeft = 1) + grid.setField(Label("Storage size (GB):"), 0, 1, anchorLeft = 1) + grid.setField(self.__storage_size, 1, 1) + return [Label("Configure local storage"), + grid] + + def get_managed_storage_page(self, screen): + volumes = [] + for volume in self.get_libvirt().list_storage_volumes(): + volumes.append(["%s (%d GB)" % (volume.name(), volume.info()[1] / (1024 ** 3)), + volume.name(), + self.__config.is_existing_storage(volume.name())]) + self.__existing_storage = RadioBar(screen, (volumes)) + grid = Grid(2, 1) + grid.setField(Label("Existing storage:"), 0, 0) + grid.setField(self.__existing_storage, 1, 0) + return [Label("Configure managed storage"), + grid] + + def get_bridge_page(self, screen): + bridges = [] + for bridge in self.get_libvirt().list_bridges(): + bridges.append(["Virtual network '%s'" % bridge.name(), bridge.name(), self.__config.get_network_bridge() == bridge.name()]) + self.__network_bridges = RadioBar(screen, (bridges)) + if self.__config.get_mac_address() == None: + self.__config.set_mac_address(self.get_libvirt().generate_mac_address()) + self.__mac_address = Entry(20, self.__config.get_mac_address()) + grid = Grid(1, 1) + grid.setField(self.__network_bridges, 0, 0) + return [Label("Select an existing bridge"), + grid] + + def get_virt_details_page(self, screen): + virt_types = [] + for type in self.get_libvirt().list_virt_types(): + virt_types.append([type, type, self.__config.is_virt_type(type)]) + self.__virt_types = RadioBar(screen, (virt_types)) + archs = [] + for arch in self.get_libvirt().list_architectures(): + archs.append([arch, arch, self.__config.is_architecture(arch)]) + self.__architectures = RadioBar(screen, (archs)) + grid = Grid(2, 2) + grid.setField(Label("Virt Type:"), 0, 0, anchorRight = 1, anchorTop = 1) + grid.setField(self.__virt_types, 1, 0, anchorLeft = 1) + grid.setField(Label("Architecture:"), 0, 1, anchorRight = 1, anchorTop = 1) + grid.setField(self.__architectures, 1, 1, anchorLeft = 1) + return [Label("Configure virtualization details"), + grid] + + def get_confirm_page(self, screen): + grid = Grid(2, 6) + grid.setField(Label("OS:"), 0, 0, anchorRight = 1) + grid.setField(Label(Guest.get_os_variant_label(self.__config.get_os_type(), + self.__config.get_os_variant())), 1, 0, anchorLeft = 1) + grid.setField(Label("Install:"), 0, 1, anchorRight = 1) + grid.setField(Label(self.__config.get_install_type_text()), 1, 1, anchorLeft = 1) + grid.setField(Label("Memory:"), 0, 2, anchorRight = 1) + grid.setField(Label("%s MB" % self.__config.get_memory()), 1, 2, anchorLeft = 1) + grid.setField(Label("CPUs:"), 0, 3, anchorRight = 1) + grid.setField(Label("%d" % self.__config.get_cpus()), 1, 3, anchorLeft = 1) + grid.setField(Label("Storage:"), 0, 4, anchorRight = 1) + grid.setField(Label(self.__config.get_existing_storage()), 1, 4, anchorLeft = 1) + grid.setField(Label("Network:"), 0, 5, anchorRight = 1) + grid.setField(Label(self.__config.get_network_bridge()), 1, 5, anchorLeft = 1) + return [Label("Ready to begin installation of %s" % self.__config.get_guest_name()), + grid] + +def AddDomain(): + screen = DomainConfigScreen() + screen.start() diff --git a/nodeadmin/createdomain.py b/nodeadmin/createdomain.py deleted file mode 100755 index 6f10b44..0000000 --- a/nodeadmin/createdomain.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# -# createdomain.py - Copyright (C) 2009 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 CreateDomainConfigScreen(DomainListConfigScreen): - LIST_PAGE = 1 - CREATE_PAGE = 2 - - def __init__(self): - DomainListConfigScreen.__init__(self, "Create A Domain") - - def get_elements_for_page(self, screen, page): - if page is self.LIST_PAGE: - return self.get_domain_list_page(screen, created = False) - elif page is self.CREATE_PAGE: - return self.get_create_domain_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.CREATE_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: - self.get_libvirt().create_domain(domain) - return True - except Exception, error: - errors.append("There was an error creating the domain: %s" % domain) - errors.append(str(error)) - else: - errors.append("You must first select a domain to create.") - - def get_create_domain_page(self, screen): - grid = Grid(1, 1) - grid.setField(Label("%s was successfully created." % self.get_selected_domain()), 0, 0) - return [grid] - -def CreateDomain(): - screen = CreateDomainConfigScreen() - screen.start() diff --git a/nodeadmin/definedomain.py b/nodeadmin/definedomain.py deleted file mode 100755 index 3fffca2..0000000 --- a/nodeadmin/definedomain.py +++ /dev/null @@ -1,470 +0,0 @@ -#!/usr/bin/env python -# -# definedomain.py - Copyright (C) 2009 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 * -import os -from domainconfig import DomainConfig -from configscreen import ConfigScreen -import urlgrabber.progress as progress -import utils -import logging - -from virtinst import * - -VM_DETAILS_PAGE = 1 -LOCAL_INSTALL_PAGE = 2 -SELECT_CDROM_PAGE = 3 -SELECT_ISO_PAGE = 4 -NETWORK_INSTALL_PAGE = 10 -OS_TYPE_PAGE = 11 -OS_VARIANT_PAGE = 12 -RAM_CPU_PAGE = 13 -ENABLE_STORAGE_PAGE = 14 -LOCAL_STORAGE_PAGE = 15 -MANAGED_STORAGE_PAGE = 16 -BRIDGE_PAGE = 17 -VIRT_DETAILS_PAGE = 18 -CONFIRM_PAGE = 19 - -LOCATION="location" -KICKSTART="kickstart" -KERNELOPTS="kernel.options" -OS_TYPE="os.type" -OS_VARIANT="os.variant" -MEMORY="memory" -CPUS="cpus" - -class DummyMeter(progress.BaseMeter): - def _do_start(self, now = None): - logging.info("Starting...") - - def _do_end(self, amount_read, now = None): - logging.info("Ending: read=%d" % amount_read) - - def _do_update(self, amount_read, now = None): - logging.info("Update: read=%d" % amount_read) - -class DomainConfigScreen(ConfigScreen): - def __init__(self): - ConfigScreen.__init__(self, "Create A New Virtual Machine") - self.__config = DomainConfig() - self.__config.set_architecture(self.get_libvirt().get_default_architecture()) - self.__config.set_virt_type(self.get_libvirt().get_default_virt_type()) - - def get_elements_for_page(self, screen, page): - if page == VM_DETAILS_PAGE: return self.get_vm_details_page(screen) - elif page == LOCAL_INSTALL_PAGE: return self.get_local_install_page(screen) - elif page == SELECT_CDROM_PAGE: return self.get_select_cdrom_page(screen) - elif page == SELECT_ISO_PAGE: return self.get_select_iso_page(screen) - elif page == NETWORK_INSTALL_PAGE: return self.get_network_install_page(screen) - elif page == OS_TYPE_PAGE: return self.get_os_type_page(screen) - elif page == OS_VARIANT_PAGE: return self.get_os_variant_page(screen) - elif page == RAM_CPU_PAGE: return self.get_ram_and_cpu_page(screen) - elif page == ENABLE_STORAGE_PAGE: return self.get_enable_storage_page(screen) - elif page == LOCAL_STORAGE_PAGE: return self.get_local_storage_page(screen) - elif page == MANAGED_STORAGE_PAGE: return self.get_managed_storage_page(screen) - elif page == BRIDGE_PAGE: return self.get_bridge_page(screen) - elif page == VIRT_DETAILS_PAGE: return self.get_virt_details_page(screen) - elif page == CONFIRM_PAGE: return self.get_confirm_page(screen) - return [] - - def validate_input(self, page, errors): - if page == VM_DETAILS_PAGE: - if len(self.__guest_name.value()) > 0: - if self.get_libvirt().domain_exists(self.__guest_name.value()): - errors.append("Guest name '%s' is already in use." % self.__guest_name.value()) - else: - return True - else: - errors.append("Guest name must be a string between 0 and 50 characters.") - elif page == LOCAL_INSTALL_PAGE: - if self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM: - return True - elif self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_ISO: - return True - elif page == SELECT_CDROM_PAGE: - if self.__install_media.getSelection() != None: - if len(self.get_hal().list_installable_volumes()) == 0: - errors.append("No installable media is available.") - else: - return True - else: - errors.append("You must select an install media.") - elif page == SELECT_ISO_PAGE: - if len(self.__iso_path.value()) > 0: - if os.path.exists(self.__iso_path.value()): - if os.path.isfile(self.__iso_path.value()): - return True - else: - errors.append("%s is not a file." % self.__iso_path.value()) - else: - errors.append("No such install media exists:") - errors.append(self.__iso_path.value()) - else: - errors.append("An install media selection is required.") - elif page == NETWORK_INSTALL_PAGE: - if len(self.__install_url.value()) > 0: - return True - else: - errors.append("An install tree is required.") - elif page == OS_TYPE_PAGE: return True - elif page == OS_VARIANT_PAGE: return True - elif page == RAM_CPU_PAGE: - if (len(self.__memory.value()) > 0 and len(self.__cpus.value()) > 0) \ - and (int(self.__memory.value()) > 0 and int(self.__cpus.value()) > 0): - return True - else: - if len(self.__memory.value()) == 0: - errors.append("A value must be entered for memory.") - elif int(self.__memory.value()) <= 0: - errors.append("A positive integer value must be entered for memory.") - if len(self.__cpus.value()) == 0: - errors.append("A value must be entered for CPUs.") - elif int(self.__cpus.value()) <= 0: - errors.append("A positive integer value must be entered for memory.") - elif page == ENABLE_STORAGE_PAGE: return True - elif page == LOCAL_STORAGE_PAGE: - if len(self.__storage_size.value()) > 0: - if float(self.__storage_size.value()) > 0: - return True - else: - errors.append("A positive value must be entered for the storage size.") - else: - errors.append("A value must be entered for the storage size.") - elif page == MANAGED_STORAGE_PAGE: - if self.__existing_storage.getSelection() is not None: - return True - else: - errors.append("Please select a storage volume.") - elif page == BRIDGE_PAGE: - if self.__network_bridges.getSelection() != None: - if len(self.__mac_address.value()) > 0: - # TODO: regex check the format - return True - else: - errors.append("MAC address must be supplied.") - else: - errors.append("A network bridge must be selected.") - elif page == VIRT_DETAILS_PAGE: - if self.__virt_types.getSelection() != None and self.__architectures.getSelection() != None: - return True - if self.__virt_types.getSelection() is None: - errors.append("Please select a virtualization type.") - if self.__architectures.getSelection() is None: - errors.append("Please selection an architecture.") - elif page == CONFIRM_PAGE: return True - return False - - def process_input(self, page): - if page == VM_DETAILS_PAGE: - self.__config.set_guest_name(self.__guest_name.value()) - self.__config.set_install_type(self.__install_type.getSelection()) - elif page == LOCAL_INSTALL_PAGE: - self.__config.set_use_cdrom_source(self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM) - elif page == SELECT_CDROM_PAGE: - self.__config.set_install_media(self.__install_media.getSelection()) - elif page == SELECT_ISO_PAGE: - self.__config.set_iso_path(self.__iso_path.value()) - elif page == NETWORK_INSTALL_PAGE: - self.__config.set_install_url(self.__install_url.value()) - self.__config.set_kickstart_url(self.__kickstart_url.value()) - self.__config.set_kernel_options(self.__kernel_options.value()) - elif page == OS_TYPE_PAGE: - self.__config.set_os_type(self.__os_types.getSelection()) - elif page == OS_VARIANT_PAGE: - self.__config.set_os_variant(self.__os_variants.getSelection()) - elif page == RAM_CPU_PAGE: - self.__config.set_memory(int(self.__memory.value())) - self.__config.set_cpus(int(self.__cpus.value())) - elif page == ENABLE_STORAGE_PAGE: - self.__config.set_enable_storage(self.__enable_storage.value()) - if self.__storage_type.getSelection() == DomainConfig.NEW_STORAGE: - self.__config.set_use_local_storage(True) - elif self.__storage_type.getSelection() == DomainConfig.EXISTING_STORAGE: - self.__config.set_use_local_storage(False) - elif page == LOCAL_STORAGE_PAGE: - self.__config.set_storage_size(float(self.__storage_size.value())) - self.__config.set_allocate_storage(self.__allocate_storage.value()) - elif page == MANAGED_STORAGE_PAGE: - self.__config.set_use_local_storage(False) - self.__config.set_existing_storage(self.__existing_storage.getSelection()) - self.__config.set_storage_size(self.get_libvirt().get_storage_size(self.__existing_storage.getSelection())) - elif page == BRIDGE_PAGE: - self.__config.set_network_bridge(self.__network_bridges.getSelection()) - elif page == VIRT_DETAILS_PAGE: - self.__config.set_virt_type(self.__virt_types.getSelection()) - self.__config.set_architecture(self.__architectures.getSelection()) - elif page == CONFIRM_PAGE: - self.get_libvirt().define_domain(self.__config, DummyMeter()) - self.set_finished() - - def get_back_page(self, page): - result = page - if page == OS_TYPE_PAGE: - install_type = self.__config.get_install_type() - if install_type == DomainConfig.LOCAL_INSTALL: - if self.__config.get_use_cdrom_source(): - result = SELECT_CDROM_PAGE - else: - result = SELECT_ISO_PAGE - elif install_type == DomainConfig.NETWORK_INSTALL: - result = NETWORK_INSTALL_PAGE - elif install_type == DomainConfig.PXE_INSTALL: - result = VM_DETAILS_PAGE - elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: - result = ENABLE_STORAGE_PAGE - elif page == NETWORK_INSTALL_PAGE: - result = VM_DETAILS_PAGE - elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: - result = LOCAL_INSTALL_PAGE - elif page == BRIDGE_PAGE: - if self.__config.get_use_local_storage(): - result = LOCAL_STORAGE_PAGE - else: - result = MANAGED_STORAGE_PAGE - else: - if page > 1: result = page - 1 - return result - - def get_next_page(self, page): - result = page - if page == VM_DETAILS_PAGE: - install_type = self.__config.get_install_type() - if install_type == DomainConfig.LOCAL_INSTALL: - result = LOCAL_INSTALL_PAGE - elif install_type == DomainConfig.NETWORK_INSTALL: - result = NETWORK_INSTALL_PAGE - elif install_type == DomainConfig.PXE_INSTALL: - result = OS_TYPE_PAGE - elif page == LOCAL_INSTALL_PAGE: - if self.__config.get_use_cdrom_source(): - result = SELECT_CDROM_PAGE - else: - result = SELECT_ISO_PAGE - elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: - result = OS_TYPE_PAGE - elif page == NETWORK_INSTALL_PAGE: - result = OS_TYPE_PAGE - elif page == ENABLE_STORAGE_PAGE: - result = BRIDGE_PAGE - if self.__config.get_enable_storage(): - if self.__config.get_use_local_storage(): - result = LOCAL_STORAGE_PAGE - else: - result = MANAGED_STORAGE_PAGE - elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: - result = BRIDGE_PAGE - else: - result = page + 1 - return result - - def page_has_finish(self, page): - if page == CONFIRM_PAGE: return True - return False - - def page_has_next(self, page): - if page < CONFIRM_PAGE: - return True - - def get_vm_details_page(self, screen): - self.__guest_name = Entry(50, self.__config.get_guest_name()) - self.__install_type = RadioBar(screen, (("Local install media (ISO image or CDROM)", - DomainConfig.LOCAL_INSTALL, - self.__config.is_install_type(DomainConfig.LOCAL_INSTALL)), - ("Network Install (HTTP, FTP, or NFS)", - DomainConfig.NETWORK_INSTALL, - self.__config.is_install_type(DomainConfig.NETWORK_INSTALL)), - ("Network Boot (PXE)", - DomainConfig.PXE_INSTALL, - self.__config.is_install_type(DomainConfig.PXE_INSTALL)))) - grid = Grid(2,3) - grid.setField(Label("Name:"), 0, 0, anchorRight = 1) - grid.setField(self.__guest_name, 1, 0, anchorLeft = 1) - grid.setField(Label("Choose how you would like to install the operating system"), 1, 1, - anchorLeft = 1, anchorTop = 1) - grid.setField(self.__install_type, 1, 2, anchorLeft = 1) - return [Label("Enter your machine details"), - grid] - - def get_local_install_page(self, screen): - self.__install_source = RadioBar(screen, (("Use CDROM or DVD", - DomainConfig.INSTALL_SOURCE_CDROM, - self.__config.get_use_cdrom_source()), - ("Use ISO image", - DomainConfig.INSTALL_SOURCE_ISO, - self.__config.get_use_cdrom_source() is False))) - grid = Grid(1,1) - grid.setField(self.__install_source, 0, 0, anchorLeft = 1) - return [Label("Locate your install media"), - grid] - - def get_select_cdrom_page(self, screen): - drives = [] - media = self.get_hal().list_installable_volumes() - for drive in media.keys(): - drives.append([media[drive], drive, self.__config.is_install_media(drive)]) - self.__install_media = RadioBar(screen, (drives)) - grid = Grid(1, 1) - grid.setField(self.__install_media, 0, 0) - return [Label("Select the install media"), - grid] - - def get_select_iso_page(self, screen): - self.__iso_path = Entry(50, self.__config.get_iso_path()) - grid = Grid(1, 2) - grid.setField(Label("Enter ISO path:"), 0, 0, anchorLeft = 1) - grid.setField(self.__iso_path, 0, 1, anchorLeft = 1) - return [Label("Enter the full path to an install ISO"), - grid] - - def get_network_install_page(self, screen): - self.__install_url = Entry(50, self.__config.get_install_url()) - self.__kickstart_url = Entry(50, self.__config.get_kickstart_url()) - self.__kernel_options = Entry(50, self.__config.get_kernel_options()) - grid = Grid(2,3) - grid.setField(Label("URL:"), 0, 0, anchorRight = 1) - grid.setField(self.__install_url, 1, 0, anchorLeft = 1) - grid.setField(Label("Kickstart URL:"), 0, 1, anchorRight = 1) - grid.setField(self.__kickstart_url, 1, 1, anchorLeft = 1) - grid.setField(Label("Kernel Options:"), 0, 2, anchorRight = 1) - grid.setField(self.__kernel_options, 1, 2, anchorLeft = 1) - return [Label("Provide the operating system URL"), - grid] - - def get_os_type_page(self, screen): - types = [] - for type in Guest.list_os_types(): - types.append([Guest.get_os_type_label(type), type, self.__config.is_os_type(type)]) - self.__os_types = RadioBar(screen, types) - grid = Grid(1, 1) - grid.setField(self.__os_types, 0, 0, anchorLeft = 1) - return [Label("Choose the operating system type"), - grid] - - def get_os_variant_page(self, screen): - variants = [] - type = self.__config.get_os_type() - for variant in Guest.list_os_variants(type): - variants.append([Guest.get_os_variant_label(type, variant), variant, self.__config.is_os_variant(variant)]) - self.__os_variants = RadioBar(screen, variants) - grid = Grid(1, 1) - grid.setField(self.__os_variants, 0, 0, anchorLeft = 1) - return [Label("Choose the operating system version"), - grid] - - def get_ram_and_cpu_page(self, screen): - self.__memory = Entry(10, str(self.__config.get_memory())) - self.__cpus = Entry(10, str(self.__config.get_cpus())) - grid = Grid(2,2) - grid.setField(Label("Memory (RAM):"), 0, 0, anchorRight = 1) - grid.setField(self.__memory, 1, 0, anchorLeft = 1) - grid.setField(Label("CPUs:"), 0, 1, anchorRight = 1) - grid.setField(self.__cpus, 1, 1, anchorLeft = 1) - return [Label("Choose memory and CPU settings"), - grid] - - def get_enable_storage_page(self, screen): - self.__enable_storage = Checkbox("Enable storage for this virtual machine", self.__config.get_enable_storage()) - self.__storage_type = RadioBar(screen,((["Create a disk image on the computer's hard disk", - DomainConfig.NEW_STORAGE, - self.__config.get_use_local_storage()]), - (["Select managed or other existing storage", - DomainConfig.EXISTING_STORAGE, - self.__config.get_use_local_storage() is False]))) - grid = Grid(1,2) - grid.setField(self.__enable_storage, 0, 0, anchorLeft = 1) - grid.setField(self.__storage_type, 0, 1, anchorLeft = 1) - return [Label("Configure storage"), - grid] - - def get_local_storage_page(self, screen): - self.__storage_size = Entry(6, str(self.__config.get_storage_size())) - self.__allocate_storage = Checkbox("Allocate entire disk now", self.__config.get_allocate_storage()) - grid = Grid(2, 2) - grid.setField(self.__allocate_storage, 0, 0, growx = 1, anchorLeft = 1) - grid.setField(Label("Storage size (GB):"), 0, 1, anchorLeft = 1) - grid.setField(self.__storage_size, 1, 1) - return [Label("Configure local storage"), - grid] - - def get_managed_storage_page(self, screen): - volumes = [] - for volume in self.get_libvirt().list_storage_volumes(): - volumes.append(["%s (%d GB)" % (volume.name(), volume.info()[1] / (1024 ** 3)), - volume.name(), - self.__config.is_existing_storage(volume.name())]) - self.__existing_storage = RadioBar(screen, (volumes)) - grid = Grid(2, 1) - grid.setField(Label("Existing storage:"), 0, 0) - grid.setField(self.__existing_storage, 1, 0) - return [Label("Configure managed storage"), - grid] - - def get_bridge_page(self, screen): - bridges = [] - for bridge in self.get_libvirt().list_bridges(): - bridges.append(["Virtual network '%s'" % bridge.name(), bridge.name(), self.__config.get_network_bridge() == bridge.name()]) - self.__network_bridges = RadioBar(screen, (bridges)) - if self.__config.get_mac_address() == None: - self.__config.set_mac_address(self.get_libvirt().generate_mac_address()) - self.__mac_address = Entry(20, self.__config.get_mac_address()) - grid = Grid(1, 1) - grid.setField(self.__network_bridges, 0, 0) - return [Label("Select an existing bridge"), - grid] - - def get_virt_details_page(self, screen): - virt_types = [] - for type in self.get_libvirt().list_virt_types(): - virt_types.append([type, type, self.__config.is_virt_type(type)]) - self.__virt_types = RadioBar(screen, (virt_types)) - archs = [] - for arch in self.get_libvirt().list_architectures(): - archs.append([arch, arch, self.__config.is_architecture(arch)]) - self.__architectures = RadioBar(screen, (archs)) - grid = Grid(2, 2) - grid.setField(Label("Virt Type:"), 0, 0, anchorRight = 1, anchorTop = 1) - grid.setField(self.__virt_types, 1, 0, anchorLeft = 1) - grid.setField(Label("Architecture:"), 0, 1, anchorRight = 1, anchorTop = 1) - grid.setField(self.__architectures, 1, 1, anchorLeft = 1) - return [Label("Configure virtualization details"), - grid] - - def get_confirm_page(self, screen): - grid = Grid(2, 6) - grid.setField(Label("OS:"), 0, 0, anchorRight = 1) - grid.setField(Label(Guest.get_os_variant_label(self.__config.get_os_type(), - self.__config.get_os_variant())), 1, 0, anchorLeft = 1) - grid.setField(Label("Install:"), 0, 1, anchorRight = 1) - grid.setField(Label(self.__config.get_install_type_text()), 1, 1, anchorLeft = 1) - grid.setField(Label("Memory:"), 0, 2, anchorRight = 1) - grid.setField(Label("%s MB" % self.__config.get_memory()), 1, 2, anchorLeft = 1) - grid.setField(Label("CPUs:"), 0, 3, anchorRight = 1) - grid.setField(Label("%d" % self.__config.get_cpus()), 1, 3, anchorLeft = 1) - grid.setField(Label("Storage:"), 0, 4, anchorRight = 1) - grid.setField(Label(self.__config.get_existing_storage()), 1, 4, anchorLeft = 1) - grid.setField(Label("Network:"), 0, 5, anchorRight = 1) - grid.setField(Label(self.__config.get_network_bridge()), 1, 5, anchorLeft = 1) - return [Label("Ready to begin installation of %s" % self.__config.get_guest_name()), - grid] - -def DefineDomain(): - screen = DomainConfigScreen() - screen.start() diff --git a/nodeadmin/destroydomain.py b/nodeadmin/destroydomain.py deleted file mode 100755 index 350c32e..0000000 --- a/nodeadmin/destroydomain.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -# destroydomain.py - Copyright (C) 2009 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 DestroyDomainConfigScreen(DomainListConfigScreen): - LIST_PAGE = 1 - DESTROY_PAGE = 2 - - def __init__(self): - DomainListConfigScreen.__init__(self, "Destroy 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.DESTROY_PAGE: - return self.get_destroy_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.DESTROY_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: - self.get_libvirt().destroy_domain(domain) - return True - except Exception, error: - errors.append("There was an error destroy the domain: %s" % domain) - errors.append(str(error)) - else: - errors.append("You must first select a domain to destroy.") - return False - - def get_destroy_page(self, screen): - grid = Grid(1, 1) - grid.setField(Label("%s was successfully destroyed." % self.get_selected_domain()), 0, 0) - return [grid] - -def DestroyDomain(): - screen = DestroyDomainConfigScreen() - screen.start() diff --git a/nodeadmin/listdomains.py b/nodeadmin/listdomains.py index 1b51ee2..7468bcf 100755 --- a/nodeadmin/listdomains.py +++ b/nodeadmin/listdomains.py @@ -27,7 +27,7 @@ class ListDomainsConfigScreen(DomainListConfigScreen): DETAIL_PAGE = 2 def __init__(self): - DomainListConfigScreen.__init__(self, 'List Domains') + DomainListConfigScreen.__init__(self, 'List Virtual Machines') def page_has_next(self, page): return (page == self.LIST_PAGE) @@ -38,7 +38,7 @@ class ListDomainsConfigScreen(DomainListConfigScreen): def validate_input(self, page, errors): if page == self.LIST_PAGE: if self.get_selected_domain() is None: - errors.append("Please select a domain to view.") + errors.append("Please select a virtual machine to view.") else: return True diff --git a/nodeadmin/nodemenu.py b/nodeadmin/nodemenu.py index 9e339ff..0503b2e 100755 --- a/nodeadmin/nodemenu.py +++ b/nodeadmin/nodemenu.py @@ -21,42 +21,42 @@ import traceback from menuscreen import MenuScreen from configscreen import ConfigScreen -from definedomain import DefineDomain +from adddomain import AddDomain from createdomain import CreateDomain -from destroydomain import DestroyDomain -from undefinedomain import UndefineDomain +from stopdomain import StopDomain +from removedomain import RemoveDomain from listdomains import ListDomains from createuser import CreateUser import utils import logging -DEFINE_DOMAIN = 1 -CREATE_DOMAIN = 2 -DESTROY_DOMAIN = 3 -UNDEFINE_DOMAIN = 4 -LIST_DOMAINS = 5 -CREATE_USER = 6 +ADD_DOMAIN = 1 +CREATE_DOMAIN = 2 +STOP_DOMAIN = 3 +REMOVE_DOMAIN = 4 +LIST_DOMAINS = 5 +CREATE_USER = 6 class NodeMenuScreen(MenuScreen): def __init__(self): MenuScreen.__init__(self, "Node Administration") def get_menu_items(self): - return (("Define A Domain", DEFINE_DOMAIN), - ("Create A Domain", CREATE_DOMAIN), - ("Destroy A Domain", DESTROY_DOMAIN), - ("Undefine A Domain", UNDEFINE_DOMAIN), - ("List All Domains", LIST_DOMAINS), - ("Create A User", CREATE_USER)) + return (("Add A Virtual Machine", ADD_DOMAIN), + ("Create A Virtual Machine", CREATE_DOMAIN), + ("Stop A Virtual Machine", STOP_DOMAIN), + ("Remove A Virtual Machine", REMOVE_DOMAIN), + ("List All Virtual Machines", LIST_DOMAINS), + ("Create A User", CREATE_USER)) def handle_selection(self, item): - if item is DEFINE_DOMAIN: DefineDomain() - elif item is CREATE_DOMAIN: CreateDomain() - elif item is DESTROY_DOMAIN: DestroyDomain() - elif item is UNDEFINE_DOMAIN: UndefineDomain() - elif item is LIST_DOMAINS: ListDomains() - elif item is CREATE_USER: CreateUser() + if item is ADD_DOMAIN: AddDomain() + elif item is CREATE_DOMAIN: CreateDomain() + elif item is STOP_DOMAIN: StopDomain() + elif item is REMOVE_DOMAIN: RemoveDomain() + elif item is LIST_DOMAINS: ListDomains() + elif item is CREATE_USER: CreateUser() def NodeMenu(): screen = NodeMenuScreen() diff --git a/nodeadmin/removedomain.py b/nodeadmin/removedomain.py new file mode 100755 index 0000000..4e31428 --- /dev/null +++ b/nodeadmin/removedomain.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# removedomain.py - Copyright (C) 2009 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 RemoveDomainConfigScreen(DomainListConfigScreen): + LIST_PAGE = 1 + CONFIRM_PAGE = 2 + REMOVE_PAGE = 3 + + def __init__(self): + DomainListConfigScreen.__init__(self, "Remove A Domain") + + def get_elements_for_page(self, screen, page): + if page is self.LIST_PAGE: return self.get_domain_list_page(screen) + elif page is self.CONFIRM_PAGE: return self.get_confirm_page(screen) + elif page is self.REMOVE_PAGE: return self.get_remove_page(screen) + + def page_has_next(self, page): + if page is self.LIST_PAGE: return self.has_selectable_domains() + elif page is self.CONFIRM_PAGE: return True + return False + + def page_has_back(self, page): + if page is self.CONFIRM_PAGE: return True + elif page is self.REMOVE_PAGE: return True + return False + + def get_back_page(self, page): + if page is self.CONFIRM_PAGE: return self.LIST_PAGE + elif page is self.REMOVE_PAGE: return self.LIST_PAGE + + def validate_input(self, page, errors): + if page is self.LIST_PAGE: + if self.get_selected_domain() is not None: + return True + else: + errors.append("You must first select a domain.") + elif page is self.CONFIRM_PAGE: + if self.__confirm_remove.value(): + domain = self.get_selected_domain() + try: + self.get_libvirt().remove_domain(domain) + return True + except Exception, error: + errors.append("Failed to remove %s." % domain) + errors.append(str(error)) + else: + errors.append("You must confirm undefining the domain to proceed.") + return False + + def get_confirm_page(self, screen): + self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 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) + return [grid] + +def RemoveDomain(): + screen = RemoveDomainConfigScreen() + screen.start() diff --git a/nodeadmin/setup.py.in b/nodeadmin/setup.py.in index 3635810..1e6e028 100644 --- a/nodeadmin/setup.py.in +++ b/nodeadmin/setup.py.in @@ -25,12 +25,12 @@ setup(name = "nodeadmin", entry_points = { 'console_scripts': [ 'nodeadmin = nodeadmin.nodeadmin:NodeAdmin', - 'definedom = nodeadmin.definedomain:DefineDomain', - 'createdom = nodeadmin.createdomain:CreateDomain', - 'destroydom = nodeadmin.destroydomain:DestroyDomain', - 'undefinedom = nodeadmin.undefinedomain:UndefineDomain', + 'addvm = nodeadmin.adddomain:AddDomain', + 'startvm = nodeadmin.startdomain:StartDomain', + 'stopvm = nodeadmin.stopdomain:StopDomain', + 'rmvm = nodeadmin.removedomain:RemoveDomain', 'createuser = nodeadmin.createuser:CreateUser', - 'listdoms = nodeadmin.listdomains:ListDomains', + 'listvms = nodeadmin.listdomains:ListDomains', 'definenet = nodeadmin.definenet:DefineNetwork', 'createnet = nodeadmin.createnetwork:CreateNetwork', 'destroynet = nodeadmin.destroynetwork:DestroyNetwork', diff --git a/nodeadmin/startdomain.py b/nodeadmin/startdomain.py new file mode 100755 index 0000000..082ac0d --- /dev/null +++ b/nodeadmin/startdomain.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# startdomain.py - Copyright (C) 2009 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 StartDomainConfigScreen(DomainListConfigScreen): + LIST_PAGE = 1 + START_PAGE = 2 + + def __init__(self): + DomainListConfigScreen.__init__(self, "Start A Domain") + + def get_elements_for_page(self, screen, page): + if page is self.LIST_PAGE: + return self.get_domain_list_page(screen, started = False) + elif page is self.START_PAGE: + return self.get_start_domain_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.START_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: + self.get_libvirt().start_domain(domain) + return True + except Exception, error: + errors.append("There was an error creating the domain: %s" % domain) + errors.append(str(error)) + else: + errors.append("You must first select a domain to start.") + + def get_start_domain_page(self, screen): + grid = Grid(1, 1) + grid.setField(Label("%s was successfully started." % self.get_selected_domain()), 0, 0) + return [grid] + +def StartDomain(): + screen = StartDomainConfigScreen() + screen.start() diff --git a/nodeadmin/stopdomain.py b/nodeadmin/stopdomain.py new file mode 100755 index 0000000..3ddd681 --- /dev/null +++ b/nodeadmin/stopdomain.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# +# stopdomain.py - Copyright (C) 2009 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 StopDomainConfigScreen(DomainListConfigScreen): + LIST_PAGE = 1 + STOP_PAGE = 2 + + def __init__(self): + DomainListConfigScreen.__init__(self, "Stop 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: + self.get_libvirt().stop_domain(domain) + return True + except Exception, error: + errors.append("There was an error stop 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 stoped." % self.get_selected_domain()), 0, 0) + return [grid] + +def StopDomain(): + screen = StopDomainConfigScreen() + screen.start() diff --git a/nodeadmin/undefinedomain.py b/nodeadmin/undefinedomain.py deleted file mode 100755 index 2620540..0000000 --- a/nodeadmin/undefinedomain.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -# -# undefinedomain.py - Copyright (C) 2009 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 UndefineDomainConfigScreen(DomainListConfigScreen): - LIST_PAGE = 1 - CONFIRM_PAGE = 2 - UNDEFINE_PAGE = 3 - - def __init__(self): - DomainListConfigScreen.__init__(self, "Undefine A Domain") - - def get_elements_for_page(self, screen, page): - if page is self.LIST_PAGE: return self.get_domain_list_page(screen) - elif page is self.CONFIRM_PAGE: return self.get_confirm_page(screen) - elif page is self.UNDEFINE_PAGE: return self.get_undefine_page(screen) - - def page_has_next(self, page): - if page is self.LIST_PAGE: return self.has_selectable_domains() - elif page is self.CONFIRM_PAGE: return True - return False - - def page_has_back(self, page): - if page is self.CONFIRM_PAGE: return True - elif page is self.UNDEFINE_PAGE: return True - return False - - def get_back_page(self, page): - if page is self.CONFIRM_PAGE: return self.LIST_PAGE - elif page is self.UNDEFINE_PAGE: return self.LIST_PAGE - - def validate_input(self, page, errors): - if page is self.LIST_PAGE: - if self.get_selected_domain() is not None: - return True - else: - errors.append("You must first select a domain.") - elif page is self.CONFIRM_PAGE: - if self.__confirm_undefine.value(): - domain = self.get_selected_domain() - try: - self.get_libvirt().undefine_domain(domain) - return True - except Exception, error: - errors.append("Failed to undefine %s." % domain) - errors.append(str(error)) - else: - errors.append("You must confirm undefining the domain to proceed.") - return False - - def get_confirm_page(self, screen): - self.__confirm_undefine = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 0) - grid = Grid(1, 1) - grid.setField(self.__confirm_undefine, 0, 0) - return [grid] - - def get_undefine_page(self, screen): - grid = Grid(1, 1) - grid.setField(Label("%s has been undefined." % self.get_selected_domain()), 0, 0) - return [grid] - -def UndefineDomain(): - screen = UndefineDomainConfigScreen() - screen.start() diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in index 2a6b7b6..49f41cb 100644 --- a/ovirt-node.spec.in +++ b/ovirt-node.spec.in @@ -183,10 +183,10 @@ cd - %{__install} -p -m0644 nodeadmin/mainmenu.py %{buildroot}%{python_sitelib}/nodeadmin %{__install} -p -m0644 nodeadmin/nodemenu.py %{buildroot}%{python_sitelib}/nodeadmin -%{__install} -p -m0755 nodeadmin/definedomain.py %{buildroot}%{python_sitelib}/nodeadmin -%{__install} -p -m0755 nodeadmin/createdomain.py %{buildroot}%{python_sitelib}/nodeadmin -%{__install} -p -m0755 nodeadmin/destroydomain.py %{buildroot}%{python_sitelib}/nodeadmin -%{__install} -p -m0755 nodeadmin/undefinedomain.py %{buildroot}%{python_sitelib}/nodeadmin +%{__install} -p -m0755 nodeadmin/adddomain.py %{buildroot}%{python_sitelib}/nodeadmin +%{__install} -p -m0755 nodeadmin/startdomain.py %{buildroot}%{python_sitelib}/nodeadmin +%{__install} -p -m0755 nodeadmin/stopdomain.py %{buildroot}%{python_sitelib}/nodeadmin +%{__install} -p -m0755 nodeadmin/removedomain.py %{buildroot}%{python_sitelib}/nodeadmin %{__install} -p -m0755 nodeadmin/listdomains.py %{buildroot}%{python_sitelib}/nodeadmin %{__install} -p -m0644 nodeadmin/domainconfig.py %{buildroot}%{python_sitelib}/nodeadmin @@ -369,11 +369,11 @@ fi %{_initrddir}/ovirt-functions %defattr(-,root,root,0644) %{_bindir}/nodeadmin -%{_bindir}/definedom -%{_bindir}/createdom -%{_bindir}/destroydom -%{_bindir}/undefinedom -%{_bindir}/listdoms +%{_bindir}/addvm +%{_bindir}/startvm +%{_bindir}/stopvm +%{_bindir}/rmvm +%{_bindir}/listvms %{_bindir}/definenet %{_bindir}/createnet %{_bindir}/destroynet -- 1.6.2.5
Joey Boggs
2009-Oct-27 14:20 UTC
[Ovirt-devel] [PATCH node] Renamed files and menu items for node administration:
Darryl L. Pierce wrote:> define domain -> add virtual machine (addvm) > undefine domain -> remove virtual machine (rmvm) > create domain -> start virtual machine (startvm) > destroy domain -> stop virtual machine (stopvm) > list domains -> list virtual machiens (listvms) > > Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> > --- > Makefile.am | 8 +- > nodeadmin/adddomain.py | 470 +++++++++++++++++++++++++++++++++++++++++++ > nodeadmin/createdomain.py | 65 ------ > nodeadmin/definedomain.py | 470 ------------------------------------------- > nodeadmin/destroydomain.py | 66 ------ > nodeadmin/listdomains.py | 4 +- > nodeadmin/nodemenu.py | 42 ++-- > nodeadmin/removedomain.py | 83 ++++++++ > nodeadmin/setup.py.in | 10 +- > nodeadmin/startdomain.py | 65 ++++++ > nodeadmin/stopdomain.py | 66 ++++++ > nodeadmin/undefinedomain.py | 83 -------- > ovirt-node.spec.in | 18 +- > 13 files changed, 725 insertions(+), 725 deletions(-) > create mode 100755 nodeadmin/adddomain.py > delete mode 100755 nodeadmin/createdomain.py > delete mode 100755 nodeadmin/definedomain.py > delete mode 100755 nodeadmin/destroydomain.py > create mode 100755 nodeadmin/removedomain.py > create mode 100755 nodeadmin/startdomain.py > create mode 100755 nodeadmin/stopdomain.py > delete mode 100755 nodeadmin/undefinedomain.py > > diff --git a/Makefile.am b/Makefile.am > index abb7c33..3ce24c1 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -27,10 +27,10 @@ EXTRA_DIST = \ > images/grub-splash.xpm.gz \ > images/syslinux-vesa-splash.jpg \ > nodeadmin/__init__.py \ > + nodeadmin/adddomain.py \ > nodeadmin/configscreen.py \ > nodeadmin/createnetwork.py \ > nodeadmin/createuser.py \ > - nodeadmin/destroydomain.py \ > nodeadmin/destroynetwork.py \ > nodeadmin/halworker.py \ > nodeadmin/libvirtworker.py \ > @@ -39,10 +39,10 @@ EXTRA_DIST = \ > nodeadmin/menuscreen.py \ > nodeadmin/netmenu.py \ > nodeadmin/nodemenu.py \ > - nodeadmin/undefinedomain.py \ > + nodeadmin/removedomain.py \ > nodeadmin/undefinenetwork.py \ > - nodeadmin/createdomain.py \ > - nodeadmin/definedomain.py \ > + nodeadmin/startdomain.py \ > + nodeadmin/stopdomain.py \ > nodeadmin/definenet.py \ > nodeadmin/domainconfig.py \ > nodeadmin/networkconfig.py \ > diff --git a/nodeadmin/adddomain.py b/nodeadmin/adddomain.py > new file mode 100755 > index 0000000..70a2011 > --- /dev/null > +++ b/nodeadmin/adddomain.py > @@ -0,0 +1,470 @@ > +#!/usr/bin/env python > +# > +# adddomain.py - Copyright (C) 2009 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 * > +import os > +from domainconfig import DomainConfig > +from configscreen import ConfigScreen > +import urlgrabber.progress as progress > +import utils > +import logging > + > +from virtinst import * > + > +VM_DETAILS_PAGE = 1 > +LOCAL_INSTALL_PAGE = 2 > +SELECT_CDROM_PAGE = 3 > +SELECT_ISO_PAGE = 4 > +NETWORK_INSTALL_PAGE = 10 > +OS_TYPE_PAGE = 11 > +OS_VARIANT_PAGE = 12 > +RAM_CPU_PAGE = 13 > +ENABLE_STORAGE_PAGE = 14 > +LOCAL_STORAGE_PAGE = 15 > +MANAGED_STORAGE_PAGE = 16 > +BRIDGE_PAGE = 17 > +VIRT_DETAILS_PAGE = 18 > +CONFIRM_PAGE = 19 > + > +LOCATION="location" > +KICKSTART="kickstart" > +KERNELOPTS="kernel.options" > +OS_TYPE="os.type" > +OS_VARIANT="os.variant" > +MEMORY="memory" > +CPUS="cpus" > + > +class DummyMeter(progress.BaseMeter): > + def _do_start(self, now = None): > + logging.info("Starting...") > + > + def _do_end(self, amount_read, now = None): > + logging.info("Ending: read=%d" % amount_read) > + > + def _do_update(self, amount_read, now = None): > + logging.info("Update: read=%d" % amount_read) > + > +class DomainConfigScreen(ConfigScreen): > + def __init__(self): > + ConfigScreen.__init__(self, "Create A New Virtual Machine") > + self.__config = DomainConfig() > + self.__config.set_architecture(self.get_libvirt().get_default_architecture()) > + self.__config.set_virt_type(self.get_libvirt().get_default_virt_type()) > + > + def get_elements_for_page(self, screen, page): > + if page == VM_DETAILS_PAGE: return self.get_vm_details_page(screen) > + elif page == LOCAL_INSTALL_PAGE: return self.get_local_install_page(screen) > + elif page == SELECT_CDROM_PAGE: return self.get_select_cdrom_page(screen) > + elif page == SELECT_ISO_PAGE: return self.get_select_iso_page(screen) > + elif page == NETWORK_INSTALL_PAGE: return self.get_network_install_page(screen) > + elif page == OS_TYPE_PAGE: return self.get_os_type_page(screen) > + elif page == OS_VARIANT_PAGE: return self.get_os_variant_page(screen) > + elif page == RAM_CPU_PAGE: return self.get_ram_and_cpu_page(screen) > + elif page == ENABLE_STORAGE_PAGE: return self.get_enable_storage_page(screen) > + elif page == LOCAL_STORAGE_PAGE: return self.get_local_storage_page(screen) > + elif page == MANAGED_STORAGE_PAGE: return self.get_managed_storage_page(screen) > + elif page == BRIDGE_PAGE: return self.get_bridge_page(screen) > + elif page == VIRT_DETAILS_PAGE: return self.get_virt_details_page(screen) > + elif page == CONFIRM_PAGE: return self.get_confirm_page(screen) > + return [] > + > + def validate_input(self, page, errors): > + if page == VM_DETAILS_PAGE: > + if len(self.__guest_name.value()) > 0: > + if self.get_libvirt().domain_exists(self.__guest_name.value()): > + errors.append("Guest name '%s' is already in use." % self.__guest_name.value()) > + else: > + return True > + else: > + errors.append("Guest name must be a string between 0 and 50 characters.") > + elif page == LOCAL_INSTALL_PAGE: > + if self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM: > + return True > + elif self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_ISO: > + return True > + elif page == SELECT_CDROM_PAGE: > + if self.__install_media.getSelection() != None: > + if len(self.get_hal().list_installable_volumes()) == 0: > + errors.append("No installable media is available.") > + else: > + return True > + else: > + errors.append("You must select an install media.") > + elif page == SELECT_ISO_PAGE: > + if len(self.__iso_path.value()) > 0: > + if os.path.exists(self.__iso_path.value()): > + if os.path.isfile(self.__iso_path.value()): > + return True > + else: > + errors.append("%s is not a file." % self.__iso_path.value()) > + else: > + errors.append("No such install media exists:") > + errors.append(self.__iso_path.value()) > + else: > + errors.append("An install media selection is required.") > + elif page == NETWORK_INSTALL_PAGE: > + if len(self.__install_url.value()) > 0: > + return True > + else: > + errors.append("An install tree is required.") > + elif page == OS_TYPE_PAGE: return True > + elif page == OS_VARIANT_PAGE: return True > + elif page == RAM_CPU_PAGE: > + if (len(self.__memory.value()) > 0 and len(self.__cpus.value()) > 0) \ > + and (int(self.__memory.value()) > 0 and int(self.__cpus.value()) > 0): > + return True > + else: > + if len(self.__memory.value()) == 0: > + errors.append("A value must be entered for memory.") > + elif int(self.__memory.value()) <= 0: > + errors.append("A positive integer value must be entered for memory.") > + if len(self.__cpus.value()) == 0: > + errors.append("A value must be entered for CPUs.") > + elif int(self.__cpus.value()) <= 0: > + errors.append("A positive integer value must be entered for memory.") > + elif page == ENABLE_STORAGE_PAGE: return True > + elif page == LOCAL_STORAGE_PAGE: > + if len(self.__storage_size.value()) > 0: > + if float(self.__storage_size.value()) > 0: > + return True > + else: > + errors.append("A positive value must be entered for the storage size.") > + else: > + errors.append("A value must be entered for the storage size.") > + elif page == MANAGED_STORAGE_PAGE: > + if self.__existing_storage.getSelection() is not None: > + return True > + else: > + errors.append("Please select a storage volume.") > + elif page == BRIDGE_PAGE: > + if self.__network_bridges.getSelection() != None: > + if len(self.__mac_address.value()) > 0: > + # TODO: regex check the format > + return True > + else: > + errors.append("MAC address must be supplied.") > + else: > + errors.append("A network bridge must be selected.") > + elif page == VIRT_DETAILS_PAGE: > + if self.__virt_types.getSelection() != None and self.__architectures.getSelection() != None: > + return True > + if self.__virt_types.getSelection() is None: > + errors.append("Please select a virtualization type.") > + if self.__architectures.getSelection() is None: > + errors.append("Please selection an architecture.") > + elif page == CONFIRM_PAGE: return True > + return False > + > + def process_input(self, page): > + if page == VM_DETAILS_PAGE: > + self.__config.set_guest_name(self.__guest_name.value()) > + self.__config.set_install_type(self.__install_type.getSelection()) > + elif page == LOCAL_INSTALL_PAGE: > + self.__config.set_use_cdrom_source(self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM) > + elif page == SELECT_CDROM_PAGE: > + self.__config.set_install_media(self.__install_media.getSelection()) > + elif page == SELECT_ISO_PAGE: > + self.__config.set_iso_path(self.__iso_path.value()) > + elif page == NETWORK_INSTALL_PAGE: > + self.__config.set_install_url(self.__install_url.value()) > + self.__config.set_kickstart_url(self.__kickstart_url.value()) > + self.__config.set_kernel_options(self.__kernel_options.value()) > + elif page == OS_TYPE_PAGE: > + self.__config.set_os_type(self.__os_types.getSelection()) > + elif page == OS_VARIANT_PAGE: > + self.__config.set_os_variant(self.__os_variants.getSelection()) > + elif page == RAM_CPU_PAGE: > + self.__config.set_memory(int(self.__memory.value())) > + self.__config.set_cpus(int(self.__cpus.value())) > + elif page == ENABLE_STORAGE_PAGE: > + self.__config.set_enable_storage(self.__enable_storage.value()) > + if self.__storage_type.getSelection() == DomainConfig.NEW_STORAGE: > + self.__config.set_use_local_storage(True) > + elif self.__storage_type.getSelection() == DomainConfig.EXISTING_STORAGE: > + self.__config.set_use_local_storage(False) > + elif page == LOCAL_STORAGE_PAGE: > + self.__config.set_storage_size(float(self.__storage_size.value())) > + self.__config.set_allocate_storage(self.__allocate_storage.value()) > + elif page == MANAGED_STORAGE_PAGE: > + self.__config.set_use_local_storage(False) > + self.__config.set_existing_storage(self.__existing_storage.getSelection()) > + self.__config.set_storage_size(self.get_libvirt().get_storage_size(self.__existing_storage.getSelection())) > + elif page == BRIDGE_PAGE: > + self.__config.set_network_bridge(self.__network_bridges.getSelection()) > + elif page == VIRT_DETAILS_PAGE: > + self.__config.set_virt_type(self.__virt_types.getSelection()) > + self.__config.set_architecture(self.__architectures.getSelection()) > + elif page == CONFIRM_PAGE: > + self.get_libvirt().define_domain(self.__config, DummyMeter()) > + self.set_finished() > + > + def get_back_page(self, page): > + result = page > + if page == OS_TYPE_PAGE: > + install_type = self.__config.get_install_type() > + if install_type == DomainConfig.LOCAL_INSTALL: > + if self.__config.get_use_cdrom_source(): > + result = SELECT_CDROM_PAGE > + else: > + result = SELECT_ISO_PAGE > + elif install_type == DomainConfig.NETWORK_INSTALL: > + result = NETWORK_INSTALL_PAGE > + elif install_type == DomainConfig.PXE_INSTALL: > + result = VM_DETAILS_PAGE > + elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: > + result = ENABLE_STORAGE_PAGE > + elif page == NETWORK_INSTALL_PAGE: > + result = VM_DETAILS_PAGE > + elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: > + result = LOCAL_INSTALL_PAGE > + elif page == BRIDGE_PAGE: > + if self.__config.get_use_local_storage(): > + result = LOCAL_STORAGE_PAGE > + else: > + result = MANAGED_STORAGE_PAGE > + else: > + if page > 1: result = page - 1 > + return result > + > + def get_next_page(self, page): > + result = page > + if page == VM_DETAILS_PAGE: > + install_type = self.__config.get_install_type() > + if install_type == DomainConfig.LOCAL_INSTALL: > + result = LOCAL_INSTALL_PAGE > + elif install_type == DomainConfig.NETWORK_INSTALL: > + result = NETWORK_INSTALL_PAGE > + elif install_type == DomainConfig.PXE_INSTALL: > + result = OS_TYPE_PAGE > + elif page == LOCAL_INSTALL_PAGE: > + if self.__config.get_use_cdrom_source(): > + result = SELECT_CDROM_PAGE > + else: > + result = SELECT_ISO_PAGE > + elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: > + result = OS_TYPE_PAGE > + elif page == NETWORK_INSTALL_PAGE: > + result = OS_TYPE_PAGE > + elif page == ENABLE_STORAGE_PAGE: > + result = BRIDGE_PAGE > + if self.__config.get_enable_storage(): > + if self.__config.get_use_local_storage(): > + result = LOCAL_STORAGE_PAGE > + else: > + result = MANAGED_STORAGE_PAGE > + elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: > + result = BRIDGE_PAGE > + else: > + result = page + 1 > + return result > + > + def page_has_finish(self, page): > + if page == CONFIRM_PAGE: return True > + return False > + > + def page_has_next(self, page): > + if page < CONFIRM_PAGE: > + return True > + > + def get_vm_details_page(self, screen): > + self.__guest_name = Entry(50, self.__config.get_guest_name()) > + self.__install_type = RadioBar(screen, (("Local install media (ISO image or CDROM)", > + DomainConfig.LOCAL_INSTALL, > + self.__config.is_install_type(DomainConfig.LOCAL_INSTALL)), > + ("Network Install (HTTP, FTP, or NFS)", > + DomainConfig.NETWORK_INSTALL, > + self.__config.is_install_type(DomainConfig.NETWORK_INSTALL)), > + ("Network Boot (PXE)", > + DomainConfig.PXE_INSTALL, > + self.__config.is_install_type(DomainConfig.PXE_INSTALL)))) > + grid = Grid(2,3) > + grid.setField(Label("Name:"), 0, 0, anchorRight = 1) > + grid.setField(self.__guest_name, 1, 0, anchorLeft = 1) > + grid.setField(Label("Choose how you would like to install the operating system"), 1, 1, > + anchorLeft = 1, anchorTop = 1) > + grid.setField(self.__install_type, 1, 2, anchorLeft = 1) > + return [Label("Enter your machine details"), > + grid] > + > + def get_local_install_page(self, screen): > + self.__install_source = RadioBar(screen, (("Use CDROM or DVD", > + DomainConfig.INSTALL_SOURCE_CDROM, > + self.__config.get_use_cdrom_source()), > + ("Use ISO image", > + DomainConfig.INSTALL_SOURCE_ISO, > + self.__config.get_use_cdrom_source() is False))) > + grid = Grid(1,1) > + grid.setField(self.__install_source, 0, 0, anchorLeft = 1) > + return [Label("Locate your install media"), > + grid] > + > + def get_select_cdrom_page(self, screen): > + drives = [] > + media = self.get_hal().list_installable_volumes() > + for drive in media.keys(): > + drives.append([media[drive], drive, self.__config.is_install_media(drive)]) > + self.__install_media = RadioBar(screen, (drives)) > + grid = Grid(1, 1) > + grid.setField(self.__install_media, 0, 0) > + return [Label("Select the install media"), > + grid] > + > + def get_select_iso_page(self, screen): > + self.__iso_path = Entry(50, self.__config.get_iso_path()) > + grid = Grid(1, 2) > + grid.setField(Label("Enter ISO path:"), 0, 0, anchorLeft = 1) > + grid.setField(self.__iso_path, 0, 1, anchorLeft = 1) > + return [Label("Enter the full path to an install ISO"), > + grid] > + > + def get_network_install_page(self, screen): > + self.__install_url = Entry(50, self.__config.get_install_url()) > + self.__kickstart_url = Entry(50, self.__config.get_kickstart_url()) > + self.__kernel_options = Entry(50, self.__config.get_kernel_options()) > + grid = Grid(2,3) > + grid.setField(Label("URL:"), 0, 0, anchorRight = 1) > + grid.setField(self.__install_url, 1, 0, anchorLeft = 1) > + grid.setField(Label("Kickstart URL:"), 0, 1, anchorRight = 1) > + grid.setField(self.__kickstart_url, 1, 1, anchorLeft = 1) > + grid.setField(Label("Kernel Options:"), 0, 2, anchorRight = 1) > + grid.setField(self.__kernel_options, 1, 2, anchorLeft = 1) > + return [Label("Provide the operating system URL"), > + grid] > + > + def get_os_type_page(self, screen): > + types = [] > + for type in Guest.list_os_types(): > + types.append([Guest.get_os_type_label(type), type, self.__config.is_os_type(type)]) > + self.__os_types = RadioBar(screen, types) > + grid = Grid(1, 1) > + grid.setField(self.__os_types, 0, 0, anchorLeft = 1) > + return [Label("Choose the operating system type"), > + grid] > + > + def get_os_variant_page(self, screen): > + variants = [] > + type = self.__config.get_os_type() > + for variant in Guest.list_os_variants(type): > + variants.append([Guest.get_os_variant_label(type, variant), variant, self.__config.is_os_variant(variant)]) > + self.__os_variants = RadioBar(screen, variants) > + grid = Grid(1, 1) > + grid.setField(self.__os_variants, 0, 0, anchorLeft = 1) > + return [Label("Choose the operating system version"), > + grid] > + > + def get_ram_and_cpu_page(self, screen): > + self.__memory = Entry(10, str(self.__config.get_memory())) > + self.__cpus = Entry(10, str(self.__config.get_cpus())) > + grid = Grid(2,2) > + grid.setField(Label("Memory (RAM):"), 0, 0, anchorRight = 1) > + grid.setField(self.__memory, 1, 0, anchorLeft = 1) > + grid.setField(Label("CPUs:"), 0, 1, anchorRight = 1) > + grid.setField(self.__cpus, 1, 1, anchorLeft = 1) > + return [Label("Choose memory and CPU settings"), > + grid] > + > + def get_enable_storage_page(self, screen): > + self.__enable_storage = Checkbox("Enable storage for this virtual machine", self.__config.get_enable_storage()) > + self.__storage_type = RadioBar(screen,((["Create a disk image on the computer's hard disk", > + DomainConfig.NEW_STORAGE, > + self.__config.get_use_local_storage()]), > + (["Select managed or other existing storage", > + DomainConfig.EXISTING_STORAGE, > + self.__config.get_use_local_storage() is False]))) > + grid = Grid(1,2) > + grid.setField(self.__enable_storage, 0, 0, anchorLeft = 1) > + grid.setField(self.__storage_type, 0, 1, anchorLeft = 1) > + return [Label("Configure storage"), > + grid] > + > + def get_local_storage_page(self, screen): > + self.__storage_size = Entry(6, str(self.__config.get_storage_size())) > + self.__allocate_storage = Checkbox("Allocate entire disk now", self.__config.get_allocate_storage()) > + grid = Grid(2, 2) > + grid.setField(self.__allocate_storage, 0, 0, growx = 1, anchorLeft = 1) > + grid.setField(Label("Storage size (GB):"), 0, 1, anchorLeft = 1) > + grid.setField(self.__storage_size, 1, 1) > + return [Label("Configure local storage"), > + grid] > + > + def get_managed_storage_page(self, screen): > + volumes = [] > + for volume in self.get_libvirt().list_storage_volumes(): > + volumes.append(["%s (%d GB)" % (volume.name(), volume.info()[1] / (1024 ** 3)), > + volume.name(), > + self.__config.is_existing_storage(volume.name())]) > + self.__existing_storage = RadioBar(screen, (volumes)) > + grid = Grid(2, 1) > + grid.setField(Label("Existing storage:"), 0, 0) > + grid.setField(self.__existing_storage, 1, 0) > + return [Label("Configure managed storage"), > + grid] > + > + def get_bridge_page(self, screen): > + bridges = [] > + for bridge in self.get_libvirt().list_bridges(): > + bridges.append(["Virtual network '%s'" % bridge.name(), bridge.name(), self.__config.get_network_bridge() == bridge.name()]) > + self.__network_bridges = RadioBar(screen, (bridges)) > + if self.__config.get_mac_address() == None: > + self.__config.set_mac_address(self.get_libvirt().generate_mac_address()) > + self.__mac_address = Entry(20, self.__config.get_mac_address()) > + grid = Grid(1, 1) > + grid.setField(self.__network_bridges, 0, 0) > + return [Label("Select an existing bridge"), > + grid] > + > + def get_virt_details_page(self, screen): > + virt_types = [] > + for type in self.get_libvirt().list_virt_types(): > + virt_types.append([type, type, self.__config.is_virt_type(type)]) > + self.__virt_types = RadioBar(screen, (virt_types)) > + archs = [] > + for arch in self.get_libvirt().list_architectures(): > + archs.append([arch, arch, self.__config.is_architecture(arch)]) > + self.__architectures = RadioBar(screen, (archs)) > + grid = Grid(2, 2) > + grid.setField(Label("Virt Type:"), 0, 0, anchorRight = 1, anchorTop = 1) > + grid.setField(self.__virt_types, 1, 0, anchorLeft = 1) > + grid.setField(Label("Architecture:"), 0, 1, anchorRight = 1, anchorTop = 1) > + grid.setField(self.__architectures, 1, 1, anchorLeft = 1) > + return [Label("Configure virtualization details"), > + grid] > + > + def get_confirm_page(self, screen): > + grid = Grid(2, 6) > + grid.setField(Label("OS:"), 0, 0, anchorRight = 1) > + grid.setField(Label(Guest.get_os_variant_label(self.__config.get_os_type(), > + self.__config.get_os_variant())), 1, 0, anchorLeft = 1) > + grid.setField(Label("Install:"), 0, 1, anchorRight = 1) > + grid.setField(Label(self.__config.get_install_type_text()), 1, 1, anchorLeft = 1) > + grid.setField(Label("Memory:"), 0, 2, anchorRight = 1) > + grid.setField(Label("%s MB" % self.__config.get_memory()), 1, 2, anchorLeft = 1) > + grid.setField(Label("CPUs:"), 0, 3, anchorRight = 1) > + grid.setField(Label("%d" % self.__config.get_cpus()), 1, 3, anchorLeft = 1) > + grid.setField(Label("Storage:"), 0, 4, anchorRight = 1) > + grid.setField(Label(self.__config.get_existing_storage()), 1, 4, anchorLeft = 1) > + grid.setField(Label("Network:"), 0, 5, anchorRight = 1) > + grid.setField(Label(self.__config.get_network_bridge()), 1, 5, anchorLeft = 1) > + return [Label("Ready to begin installation of %s" % self.__config.get_guest_name()), > + grid] > + > +def AddDomain(): > + screen = DomainConfigScreen() > + screen.start() > diff --git a/nodeadmin/createdomain.py b/nodeadmin/createdomain.py > deleted file mode 100755 > index 6f10b44..0000000 > --- a/nodeadmin/createdomain.py > +++ /dev/null > @@ -1,65 +0,0 @@ > -#!/usr/bin/env python > -# > -# createdomain.py - Copyright (C) 2009 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 CreateDomainConfigScreen(DomainListConfigScreen): > - LIST_PAGE = 1 > - CREATE_PAGE = 2 > - > - def __init__(self): > - DomainListConfigScreen.__init__(self, "Create A Domain") > - > - def get_elements_for_page(self, screen, page): > - if page is self.LIST_PAGE: > - return self.get_domain_list_page(screen, created = False) > - elif page is self.CREATE_PAGE: > - return self.get_create_domain_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.CREATE_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: > - self.get_libvirt().create_domain(domain) > - return True > - except Exception, error: > - errors.append("There was an error creating the domain: %s" % domain) > - errors.append(str(error)) > - else: > - errors.append("You must first select a domain to create.") > - > - def get_create_domain_page(self, screen): > - grid = Grid(1, 1) > - grid.setField(Label("%s was successfully created." % self.get_selected_domain()), 0, 0) > - return [grid] > - > -def CreateDomain(): > - screen = CreateDomainConfigScreen() > - screen.start() > diff --git a/nodeadmin/definedomain.py b/nodeadmin/definedomain.py > deleted file mode 100755 > index 3fffca2..0000000 > --- a/nodeadmin/definedomain.py > +++ /dev/null > @@ -1,470 +0,0 @@ > -#!/usr/bin/env python > -# > -# definedomain.py - Copyright (C) 2009 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 * > -import os > -from domainconfig import DomainConfig > -from configscreen import ConfigScreen > -import urlgrabber.progress as progress > -import utils > -import logging > - > -from virtinst import * > - > -VM_DETAILS_PAGE = 1 > -LOCAL_INSTALL_PAGE = 2 > -SELECT_CDROM_PAGE = 3 > -SELECT_ISO_PAGE = 4 > -NETWORK_INSTALL_PAGE = 10 > -OS_TYPE_PAGE = 11 > -OS_VARIANT_PAGE = 12 > -RAM_CPU_PAGE = 13 > -ENABLE_STORAGE_PAGE = 14 > -LOCAL_STORAGE_PAGE = 15 > -MANAGED_STORAGE_PAGE = 16 > -BRIDGE_PAGE = 17 > -VIRT_DETAILS_PAGE = 18 > -CONFIRM_PAGE = 19 > - > -LOCATION="location" > -KICKSTART="kickstart" > -KERNELOPTS="kernel.options" > -OS_TYPE="os.type" > -OS_VARIANT="os.variant" > -MEMORY="memory" > -CPUS="cpus" > - > -class DummyMeter(progress.BaseMeter): > - def _do_start(self, now = None): > - logging.info("Starting...") > - > - def _do_end(self, amount_read, now = None): > - logging.info("Ending: read=%d" % amount_read) > - > - def _do_update(self, amount_read, now = None): > - logging.info("Update: read=%d" % amount_read) > - > -class DomainConfigScreen(ConfigScreen): > - def __init__(self): > - ConfigScreen.__init__(self, "Create A New Virtual Machine") > - self.__config = DomainConfig() > - self.__config.set_architecture(self.get_libvirt().get_default_architecture()) > - self.__config.set_virt_type(self.get_libvirt().get_default_virt_type()) > - > - def get_elements_for_page(self, screen, page): > - if page == VM_DETAILS_PAGE: return self.get_vm_details_page(screen) > - elif page == LOCAL_INSTALL_PAGE: return self.get_local_install_page(screen) > - elif page == SELECT_CDROM_PAGE: return self.get_select_cdrom_page(screen) > - elif page == SELECT_ISO_PAGE: return self.get_select_iso_page(screen) > - elif page == NETWORK_INSTALL_PAGE: return self.get_network_install_page(screen) > - elif page == OS_TYPE_PAGE: return self.get_os_type_page(screen) > - elif page == OS_VARIANT_PAGE: return self.get_os_variant_page(screen) > - elif page == RAM_CPU_PAGE: return self.get_ram_and_cpu_page(screen) > - elif page == ENABLE_STORAGE_PAGE: return self.get_enable_storage_page(screen) > - elif page == LOCAL_STORAGE_PAGE: return self.get_local_storage_page(screen) > - elif page == MANAGED_STORAGE_PAGE: return self.get_managed_storage_page(screen) > - elif page == BRIDGE_PAGE: return self.get_bridge_page(screen) > - elif page == VIRT_DETAILS_PAGE: return self.get_virt_details_page(screen) > - elif page == CONFIRM_PAGE: return self.get_confirm_page(screen) > - return [] > - > - def validate_input(self, page, errors): > - if page == VM_DETAILS_PAGE: > - if len(self.__guest_name.value()) > 0: > - if self.get_libvirt().domain_exists(self.__guest_name.value()): > - errors.append("Guest name '%s' is already in use." % self.__guest_name.value()) > - else: > - return True > - else: > - errors.append("Guest name must be a string between 0 and 50 characters.") > - elif page == LOCAL_INSTALL_PAGE: > - if self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM: > - return True > - elif self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_ISO: > - return True > - elif page == SELECT_CDROM_PAGE: > - if self.__install_media.getSelection() != None: > - if len(self.get_hal().list_installable_volumes()) == 0: > - errors.append("No installable media is available.") > - else: > - return True > - else: > - errors.append("You must select an install media.") > - elif page == SELECT_ISO_PAGE: > - if len(self.__iso_path.value()) > 0: > - if os.path.exists(self.__iso_path.value()): > - if os.path.isfile(self.__iso_path.value()): > - return True > - else: > - errors.append("%s is not a file." % self.__iso_path.value()) > - else: > - errors.append("No such install media exists:") > - errors.append(self.__iso_path.value()) > - else: > - errors.append("An install media selection is required.") > - elif page == NETWORK_INSTALL_PAGE: > - if len(self.__install_url.value()) > 0: > - return True > - else: > - errors.append("An install tree is required.") > - elif page == OS_TYPE_PAGE: return True > - elif page == OS_VARIANT_PAGE: return True > - elif page == RAM_CPU_PAGE: > - if (len(self.__memory.value()) > 0 and len(self.__cpus.value()) > 0) \ > - and (int(self.__memory.value()) > 0 and int(self.__cpus.value()) > 0): > - return True > - else: > - if len(self.__memory.value()) == 0: > - errors.append("A value must be entered for memory.") > - elif int(self.__memory.value()) <= 0: > - errors.append("A positive integer value must be entered for memory.") > - if len(self.__cpus.value()) == 0: > - errors.append("A value must be entered for CPUs.") > - elif int(self.__cpus.value()) <= 0: > - errors.append("A positive integer value must be entered for memory.") > - elif page == ENABLE_STORAGE_PAGE: return True > - elif page == LOCAL_STORAGE_PAGE: > - if len(self.__storage_size.value()) > 0: > - if float(self.__storage_size.value()) > 0: > - return True > - else: > - errors.append("A positive value must be entered for the storage size.") > - else: > - errors.append("A value must be entered for the storage size.") > - elif page == MANAGED_STORAGE_PAGE: > - if self.__existing_storage.getSelection() is not None: > - return True > - else: > - errors.append("Please select a storage volume.") > - elif page == BRIDGE_PAGE: > - if self.__network_bridges.getSelection() != None: > - if len(self.__mac_address.value()) > 0: > - # TODO: regex check the format > - return True > - else: > - errors.append("MAC address must be supplied.") > - else: > - errors.append("A network bridge must be selected.") > - elif page == VIRT_DETAILS_PAGE: > - if self.__virt_types.getSelection() != None and self.__architectures.getSelection() != None: > - return True > - if self.__virt_types.getSelection() is None: > - errors.append("Please select a virtualization type.") > - if self.__architectures.getSelection() is None: > - errors.append("Please selection an architecture.") > - elif page == CONFIRM_PAGE: return True > - return False > - > - def process_input(self, page): > - if page == VM_DETAILS_PAGE: > - self.__config.set_guest_name(self.__guest_name.value()) > - self.__config.set_install_type(self.__install_type.getSelection()) > - elif page == LOCAL_INSTALL_PAGE: > - self.__config.set_use_cdrom_source(self.__install_source.getSelection() == DomainConfig.INSTALL_SOURCE_CDROM) > - elif page == SELECT_CDROM_PAGE: > - self.__config.set_install_media(self.__install_media.getSelection()) > - elif page == SELECT_ISO_PAGE: > - self.__config.set_iso_path(self.__iso_path.value()) > - elif page == NETWORK_INSTALL_PAGE: > - self.__config.set_install_url(self.__install_url.value()) > - self.__config.set_kickstart_url(self.__kickstart_url.value()) > - self.__config.set_kernel_options(self.__kernel_options.value()) > - elif page == OS_TYPE_PAGE: > - self.__config.set_os_type(self.__os_types.getSelection()) > - elif page == OS_VARIANT_PAGE: > - self.__config.set_os_variant(self.__os_variants.getSelection()) > - elif page == RAM_CPU_PAGE: > - self.__config.set_memory(int(self.__memory.value())) > - self.__config.set_cpus(int(self.__cpus.value())) > - elif page == ENABLE_STORAGE_PAGE: > - self.__config.set_enable_storage(self.__enable_storage.value()) > - if self.__storage_type.getSelection() == DomainConfig.NEW_STORAGE: > - self.__config.set_use_local_storage(True) > - elif self.__storage_type.getSelection() == DomainConfig.EXISTING_STORAGE: > - self.__config.set_use_local_storage(False) > - elif page == LOCAL_STORAGE_PAGE: > - self.__config.set_storage_size(float(self.__storage_size.value())) > - self.__config.set_allocate_storage(self.__allocate_storage.value()) > - elif page == MANAGED_STORAGE_PAGE: > - self.__config.set_use_local_storage(False) > - self.__config.set_existing_storage(self.__existing_storage.getSelection()) > - self.__config.set_storage_size(self.get_libvirt().get_storage_size(self.__existing_storage.getSelection())) > - elif page == BRIDGE_PAGE: > - self.__config.set_network_bridge(self.__network_bridges.getSelection()) > - elif page == VIRT_DETAILS_PAGE: > - self.__config.set_virt_type(self.__virt_types.getSelection()) > - self.__config.set_architecture(self.__architectures.getSelection()) > - elif page == CONFIRM_PAGE: > - self.get_libvirt().define_domain(self.__config, DummyMeter()) > - self.set_finished() > - > - def get_back_page(self, page): > - result = page > - if page == OS_TYPE_PAGE: > - install_type = self.__config.get_install_type() > - if install_type == DomainConfig.LOCAL_INSTALL: > - if self.__config.get_use_cdrom_source(): > - result = SELECT_CDROM_PAGE > - else: > - result = SELECT_ISO_PAGE > - elif install_type == DomainConfig.NETWORK_INSTALL: > - result = NETWORK_INSTALL_PAGE > - elif install_type == DomainConfig.PXE_INSTALL: > - result = VM_DETAILS_PAGE > - elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: > - result = ENABLE_STORAGE_PAGE > - elif page == NETWORK_INSTALL_PAGE: > - result = VM_DETAILS_PAGE > - elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: > - result = LOCAL_INSTALL_PAGE > - elif page == BRIDGE_PAGE: > - if self.__config.get_use_local_storage(): > - result = LOCAL_STORAGE_PAGE > - else: > - result = MANAGED_STORAGE_PAGE > - else: > - if page > 1: result = page - 1 > - return result > - > - def get_next_page(self, page): > - result = page > - if page == VM_DETAILS_PAGE: > - install_type = self.__config.get_install_type() > - if install_type == DomainConfig.LOCAL_INSTALL: > - result = LOCAL_INSTALL_PAGE > - elif install_type == DomainConfig.NETWORK_INSTALL: > - result = NETWORK_INSTALL_PAGE > - elif install_type == DomainConfig.PXE_INSTALL: > - result = OS_TYPE_PAGE > - elif page == LOCAL_INSTALL_PAGE: > - if self.__config.get_use_cdrom_source(): > - result = SELECT_CDROM_PAGE > - else: > - result = SELECT_ISO_PAGE > - elif page == SELECT_CDROM_PAGE or page == SELECT_ISO_PAGE: > - result = OS_TYPE_PAGE > - elif page == NETWORK_INSTALL_PAGE: > - result = OS_TYPE_PAGE > - elif page == ENABLE_STORAGE_PAGE: > - result = BRIDGE_PAGE > - if self.__config.get_enable_storage(): > - if self.__config.get_use_local_storage(): > - result = LOCAL_STORAGE_PAGE > - else: > - result = MANAGED_STORAGE_PAGE > - elif page == LOCAL_STORAGE_PAGE or page == MANAGED_STORAGE_PAGE: > - result = BRIDGE_PAGE > - else: > - result = page + 1 > - return result > - > - def page_has_finish(self, page): > - if page == CONFIRM_PAGE: return True > - return False > - > - def page_has_next(self, page): > - if page < CONFIRM_PAGE: > - return True > - > - def get_vm_details_page(self, screen): > - self.__guest_name = Entry(50, self.__config.get_guest_name()) > - self.__install_type = RadioBar(screen, (("Local install media (ISO image or CDROM)", > - DomainConfig.LOCAL_INSTALL, > - self.__config.is_install_type(DomainConfig.LOCAL_INSTALL)), > - ("Network Install (HTTP, FTP, or NFS)", > - DomainConfig.NETWORK_INSTALL, > - self.__config.is_install_type(DomainConfig.NETWORK_INSTALL)), > - ("Network Boot (PXE)", > - DomainConfig.PXE_INSTALL, > - self.__config.is_install_type(DomainConfig.PXE_INSTALL)))) > - grid = Grid(2,3) > - grid.setField(Label("Name:"), 0, 0, anchorRight = 1) > - grid.setField(self.__guest_name, 1, 0, anchorLeft = 1) > - grid.setField(Label("Choose how you would like to install the operating system"), 1, 1, > - anchorLeft = 1, anchorTop = 1) > - grid.setField(self.__install_type, 1, 2, anchorLeft = 1) > - return [Label("Enter your machine details"), > - grid] > - > - def get_local_install_page(self, screen): > - self.__install_source = RadioBar(screen, (("Use CDROM or DVD", > - DomainConfig.INSTALL_SOURCE_CDROM, > - self.__config.get_use_cdrom_source()), > - ("Use ISO image", > - DomainConfig.INSTALL_SOURCE_ISO, > - self.__config.get_use_cdrom_source() is False))) > - grid = Grid(1,1) > - grid.setField(self.__install_source, 0, 0, anchorLeft = 1) > - return [Label("Locate your install media"), > - grid] > - > - def get_select_cdrom_page(self, screen): > - drives = [] > - media = self.get_hal().list_installable_volumes() > - for drive in media.keys(): > - drives.append([media[drive], drive, self.__config.is_install_media(drive)]) > - self.__install_media = RadioBar(screen, (drives)) > - grid = Grid(1, 1) > - grid.setField(self.__install_media, 0, 0) > - return [Label("Select the install media"), > - grid] > - > - def get_select_iso_page(self, screen): > - self.__iso_path = Entry(50, self.__config.get_iso_path()) > - grid = Grid(1, 2) > - grid.setField(Label("Enter ISO path:"), 0, 0, anchorLeft = 1) > - grid.setField(self.__iso_path, 0, 1, anchorLeft = 1) > - return [Label("Enter the full path to an install ISO"), > - grid] > - > - def get_network_install_page(self, screen): > - self.__install_url = Entry(50, self.__config.get_install_url()) > - self.__kickstart_url = Entry(50, self.__config.get_kickstart_url()) > - self.__kernel_options = Entry(50, self.__config.get_kernel_options()) > - grid = Grid(2,3) > - grid.setField(Label("URL:"), 0, 0, anchorRight = 1) > - grid.setField(self.__install_url, 1, 0, anchorLeft = 1) > - grid.setField(Label("Kickstart URL:"), 0, 1, anchorRight = 1) > - grid.setField(self.__kickstart_url, 1, 1, anchorLeft = 1) > - grid.setField(Label("Kernel Options:"), 0, 2, anchorRight = 1) > - grid.setField(self.__kernel_options, 1, 2, anchorLeft = 1) > - return [Label("Provide the operating system URL"), > - grid] > - > - def get_os_type_page(self, screen): > - types = [] > - for type in Guest.list_os_types(): > - types.append([Guest.get_os_type_label(type), type, self.__config.is_os_type(type)]) > - self.__os_types = RadioBar(screen, types) > - grid = Grid(1, 1) > - grid.setField(self.__os_types, 0, 0, anchorLeft = 1) > - return [Label("Choose the operating system type"), > - grid] > - > - def get_os_variant_page(self, screen): > - variants = [] > - type = self.__config.get_os_type() > - for variant in Guest.list_os_variants(type): > - variants.append([Guest.get_os_variant_label(type, variant), variant, self.__config.is_os_variant(variant)]) > - self.__os_variants = RadioBar(screen, variants) > - grid = Grid(1, 1) > - grid.setField(self.__os_variants, 0, 0, anchorLeft = 1) > - return [Label("Choose the operating system version"), > - grid] > - > - def get_ram_and_cpu_page(self, screen): > - self.__memory = Entry(10, str(self.__config.get_memory())) > - self.__cpus = Entry(10, str(self.__config.get_cpus())) > - grid = Grid(2,2) > - grid.setField(Label("Memory (RAM):"), 0, 0, anchorRight = 1) > - grid.setField(self.__memory, 1, 0, anchorLeft = 1) > - grid.setField(Label("CPUs:"), 0, 1, anchorRight = 1) > - grid.setField(self.__cpus, 1, 1, anchorLeft = 1) > - return [Label("Choose memory and CPU settings"), > - grid] > - > - def get_enable_storage_page(self, screen): > - self.__enable_storage = Checkbox("Enable storage for this virtual machine", self.__config.get_enable_storage()) > - self.__storage_type = RadioBar(screen,((["Create a disk image on the computer's hard disk", > - DomainConfig.NEW_STORAGE, > - self.__config.get_use_local_storage()]), > - (["Select managed or other existing storage", > - DomainConfig.EXISTING_STORAGE, > - self.__config.get_use_local_storage() is False]))) > - grid = Grid(1,2) > - grid.setField(self.__enable_storage, 0, 0, anchorLeft = 1) > - grid.setField(self.__storage_type, 0, 1, anchorLeft = 1) > - return [Label("Configure storage"), > - grid] > - > - def get_local_storage_page(self, screen): > - self.__storage_size = Entry(6, str(self.__config.get_storage_size())) > - self.__allocate_storage = Checkbox("Allocate entire disk now", self.__config.get_allocate_storage()) > - grid = Grid(2, 2) > - grid.setField(self.__allocate_storage, 0, 0, growx = 1, anchorLeft = 1) > - grid.setField(Label("Storage size (GB):"), 0, 1, anchorLeft = 1) > - grid.setField(self.__storage_size, 1, 1) > - return [Label("Configure local storage"), > - grid] > - > - def get_managed_storage_page(self, screen): > - volumes = [] > - for volume in self.get_libvirt().list_storage_volumes(): > - volumes.append(["%s (%d GB)" % (volume.name(), volume.info()[1] / (1024 ** 3)), > - volume.name(), > - self.__config.is_existing_storage(volume.name())]) > - self.__existing_storage = RadioBar(screen, (volumes)) > - grid = Grid(2, 1) > - grid.setField(Label("Existing storage:"), 0, 0) > - grid.setField(self.__existing_storage, 1, 0) > - return [Label("Configure managed storage"), > - grid] > - > - def get_bridge_page(self, screen): > - bridges = [] > - for bridge in self.get_libvirt().list_bridges(): > - bridges.append(["Virtual network '%s'" % bridge.name(), bridge.name(), self.__config.get_network_bridge() == bridge.name()]) > - self.__network_bridges = RadioBar(screen, (bridges)) > - if self.__config.get_mac_address() == None: > - self.__config.set_mac_address(self.get_libvirt().generate_mac_address()) > - self.__mac_address = Entry(20, self.__config.get_mac_address()) > - grid = Grid(1, 1) > - grid.setField(self.__network_bridges, 0, 0) > - return [Label("Select an existing bridge"), > - grid] > - > - def get_virt_details_page(self, screen): > - virt_types = [] > - for type in self.get_libvirt().list_virt_types(): > - virt_types.append([type, type, self.__config.is_virt_type(type)]) > - self.__virt_types = RadioBar(screen, (virt_types)) > - archs = [] > - for arch in self.get_libvirt().list_architectures(): > - archs.append([arch, arch, self.__config.is_architecture(arch)]) > - self.__architectures = RadioBar(screen, (archs)) > - grid = Grid(2, 2) > - grid.setField(Label("Virt Type:"), 0, 0, anchorRight = 1, anchorTop = 1) > - grid.setField(self.__virt_types, 1, 0, anchorLeft = 1) > - grid.setField(Label("Architecture:"), 0, 1, anchorRight = 1, anchorTop = 1) > - grid.setField(self.__architectures, 1, 1, anchorLeft = 1) > - return [Label("Configure virtualization details"), > - grid] > - > - def get_confirm_page(self, screen): > - grid = Grid(2, 6) > - grid.setField(Label("OS:"), 0, 0, anchorRight = 1) > - grid.setField(Label(Guest.get_os_variant_label(self.__config.get_os_type(), > - self.__config.get_os_variant())), 1, 0, anchorLeft = 1) > - grid.setField(Label("Install:"), 0, 1, anchorRight = 1) > - grid.setField(Label(self.__config.get_install_type_text()), 1, 1, anchorLeft = 1) > - grid.setField(Label("Memory:"), 0, 2, anchorRight = 1) > - grid.setField(Label("%s MB" % self.__config.get_memory()), 1, 2, anchorLeft = 1) > - grid.setField(Label("CPUs:"), 0, 3, anchorRight = 1) > - grid.setField(Label("%d" % self.__config.get_cpus()), 1, 3, anchorLeft = 1) > - grid.setField(Label("Storage:"), 0, 4, anchorRight = 1) > - grid.setField(Label(self.__config.get_existing_storage()), 1, 4, anchorLeft = 1) > - grid.setField(Label("Network:"), 0, 5, anchorRight = 1) > - grid.setField(Label(self.__config.get_network_bridge()), 1, 5, anchorLeft = 1) > - return [Label("Ready to begin installation of %s" % self.__config.get_guest_name()), > - grid] > - > -def DefineDomain(): > - screen = DomainConfigScreen() > - screen.start() > diff --git a/nodeadmin/destroydomain.py b/nodeadmin/destroydomain.py > deleted file mode 100755 > index 350c32e..0000000 > --- a/nodeadmin/destroydomain.py > +++ /dev/null > @@ -1,66 +0,0 @@ > -#!/usr/bin/env python > -# > -# destroydomain.py - Copyright (C) 2009 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 DestroyDomainConfigScreen(DomainListConfigScreen): > - LIST_PAGE = 1 > - DESTROY_PAGE = 2 > - > - def __init__(self): > - DomainListConfigScreen.__init__(self, "Destroy 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.DESTROY_PAGE: > - return self.get_destroy_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.DESTROY_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: > - self.get_libvirt().destroy_domain(domain) > - return True > - except Exception, error: > - errors.append("There was an error destroy the domain: %s" % domain) > - errors.append(str(error)) > - else: > - errors.append("You must first select a domain to destroy.") > - return False > - > - def get_destroy_page(self, screen): > - grid = Grid(1, 1) > - grid.setField(Label("%s was successfully destroyed." % self.get_selected_domain()), 0, 0) > - return [grid] > - > -def DestroyDomain(): > - screen = DestroyDomainConfigScreen() > - screen.start() > diff --git a/nodeadmin/listdomains.py b/nodeadmin/listdomains.py > index 1b51ee2..7468bcf 100755 > --- a/nodeadmin/listdomains.py > +++ b/nodeadmin/listdomains.py > @@ -27,7 +27,7 @@ class ListDomainsConfigScreen(DomainListConfigScreen): > DETAIL_PAGE = 2 > > def __init__(self): > - DomainListConfigScreen.__init__(self, 'List Domains') > + DomainListConfigScreen.__init__(self, 'List Virtual Machines') > > def page_has_next(self, page): > return (page == self.LIST_PAGE) > @@ -38,7 +38,7 @@ class ListDomainsConfigScreen(DomainListConfigScreen): > def validate_input(self, page, errors): > if page == self.LIST_PAGE: > if self.get_selected_domain() is None: > - errors.append("Please select a domain to view.") > + errors.append("Please select a virtual machine to view.") > else: > return True > > diff --git a/nodeadmin/nodemenu.py b/nodeadmin/nodemenu.py > index 9e339ff..0503b2e 100755 > --- a/nodeadmin/nodemenu.py > +++ b/nodeadmin/nodemenu.py > @@ -21,42 +21,42 @@ import traceback > > from menuscreen import MenuScreen > from configscreen import ConfigScreen > -from definedomain import DefineDomain > +from adddomain import AddDomain > from createdomain import CreateDomain > -from destroydomain import DestroyDomain > -from undefinedomain import UndefineDomain > +from stopdomain import StopDomain > +from removedomain import RemoveDomain > from listdomains import ListDomains > from createuser import CreateUser > > import utils > import logging > > -DEFINE_DOMAIN = 1 > -CREATE_DOMAIN = 2 > -DESTROY_DOMAIN = 3 > -UNDEFINE_DOMAIN = 4 > -LIST_DOMAINS = 5 > -CREATE_USER = 6 > +ADD_DOMAIN = 1 > +CREATE_DOMAIN = 2 > +STOP_DOMAIN = 3 > +REMOVE_DOMAIN = 4 > +LIST_DOMAINS = 5 > +CREATE_USER = 6 > > class NodeMenuScreen(MenuScreen): > def __init__(self): > MenuScreen.__init__(self, "Node Administration") > > def get_menu_items(self): > - return (("Define A Domain", DEFINE_DOMAIN), > - ("Create A Domain", CREATE_DOMAIN), > - ("Destroy A Domain", DESTROY_DOMAIN), > - ("Undefine A Domain", UNDEFINE_DOMAIN), > - ("List All Domains", LIST_DOMAINS), > - ("Create A User", CREATE_USER)) > + return (("Add A Virtual Machine", ADD_DOMAIN), > + ("Create A Virtual Machine", CREATE_DOMAIN), > + ("Stop A Virtual Machine", STOP_DOMAIN), > + ("Remove A Virtual Machine", REMOVE_DOMAIN), > + ("List All Virtual Machines", LIST_DOMAINS), > + ("Create A User", CREATE_USER)) > > def handle_selection(self, item): > - if item is DEFINE_DOMAIN: DefineDomain() > - elif item is CREATE_DOMAIN: CreateDomain() > - elif item is DESTROY_DOMAIN: DestroyDomain() > - elif item is UNDEFINE_DOMAIN: UndefineDomain() > - elif item is LIST_DOMAINS: ListDomains() > - elif item is CREATE_USER: CreateUser() > + if item is ADD_DOMAIN: AddDomain() > + elif item is CREATE_DOMAIN: CreateDomain() > + elif item is STOP_DOMAIN: StopDomain() > + elif item is REMOVE_DOMAIN: RemoveDomain() > + elif item is LIST_DOMAINS: ListDomains() > + elif item is CREATE_USER: CreateUser() > > def NodeMenu(): > screen = NodeMenuScreen() > diff --git a/nodeadmin/removedomain.py b/nodeadmin/removedomain.py > new file mode 100755 > index 0000000..4e31428 > --- /dev/null > +++ b/nodeadmin/removedomain.py > @@ -0,0 +1,83 @@ > +#!/usr/bin/env python > +# > +# removedomain.py - Copyright (C) 2009 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 RemoveDomainConfigScreen(DomainListConfigScreen): > + LIST_PAGE = 1 > + CONFIRM_PAGE = 2 > + REMOVE_PAGE = 3 > + > + def __init__(self): > + DomainListConfigScreen.__init__(self, "Remove A Domain") > + > + def get_elements_for_page(self, screen, page): > + if page is self.LIST_PAGE: return self.get_domain_list_page(screen) > + elif page is self.CONFIRM_PAGE: return self.get_confirm_page(screen) > + elif page is self.REMOVE_PAGE: return self.get_remove_page(screen) > + > + def page_has_next(self, page): > + if page is self.LIST_PAGE: return self.has_selectable_domains() > + elif page is self.CONFIRM_PAGE: return True > + return False > + > + def page_has_back(self, page): > + if page is self.CONFIRM_PAGE: return True > + elif page is self.REMOVE_PAGE: return True > + return False > + > + def get_back_page(self, page): > + if page is self.CONFIRM_PAGE: return self.LIST_PAGE > + elif page is self.REMOVE_PAGE: return self.LIST_PAGE > + > + def validate_input(self, page, errors): > + if page is self.LIST_PAGE: > + if self.get_selected_domain() is not None: > + return True > + else: > + errors.append("You must first select a domain.") > + elif page is self.CONFIRM_PAGE: > + if self.__confirm_remove.value(): > + domain = self.get_selected_domain() > + try: > + self.get_libvirt().remove_domain(domain) > + return True > + except Exception, error: > + errors.append("Failed to remove %s." % domain) > + errors.append(str(error)) > + else: > + errors.append("You must confirm undefining the domain to proceed.") > + return False > + > + def get_confirm_page(self, screen): > + self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 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) > + return [grid] > + > +def RemoveDomain(): > + screen = RemoveDomainConfigScreen() > + screen.start() > diff --git a/nodeadmin/setup.py.in b/nodeadmin/setup.py.in > index 3635810..1e6e028 100644 > --- a/nodeadmin/setup.py.in > +++ b/nodeadmin/setup.py.in > @@ -25,12 +25,12 @@ setup(name = "nodeadmin", > entry_points = { > 'console_scripts': [ > 'nodeadmin = nodeadmin.nodeadmin:NodeAdmin', > - 'definedom = nodeadmin.definedomain:DefineDomain', > - 'createdom = nodeadmin.createdomain:CreateDomain', > - 'destroydom = nodeadmin.destroydomain:DestroyDomain', > - 'undefinedom = nodeadmin.undefinedomain:UndefineDomain', > + 'addvm = nodeadmin.adddomain:AddDomain', > + 'startvm = nodeadmin.startdomain:StartDomain', > + 'stopvm = nodeadmin.stopdomain:StopDomain', > + 'rmvm = nodeadmin.removedomain:RemoveDomain', > 'createuser = nodeadmin.createuser:CreateUser', > - 'listdoms = nodeadmin.listdomains:ListDomains', > + 'listvms = nodeadmin.listdomains:ListDomains', > 'definenet = nodeadmin.definenet:DefineNetwork', > 'createnet = nodeadmin.createnetwork:CreateNetwork', > 'destroynet = nodeadmin.destroynetwork:DestroyNetwork', > diff --git a/nodeadmin/startdomain.py b/nodeadmin/startdomain.py > new file mode 100755 > index 0000000..082ac0d > --- /dev/null > +++ b/nodeadmin/startdomain.py > @@ -0,0 +1,65 @@ > +#!/usr/bin/env python > +# > +# startdomain.py - Copyright (C) 2009 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 StartDomainConfigScreen(DomainListConfigScreen): > + LIST_PAGE = 1 > + START_PAGE = 2 > + > + def __init__(self): > + DomainListConfigScreen.__init__(self, "Start A Domain") > + > + def get_elements_for_page(self, screen, page): > + if page is self.LIST_PAGE: > + return self.get_domain_list_page(screen, started = False) > + elif page is self.START_PAGE: > + return self.get_start_domain_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.START_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: > + self.get_libvirt().start_domain(domain) > + return True > + except Exception, error: > + errors.append("There was an error creating the domain: %s" % domain) > + errors.append(str(error)) > + else: > + errors.append("You must first select a domain to start.") > + > + def get_start_domain_page(self, screen): > + grid = Grid(1, 1) > + grid.setField(Label("%s was successfully started." % self.get_selected_domain()), 0, 0) > + return [grid] > + > +def StartDomain(): > + screen = StartDomainConfigScreen() > + screen.start() > diff --git a/nodeadmin/stopdomain.py b/nodeadmin/stopdomain.py > new file mode 100755 > index 0000000..3ddd681 > --- /dev/null > +++ b/nodeadmin/stopdomain.py > @@ -0,0 +1,66 @@ > +#!/usr/bin/env python > +# > +# stopdomain.py - Copyright (C) 2009 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 StopDomainConfigScreen(DomainListConfigScreen): > + LIST_PAGE = 1 > + STOP_PAGE = 2 > + > + def __init__(self): > + DomainListConfigScreen.__init__(self, "Stop 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: > + self.get_libvirt().stop_domain(domain) > + return True > + except Exception, error: > + errors.append("There was an error stop 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 stoped." % self.get_selected_domain()), 0, 0) > + return [grid] > + > +def StopDomain(): > + screen = StopDomainConfigScreen() > + screen.start() > diff --git a/nodeadmin/undefinedomain.py b/nodeadmin/undefinedomain.py > deleted file mode 100755 > index 2620540..0000000 > --- a/nodeadmin/undefinedomain.py > +++ /dev/null > @@ -1,83 +0,0 @@ > -#!/usr/bin/env python > -# > -# undefinedomain.py - Copyright (C) 2009 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 UndefineDomainConfigScreen(DomainListConfigScreen): > - LIST_PAGE = 1 > - CONFIRM_PAGE = 2 > - UNDEFINE_PAGE = 3 > - > - def __init__(self): > - DomainListConfigScreen.__init__(self, "Undefine A Domain") > - > - def get_elements_for_page(self, screen, page): > - if page is self.LIST_PAGE: return self.get_domain_list_page(screen) > - elif page is self.CONFIRM_PAGE: return self.get_confirm_page(screen) > - elif page is self.UNDEFINE_PAGE: return self.get_undefine_page(screen) > - > - def page_has_next(self, page): > - if page is self.LIST_PAGE: return self.has_selectable_domains() > - elif page is self.CONFIRM_PAGE: return True > - return False > - > - def page_has_back(self, page): > - if page is self.CONFIRM_PAGE: return True > - elif page is self.UNDEFINE_PAGE: return True > - return False > - > - def get_back_page(self, page): > - if page is self.CONFIRM_PAGE: return self.LIST_PAGE > - elif page is self.UNDEFINE_PAGE: return self.LIST_PAGE > - > - def validate_input(self, page, errors): > - if page is self.LIST_PAGE: > - if self.get_selected_domain() is not None: > - return True > - else: > - errors.append("You must first select a domain.") > - elif page is self.CONFIRM_PAGE: > - if self.__confirm_undefine.value(): > - domain = self.get_selected_domain() > - try: > - self.get_libvirt().undefine_domain(domain) > - return True > - except Exception, error: > - errors.append("Failed to undefine %s." % domain) > - errors.append(str(error)) > - else: > - errors.append("You must confirm undefining the domain to proceed.") > - return False > - > - def get_confirm_page(self, screen): > - self.__confirm_undefine = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 0) > - grid = Grid(1, 1) > - grid.setField(self.__confirm_undefine, 0, 0) > - return [grid] > - > - def get_undefine_page(self, screen): > - grid = Grid(1, 1) > - grid.setField(Label("%s has been undefined." % self.get_selected_domain()), 0, 0) > - return [grid] > - > -def UndefineDomain(): > - screen = UndefineDomainConfigScreen() > - screen.start() > diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in > index 2a6b7b6..49f41cb 100644 > --- a/ovirt-node.spec.in > +++ b/ovirt-node.spec.in > @@ -183,10 +183,10 @@ cd - > %{__install} -p -m0644 nodeadmin/mainmenu.py %{buildroot}%{python_sitelib}/nodeadmin > > %{__install} -p -m0644 nodeadmin/nodemenu.py %{buildroot}%{python_sitelib}/nodeadmin > -%{__install} -p -m0755 nodeadmin/definedomain.py %{buildroot}%{python_sitelib}/nodeadmin > -%{__install} -p -m0755 nodeadmin/createdomain.py %{buildroot}%{python_sitelib}/nodeadmin > -%{__install} -p -m0755 nodeadmin/destroydomain.py %{buildroot}%{python_sitelib}/nodeadmin > -%{__install} -p -m0755 nodeadmin/undefinedomain.py %{buildroot}%{python_sitelib}/nodeadmin > +%{__install} -p -m0755 nodeadmin/adddomain.py %{buildroot}%{python_sitelib}/nodeadmin > +%{__install} -p -m0755 nodeadmin/startdomain.py %{buildroot}%{python_sitelib}/nodeadmin > +%{__install} -p -m0755 nodeadmin/stopdomain.py %{buildroot}%{python_sitelib}/nodeadmin > +%{__install} -p -m0755 nodeadmin/removedomain.py %{buildroot}%{python_sitelib}/nodeadmin > %{__install} -p -m0755 nodeadmin/listdomains.py %{buildroot}%{python_sitelib}/nodeadmin > %{__install} -p -m0644 nodeadmin/domainconfig.py %{buildroot}%{python_sitelib}/nodeadmin > > @@ -369,11 +369,11 @@ fi > %{_initrddir}/ovirt-functions > %defattr(-,root,root,0644) > %{_bindir}/nodeadmin > -%{_bindir}/definedom > -%{_bindir}/createdom > -%{_bindir}/destroydom > -%{_bindir}/undefinedom > -%{_bindir}/listdoms > +%{_bindir}/addvm > +%{_bindir}/startvm > +%{_bindir}/stopvm > +%{_bindir}/rmvm > +%{_bindir}/listvms > %{_bindir}/definenet > %{_bindir}/createnet > %{_bindir}/destroynet >ACK, pending below changes CreateDomain -> StartDomain nodeadmin/nodemenu.py:from createdomain import CreateDomain nodeadmin/nodemenu.py: elif item is CREATE_DOMAIN: CreateDomain()