tui: Remove trailing \r

This commit is contained in:
Cole Robinson 2011-05-03 14:57:35 -04:00
parent 85e90b92fd
commit f0fad087d5
42 changed files with 4379 additions and 4379 deletions

View File

@ -1,19 +1,19 @@
# __init__.py - Copyright (C) 2009 Red Hat, Inc. # __init__.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from nodeadmin import NodeAdmin from nodeadmin import NodeAdmin

File diff suppressed because it is too large Load Diff

View File

@ -1,135 +1,135 @@
# addhost.py - Copyright (C) 2009 Red Hat, Inc. # addhost.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
DETAILS_PAGE = 1 DETAILS_PAGE = 1
CONFIRM_PAGE = 2 CONFIRM_PAGE = 2
HYPERVISOR_XEN = "xen" HYPERVISOR_XEN = "xen"
HYPERVISOR_KVM = "kvm" HYPERVISOR_KVM = "kvm"
HYPERVISORS = {HYPERVISOR_XEN : "Xen", HYPERVISORS = {HYPERVISOR_XEN : "Xen",
HYPERVISOR_KVM : "QEMU/KVM"} HYPERVISOR_KVM : "QEMU/KVM"}
CONNECTION_LOCAL = "local" CONNECTION_LOCAL = "local"
CONNECTION_KERBEROS = "kerberos" CONNECTION_KERBEROS = "kerberos"
CONNECTION_SSL = "ssl" CONNECTION_SSL = "ssl"
CONNECTION_SSH = "ssh" CONNECTION_SSH = "ssh"
CONNECTIONS = {CONNECTION_LOCAL : "Local", CONNECTIONS = {CONNECTION_LOCAL : "Local",
CONNECTION_KERBEROS : "Remote Password or Kerberos", CONNECTION_KERBEROS : "Remote Password or Kerberos",
CONNECTION_SSL : "Remote SSL/TLS with x509 certificate", CONNECTION_SSL : "Remote SSL/TLS with x509 certificate",
CONNECTION_SSH : "Remote tunnel over SSH"} CONNECTION_SSH : "Remote tunnel over SSH"}
class AddHostConfigScreen(ConfigScreen): class AddHostConfigScreen(ConfigScreen):
def __init__(self): def __init__(self):
ConfigScreen.__init__(self, "Add A Remote Host") ConfigScreen.__init__(self, "Add A Remote Host")
self.__configured = False self.__configured = False
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is DETAILS_PAGE: return self.get_details_page(screen) if page is DETAILS_PAGE: return self.get_details_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page < CONFIRM_PAGE return page < CONFIRM_PAGE
def page_has_back(self, page): def page_has_back(self, page):
return page > DETAILS_PAGE return page > DETAILS_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is DETAILS_PAGE: if page is DETAILS_PAGE:
if self.__connection.getSelection() is CONNECTION_LOCAL: if self.__connection.getSelection() is CONNECTION_LOCAL:
return True return True
elif len(self.__hostname.value()) > 0: elif len(self.__hostname.value()) > 0:
return True return True
else: else:
errors.append("You must enter a remote hostname.") errors.append("You must enter a remote hostname.")
elif page is CONFIRM_PAGE: return True elif page is CONFIRM_PAGE: return True
return False return False
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_PAGE: if page is CONFIRM_PAGE:
hv = self.__hypervisor.getSelection() hv = self.__hypervisor.getSelection()
conn = self.__connection.getSelection() conn = self.__connection.getSelection()
hostname = self.__hostname.value() hostname = self.__hostname.value()
if hv is HYPERVISOR_XEN: if hv is HYPERVISOR_XEN:
if conn is CONNECTION_LOCAL: url = "xen:///" if conn is CONNECTION_LOCAL: url = "xen:///"
elif conn is CONNECTION_KERBEROS: url = "xen+tcp:///" + hostname + "/" elif conn is CONNECTION_KERBEROS: url = "xen+tcp:///" + hostname + "/"
elif conn is CONNECTION_SSL: url = "xen+tls:///" + hostname + "/" elif conn is CONNECTION_SSL: url = "xen+tls:///" + hostname + "/"
elif conn is CONNECTION_SSH: url = "xen+ssh:///" + hostname + "/" elif conn is CONNECTION_SSH: url = "xen+ssh:///" + hostname + "/"
elif hv is HYPERVISOR_KVM: elif hv is HYPERVISOR_KVM:
if conn is CONNECTION_LOCAL: url = "qemu:///system" if conn is CONNECTION_LOCAL: url = "qemu:///system"
elif conn is CONNECTION_KERBEROS: url = "qemu+tcp://" + hostname + "/system" elif conn is CONNECTION_KERBEROS: url = "qemu+tcp://" + hostname + "/system"
elif conn is CONNECTION_SSL: url = "qemu+tls://" + hostname + "/system" elif conn is CONNECTION_SSL: url = "qemu+tls://" + hostname + "/system"
elif conn is CONNECTION_SSH: url = "qemu+ssh://" + hostname + "/system" elif conn is CONNECTION_SSH: url = "qemu+ssh://" + hostname + "/system"
self.get_virt_manager_config().add_connection(url) self.get_virt_manager_config().add_connection(url)
self.set_finished() self.set_finished()
def get_details_page(self, screen): def get_details_page(self, screen):
if not self.__configured: if not self.__configured:
self.__hypervisor = RadioBar(screen, ((HYPERVISORS[HYPERVISOR_XEN], HYPERVISOR_XEN, True), self.__hypervisor = RadioBar(screen, ((HYPERVISORS[HYPERVISOR_XEN], HYPERVISOR_XEN, True),
(HYPERVISORS[HYPERVISOR_KVM], HYPERVISOR_KVM, False))) (HYPERVISORS[HYPERVISOR_KVM], HYPERVISOR_KVM, False)))
self.__connection = RadioBar(screen, ((CONNECTIONS[CONNECTION_LOCAL], CONNECTION_LOCAL, True), self.__connection = RadioBar(screen, ((CONNECTIONS[CONNECTION_LOCAL], CONNECTION_LOCAL, True),
(CONNECTIONS[CONNECTION_KERBEROS], CONNECTION_KERBEROS, False), (CONNECTIONS[CONNECTION_KERBEROS], CONNECTION_KERBEROS, False),
(CONNECTIONS[CONNECTION_SSL], CONNECTION_SSL, False), (CONNECTIONS[CONNECTION_SSL], CONNECTION_SSL, False),
(CONNECTIONS[CONNECTION_SSH], CONNECTION_SSH, False))) (CONNECTIONS[CONNECTION_SSH], CONNECTION_SSH, False)))
self.__hostname = Entry(50, "") self.__hostname = Entry(50, "")
self.__autoconnect = Checkbox("Autoconnect on Startup") self.__autoconnect = Checkbox("Autoconnect on Startup")
self.__configured = True self.__configured = True
grid = Grid(2, 4) grid = Grid(2, 4)
grid.setField(Label("Hypervisor:"), 0, 0, anchorRight = 1, anchorTop = 1) grid.setField(Label("Hypervisor:"), 0, 0, anchorRight = 1, anchorTop = 1)
grid.setField(self.__hypervisor, 1, 0, anchorLeft = 1) grid.setField(self.__hypervisor, 1, 0, anchorLeft = 1)
grid.setField(Label("Connection:"), 0, 1, anchorRight = 1, anchorTop = 1) grid.setField(Label("Connection:"), 0, 1, anchorRight = 1, anchorTop = 1)
grid.setField(self.__connection, 1, 1, anchorLeft = 1) grid.setField(self.__connection, 1, 1, anchorLeft = 1)
grid.setField(Label("Hostname:"), 0, 2, anchorRight = 1) grid.setField(Label("Hostname:"), 0, 2, anchorRight = 1)
grid.setField(self.__hostname, 1, 2, anchorLeft = 1) grid.setField(self.__hostname, 1, 2, anchorLeft = 1)
grid.setField(Label(""), 0, 3, anchorRight = 1) grid.setField(Label(""), 0, 3, anchorRight = 1)
grid.setField(self.__autoconnect, 1, 3, anchorLeft = 1) grid.setField(self.__autoconnect, 1, 3, anchorLeft = 1)
return [Label("Add Connection"), return [Label("Add Connection"),
grid] grid]
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
grid = Grid(2, 4) grid = Grid(2, 4)
grid.setField(Label("Hypervisor:"), 0, 0, anchorRight = 1) grid.setField(Label("Hypervisor:"), 0, 0, anchorRight = 1)
grid.setField(Label(HYPERVISORS[self.__hypervisor.getSelection()]), 1, 0, anchorLeft = 1) grid.setField(Label(HYPERVISORS[self.__hypervisor.getSelection()]), 1, 0, anchorLeft = 1)
grid.setField(Label("Connection:"), 0, 1, anchorRight = 1) grid.setField(Label("Connection:"), 0, 1, anchorRight = 1)
grid.setField(Label(CONNECTIONS[self.__connection.getSelection()]), 1, 1, anchorLeft = 1) grid.setField(Label(CONNECTIONS[self.__connection.getSelection()]), 1, 1, anchorLeft = 1)
if self.__connection.getSelection() is not CONNECTION_LOCAL: if self.__connection.getSelection() is not CONNECTION_LOCAL:
hostname = self.__hostname.value() hostname = self.__hostname.value()
else: else:
hostname = "local" hostname = "local"
grid.setField(Label("Hostname:"), 0, 2, anchorRight = 1) grid.setField(Label("Hostname:"), 0, 2, anchorRight = 1)
grid.setField(Label(hostname), 1, 2, anchorLeft = 1) grid.setField(Label(hostname), 1, 2, anchorLeft = 1)
grid.setField(Label("Autoconnect on Startup:"), 0, 3, anchorRight = 1) grid.setField(Label("Autoconnect on Startup:"), 0, 3, anchorRight = 1)
label = "Yes" label = "Yes"
if not self.__autoconnect.value(): label = "No" if not self.__autoconnect.value(): label = "No"
grid.setField(Label(label), 1, 3, anchorLeft = 1) grid.setField(Label(label), 1, 3, anchorLeft = 1)
return [Label("Confirm Connection"), return [Label("Confirm Connection"),
grid] grid]
def AddHost(): def AddHost():
screen = AddHostConfigScreen() screen = AddHostConfigScreen()
screen.start() screen.start()

View File

@ -1,187 +1,187 @@
# addstorage.py - Copyright (C) 2009 Red Hat, Inc. # addstorage.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
import utils import utils
from configscreen import * from configscreen import *
from poolconfig import PoolConfig from poolconfig import PoolConfig
from virtinst import Storage from virtinst import Storage
POOL_NAME_PAGE = 1 POOL_NAME_PAGE = 1
POOL_DETAILS_PAGE = 2 POOL_DETAILS_PAGE = 2
CONFIRM_PAGE = 3 CONFIRM_PAGE = 3
class AddStoragePoolConfigScreen(ConfigScreen): class AddStoragePoolConfigScreen(ConfigScreen):
def __init__(self): def __init__(self):
ConfigScreen.__init__(self, "Add A Storage Pool") ConfigScreen.__init__(self, "Add A Storage Pool")
self.__config = PoolConfig(self.get_libvirt()) self.__config = PoolConfig(self.get_libvirt())
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is POOL_NAME_PAGE: return self.get_pool_name_page(screen) if page is POOL_NAME_PAGE: return self.get_pool_name_page(screen)
elif page is POOL_DETAILS_PAGE: return self.get_pool_details_page(screen) elif page is POOL_DETAILS_PAGE: return self.get_pool_details_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page < CONFIRM_PAGE return page < CONFIRM_PAGE
def page_has_back(self, page): def page_has_back(self, page):
return page > POOL_NAME_PAGE return page > POOL_NAME_PAGE
return page > POOL_NAME_PAGE return page > POOL_NAME_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is POOL_NAME_PAGE: if page is POOL_NAME_PAGE:
if utils.string_is_not_blank(self.__name.value()): if utils.string_is_not_blank(self.__name.value()):
if self.get_libvirt().storage_pool_exists(self.__name.value()): if self.get_libvirt().storage_pool_exists(self.__name.value()):
errors.append("Name '%s' already in use by another pool." % self.__name.value()) errors.append("Name '%s' already in use by another pool." % self.__name.value())
else: else:
return True return True
else: else:
errors.append("Storage object name must be a string between 0 and 50 characters.") errors.append("Storage object name must be a string between 0 and 50 characters.")
elif page is POOL_DETAILS_PAGE: elif page is POOL_DETAILS_PAGE:
result = True result = True
if self.__config.needs_target_path(): if self.__config.needs_target_path():
if utils.string_is_not_blank(self.__target_path.value()): if utils.string_is_not_blank(self.__target_path.value()):
if self.__target_path.value()[0:1] is not '/': if self.__target_path.value()[0:1] is not '/':
errors.append("'%s' is not an absolute path." % self.__target_path.value()) errors.append("'%s' is not an absolute path." % self.__target_path.value())
result = False result = False
else: else:
errors.append("You must enter a target path.") errors.append("You must enter a target path.")
result = False result = False
if self.__config.needs_format(): if self.__config.needs_format():
if self.__formats.getSelection() is None: if self.__formats.getSelection() is None:
errors.append("You must select a pool format.") errors.append("You must select a pool format.")
result = False result = False
if self.__config.needs_hostname(): if self.__config.needs_hostname():
if not utils.string_is_not_blank(self.__hostname.value()): if not utils.string_is_not_blank(self.__hostname.value()):
errors.append("You must enter a hostname.") errors.append("You must enter a hostname.")
result = False result = False
if self.__config.needs_source_path(): if self.__config.needs_source_path():
if utils.string_is_not_blank(self.__source_path.value()): if utils.string_is_not_blank(self.__source_path.value()):
if self.__config.source_must_be_absolute(): if self.__config.source_must_be_absolute():
if self.__source_path.value()[0:1] is not '/': if self.__source_path.value()[0:1] is not '/':
errors.append("'%s' is not an absolute path." % self.__source_path.value()) errors.append("'%s' is not an absolute path." % self.__source_path.value())
result = False result = False
else: else:
errors.append("you must enter a source path.") errors.append("you must enter a source path.")
result = False result = False
return result return result
elif page is CONFIRM_PAGE: return True elif page is CONFIRM_PAGE: return True
return False return False
def process_input(self, page): def process_input(self, page):
if page is POOL_NAME_PAGE: if page is POOL_NAME_PAGE:
self.__config.set_name(self.__name.value()) self.__config.set_name(self.__name.value())
self.__config.set_type(self.__type.getSelection()) self.__config.set_type(self.__type.getSelection())
#self._reset_flags(self.__type.current()) #self._reset_flags(self.__type.current())
elif page is POOL_DETAILS_PAGE: elif page is POOL_DETAILS_PAGE:
if self.__config.needs_target_path(): if self.__config.needs_target_path():
self.__config.set_target_path(self.__target_path.value()) self.__config.set_target_path(self.__target_path.value())
if self.__config.needs_format(): if self.__config.needs_format():
self.__config.set_format(self.__formats.getSelection()) self.__config.set_format(self.__formats.getSelection())
if self.__config.needs_hostname(): if self.__config.needs_hostname():
self.__config.set_hostname(self.__hostname.value()) self.__config.set_hostname(self.__hostname.value())
if self.__config.needs_source_path(): if self.__config.needs_source_path():
self.__config.set_source_path(self.__source_path.value()) self.__config.set_source_path(self.__source_path.value())
if self.__config.needs_build_pool(): if self.__config.needs_build_pool():
self.__config.set_build_pool(self.__build_pool.value()) self.__config.set_build_pool(self.__build_pool.value())
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
self.get_libvirt().define_storage_pool(self.__config.get_name(), config = self.__config) self.get_libvirt().define_storage_pool(self.__config.get_name(), config = self.__config)
self.get_libvirt().create_storage_pool(self.__config.get_name()) self.get_libvirt().create_storage_pool(self.__config.get_name())
self.set_finished() self.set_finished()
def get_pool_name_page(self, screen): def get_pool_name_page(self, screen):
self.__name = Entry(50, self.__config.get_name()) self.__name = Entry(50, self.__config.get_name())
pooltypes = [] pooltypes = []
for pooltype in Storage.StoragePool.get_pool_types(): for pooltype in Storage.StoragePool.get_pool_types():
pooltypes.append(["%s: %s" % (pooltype, Storage.StoragePool.get_pool_type_desc(pooltype)), pooltypes.append(["%s: %s" % (pooltype, Storage.StoragePool.get_pool_type_desc(pooltype)),
pooltype, pooltype,
self.__config.get_type() is pooltype]) self.__config.get_type() is pooltype])
self.__type = RadioBar(screen, pooltypes) self.__type = RadioBar(screen, pooltypes)
grid = Grid(2, 2) grid = Grid(2, 2)
grid.setField(Label("Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Name:"), 0, 0, anchorRight = 1)
grid.setField(self.__name, 1, 0, anchorLeft = 1) grid.setField(self.__name, 1, 0, anchorLeft = 1)
grid.setField(Label("Type:"), 0, 1, anchorRight = 1, anchorTop = 1) grid.setField(Label("Type:"), 0, 1, anchorRight = 1, anchorTop = 1)
grid.setField(self.__type, 1, 1, anchorLeft = 1) grid.setField(self.__type, 1, 1, anchorLeft = 1)
return [Label("Add Storage Pool"), return [Label("Add Storage Pool"),
grid] grid]
def get_pool_details_page(self, screen): def get_pool_details_page(self, screen):
rows = 0 rows = 0
if self.__config.needs_target_path(): if self.__config.needs_target_path():
self.__target_path = Entry(50, self.__config.get_target_path()) self.__target_path = Entry(50, self.__config.get_target_path())
rows += 1 rows += 1
if self.__config.needs_format(): if self.__config.needs_format():
formats = [] formats = []
for format in self.__config.get_formats(): for format in self.__config.get_formats():
formats.append([format, format, format is self.__config.get_format()]) formats.append([format, format, format is self.__config.get_format()])
self.__formats = RadioBar(screen, formats) self.__formats = RadioBar(screen, formats)
rows += 1 rows += 1
if self.__config.needs_hostname(): if self.__config.needs_hostname():
self.__hostname = Entry(50, self.__config.get_hostname()) self.__hostname = Entry(50, self.__config.get_hostname())
rows += 1 rows += 1
if self.__config.needs_source_path(): if self.__config.needs_source_path():
self.__source_path = Entry(50, self.__config.get_source_path()) self.__source_path = Entry(50, self.__config.get_source_path())
rows += 1 rows += 1
if self.__config.needs_build_pool(): if self.__config.needs_build_pool():
self.__build_pool = Checkbox("Build Pool", self.__config.get_build_pool()) self.__build_pool = Checkbox("Build Pool", self.__config.get_build_pool())
rows += 1 rows += 1
self.__build_pool = Checkbox("Build Pool", self.__config.get_build_pool()) self.__build_pool = Checkbox("Build Pool", self.__config.get_build_pool())
rows += 1 rows += 1
grid = Grid(2, rows) grid = Grid(2, rows)
currentrow = 0 currentrow = 0
if self.__config.needs_target_path(): if self.__config.needs_target_path():
grid.setField(Label("Target Path:"), 0, currentrow, anchorRight = 1) grid.setField(Label("Target Path:"), 0, currentrow, anchorRight = 1)
grid.setField(self.__target_path, 1, currentrow, anchorLeft = 1) grid.setField(self.__target_path, 1, currentrow, anchorLeft = 1)
currentrow += 1 currentrow += 1
if self.__config.needs_format(): if self.__config.needs_format():
grid.setField(Label("Format:"), 0, currentrow, anchorRight = 1, anchorTop = 1) grid.setField(Label("Format:"), 0, currentrow, anchorRight = 1, anchorTop = 1)
grid.setField(self.__formats, 1, currentrow, anchorLeft = 1) grid.setField(self.__formats, 1, currentrow, anchorLeft = 1)
currentrow += 1 currentrow += 1
if self.__config.needs_hostname(): if self.__config.needs_hostname():
grid.setField(Label("Host Name:"), 0, currentrow, anchorRight = 1) grid.setField(Label("Host Name:"), 0, currentrow, anchorRight = 1)
grid.setField(self.__hostname, 1, currentrow, anchorRight = 1) grid.setField(self.__hostname, 1, currentrow, anchorRight = 1)
currentrow += 1 currentrow += 1
if self.__config.needs_source_path(): if self.__config.needs_source_path():
grid.setField(Label("Source Path:"), 0, currentrow, anchorRight = 1) grid.setField(Label("Source Path:"), 0, currentrow, anchorRight = 1)
grid.setField(self.__source_path, 1, currentrow, anchorLeft = 1) grid.setField(self.__source_path, 1, currentrow, anchorLeft = 1)
currentrow += 1 currentrow += 1
if self.__config.needs_build_pool(): if self.__config.needs_build_pool():
grid.setField(Label(" "), 0, currentrow, anchorRight = 1) grid.setField(Label(" "), 0, currentrow, anchorRight = 1)
grid.setField(self.__build_pool, 1, currentrow, anchorLeft = 1) grid.setField(self.__build_pool, 1, currentrow, anchorLeft = 1)
currentrow += 1 currentrow += 1
return [Label("Specify a storage location to be later split into virtual machine storage"), return [Label("Specify a storage location to be later split into virtual machine storage"),
grid] grid]
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
grid = Grid(2, 2) grid = Grid(2, 2)
grid.setField(Label("Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Name:"), 0, 0, anchorRight = 1)
grid.setField(Label(self.__config.get_name()), 1, 0, anchorLeft = 1) grid.setField(Label(self.__config.get_name()), 1, 0, anchorLeft = 1)
grid.setField(Label("Target Path:"), 0, 1, anchorRight = 1) grid.setField(Label("Target Path:"), 0, 1, anchorRight = 1)
grid.setField(Label(self.__config.get_target_path()), 1, 1, anchorLeft = 1) grid.setField(Label(self.__config.get_target_path()), 1, 1, anchorLeft = 1)
return [Label("Confirm Pool Details"), return [Label("Confirm Pool Details"),
grid] grid]
def AddStoragePool(): def AddStoragePool():
screen = AddStoragePoolConfigScreen() screen = AddStoragePoolConfigScreen()
screen.start() screen.start()

View File

@ -1,178 +1,178 @@
# addvolume.py - Copyright (C) 2009 Red Hat, Inc. # addvolume.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from createmeter import CreateMeter from createmeter import CreateMeter
from configscreen import * from configscreen import *
from volumeconfig import StorageVolumeConfig from volumeconfig import StorageVolumeConfig
from utils import * from utils import *
SELECT_POOL_PAGE = 1 SELECT_POOL_PAGE = 1
VOLUME_NAME_PAGE = 2 VOLUME_NAME_PAGE = 2
VOLUME_FORMAT_PAGE = 3 VOLUME_FORMAT_PAGE = 3
MAX_CAPACITY_PAGE = 4 MAX_CAPACITY_PAGE = 4
CONFIRM_PAGE = 5 CONFIRM_PAGE = 5
class AddVolumeConfigScreen(StorageListConfigScreen): class AddVolumeConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "Add A New Storage Volume") StorageListConfigScreen.__init__(self, "Add A New Storage Volume")
self.__config = StorageVolumeConfig() self.__config = StorageVolumeConfig()
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is SELECT_POOL_PAGE: return self.get_storage_pool_list_page(screen) if page is SELECT_POOL_PAGE: return self.get_storage_pool_list_page(screen)
elif page is VOLUME_NAME_PAGE: return self.get_volume_name_page(screen) elif page is VOLUME_NAME_PAGE: return self.get_volume_name_page(screen)
elif page is VOLUME_FORMAT_PAGE: return self.get_volume_format_page(screen) elif page is VOLUME_FORMAT_PAGE: return self.get_volume_format_page(screen)
elif page is MAX_CAPACITY_PAGE: return self.get_max_capacity_page(screen) elif page is MAX_CAPACITY_PAGE: return self.get_max_capacity_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is SELECT_POOL_PAGE: if page is SELECT_POOL_PAGE:
return self.has_selectable_pools() return self.has_selectable_pools()
else: else:
if page < CONFIRM_PAGE: return True if page < CONFIRM_PAGE: return True
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page > SELECT_POOL_PAGE: return True if page > SELECT_POOL_PAGE: return True
return False return False
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def get_next_page(self, page): def get_next_page(self, page):
if page is VOLUME_NAME_PAGE: if page is VOLUME_NAME_PAGE:
if self.__config.needs_format(): if self.__config.needs_format():
return VOLUME_FORMAT_PAGE return VOLUME_FORMAT_PAGE
else: else:
return MAX_CAPACITY_PAGE return MAX_CAPACITY_PAGE
return StorageListConfigScreen.get_next_page(self, page) return StorageListConfigScreen.get_next_page(self, page)
def get_back_page(self, page): def get_back_page(self, page):
if page is MAX_CAPACITY_PAGE: if page is MAX_CAPACITY_PAGE:
if self.__config.needs_format(): if self.__config.needs_format():
return VOLUME_FORMAT_PATH return VOLUME_FORMAT_PATH
else: else:
return VOLUME_NAME_PAGE return VOLUME_NAME_PAGE
return StorageListConfigScreen.get_back_page(self, page) return StorageListConfigScreen.get_back_page(self, page)
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is SELECT_POOL_PAGE: if page is SELECT_POOL_PAGE:
if self.get_selected_pool() is not None: if self.get_selected_pool() is not None:
return True return True
else: else:
errors.append("You must select a storage pool.") errors.append("You must select a storage pool.")
elif page is VOLUME_NAME_PAGE: elif page is VOLUME_NAME_PAGE:
if string_is_not_blank(self.__name.value()): if string_is_not_blank(self.__name.value()):
return True return True
else: else:
errors.append("Storage object name can only contain alphanumeric, '_', '.', or '-' characters.") errors.append("Storage object name can only contain alphanumeric, '_', '.', or '-' characters.")
elif page is VOLUME_FORMAT_PAGE: elif page is VOLUME_FORMAT_PAGE:
if self.__formats.current() is not None: if self.__formats.current() is not None:
return True return True
else: else:
errors.append("You must select a volume format.") errors.append("You must select a volume format.")
elif page is MAX_CAPACITY_PAGE: elif page is MAX_CAPACITY_PAGE:
if string_is_not_blank(self.__capacity.value()): if string_is_not_blank(self.__capacity.value()):
if string_is_not_blank(self.__allocation.value()): if string_is_not_blank(self.__allocation.value()):
capacity = int(self.__capacity.value()) capacity = int(self.__capacity.value())
allocation = int(self.__allocation.value()) allocation = int(self.__allocation.value())
if capacity > 0: if capacity > 0:
if capacity <= self.__config.get_pool().info()[3] / 1024**2: if capacity <= self.__config.get_pool().info()[3] / 1024**2:
if allocation >= 0: if allocation >= 0:
if allocation <= capacity: if allocation <= capacity:
return True return True
else: else:
errors.append("Allocation cannot exceed the maximum capacity.") errors.append("Allocation cannot exceed the maximum capacity.")
else: else:
errors.append("The allocation must be greater than or equal to 0.") errors.append("The allocation must be greater than or equal to 0.")
else: else:
errors.append("The maximum capacity cannot exceed the storage pool size.") errors.append("The maximum capacity cannot exceed the storage pool size.")
else: else:
errors.append("The capacity must be greater than zero.") errors.append("The capacity must be greater than zero.")
else: else:
errors.append("An allocation value must be entered.") errors.append("An allocation value must be entered.")
else: else:
errors.append("A maximum volume capacity must be entered.") errors.append("A maximum volume capacity must be entered.")
elif page is CONFIRM_PAGE: return True elif page is CONFIRM_PAGE: return True
return False return False
def process_input(self, page): def process_input(self, page):
if page is SELECT_POOL_PAGE: if page is SELECT_POOL_PAGE:
self.__config.set_pool(self.get_libvirt().get_storage_pool(self.get_selected_pool())) self.__config.set_pool(self.get_libvirt().get_storage_pool(self.get_selected_pool()))
elif page is VOLUME_NAME_PAGE: elif page is VOLUME_NAME_PAGE:
self.__config.set_name(self.__name.value()) self.__config.set_name(self.__name.value())
elif page is VOLUME_FORMAT_PAGE: elif page is VOLUME_FORMAT_PAGE:
self.__config.set_format(self.__formats.current()) self.__config.set_format(self.__formats.current())
elif page is MAX_CAPACITY_PAGE: elif page is MAX_CAPACITY_PAGE:
self.__config.set_max_capacity(int(self.__capacity.value())) self.__config.set_max_capacity(int(self.__capacity.value()))
self.__config.set_allocation(int(self.__allocation.value())) self.__config.set_allocation(int(self.__allocation.value()))
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
self.get_libvirt().define_storage_volume(self.__config, CreateMeter()) self.get_libvirt().define_storage_volume(self.__config, CreateMeter())
self.set_finished() self.set_finished()
def get_volume_name_page(self, screen): def get_volume_name_page(self, screen):
self.__name = Entry(50, self.__config.get_name()) self.__name = Entry(50, self.__config.get_name())
grid = Grid(2, 1) grid = Grid(2, 1)
grid.setField(Label("Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Name:"), 0, 0, anchorRight = 1)
grid.setField(self.__name, 1, 0, anchorLeft = 1) grid.setField(self.__name, 1, 0, anchorLeft = 1)
return [Label("New Storage Volume"), return [Label("New Storage Volume"),
grid, grid,
Label("Name of the volume to create. File extension may be appended.")] Label("Name of the volume to create. File extension may be appended.")]
def get_volume_format_page(self, screen): def get_volume_format_page(self, screen):
self.__formats = Listbox(0) self.__formats = Listbox(0)
for format in self.__config.get_formats_for_pool(): for format in self.__config.get_formats_for_pool():
self.__formats.append(format, format) self.__formats.append(format, format)
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__formats, 0, 0) grid.setField(self.__formats, 0, 0)
return [Label("Select The Volume Format"), return [Label("Select The Volume Format"),
grid] grid]
def get_max_capacity_page(self, screen): def get_max_capacity_page(self, screen):
self.__capacity = Entry(6, str(self.__config.get_max_capacity())) self.__capacity = Entry(6, str(self.__config.get_max_capacity()))
self.__allocation = Entry(6, str(self.__config.get_allocation())) self.__allocation = Entry(6, str(self.__config.get_allocation()))
grid = Grid(2, 2) grid = Grid(2, 2)
grid.setField(Label("Max. Capacity (MB):"), 0, 0, anchorRight = 1) grid.setField(Label("Max. Capacity (MB):"), 0, 0, anchorRight = 1)
grid.setField(self.__capacity, 1, 0, anchorLeft = 1) grid.setField(self.__capacity, 1, 0, anchorLeft = 1)
grid.setField(Label("Allocation (MB):"), 0, 1, anchorRight = 1) grid.setField(Label("Allocation (MB):"), 0, 1, anchorRight = 1)
grid.setField(self.__allocation, 1, 1, anchorLeft = 1) grid.setField(self.__allocation, 1, 1, anchorLeft = 1)
return [Label("Storage Volume Quota"), return [Label("Storage Volume Quota"),
Label("%s's available space: %s" % (self.__config.get_pool().name(), Label("%s's available space: %s" % (self.__config.get_pool().name(),
size_as_mb_or_gb(self.__config.get_pool().info()[3]))), size_as_mb_or_gb(self.__config.get_pool().info()[3]))),
grid] grid]
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
grid = Grid(2, 5) grid = Grid(2, 5)
grid.setField(Label("Volume Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Volume Name:"), 0, 0, anchorRight = 1)
grid.setField(Label("%s (%s)" % (self.__config.get_name(), self.__config.get_pool().name())), 1, 0, anchorLeft = 1) grid.setField(Label("%s (%s)" % (self.__config.get_name(), self.__config.get_pool().name())), 1, 0, anchorLeft = 1)
if self.__config.needs_format(): if self.__config.needs_format():
grid.setField(Label("Format:"), 0, 1, anchorRight = 1) grid.setField(Label("Format:"), 0, 1, anchorRight = 1)
grid.setField(Label(self.__config.get_format()), 1, 1, anchorLeft = 1) grid.setField(Label(self.__config.get_format()), 1, 1, anchorLeft = 1)
# NOTE: here we multiply the sizes by 1024^2 since the size_as_mb_or_gb is expect bytes # NOTE: here we multiply the sizes by 1024^2 since the size_as_mb_or_gb is expect bytes
grid.setField(Label("Max. Capacity:"), 0, 2, anchorRight = 1) grid.setField(Label("Max. Capacity:"), 0, 2, anchorRight = 1)
grid.setField(Label("%s" % (size_as_mb_or_gb(self.__config.get_max_capacity() * 1024**2))), 1, 2, anchorLeft = 1) grid.setField(Label("%s" % (size_as_mb_or_gb(self.__config.get_max_capacity() * 1024**2))), 1, 2, anchorLeft = 1)
grid.setField(Label("Allocation:"), 0, 3, anchorRight = 1) grid.setField(Label("Allocation:"), 0, 3, anchorRight = 1)
grid.setField(Label("%s" % (size_as_mb_or_gb(self.__config.get_allocation() * 1024**2))), 1, 3, anchorLeft = 1) grid.setField(Label("%s" % (size_as_mb_or_gb(self.__config.get_allocation() * 1024**2))), 1, 3, anchorLeft = 1)
return [Label("Ready To Allocation New Storage Volume"), return [Label("Ready To Allocation New Storage Volume"),
grid] grid]
def AddStorageVolume(): def AddStorageVolume():
screen = AddVolumeConfigScreen() screen = AddVolumeConfigScreen()
screen.start() screen.start()

View File

@ -1,60 +1,60 @@
# changehost.py - Copyright (C) 2009 Red Hat, Inc. # changehost.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import logging import logging
import libvirtworker import libvirtworker
from configscreen import * from configscreen import *
CONNECTION_LIST_PAGE = 1 CONNECTION_LIST_PAGE = 1
CONNECTED_PAGE = 2 CONNECTED_PAGE = 2
class ChangeHostConfigScreen(HostListConfigScreen): class ChangeHostConfigScreen(HostListConfigScreen):
def __init__(self): def __init__(self):
HostListConfigScreen.__init__(self, "") HostListConfigScreen.__init__(self, "")
def get_title(self): def get_title(self):
return "Currently: %s" % self.get_libvirt().get_url() return "Currently: %s" % self.get_libvirt().get_url()
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is CONNECTION_LIST_PAGE: return self.get_connection_list_page(screen) if page is CONNECTION_LIST_PAGE: return self.get_connection_list_page(screen)
elif page is CONNECTED_PAGE: return self.get_connected_page(screen) elif page is CONNECTED_PAGE: return self.get_connected_page(screen)
def process_input(self, page): def process_input(self, page):
if page is CONNECTION_LIST_PAGE: if page is CONNECTION_LIST_PAGE:
logging.info("Changing libvirt connection to %s" % self.get_selected_connection()) logging.info("Changing libvirt connection to %s" % self.get_selected_connection())
self.get_libvirt().open_connection(self.get_selected_connection()) self.get_libvirt().open_connection(self.get_selected_connection())
elif page is CONNECTED_PAGE: self.set_finished() elif page is CONNECTED_PAGE: self.set_finished()
def page_has_next(self, page): def page_has_next(self, page):
if page is CONNECTION_LIST_PAGE: return self.has_selectable_connections() if page is CONNECTION_LIST_PAGE: return self.has_selectable_connections()
return False return False
def page_has_back(self, page): def page_has_back(self, page):
return page > CONNECTION_LIST_PAGE return page > CONNECTION_LIST_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONNECTED_PAGE return page is CONNECTED_PAGE
def get_connected_page(self, screen): def get_connected_page(self, screen):
return [Label("Connected to %s" % self.get_selected_connection())] return [Label("Connected to %s" % self.get_selected_connection())]
def ChangeHost(): def ChangeHost():
screen = ChangeHostConfigScreen() screen = ChangeHostConfigScreen()
screen.start() screen.start()

View File

@ -1,295 +1,295 @@
# configscreen.py - Copyright (C) 2009 Red Hat, Inc. # configscreen.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from halworker import HALWorker from halworker import HALWorker
from libvirtworker import * from libvirtworker import *
import traceback import traceback
BACK_BUTTON = "back" BACK_BUTTON = "back"
NEXT_BUTTON = "next" NEXT_BUTTON = "next"
CANCEL_BUTTON = "cancel" CANCEL_BUTTON = "cancel"
FINISH_BUTTON = "finish" FINISH_BUTTON = "finish"
class ConfigScreen: class ConfigScreen:
'''Enables the creation of navigable, multi-paged configuration screens.''' '''Enables the creation of navigable, multi-paged configuration screens.'''
def __init__(self, title): def __init__(self, title):
self.__title = title self.__title = title
self.__current_page = 1 self.__current_page = 1
self.__finished = False self.__finished = False
self.__hal = HALWorker() self.__hal = HALWorker()
self.__libvirt = LibvirtWorker() self.__libvirt = LibvirtWorker()
self.__vm_config = VirtManagerConfig() self.__vm_config = VirtManagerConfig()
def get_title(self): def get_title(self):
return self.__title return self.__title
def get_hal(self): def get_hal(self):
return self.__hal return self.__hal
def get_libvirt(self): def get_libvirt(self):
return self.__libvirt return self.__libvirt
def get_virt_manager_config(self): def get_virt_manager_config(self):
return self.__vm_config return self.__vm_config
def set_finished(self): def set_finished(self):
self.__finished = True self.__finished = True
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
return [] return []
def page_has_next(self, page): def page_has_next(self, page):
return False return False
def page_has_finish(self, page): def page_has_finish(self, page):
return False return False
def get_back_page(self, page): def get_back_page(self, page):
if page > 1: return page - 1 if page > 1: return page - 1
return page return page
def go_back(self): def go_back(self):
self.__current_page = self.get_back_page(self.__current_page) self.__current_page = self.get_back_page(self.__current_page)
def get_next_page(self, page): def get_next_page(self, page):
return page + 1 return page + 1
def go_next(self): def go_next(self):
self.__current_page = self.get_next_page(self.__current_page) self.__current_page = self.get_next_page(self.__current_page)
def validate_input(self, page, errors): def validate_input(self, page, errors):
return True return True
def process_input(self, page): def process_input(self, page):
return return
def get_page_list(self): def get_page_list(self):
return [] return []
def get_current_page(self): def get_current_page(self):
0 0
def start(self): def start(self):
active = True active = True
while active and (self.__finished == False): while active and (self.__finished == False):
screen = SnackScreen() screen = SnackScreen()
elements = self.get_elements_for_page(screen, self.__current_page) elements = self.get_elements_for_page(screen, self.__current_page)
# TODO: need to set the form height to the number of elements on the page # TODO: need to set the form height to the number of elements on the page
gridform = GridForm(screen, self.get_title(), 2, 2) gridform = GridForm(screen, self.get_title(), 2, 2)
# Here you would put the list of elements # Here you would put the list of elements
# and programmatically set the indicator as # and programmatically set the indicator as
# they're rendered # they're rendered
pages = self.get_page_list() pages = self.get_page_list()
if len(pages) > 0: if len(pages) > 0:
leftmenu = Grid(2, len(pages)) leftmenu = Grid(2, len(pages))
current_element = 0 current_element = 0
for page in pages: for page in pages:
leftmenu.setField(Label(page), 0, current_element, anchorLeft = 1) leftmenu.setField(Label(page), 0, current_element, anchorLeft = 1)
indicator = " " indicator = " "
if current_element == self.__current_page - 1: if current_element == self.__current_page - 1:
indicator = "<-" indicator = "<-"
leftmenu.setField(Label(indicator), 1, current_element) leftmenu.setField(Label(indicator), 1, current_element)
current_element += 1 current_element += 1
gridform.add(leftmenu, 0, 0, anchorTop = 1, padding = (3, 0, 3, 0)) gridform.add(leftmenu, 0, 0, anchorTop = 1, padding = (3, 0, 3, 0))
content = Grid(1, len(elements) + 1) content = Grid(1, len(elements) + 1)
current_element = 0 current_element = 0
for element in elements: for element in elements:
content.setField(element, 0, current_element) content.setField(element, 0, current_element)
current_element += 1 current_element += 1
# create the navigation buttons # create the navigation buttons
buttons = [] buttons = []
if self.__current_page > 1: buttons.append(["Back", BACK_BUTTON, "F11"]) if self.__current_page > 1: buttons.append(["Back", BACK_BUTTON, "F11"])
if self.page_has_next(self.__current_page): buttons.append(["Next", NEXT_BUTTON, "F12"]) if self.page_has_next(self.__current_page): buttons.append(["Next", NEXT_BUTTON, "F12"])
if self.page_has_finish(self.__current_page): buttons.append(["Finish", FINISH_BUTTON, "F10"]) if self.page_has_finish(self.__current_page): buttons.append(["Finish", FINISH_BUTTON, "F10"])
buttons.append(["Cancel", CANCEL_BUTTON, "ESC"]) buttons.append(["Cancel", CANCEL_BUTTON, "ESC"])
buttonbar = ButtonBar(screen, buttons) buttonbar = ButtonBar(screen, buttons)
content.setField(buttonbar, 0, current_element, growx = 1) content.setField(buttonbar, 0, current_element, growx = 1)
gridform.add(content, 1, 0, anchorTop = 1) gridform.add(content, 1, 0, anchorTop = 1)
current_element += 1 current_element += 1
try: try:
result = gridform.runOnce() result = gridform.runOnce()
pressed = buttonbar.buttonPressed(result) pressed = buttonbar.buttonPressed(result)
if pressed == BACK_BUTTON: if pressed == BACK_BUTTON:
self.go_back() self.go_back()
elif pressed == NEXT_BUTTON or pressed == FINISH_BUTTON: elif pressed == NEXT_BUTTON or pressed == FINISH_BUTTON:
errors = [] errors = []
if self.validate_input(self.__current_page, errors): if self.validate_input(self.__current_page, errors):
self.process_input(self.__current_page) self.process_input(self.__current_page)
self.go_next() self.go_next()
else: else:
error_text = "" error_text = ""
for error in errors: for error in errors:
error_text += "%s\n" % error error_text += "%s\n" % error
ButtonChoiceWindow(screen, ButtonChoiceWindow(screen,
"There Were Errors", "There Were Errors",
error_text, error_text,
buttons = ["OK"]) buttons = ["OK"])
elif pressed == CANCEL_BUTTON: elif pressed == CANCEL_BUTTON:
active = False active = False
except Exception, error: except Exception, error:
ButtonChoiceWindow(screen, ButtonChoiceWindow(screen,
"An Exception Has Occurred", "An Exception Has Occurred",
str(error) + "\n" + traceback.format_exc(), str(error) + "\n" + traceback.format_exc(),
buttons = ["OK"]) buttons = ["OK"])
screen.popWindow() screen.popWindow()
screen.finish() screen.finish()
class DomainListConfigScreen(ConfigScreen): class DomainListConfigScreen(ConfigScreen):
'''Provides a base class for all config screens that require a domain list.''' '''Provides a base class for all config screens that require a domain list.'''
def __init__(self, title): def __init__(self, title):
ConfigScreen.__init__(self, title) ConfigScreen.__init__(self, title)
def get_domain_list_page(self, screen, defined=True, created=True): def get_domain_list_page(self, screen, defined=True, created=True):
domains = self.get_libvirt().list_domains(defined, created) domains = self.get_libvirt().list_domains(defined, created)
result = None result = None
if len(domains) > 0: if len(domains) > 0:
self.__has_domains = True self.__has_domains = True
self.__domain_list = Listbox(0) self.__domain_list = Listbox(0)
for name in domains: for name in domains:
self.__domain_list.append(name, name) self.__domain_list.append(name, name)
result = [self.__domain_list] result = [self.__domain_list]
else: else:
self.__has_domains = False self.__has_domains = False
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(Label("There are no domains available."), 0, 0) grid.setField(Label("There are no domains available."), 0, 0)
result = [grid] result = [grid]
return result return result
def get_selected_domain(self): def get_selected_domain(self):
return self.__domain_list.current() return self.__domain_list.current()
def has_selectable_domains(self): def has_selectable_domains(self):
return self.__has_domains return self.__has_domains
class NetworkListConfigScreen(ConfigScreen): class NetworkListConfigScreen(ConfigScreen):
'''Provides a base class for all config screens that require a network list.''' '''Provides a base class for all config screens that require a network list.'''
def __init__(self, title): def __init__(self, title):
ConfigScreen.__init__(self, title) ConfigScreen.__init__(self, title)
def get_network_list_page(self, screen, defined=True, created=True): def get_network_list_page(self, screen, defined=True, created=True):
networks = self.get_libvirt().list_networks(defined, created) networks = self.get_libvirt().list_networks(defined, created)
result = None result = None
if len(networks) > 0: if len(networks) > 0:
self.__has_networks = True self.__has_networks = True
self.__network_list = Listbox(0) self.__network_list = Listbox(0)
for name in networks: for name in networks:
self.__network_list.append(name, name) self.__network_list.append(name, name)
result = self.__network_list result = self.__network_list
else: else:
self.__has_networks = False self.__has_networks = False
result = Label("There are no networks available.") result = Label("There are no networks available.")
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(result, 0, 0) grid.setField(result, 0, 0)
return [Label("Network List"), return [Label("Network List"),
grid] grid]
def get_selected_network(self): def get_selected_network(self):
return self.__network_list.current() return self.__network_list.current()
def has_selectable_networks(self): def has_selectable_networks(self):
return self.__has_networks return self.__has_networks
class StorageListConfigScreen(ConfigScreen): class StorageListConfigScreen(ConfigScreen):
'''Provides a base class for any configuration screen that deals with storage pool lists.''' '''Provides a base class for any configuration screen that deals with storage pool lists.'''
def __init__(self, title): def __init__(self, title):
ConfigScreen.__init__(self, title) ConfigScreen.__init__(self, title)
def get_storage_pool_list_page(self, screen, defined=True, created=True): def get_storage_pool_list_page(self, screen, defined=True, created=True):
pools = self.get_libvirt().list_storage_pools(defined=defined, created=created) pools = self.get_libvirt().list_storage_pools(defined=defined, created=created)
if len(pools) > 0: if len(pools) > 0:
self.__has_pools = True self.__has_pools = True
self.__pools_list = Listbox(0) self.__pools_list = Listbox(0)
for pool in pools: for pool in pools:
self.__pools_list.append(pool, pool) self.__pools_list.append(pool, pool)
result = self.__pools_list result = self.__pools_list
else: else:
self.__has_pools = False self.__has_pools = False
result = Label("There are no storage pools available.") result = Label("There are no storage pools available.")
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(result, 0, 0) grid.setField(result, 0, 0)
return [Label("Storage Pool List"), return [Label("Storage Pool List"),
grid] grid]
def get_selected_pool(self): def get_selected_pool(self):
return self.__pools_list.current() return self.__pools_list.current()
def has_selectable_pools(self): def has_selectable_pools(self):
return self.__has_pools return self.__has_pools
def get_storage_volume_list_page(self, screen): def get_storage_volume_list_page(self, screen):
'''Requires that self.__pools_list have a selected element.''' '''Requires that self.__pools_list have a selected element.'''
pool = self.get_libvirt().get_storage_pool(self.get_selected_pool()) pool = self.get_libvirt().get_storage_pool(self.get_selected_pool())
if len(pool.listVolumes()) > 0: if len(pool.listVolumes()) > 0:
self.__has_volumes = True self.__has_volumes = True
self.__volumes_list = Listbox(0) self.__volumes_list = Listbox(0)
for volname in pool.listVolumes(): for volname in pool.listVolumes():
volume = pool.storageVolLookupByName(volname) volume = pool.storageVolLookupByName(volname)
self.__volumes_list.append("%s (%0.2f GB)" % (volume.name(), volume.info()[2] / 1024**3), volume.name()) self.__volumes_list.append("%s (%0.2f GB)" % (volume.name(), volume.info()[2] / 1024**3), volume.name())
result = self.__volumes_list result = self.__volumes_list
else: else:
self.__has_volumes = False self.__has_volumes = False
result = Label("There are no storage volumes available.") result = Label("There are no storage volumes available.")
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(result, 0, 0) grid.setField(result, 0, 0)
return [Label("Storage Volume List"), return [Label("Storage Volume List"),
grid] grid]
def get_selected_volume(self): def get_selected_volume(self):
return self.__volumes_list.current() return self.__volumes_list.current()
def has_selectable_volumes(self): def has_selectable_volumes(self):
return self.__has_volumes return self.__has_volumes
class HostListConfigScreen(ConfigScreen): class HostListConfigScreen(ConfigScreen):
'''Provides a base class for working with lists of libvirt hosts.''' '''Provides a base class for working with lists of libvirt hosts.'''
def __init__(self, title): def __init__(self, title):
ConfigScreen.__init__(self, title) ConfigScreen.__init__(self, title)
def get_connection_list_page(self, screen): def get_connection_list_page(self, screen):
connections = self.get_virt_manager_config().get_connection_list() connections = self.get_virt_manager_config().get_connection_list()
result = None result = None
if len(connections) > 0: if len(connections) > 0:
self.__has_connections = True self.__has_connections = True
self.__connection_list = Listbox(0) self.__connection_list = Listbox(0)
for connection in connections: for connection in connections:
self.__connection_list.append(connection, connection) self.__connection_list.append(connection, connection)
result = self.__connection_list result = self.__connection_list
else: else:
self.__has_connections = False self.__has_connections = False
result = Label("There are no defined connections.") result = Label("There are no defined connections.")
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(result, 0, 0) grid.setField(result, 0, 0)
return [Label("Host List"), return [Label("Host List"),
grid] grid]
def get_selected_connection(self): def get_selected_connection(self):
return self.__connection_list.current() return self.__connection_list.current()
def has_selectable_connections(self): def has_selectable_connections(self):
return self.__has_connections return self.__has_connections

View File

@ -1,30 +1,30 @@
# createmeter.py - Copyright (C) 2009 Red Hat, Inc. # createmeter.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import urlgrabber.progress as progress import urlgrabber.progress as progress
import logging import logging
class CreateMeter(progress.BaseMeter): class CreateMeter(progress.BaseMeter):
def _do_start(self, now = None): def _do_start(self, now = None):
logging.info("Starting...") logging.info("Starting...")
def _do_end(self, amount_read, now = None): def _do_end(self, amount_read, now = None):
logging.info("Ending: read=%d" % amount_read) logging.info("Ending: read=%d" % amount_read)
def _do_update(self, amount_read, now = None): def _do_update(self, amount_read, now = None):
logging.info("Update: read=%d" % amount_read) logging.info("Update: read=%d" % amount_read)

View File

@ -1,52 +1,52 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# createnetwork.py - Copyright (C) 2009 Red Hat, Inc. # createnetwork.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_PAGE = 1 LIST_PAGE = 1
CREATE_PAGE = 2 CREATE_PAGE = 2
class CreateNetworkConfigScreen(NetworkListConfigScreen): class CreateNetworkConfigScreen(NetworkListConfigScreen):
def __init__(self): def __init__(self):
NetworkListConfigScreen.__init__(self, "Create A Network") NetworkListConfigScreen.__init__(self, "Create A Network")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_PAGE: return self.get_network_list_page(screen, created = False) if page is LIST_PAGE: return self.get_network_list_page(screen, created = False)
elif page is CREATE_PAGE: return self.get_create_network_page(screen) elif page is CREATE_PAGE: return self.get_create_network_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is LIST_PAGE: return self.has_selectable_networks() if page is LIST_PAGE: return self.has_selectable_networks()
def page_has_back(self, page): def page_has_back(self, page):
return (page is CREATE_PAGE) return (page is CREATE_PAGE)
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_PAGE: if page is LIST_PAGE:
self.get_libvirt().create_network(self.get_selected_network()) self.get_libvirt().create_network(self.get_selected_network())
return True return True
def get_create_network_page(self, screen): def get_create_network_page(self, screen):
return [Label("Network Started"), return [Label("Network Started"),
Label("%s was successfully started." % self.get_selected_network())] Label("%s was successfully started." % self.get_selected_network())]
def CreateNetwork(): def CreateNetwork():
screen = CreateNetworkConfigScreen() screen = CreateNetworkConfigScreen()
screen.start() screen.start()

View File

@ -1,106 +1,106 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# createuser.py - Copyright (C) 2009 Red Hat, Inc. # createuser.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import ConfigScreen from configscreen import ConfigScreen
from userworker import UserWorker from userworker import UserWorker
import libuser import libuser
DETAILS_PAGE = 1 DETAILS_PAGE = 1
CONFIRM_PAGE = 2 CONFIRM_PAGE = 2
class CreateUserConfigScreen(ConfigScreen): class CreateUserConfigScreen(ConfigScreen):
def __init__(self): def __init__(self):
ConfigScreen.__init__(self, "Create A User Account") ConfigScreen.__init__(self, "Create A User Account")
self.__username = None self.__username = None
self.__useradmin = libuser.admin() self.__useradmin = libuser.admin()
self.__user_worker = UserWorker() self.__user_worker = UserWorker()
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is DETAILS_PAGE: return self.get_details_page(screen) if page is DETAILS_PAGE: return self.get_details_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is DETAILS_PAGE: if page is DETAILS_PAGE:
if len(self.__username.value()) > 0: if len(self.__username.value()) > 0:
name = self.__username.value() name = self.__username.value()
if self.__useradmin.lookupUserByName(name) is None: if self.__useradmin.lookupUserByName(name) is None:
if len(self.__password.value()) > 0: if len(self.__password.value()) > 0:
if self.__password.value() == self.__confirm.value(): if self.__password.value() == self.__confirm.value():
return True return True
else: else:
errors.append("Passwords do not match.") errors.append("Passwords do not match.")
else: else:
errors.append("You must enter a password.") errors.append("You must enter a password.")
else: else:
errors.append("User %s already exists." % name) errors.append("User %s already exists." % name)
else: else:
errors.append("You must enter a username.") errors.append("You must enter a username.")
self.__confirm.value() self.__confirm.value()
return False return False
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_PAGE: if page is CONFIRM_PAGE:
self.__user_worker.create_user(self.__username.value(), self.__user_worker.create_user(self.__username.value(),
self.__password.value(), self.__password.value(),
"wheel" if self.__adminuser.value() else None) "wheel" if self.__adminuser.value() else None)
self.set_finished() self.set_finished()
def page_has_next(self, page): def page_has_next(self, page):
return (page is DETAILS_PAGE) return (page is DETAILS_PAGE)
def page_has_back(self, page): def page_has_back(self, page):
return (page is CONFIRM_PAGE) return (page is CONFIRM_PAGE)
def page_has_finish(self, page): def page_has_finish(self, page):
return (page is CONFIRM_PAGE) return (page is CONFIRM_PAGE)
def get_details_page(self, screen): def get_details_page(self, screen):
if self.__username is None: if self.__username is None:
self.__username = Entry(50, "") self.__username = Entry(50, "")
self.__password = Entry(50, "", password = 1) self.__password = Entry(50, "", password = 1)
self.__confirm = Entry(50, "", password = 1) self.__confirm = Entry(50, "", password = 1)
self.__adminuser = Checkbox("This user is an administrator", False) self.__adminuser = Checkbox("This user is an administrator", False)
grid = Grid(2, 4) grid = Grid(2, 4)
grid.setField(Label("Username:"), 0, 0, anchorRight = 1) grid.setField(Label("Username:"), 0, 0, anchorRight = 1)
grid.setField(self.__username, 1, 0, anchorLeft = 1) grid.setField(self.__username, 1, 0, anchorLeft = 1)
grid.setField(Label("Password:"), 0, 1, anchorRight = 1) grid.setField(Label("Password:"), 0, 1, anchorRight = 1)
grid.setField(self.__password, 1, 1, anchorLeft = 1) grid.setField(self.__password, 1, 1, anchorLeft = 1)
grid.setField(Label("Confirm password:"), 0, 2, anchorRight = 1) grid.setField(Label("Confirm password:"), 0, 2, anchorRight = 1)
grid.setField(self.__confirm, 1, 2, anchorLeft = 1) grid.setField(self.__confirm, 1, 2, anchorLeft = 1)
grid.setField(Label(" "), 0, 3) grid.setField(Label(" "), 0, 3)
grid.setField(self.__adminuser, 1, 3, anchorLeft = 1) grid.setField(self.__adminuser, 1, 3, anchorLeft = 1)
return [Label("Enter The User Details"), return [Label("Enter The User Details"),
grid] grid]
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
grid = Grid(1, 2) grid = Grid(1, 2)
grid.setField(Label("Username: %s" % self.__username.value()), 0, 0) grid.setField(Label("Username: %s" % self.__username.value()), 0, 0)
admin_label = "is not" admin_label = "is not"
if self.__adminuser.value(): if self.__adminuser.value():
admin_label = "is" admin_label = "is"
grid.setField(Label("This user %s an administrator." % admin_label), 0, 1) grid.setField(Label("This user %s an administrator." % admin_label), 0, 1)
return [Label("Create this user account?"), return [Label("Create this user account?"),
grid] grid]
def CreateUser(): def CreateUser():
screen = CreateUserConfigScreen() screen = CreateUserConfigScreen()
screen.start() screen.start()

View File

@ -1,257 +1,257 @@
# definenet.py - Copyright (C) 2009 Red Hat, Inc. # definenet.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from IPy import IP from IPy import IP
import traceback import traceback
import logging import logging
import re import re
from configscreen import ConfigScreen from configscreen import ConfigScreen
from networkconfig import NetworkConfig from networkconfig import NetworkConfig
from utils import * from utils import *
NETWORK_NAME_PAGE = 1 NETWORK_NAME_PAGE = 1
IPV4_ADDRESS_PAGE = 2 IPV4_ADDRESS_PAGE = 2
PUBLIC_NETWORK_ALERT_PAGE = 3 PUBLIC_NETWORK_ALERT_PAGE = 3
NETWORK_DETAILS_PAGE = 4 NETWORK_DETAILS_PAGE = 4
DHCP_RANGE_PAGE = 5 DHCP_RANGE_PAGE = 5
NETWORK_TYPE_PAGE = 6 NETWORK_TYPE_PAGE = 6
SELECT_PHYSICAL_NETWORK_PAGE = 7 SELECT_PHYSICAL_NETWORK_PAGE = 7
SUMMARY_PAGE = 8 SUMMARY_PAGE = 8
class DefineNetworkConfigScreen(ConfigScreen): class DefineNetworkConfigScreen(ConfigScreen):
def __init__(self): def __init__(self):
ConfigScreen.__init__(self, "Create A Virtual Network Interface") ConfigScreen.__init__(self, "Create A Virtual Network Interface")
self.__config = NetworkConfig() self.__config = NetworkConfig()
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is NETWORK_NAME_PAGE: return self.get_network_name_page(screen) if page is NETWORK_NAME_PAGE: return self.get_network_name_page(screen)
elif page is IPV4_ADDRESS_PAGE: return self.get_ipv4_address_page(screen) elif page is IPV4_ADDRESS_PAGE: return self.get_ipv4_address_page(screen)
elif page is PUBLIC_NETWORK_ALERT_PAGE: return self.get_public_network_alert_page(screen) elif page is PUBLIC_NETWORK_ALERT_PAGE: return self.get_public_network_alert_page(screen)
elif page is NETWORK_DETAILS_PAGE: return self.get_network_details_page(screen) elif page is NETWORK_DETAILS_PAGE: return self.get_network_details_page(screen)
elif page is DHCP_RANGE_PAGE: return self.get_dhcp_range_page(screen) elif page is DHCP_RANGE_PAGE: return self.get_dhcp_range_page(screen)
elif page is NETWORK_TYPE_PAGE: return self.get_network_type_page(screen) elif page is NETWORK_TYPE_PAGE: return self.get_network_type_page(screen)
elif page is SELECT_PHYSICAL_NETWORK_PAGE: return self.get_select_physical_network_page(screen) elif page is SELECT_PHYSICAL_NETWORK_PAGE: return self.get_select_physical_network_page(screen)
elif page is SUMMARY_PAGE: return self.get_summary_page(screen) elif page is SUMMARY_PAGE: return self.get_summary_page(screen)
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is NETWORK_NAME_PAGE: if page is NETWORK_NAME_PAGE:
if len(self.__name.value()) > 0: if len(self.__name.value()) > 0:
if re.match("^[a-zA-Z0-9_]*$", self.__name.value()): if re.match("^[a-zA-Z0-9_]*$", self.__name.value()):
return True return True
else: else:
errors.append("The network name can only contain letters, numbers and the underscore, and no spaces.") errors.append("The network name can only contain letters, numbers and the underscore, and no spaces.")
else: else:
errors.append("Network name must be non-blank and less than 50 characters") errors.append("Network name must be non-blank and less than 50 characters")
elif page is IPV4_ADDRESS_PAGE: elif page is IPV4_ADDRESS_PAGE:
if len(self.__ipv4_address.value()) > 0: if len(self.__ipv4_address.value()) > 0:
try: try:
self.__config.set_ipv4_address(self.__ipv4_address.value()) self.__config.set_ipv4_address(self.__ipv4_address.value())
return True return True
except Exception, error: except Exception, error:
errors.append("The network address could not be understood: %s" % str(error)) errors.append("The network address could not be understood: %s" % str(error))
else: else:
errors.append("Network must be entered in the format 1.2.3.4/8") errors.append("Network must be entered in the format 1.2.3.4/8")
elif page is PUBLIC_NETWORK_ALERT_PAGE: return True elif page is PUBLIC_NETWORK_ALERT_PAGE: return True
elif page is NETWORK_DETAILS_PAGE: return True elif page is NETWORK_DETAILS_PAGE: return True
elif page is DHCP_RANGE_PAGE: elif page is DHCP_RANGE_PAGE:
try: try:
if len(self.__start_address.value()) > 0 and len(self.__end_address.value()) > 0: if len(self.__start_address.value()) > 0 and len(self.__end_address.value()) > 0:
start = IP(self.__start_address.value(), ) start = IP(self.__start_address.value(), )
end = IP(self.__end_address.value()) end = IP(self.__end_address.value())
if not self.__config.is_bad_address(start) and not self.__config.is_bad_address(end): if not self.__config.is_bad_address(start) and not self.__config.is_bad_address(end):
return True return True
else: else:
errors.append("Start and/or end address are outside of the choosen network.") errors.append("Start and/or end address are outside of the choosen network.")
else: else:
errors.append("Start and end address must be non-blank.") errors.append("Start and end address must be non-blank.")
except Exception, error: except Exception, error:
logging.error(str(error)) logging.error(str(error))
errors.append("The start and/or end addresses could not be understood.") errors.append("The start and/or end addresses could not be understood.")
elif page is NETWORK_TYPE_PAGE: return True elif page is NETWORK_TYPE_PAGE: return True
elif page is SELECT_PHYSICAL_NETWORK_PAGE: return True elif page is SELECT_PHYSICAL_NETWORK_PAGE: return True
elif page is SUMMARY_PAGE: return True elif page is SUMMARY_PAGE: return True
return False return False
def process_input(self, page): def process_input(self, page):
if page is NETWORK_NAME_PAGE: if page is NETWORK_NAME_PAGE:
self.__config.set_name(self.__name.value()) self.__config.set_name(self.__name.value())
elif page is DHCP_RANGE_PAGE: elif page is DHCP_RANGE_PAGE:
self.__config.set_ipv4_start_address(self.__start_address.value()) self.__config.set_ipv4_start_address(self.__start_address.value())
self.__config.set_ipv4_end_address(self.__end_address.value()) self.__config.set_ipv4_end_address(self.__end_address.value())
elif page is NETWORK_TYPE_PAGE: elif page is NETWORK_TYPE_PAGE:
self.__config.set_isolated_network(self.__isolated_network.value()) self.__config.set_isolated_network(self.__isolated_network.value())
elif page is SELECT_PHYSICAL_NETWORK_PAGE: elif page is SELECT_PHYSICAL_NETWORK_PAGE:
self.__config.set_physical_device(self.__physical_devices.getSelection()) self.__config.set_physical_device(self.__physical_devices.getSelection())
elif page is SUMMARY_PAGE: elif page is SUMMARY_PAGE:
self.get_libvirt().define_network(self.__config) self.get_libvirt().define_network(self.__config)
self.set_finished() self.set_finished()
def get_next_page(self, page): def get_next_page(self, page):
if page is IPV4_ADDRESS_PAGE: if page is IPV4_ADDRESS_PAGE:
if self.__config.is_public_ipv4_network(): if self.__config.is_public_ipv4_network():
return PUBLIC_NETWORK_ALERT_PAGE return PUBLIC_NETWORK_ALERT_PAGE
else: else:
return NETWORK_DETAILS_PAGE return NETWORK_DETAILS_PAGE
if page is NETWORK_TYPE_PAGE: if page is NETWORK_TYPE_PAGE:
if self.__config.is_isolated_network(): if self.__config.is_isolated_network():
return SUMMARY_PAGE return SUMMARY_PAGE
else: else:
return SELECT_PHYSICAL_NETWORK_PAGE return SELECT_PHYSICAL_NETWORK_PAGE
return ConfigScreen.get_next_page(self, page) return ConfigScreen.get_next_page(self, page)
def get_back_page(self, page): def get_back_page(self, page):
if page is NETWORK_DETAILS_PAGE: if page is NETWORK_DETAILS_PAGE:
return IPV4_ADDRESS_PAGE return IPV4_ADDRESS_PAGE
if page is SUMMARY_PAGE: if page is SUMMARY_PAGE:
if self.__config.is_isolated_network(): if self.__config.is_isolated_network():
return NETWORK_TYPE_PAGE return NETWORK_TYPE_PAGE
else: else:
return SELECT_PHYSICAL_NETWORK_PAGE return SELECT_PHYSICAL_NETWORK_PAGE
return ConfigScreen.get_back_page(self, page) return ConfigScreen.get_back_page(self, page)
def page_has_finish(self, page): def page_has_finish(self, page):
if page is SUMMARY_PAGE: return True if page is SUMMARY_PAGE: return True
return False return False
def page_has_next(self, page): def page_has_next(self, page):
if page < SUMMARY_PAGE: return True if page < SUMMARY_PAGE: return True
def page_has_back(self, page): def page_has_back(self, page):
if page > NETWORK_NAME_PAGE: return True if page > NETWORK_NAME_PAGE: return True
return False return False
def get_network_name_page(self, screen): def get_network_name_page(self, screen):
self.__name = Entry(50, self.__config.get_name()) self.__name = Entry(50, self.__config.get_name())
grid = Grid(2, 1) grid = Grid(2, 1)
grid.setField(Label("Network Name:"), 0, 0) grid.setField(Label("Network Name:"), 0, 0)
grid.setField(self.__name, 1, 0) grid.setField(self.__name, 1, 0)
return [Label("Please choose a name for your virtual network"), return [Label("Please choose a name for your virtual network"),
grid] grid]
def get_ipv4_address_page(self, screen): def get_ipv4_address_page(self, screen):
self.__ipv4_address = Entry(18, self.__config.get_ipv4_address()) self.__ipv4_address = Entry(18, self.__config.get_ipv4_address())
grid = Grid(2, 1) grid = Grid(2, 1)
grid.setField(Label("Network:"), 0, 0, anchorRight = 1) grid.setField(Label("Network:"), 0, 0, anchorRight = 1)
grid.setField(self.__ipv4_address, 1, 0, anchorLeft = 1) grid.setField(self.__ipv4_address, 1, 0, anchorLeft = 1)
return [Label("You will need to choose an IPv4 address space for the virtual network:"), return [Label("You will need to choose an IPv4 address space for the virtual network:"),
grid, grid,
Label("HINT: The network should be chosen from"), Label("HINT: The network should be chosen from"),
Label("one of the IPv4 private address ranges;"), Label("one of the IPv4 private address ranges;"),
Label("e.g., 10.0.0.0/8, 172.168.0.0/12, 192.168.0.0/16")] Label("e.g., 10.0.0.0/8, 172.168.0.0/12, 192.168.0.0/16")]
def get_network_details_page(self, screen): def get_network_details_page(self, screen):
grid = Grid(2, 6) grid = Grid(2, 6)
grid.setField(Label("Network:"), 0, 0, anchorRight = 1) grid.setField(Label("Network:"), 0, 0, anchorRight = 1)
grid.setField(Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft = 1) grid.setField(Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft = 1)
grid.setField(Label("Netmask:"), 0, 1, anchorRight = 1) grid.setField(Label("Netmask:"), 0, 1, anchorRight = 1)
grid.setField(Label(self.__config.get_ipv4_netmask()), 1, 1, anchorLeft = 1) grid.setField(Label(self.__config.get_ipv4_netmask()), 1, 1, anchorLeft = 1)
grid.setField(Label("Broadcast:"), 0, 2, anchorRight = 1) grid.setField(Label("Broadcast:"), 0, 2, anchorRight = 1)
grid.setField(Label(self.__config.get_ipv4_broadcast()), 1, 2, anchorLeft = 1) grid.setField(Label(self.__config.get_ipv4_broadcast()), 1, 2, anchorLeft = 1)
grid.setField(Label("Gateway:"), 0, 3, anchorRight = 1) grid.setField(Label("Gateway:"), 0, 3, anchorRight = 1)
grid.setField(Label(self.__config.get_ipv4_gateway()), 1, 3, anchorLeft = 1) grid.setField(Label(self.__config.get_ipv4_gateway()), 1, 3, anchorLeft = 1)
grid.setField(Label("Size:"), 0, 4, anchorRight = 1) grid.setField(Label("Size:"), 0, 4, anchorRight = 1)
grid.setField(Label("%d addresses" % self.__config.get_ipv4_max_addresses()), 1, 4, anchorLeft = 1) grid.setField(Label("%d addresses" % self.__config.get_ipv4_max_addresses()), 1, 4, anchorLeft = 1)
grid.setField(Label("Type:"), 0, 5, anchorRight = 1) grid.setField(Label("Type:"), 0, 5, anchorRight = 1)
grid.setField(Label(self.__config.get_ipv4_network_type()), 1, 5, anchorLeft = 1) grid.setField(Label(self.__config.get_ipv4_network_type()), 1, 5, anchorLeft = 1)
return [Label("Network Details"), return [Label("Network Details"),
grid] grid]
def get_public_network_alert_page(self, screen): def get_public_network_alert_page(self, screen):
grid = Grid(1, 2) grid = Grid(1, 2)
grid.setField(Label("The network should normally use a private IPv4 address."), 0, 0, anchorLeft = 1) grid.setField(Label("The network should normally use a private IPv4 address."), 0, 0, anchorLeft = 1)
grid.setField(Label("Use this non-private address anyway?"), 0, 1, anchorLeft = 1) grid.setField(Label("Use this non-private address anyway?"), 0, 1, anchorLeft = 1)
return [Label("Check Network Address"), return [Label("Check Network Address"),
grid] grid]
def get_dhcp_range_page(self, screen): def get_dhcp_range_page(self, screen):
self.__start_address = Entry(15, self.__config.get_ipv4_start_address()) self.__start_address = Entry(15, self.__config.get_ipv4_start_address())
self.__end_address = Entry(15, self.__config.get_ipv4_end_address()) self.__end_address = Entry(15, self.__config.get_ipv4_end_address())
grid = Grid(2,2) grid = Grid(2,2)
grid.setField(Label("Start:"), 0, 0, anchorRight = 1) grid.setField(Label("Start:"), 0, 0, anchorRight = 1)
grid.setField(self.__start_address, 1, 0, anchorLeft = 1) grid.setField(self.__start_address, 1, 0, anchorLeft = 1)
grid.setField(Label("End:"), 0, 1, anchorRight = 1) grid.setField(Label("End:"), 0, 1, anchorRight = 1)
grid.setField(self.__end_address, 1, 1, anchorLeft = 1) grid.setField(self.__end_address, 1, 1, anchorLeft = 1)
return [Label("Selecting The DHCP Range"), return [Label("Selecting The DHCP Range"),
grid, grid,
Label("TIP: Unless you wish to reserve some addresses to allow static network"), Label("TIP: Unless you wish to reserve some addresses to allow static network"),
Label("configuration in virtual machines, these paraemters can be left with"), Label("configuration in virtual machines, these paraemters can be left with"),
Label("their default values.")] Label("their default values.")]
def get_network_type_page(self, screen): def get_network_type_page(self, screen):
self.__isolated_network = Checkbox("Isolated virtual network", self.__isolated_network = Checkbox("Isolated virtual network",
self.__config.is_isolated_network()) self.__config.is_isolated_network())
grid = Grid(1, 3) grid = Grid(1, 3)
grid.setField(Label("Please indicate whether this virtual network should be"), 0, 0, anchorLeft = 1) grid.setField(Label("Please indicate whether this virtual network should be"), 0, 0, anchorLeft = 1)
grid.setField(Label("connected to the physical network."), 0, 1, anchorLeft = 1) grid.setField(Label("connected to the physical network."), 0, 1, anchorLeft = 1)
grid.setField(self.__isolated_network, 0, 2) grid.setField(self.__isolated_network, 0, 2)
return [Label("Connecting To Physical Network"), return [Label("Connecting To Physical Network"),
grid] grid]
def get_select_physical_network_page(self, screen): def get_select_physical_network_page(self, screen):
devices = [] devices = []
devices.append(["NAT to any physical device", "", self.__config.get_physical_device() == ""]) devices.append(["NAT to any physical device", "", self.__config.get_physical_device() == ""])
for device in self.get_hal().list_network_devices(): for device in self.get_hal().list_network_devices():
devices.append(["NAT to physical device %s" % device, device, self.__config.get_physical_device() == device]) devices.append(["NAT to physical device %s" % device, device, self.__config.get_physical_device() == device])
self.__physical_devices = RadioBar(screen, (devices)) self.__physical_devices = RadioBar(screen, (devices))
grid = Grid(1, 2) grid = Grid(1, 2)
grid.setField(Label("Forward to physical network:"), 0, 0) grid.setField(Label("Forward to physical network:"), 0, 0)
grid.setField(self.__physical_devices, 0, 1) grid.setField(self.__physical_devices, 0, 1)
return [Label("Connecting To Physical Network"), return [Label("Connecting To Physical Network"),
grid] grid]
def get_summary_page(self, screen): def get_summary_page(self, screen):
grid1 = Grid(2, 1) grid1 = Grid(2, 1)
grid1.setField(Label("Network name:"), 0, 0, anchorRight = 1) grid1.setField(Label("Network name:"), 0, 0, anchorRight = 1)
grid1.setField(Label(self.__config.get_name()), 1, 0, anchorLeft = 1) grid1.setField(Label(self.__config.get_name()), 1, 0, anchorLeft = 1)
grid2 = Grid(2, 3) grid2 = Grid(2, 3)
grid2.setField(Label("Network:"), 0, 0, anchorRight = 1) grid2.setField(Label("Network:"), 0, 0, anchorRight = 1)
grid2.setField(Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft = 1) grid2.setField(Label(self.__config.get_ipv4_address()), 1, 0, anchorLeft = 1)
grid2.setField(Label("Gateway:"), 0, 1, anchorRight = 1) grid2.setField(Label("Gateway:"), 0, 1, anchorRight = 1)
grid2.setField(Label(self.__config.get_ipv4_gateway()), 1, 1, anchorLeft = 1) grid2.setField(Label(self.__config.get_ipv4_gateway()), 1, 1, anchorLeft = 1)
grid2.setField(Label("Netmask:"), 0, 2, anchorRight = 1) grid2.setField(Label("Netmask:"), 0, 2, anchorRight = 1)
grid2.setField(Label(self.__config.get_ipv4_netmask()), 1, 2, anchorLeft = 1) grid2.setField(Label(self.__config.get_ipv4_netmask()), 1, 2, anchorLeft = 1)
grid3 = Grid(2, 2) grid3 = Grid(2, 2)
grid3.setField(Label("Start address:"), 0, 0, anchorRight = 1) grid3.setField(Label("Start address:"), 0, 0, anchorRight = 1)
grid3.setField(Label(self.__config.get_ipv4_start_address()), 1, 0, anchorLeft = 1) grid3.setField(Label(self.__config.get_ipv4_start_address()), 1, 0, anchorLeft = 1)
grid3.setField(Label("End address:"), 0, 1, anchorRight = 1) grid3.setField(Label("End address:"), 0, 1, anchorRight = 1)
grid3.setField(Label(self.__config.get_ipv4_end_address()), 1, 1, anchorLeft = 1) grid3.setField(Label(self.__config.get_ipv4_end_address()), 1, 1, anchorLeft = 1)
grid4 = Grid(2, 1) grid4 = Grid(2, 1)
grid4.setField(Label("Connectivity:"), 0, 0, anchorRight = 1) grid4.setField(Label("Connectivity:"), 0, 0, anchorRight = 1)
if self.__config.is_isolated_network(): if self.__config.is_isolated_network():
grid4.setField(Label("Isolated virtual network"), 1, 0, anchorLeft = 1) grid4.setField(Label("Isolated virtual network"), 1, 0, anchorLeft = 1)
else: else:
grid4.setField(Label("NAT to %s" % self.__config.get_physical_device_text()), 1, 0, anchorLeft = 1) grid4.setField(Label("NAT to %s" % self.__config.get_physical_device_text()), 1, 0, anchorLeft = 1)
return [Label("Ready To Create Network"), return [Label("Ready To Create Network"),
Label("Summary"), Label("Summary"),
grid1, grid1,
Label("IPv4 Network"), Label("IPv4 Network"),
grid2, grid2,
Label("DHCP"), Label("DHCP"),
grid3, grid3,
Label("Forwarding"), Label("Forwarding"),
grid4] grid4]
def DefineNetwork(): def DefineNetwork():
screen = DefineNetworkConfigScreen() screen = DefineNetworkConfigScreen()
screen.start() screen.start()

View File

@ -1,56 +1,56 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# destroynetwork.py - Copyright (C) 2009 Red Hat, Inc. # destroynetwork.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_PAGE = 1 LIST_PAGE = 1
DESTROY_PAGE = 2 DESTROY_PAGE = 2
class DestroyNetworkConfigScreen(NetworkListConfigScreen): class DestroyNetworkConfigScreen(NetworkListConfigScreen):
def __init__(self): def __init__(self):
NetworkListConfigScreen.__init__(self, "Destroy A Network") NetworkListConfigScreen.__init__(self, "Destroy A Network")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_PAGE: return self.get_network_list_page(screen, defined = False) if page is LIST_PAGE: return self.get_network_list_page(screen, defined = False)
elif page is DESTROY_PAGE: return self.get_destroy_network_page(screen) elif page is DESTROY_PAGE: return self.get_destroy_network_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is LIST_PAGE: return self.has_selectable_networks() if page is LIST_PAGE: return self.has_selectable_networks()
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is DESTROY_PAGE: return True if page is DESTROY_PAGE: return True
return False return False
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_PAGE: if page is LIST_PAGE:
network = self.get_selected_network() network = self.get_selected_network()
self.get_libvirt().destroy_network(network) self.get_libvirt().destroy_network(network)
return True return True
return False return False
def get_destroy_network_page(self, screen): def get_destroy_network_page(self, screen):
return [Label("Network Destroyed"), return [Label("Network Destroyed"),
Label("%s has been destroyed." % self.get_selected_network())] Label("%s has been destroyed." % self.get_selected_network())]
def DestroyNetwork(): def DestroyNetwork():
screen = DestroyNetworkConfigScreen() screen = DestroyNetworkConfigScreen()
screen.start() screen.start()

View File

@ -1,224 +1,224 @@
# domainconfig.py - Copyright (C) 2009 Red Hat, Inc. # domainconfig.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from virtinst import Guest from virtinst import Guest
class DomainConfig: class DomainConfig:
LOCAL_INSTALL = "local" LOCAL_INSTALL = "local"
NETWORK_INSTALL = "network" NETWORK_INSTALL = "network"
PXE_INSTALL = "pxe" PXE_INSTALL = "pxe"
INSTALL_TYPE_TEXT = {LOCAL_INSTALL : "Local CDROM/ISO", INSTALL_TYPE_TEXT = {LOCAL_INSTALL : "Local CDROM/ISO",
NETWORK_INSTALL : "URL INstall Tree", NETWORK_INSTALL : "URL INstall Tree",
PXE_INSTALL : "PXE Install"} PXE_INSTALL : "PXE Install"}
INSTALL_SOURCE_CDROM = "cdrom" INSTALL_SOURCE_CDROM = "cdrom"
INSTALL_SOURCE_ISO = "iso" INSTALL_SOURCE_ISO = "iso"
NEW_STORAGE = "new" NEW_STORAGE = "new"
EXISTING_STORAGE = "existing" EXISTING_STORAGE = "existing"
def __init__(self): def __init__(self):
self.__guest_name = "" self.__guest_name = ""
self.__install_type = DomainConfig.LOCAL_INSTALL self.__install_type = DomainConfig.LOCAL_INSTALL
self.__use_cdrom_source = True self.__use_cdrom_source = True
self.__install_location = "" self.__install_location = ""
self.__install_media = "" self.__install_media = ""
self.__iso_path = "" self.__iso_path = ""
self.__install_url = "" self.__install_url = ""
self.__kickstart_url = "" self.__kickstart_url = ""
self.__kernel_options = "" self.__kernel_options = ""
self.__os_type = "other" self.__os_type = "other"
self.__os_variant = None self.__os_variant = None
self.__memory = 512 self.__memory = 512
self.__cpus = 1 self.__cpus = 1
self.__enable_storage = True self.__enable_storage = True
self.__use_local_storage = True self.__use_local_storage = True
self.__storage_size = 8.0 self.__storage_size = 8.0
self.__allocate_storage = True self.__allocate_storage = True
self.__storage_pool = "" self.__storage_pool = ""
self.__storage_volume = "" self.__storage_volume = ""
self.__network_bridge = None self.__network_bridge = None
self.__mac_address = None self.__mac_address = None
self.__virt_type = None self.__virt_type = None
self.__architecture = None self.__architecture = None
def set_guest_name(self, name): def set_guest_name(self, name):
self.__guest_name = name self.__guest_name = name
def get_guest_name(self): def get_guest_name(self):
return self.__guest_name return self.__guest_name
def set_install_type(self, type): def set_install_type(self, type):
self.__install_type = type self.__install_type = type
def get_install_type(self): def get_install_type(self):
return self.__install_type return self.__install_type
def get_install_type_text(self): def get_install_type_text(self):
return DomainConfig.INSTALL_TYPE_TEXT[self.get_install_type()] return DomainConfig.INSTALL_TYPE_TEXT[self.get_install_type()]
def is_install_type(self, type): def is_install_type(self, type):
return self.__install_type == type return self.__install_type == type
def set_install_location(self, location): def set_install_location(self, location):
self.__install_location = location self.__install_location = location
def set_use_cdrom_source(self, use): def set_use_cdrom_source(self, use):
self.__use_cdrom_source = use self.__use_cdrom_source = use
def get_use_cdrom_source(self): def get_use_cdrom_source(self):
return self.__use_cdrom_source return self.__use_cdrom_source
def get_install_location(self): def get_install_location(self):
return self.__install_location return self.__install_location
def is_install_location(self, location): def is_install_location(self, location):
return self.__install_location == location return self.__install_location == location
def set_install_media(self, media): def set_install_media(self, media):
self.__install_media = media self.__install_media = media
def get_install_media(self): def get_install_media(self):
return self.__install_media return self.__install_media
def is_install_media(self, media): def is_install_media(self, media):
return self.__install_media == media return self.__install_media == media
def set_iso_path(self, path): def set_iso_path(self, path):
self.__iso_path = path self.__iso_path = path
def get_iso_path(self): def get_iso_path(self):
return self.__iso_path return self.__iso_path
def set_install_url(self, url): def set_install_url(self, url):
self.__install_url = url self.__install_url = url
def get_install_url(self): def get_install_url(self):
return self.__install_url return self.__install_url
def set_kickstart_url(self, url): def set_kickstart_url(self, url):
self.__kickstart_url = url self.__kickstart_url = url
def get_kickstart_url(self): def get_kickstart_url(self):
return self.__kickstart_url return self.__kickstart_url
def set_kernel_options(self, options): def set_kernel_options(self, options):
self.__kernel_options = options self.__kernel_options = options
def get_kernel_options(self): def get_kernel_options(self):
return self.__kernel_options return self.__kernel_options
def set_os_type(self, type): def set_os_type(self, type):
self.__os_type = type self.__os_type = type
self.__os_variant = Guest.list_os_variants(type)[0] self.__os_variant = Guest.list_os_variants(type)[0]
def get_os_type(self): def get_os_type(self):
return self.__os_type return self.__os_type
def is_os_type(self, type): def is_os_type(self, type):
return self.__os_type == type return self.__os_type == type
def set_os_variant(self, variant): def set_os_variant(self, variant):
self.__os_variant = variant self.__os_variant = variant
def get_os_variant(self): def get_os_variant(self):
return self.__os_variant return self.__os_variant
def is_os_variant(self, variant): def is_os_variant(self, variant):
return self.__os_variant == variant return self.__os_variant == variant
def set_memory(self, memory): def set_memory(self, memory):
self.__memory = int(memory) self.__memory = int(memory)
def get_memory(self): def get_memory(self):
return self.__memory return self.__memory
def set_cpus(self, cpus): def set_cpus(self, cpus):
self.__cpus = cpus self.__cpus = cpus
def get_cpus(self): def get_cpus(self):
return self.__cpus return self.__cpus
def set_enable_storage(self, enable): def set_enable_storage(self, enable):
self.__enable_storage = enable self.__enable_storage = enable
def get_enable_storage(self): def get_enable_storage(self):
return self.__enable_storage return self.__enable_storage
def set_use_local_storage(self, use): def set_use_local_storage(self, use):
self.__use_local_storage = use self.__use_local_storage = use
def get_use_local_storage(self): def get_use_local_storage(self):
return self.__use_local_storage return self.__use_local_storage
def set_storage_size(self, size): def set_storage_size(self, size):
self.__storage_size = size self.__storage_size = size
def get_storage_size(self): def get_storage_size(self):
return self.__storage_size return self.__storage_size
def set_allocate_storage(self, allocate): def set_allocate_storage(self, allocate):
self.__allocate_storage = allocate self.__allocate_storage = allocate
def get_allocate_storage(self): def get_allocate_storage(self):
return self.__allocate_storage return self.__allocate_storage
def set_storage_pool(self, pool): def set_storage_pool(self, pool):
self.__storage_pool = pool self.__storage_pool = pool
def get_storage_pool(self): def get_storage_pool(self):
return self.__storage_pool return self.__storage_pool
def set_storage_volume(self, volume): def set_storage_volume(self, volume):
self.__storage_volume = volume self.__storage_volume = volume
def get_storage_volume(self): def get_storage_volume(self):
return self.__storage_volume return self.__storage_volume
def is_existing_storage(self, storage): def is_existing_storage(self, storage):
return self.__existing_storage == storage return self.__existing_storage == storage
def set_network_bridge(self, bridge): def set_network_bridge(self, bridge):
self.__network_bridge = bridge self.__network_bridge = bridge
def get_network_bridge(self): def get_network_bridge(self):
return self.__network_bridge return self.__network_bridge
def set_mac_address(self, address): def set_mac_address(self, address):
self.__mac_address = address self.__mac_address = address
def get_mac_address(self): def get_mac_address(self):
return self.__mac_address return self.__mac_address
def set_virt_type(self, type): def set_virt_type(self, type):
self.__virt_type = type self.__virt_type = type
def get_virt_type(self): def get_virt_type(self):
return self.__virt_type return self.__virt_type
def is_virt_type(self, type): def is_virt_type(self, type):
return self.__virt_type == type return self.__virt_type == type
def set_architecture(self, architecture): def set_architecture(self, architecture):
self.__architecture = architecture self.__architecture = architecture
def get_architecture(self): def get_architecture(self):
return self.__architecture return self.__architecture
def is_architecture(self, architecture): def is_architecture(self, architecture):
return self.__architecture == architecture return self.__architecture == architecture

View File

@ -1,45 +1,45 @@
# halworker.py - Copyright (C) 2009 Red Hat, Inc. # halworker.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import dbus import dbus
import virtinst import virtinst
class HALWorker: class HALWorker:
'''Provides utilities for working with HAL to get hardware information.''' '''Provides utilities for working with HAL to get hardware information.'''
def __init__(self): def __init__(self):
self.__bus = dbus.SystemBus() self.__bus = dbus.SystemBus()
hobj = self.__bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") hobj = self.__bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
self.__conn = dbus.Interface(hobj, "org.freedesktop.Hal.Manager") self.__conn = dbus.Interface(hobj, "org.freedesktop.Hal.Manager")
def list_installable_volumes(self): def list_installable_volumes(self):
result = {} result = {}
for udi in self.__conn.FindDeviceByCapability("volume"): for udi in self.__conn.FindDeviceByCapability("volume"):
device = self.__bus.get_object("org.freedesktop.Hal", udi) device = self.__bus.get_object("org.freedesktop.Hal", udi)
info = dbus.Interface(device, "org.freedesktop.Hal.Device") info = dbus.Interface(device, "org.freedesktop.Hal.Device")
if info.GetProperty("volume.is_disc"): if info.GetProperty("volume.is_disc"):
if info.GetProperty("volume.disc.has_data"): if info.GetProperty("volume.disc.has_data"):
result[str(info.GetProperty("block.device"))] = info.GetProperty("volume.label") result[str(info.GetProperty("block.device"))] = info.GetProperty("volume.label")
return result return result
def list_network_devices(self): def list_network_devices(self):
result = [] result = []
for udi in self.__conn.FindDeviceByCapability("net"): for udi in self.__conn.FindDeviceByCapability("net"):
device = self.__bus.get_object("org.freedesktop.Hal", udi) device = self.__bus.get_object("org.freedesktop.Hal", udi)
info = dbus.Interface(device, "org.freedesktop.Hal.Device") info = dbus.Interface(device, "org.freedesktop.Hal.Device")
result.append(info.GetProperty("net.interface")) result.append(info.GetProperty("net.interface"))
return result return result

View File

@ -1,29 +1,29 @@
# hostconnect.py - Copyright (C) 2009 Red Hat, Inc. # hostconnect.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
class HostConnectConfigScreen(ConfigScreen): class HostConnectConfigScreen(ConfigScreen):
def __init__(self): def __init__(self):
ConfigScree ConfigScree
def HostConnect(): def HostConnect():
screen = HostConnectConfigScreen() screen = HostConnectConfigScreen()
screen.start() screen.start()

View File

@ -1,46 +1,46 @@
# hostmenu.py - Copyright (C) 2009 Red Hat, Inc. # hostmenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from menuscreen import MenuScreen from menuscreen import MenuScreen
from changehost import ChangeHost from changehost import ChangeHost
from addhost import AddHost from addhost import AddHost
from removehost import RemoveHost from removehost import RemoveHost
SELECT_HOST = 1 SELECT_HOST = 1
ADD_HOST = 2 ADD_HOST = 2
REMOVE_HOST = 3 REMOVE_HOST = 3
class HostMenuScreen(MenuScreen): class HostMenuScreen(MenuScreen):
def __init__(self): def __init__(self):
MenuScreen.__init__(self, "Host Menu Screen") MenuScreen.__init__(self, "Host Menu Screen")
def get_menu_items(self): def get_menu_items(self):
return (("Select A Host", SELECT_HOST), return (("Select A Host", SELECT_HOST),
("Add A Host", ADD_HOST), ("Add A Host", ADD_HOST),
("Remove A Host", REMOVE_HOST)) ("Remove A Host", REMOVE_HOST))
def handle_selection(self, item): def handle_selection(self, item):
if item is SELECT_HOST: ChangeHost() if item is SELECT_HOST: ChangeHost()
elif item is ADD_HOST: AddHost() elif item is ADD_HOST: AddHost()
elif item is REMOVE_HOST: RemoveHost() elif item is REMOVE_HOST: RemoveHost()
def HostMenu(): def HostMenu():
screen = HostMenuScreen() screen = HostMenuScreen()
screen.start() screen.start()

View File

@ -1,463 +1,463 @@
# libvirtworker.py - Copyright (C) 2009 Red Hat, Inc. # libvirtworker.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import dbus import dbus
import libvirt import libvirt
import os import os
import virtinst import virtinst
import utils import utils
import logging import logging
from domainconfig import DomainConfig from domainconfig import DomainConfig
DEFAULT_POOL_TARGET_PATH="/var/lib/libvirt/images" DEFAULT_POOL_TARGET_PATH="/var/lib/libvirt/images"
DEFAULT_URL="qemu:///system" DEFAULT_URL="qemu:///system"
default_url = DEFAULT_URL default_url = DEFAULT_URL
def set_default_url(url): def set_default_url(url):
logging.info("Changing DEFAULT_URL to %s" % url) logging.info("Changing DEFAULT_URL to %s" % url)
global default_url global default_url
default_url = url default_url = url
def get_default_url(): def get_default_url():
logging.info("Returning default URL of %s" % default_url) logging.info("Returning default URL of %s" % default_url)
return default_url return default_url
class VirtManagerConfig: class VirtManagerConfig:
def __init__(self, filename=None): def __init__(self, filename=None):
if filename is None: if filename is None:
filename = os.path.expanduser("~/.virt-manager/virt-manager-tui.conf") filename = os.path.expanduser("~/.virt-manager/virt-manager-tui.conf")
self.__filename = filename self.__filename = filename
def get_connection_list(self): def get_connection_list(self):
result = [] result = []
if os.path.exists(self.__filename): if os.path.exists(self.__filename):
input = file(self.__filename, "r") input = file(self.__filename, "r")
for entry in input: result.append(entry[0:-1]) for entry in input: result.append(entry[0:-1])
return result return result
def add_connection(self, connection): def add_connection(self, connection):
connections = self.get_connection_list() connections = self.get_connection_list()
if connections.count(connection) is 0: if connections.count(connection) is 0:
connections.append(connection) connections.append(connection)
self._save_connections(connections) self._save_connections(connections)
def remove_connection(self, connection): def remove_connection(self, connection):
connections = self.get_connection_list() connections = self.get_connection_list()
if connections.count(connection) > 0: if connections.count(connection) > 0:
connections.remove(connection) connections.remove(connection)
self._save_connections(connections) self._save_connections(connections)
def _save_connections(self, connections): def _save_connections(self, connections):
output = file(self.__filename, "w") output = file(self.__filename, "w")
for entry in connections: for entry in connections:
print >> output, entry print >> output, entry
output.close output.close
class LibvirtWorker: class LibvirtWorker:
'''Provides utilities for interfacing with libvirt.''' '''Provides utilities for interfacing with libvirt.'''
def __init__(self, url = None): def __init__(self, url = None):
if url is None: url = get_default_url() if url is None: url = get_default_url()
logging.info("Connecting to libvirt: %s" % url) logging.info("Connecting to libvirt: %s" % url)
self.__url = None self.__url = None
self.__conn = None self.__conn = None
self.open_connection(url) self.open_connection(url)
self.__capabilities = virtinst.CapabilitiesParser.parse(self.__conn.getCapabilities()) self.__capabilities = virtinst.CapabilitiesParser.parse(self.__conn.getCapabilities())
self.__net = virtinst.VirtualNetworkInterface(conn = self.__conn) self.__net = virtinst.VirtualNetworkInterface(conn = self.__conn)
self.__net.setup(self.__conn) self.__net.setup(self.__conn)
(self.__new_guest, self.__new_domain) = virtinst.CapabilitiesParser.guest_lookup(conn = self.__conn) (self.__new_guest, self.__new_domain) = virtinst.CapabilitiesParser.guest_lookup(conn = self.__conn)
def get_connection(self): def get_connection(self):
'''Returns the underlying connection.''' '''Returns the underlying connection.'''
return self.__conn return self.__conn
def get_url(self): def get_url(self):
return self.__url return self.__url
def open_connection(self, url): def open_connection(self, url):
'''Lets the user change the url for the connection.''' '''Lets the user change the url for the connection.'''
old_conn = self.__conn old_conn = self.__conn
old_url = self.__url old_url = self.__url
try: try:
self.__conn = libvirt.open(url) self.__conn = libvirt.open(url)
self.__url = url self.__url = url
set_default_url(url) set_default_url(url)
except Exception, error: except Exception, error:
self.__conn = old_conn self.__conn = old_conn
self.__url = old_url self.__url = old_url
raise error raise error
def list_domains(self, defined = True, started = True): def list_domains(self, defined = True, started = True):
'''Lists all domains.''' '''Lists all domains.'''
result = [] result = []
if defined: if defined:
result.extend(self.__conn.listDefinedDomains()) result.extend(self.__conn.listDefinedDomains())
if started: if started:
for id in self.__conn.listDomainsID(): for id in self.__conn.listDomainsID():
result.append(self.__conn.lookupByID(id).name()) result.append(self.__conn.lookupByID(id).name())
return result return result
def get_domain(self, name): def get_domain(self, name):
'''Returns the specified domain.''' '''Returns the specified domain.'''
result = self.__conn.lookupByName(name) result = self.__conn.lookupByName(name)
if result is None: raise Exception("No such domain exists: %s" % name) if result is None: raise Exception("No such domain exists: %s" % name)
return result return result
def domain_exists(self, name): def domain_exists(self, name):
'''Returns whether a domain with the specified node exists.''' '''Returns whether a domain with the specified node exists.'''
domains = self.list_domains() domains = self.list_domains()
if name in domains: return True if name in domains: return True
return False return False
def create_domain(self, name): def create_domain(self, name):
'''Creates the specified domain.''' '''Creates the specified domain.'''
domain = self.get_domain(name) domain = self.get_domain(name)
domain.create() domain.create()
def destroy_domain(self, name): def destroy_domain(self, name):
'''Destroys the specified domain.''' '''Destroys the specified domain.'''
domain = self.get_domain(name) domain = self.get_domain(name)
domain.destroy() domain.destroy()
def undefine_domain(self, name): def undefine_domain(self, name):
'''Undefines the specified domain.''' '''Undefines the specified domain.'''
domain = self.get_domain(name) domain = self.get_domain(name)
domain.undefine() domain.undefine()
def migrate_domain(self, name, target): def migrate_domain(self, name, target):
'''Migrates the specified domain to the target machine.''' '''Migrates the specified domain to the target machine.'''
target_conn = libvirt.open(target) target_conn = libvirt.open(target)
virtmachine = self.get_domain(name) virtmachine = self.get_domain(name)
virtmachine.migrate(target_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0) virtmachine.migrate(target_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0)
def list_networks(self, defined = True, started = True): def list_networks(self, defined = True, started = True):
'''Lists all networks.''' '''Lists all networks.'''
result = [] result = []
if defined: result.extend(self.__conn.listDefinedNetworks()) if defined: result.extend(self.__conn.listDefinedNetworks())
if started: result.extend(self.__conn.listNetworks()) if started: result.extend(self.__conn.listNetworks())
return result return result
def get_network(self, name): def get_network(self, name):
'''Returns the specified network.''' '''Returns the specified network.'''
result = self.__conn.networkLookupByName(name) result = self.__conn.networkLookupByName(name)
if result is None: raise Exception("No such network exists: %s" % name) if result is None: raise Exception("No such network exists: %s" % name)
return result return result
def network_exists(self, name): def network_exists(self, name):
'''Returns if a network with the given name already exists.''' '''Returns if a network with the given name already exists.'''
networks = self.list_networks() networks = self.list_networks()
if name in networks: return True if name in networks: return True
return False return False
def define_network(self, config): def define_network(self, config):
'''Defines a new network.''' '''Defines a new network.'''
# since there's no other way currently, we'll have to use XML # since there's no other way currently, we'll have to use XML
name = config.get_name() name = config.get_name()
ip = config.get_ipv4_address_raw() ip = config.get_ipv4_address_raw()
start = config.get_ipv4_start_address() start = config.get_ipv4_start_address()
end = config.get_ipv4_end_address() end = config.get_ipv4_end_address()
fw = config.get_physical_device() fw = config.get_physical_device()
xml = "<network>" + \ xml = "<network>" + \
" <name>%s</name>\n" % name " <name>%s</name>\n" % name
if not config.is_public_ipv4_network(): if not config.is_public_ipv4_network():
if fw is not "": if fw is not "":
xml += " <forward dev='%s'/>\n" % fw[1] xml += " <forward dev='%s'/>\n" % fw[1]
else: else:
xml += " <forward/>\n" xml += " <forward/>\n"
xml += " <ip address='%s' netmask='%s'>\n" % (str(ip[1]), str(ip.netmask())) xml += " <ip address='%s' netmask='%s'>\n" % (str(ip[1]), str(ip.netmask()))
xml += " <dhcp>\n" xml += " <dhcp>\n"
xml += " <range start='%s' end='%s'/>\n" % (str(start), str(end)) xml += " <range start='%s' end='%s'/>\n" % (str(start), str(end))
xml += " </dhcp>\n" xml += " </dhcp>\n"
xml += " </ip>\n" xml += " </ip>\n"
xml += "</network>\n" xml += "</network>\n"
self.__conn.networkDefineXML(xml) self.__conn.networkDefineXML(xml)
def create_network(self, name): def create_network(self, name):
'''Creates a defined network.''' '''Creates a defined network.'''
network = self.get_network(name) network = self.get_network(name)
network.create() network.create()
def destroy_network(self, name): def destroy_network(self, name):
'''Destroys the specified network.''' '''Destroys the specified network.'''
network = self.get_network(name) network = self.get_network(name)
network.destroy() network.destroy()
def undefine_network(self, name): def undefine_network(self, name):
'''Undefines the specified network.''' '''Undefines the specified network.'''
network = self.get_network(name) network = self.get_network(name)
network.undefine() network.undefine()
def list_storage_pools(self, defined=True, created=True): def list_storage_pools(self, defined=True, created=True):
'''Returns the list of all defined storage pools.''' '''Returns the list of all defined storage pools.'''
pools = [] pools = []
if defined: pools.extend(self.__conn.listDefinedStoragePools()) if defined: pools.extend(self.__conn.listDefinedStoragePools())
if created: pools.extend(self.__conn.listStoragePools()) if created: pools.extend(self.__conn.listStoragePools())
return pools return pools
def storage_pool_exists(self, name): def storage_pool_exists(self, name):
'''Returns whether a storage pool exists.''' '''Returns whether a storage pool exists.'''
pools = self.list_storage_pools() pools = self.list_storage_pools()
if name in pools: return True if name in pools: return True
return False return False
def create_storage_pool(self, name): def create_storage_pool(self, name):
'''Starts the named storage pool if it is not currently started.''' '''Starts the named storage pool if it is not currently started.'''
if name not in self.list_storage_pools(defined = False): if name not in self.list_storage_pools(defined = False):
pool = self.get_storage_pool(name) pool = self.get_storage_pool(name)
pool.create(0) pool.create(0)
def destroy_storage_pool(self, name): def destroy_storage_pool(self, name):
'''Stops the specified storage pool.''' '''Stops the specified storage pool.'''
if name in self.list_storage_pools(defined = False): if name in self.list_storage_pools(defined = False):
pool = self.get_storage_pool(name) pool = self.get_storage_pool(name)
pool.destroy() pool.destroy()
def define_storage_pool(self, name, config = None, meter = None): def define_storage_pool(self, name, config = None, meter = None):
'''Defines a storage pool with the given name.''' '''Defines a storage pool with the given name.'''
if config is None: if config is None:
pool = virtinst.Storage.DirectoryPool(conn=self.__conn, pool = virtinst.Storage.DirectoryPool(conn=self.__conn,
name=name, name=name,
target_path=DEFAULT_POOL_TARGET_PATH) target_path=DEFAULT_POOL_TARGET_PATH)
newpool = pool.install(build=True, create=True, meter=meter) newpool = pool.install(build=True, create=True, meter=meter)
newpool.setAutostart(True) newpool.setAutostart(True)
else: else:
pool = config.get_pool() pool = config.get_pool()
pool.target_path = config.get_target_path() pool.target_path = config.get_target_path()
if config.needs_hostname(): if config.needs_hostname():
pool.host = config.get_hostname() pool.host = config.get_hostname()
if config.needs_source_path(): if config.needs_source_path():
pool.source_path = config.get_source_path() pool.source_path = config.get_source_path()
if config.needs_format(): if config.needs_format():
pool.format = config.get_format() pool.format = config.get_format()
pool.conn = self.__conn pool.conn = self.__conn
pool.get_xml_config() pool.get_xml_config()
newpool = pool.install(meter=meter, newpool = pool.install(meter=meter,
build=True, # config.get_build_pool(), build=True, # config.get_build_pool(),
create=True) create=True)
newpool.setAutostart(True) newpool.setAutostart(True)
def undefine_storage_pool(self, name): def undefine_storage_pool(self, name):
'''Undefines the specified storage pool.''' '''Undefines the specified storage pool.'''
pool = self.get_storage_pool(name) pool = self.get_storage_pool(name)
pool.undefine() pool.undefine()
def get_storage_pool(self, name): def get_storage_pool(self, name):
'''Returns the storage pool with the specified name.''' '''Returns the storage pool with the specified name.'''
return self.__conn.storagePoolLookupByName(name) return self.__conn.storagePoolLookupByName(name)
def list_storage_volumes(self, poolname): def list_storage_volumes(self, poolname):
'''Returns the list of all defined storage volumes for a given pool.''' '''Returns the list of all defined storage volumes for a given pool.'''
pool = self.get_storage_pool(poolname) pool = self.get_storage_pool(poolname)
return pool.listVolumes() return pool.listVolumes()
def define_storage_volume(self, config, meter): def define_storage_volume(self, config, meter):
'''Defines a new storage volume.''' '''Defines a new storage volume.'''
self.create_storage_pool(config.get_pool().name()) self.create_storage_pool(config.get_pool().name())
volume = config.create_volume() volume = config.create_volume()
volume.install(meter = meter) volume.install(meter = meter)
def remove_storage_volume(self, poolname, volumename): def remove_storage_volume(self, poolname, volumename):
'''Removes the specified storage volume.''' '''Removes the specified storage volume.'''
volume = self.get_storage_volume(poolname, volumename) volume = self.get_storage_volume(poolname, volumename)
volume.delete(0) volume.delete(0)
def get_storage_volume(self, poolname, volumename): def get_storage_volume(self, poolname, volumename):
'''Returns a reference to the specified storage volume.''' '''Returns a reference to the specified storage volume.'''
pool =self.get_storage_pool(poolname) pool =self.get_storage_pool(poolname)
volume = pool.storageVolLookupByName(volumename) volume = pool.storageVolLookupByName(volumename)
return volume return volume
def list_bridges(self): def list_bridges(self):
'''Lists all defined and active bridges.''' '''Lists all defined and active bridges.'''
bridges = self.__conn.listNetworks() bridges = self.__conn.listNetworks()
bridges.extend(self.__conn.listDefinedNetworks()) bridges.extend(self.__conn.listDefinedNetworks())
result = [] result = []
for name in bridges: for name in bridges:
bridge = self.__conn.networkLookupByName(name) bridge = self.__conn.networkLookupByName(name)
result.append(bridge) result.append(bridge)
return result return result
def generate_mac_address(self): def generate_mac_address(self):
return self.__net.macaddr return self.__net.macaddr
def get_storage_size(self, poolname, volumename): def get_storage_size(self, poolname, volumename):
'''Returns the size of the specified storage volume.''' '''Returns the size of the specified storage volume.'''
volume = self.get_storage_volume(poolname, volumename) volume = self.get_storage_volume(poolname, volumename)
return volume.info()[1] / (1024.0 ** 3) return volume.info()[1] / (1024.0 ** 3)
def get_virt_types(self): def get_virt_types(self):
result = [] result = []
for guest in self.__capabilities.guests: for guest in self.__capabilities.guests:
guest_type = guest.os_type guest_type = guest.os_type
for domain in guest.domains: for domain in guest.domains:
domain_type = domain.hypervisor_type domain_type = domain.hypervisor_type
label = domain_type label = domain_type
if domain_type is "kvm" and guest_type is "xen": label = "xenner" if domain_type is "kvm" and guest_type is "xen": label = "xenner"
elif domain_type is "xen": elif domain_type is "xen":
if guest_type is "xen": if guest_type is "xen":
label = "xen (paravirt)" label = "xen (paravirt)"
elif guest_type is "kvm": elif guest_type is "kvm":
label = "xen (fullvirt)" label = "xen (fullvirt)"
elif domain_type is "test": elif domain_type is "test":
if guest_type is "xen": if guest_type is "xen":
label = "test (xen)" label = "test (xen)"
elif guest_type is "hvm": elif guest_type is "hvm":
label = "test (hvm)" label = "test (hvm)"
for row in result: for row in result:
if row[0] == label: if row[0] == label:
label = None label = None
break break
if label is None: continue if label is None: continue
result.append([label, domain_type, guest_type]) result.append([label, domain_type, guest_type])
return result return result
def list_virt_types(self): def list_virt_types(self):
virt_types = self.get_virt_types() virt_types = self.get_virt_types()
result = [] result = []
for type in virt_types: for type in virt_types:
result.append(type[0]) result.append(type[0])
return result return result
def get_default_architecture(self): def get_default_architecture(self):
'''Returns a default hypervisor type for new domains.''' '''Returns a default hypervisor type for new domains.'''
return self.__new_guest.arch return self.__new_guest.arch
def get_hypervisor(self, virt_type): def get_hypervisor(self, virt_type):
virt_types = self.get_virt_types() virt_types = self.get_virt_types()
for type in virt_types: for type in virt_types:
if type[0] is virt_type: return type[1] if type[0] is virt_type: return type[1]
return None return None
def get_default_virt_type(self): def get_default_virt_type(self):
'''Returns the default virtualization type for new domains.''' '''Returns the default virtualization type for new domains.'''
return self.__new_domain.hypervisor_type return self.__new_domain.hypervisor_type
def get_os_type(self, virt_type): def get_os_type(self, virt_type):
virt_types = self.get_virt_types() virt_types = self.get_virt_types()
for type in virt_types: for type in virt_types:
if type[0] is virt_type: return type[2] if type[0] is virt_type: return type[2]
return None return None
def list_architectures(self): def list_architectures(self):
result = [] result = []
for guest in self.__capabilities.guests: for guest in self.__capabilities.guests:
for domain in guest.domains: for domain in guest.domains:
label = guest.arch label = guest.arch
for row in result: for row in result:
if row == label: if row == label:
label = None label = None
break break
if label is None: continue if label is None: continue
result.append(label) result.append(label)
return result return result
def define_domain(self, config, meter): def define_domain(self, config, meter):
location = extra = kickstart = None location = extra = kickstart = None
if config.get_install_type() == DomainConfig.LOCAL_INSTALL: if config.get_install_type() == DomainConfig.LOCAL_INSTALL:
if config.get_use_cdrom_source(): if config.get_use_cdrom_source():
iclass = virtinst.DistroInstaller iclass = virtinst.DistroInstaller
location = config.get_install_media() location = config.get_install_media()
else: else:
iclass = virtinst.LiveCDInstaller iclass = virtinst.LiveCDInstaller
location = config.get_iso_path() location = config.get_iso_path()
elif config.get_install_type() == DomainConfig.NETWORK_INSTALL: elif config.get_install_type() == DomainConfig.NETWORK_INSTALL:
iclass = virtinst.DistroInstaller iclass = virtinst.DistroInstaller
location = config.get_install_url() location = config.get_install_url()
extra = config.get_kernel_options() extra = config.get_kernel_options()
kickstart = config.get_kickstart_url() kickstart = config.get_kickstart_url()
elif config.get_install_type() == DomainConfig.PXE_INSTALL: elif config.get_install_type() == DomainConfig.PXE_INSTALL:
iclass = virtinst.PXEInstaller iclass = virtinst.PXEInstaller
installer = iclass(conn = self.__conn, installer = iclass(conn = self.__conn,
type = self.get_hypervisor(config.get_virt_type()), type = self.get_hypervisor(config.get_virt_type()),
os_type = self.get_os_type(config.get_virt_type())) os_type = self.get_os_type(config.get_virt_type()))
self.__guest = installer.guest_from_installer() self.__guest = installer.guest_from_installer()
self.__guest.name = config.get_guest_name() self.__guest.name = config.get_guest_name()
self.__guest.vcpus = config.get_cpus() self.__guest.vcpus = config.get_cpus()
self.__guest.memory = config.get_memory() self.__guest.memory = config.get_memory()
self.__guest.maxmemory = config.get_memory() self.__guest.maxmemory = config.get_memory()
self.__guest.installer.location = location self.__guest.installer.location = location
if config.get_use_cdrom_source(): self.__guest.installer.cdrom = True if config.get_use_cdrom_source(): self.__guest.installer.cdrom = True
extraargs = "" extraargs = ""
if extra: extraargs += extra if extra: extraargs += extra
if kickstart: extraargs += " ks=%s" % kickstart if kickstart: extraargs += " ks=%s" % kickstart
if extraargs: self.__guest.installer.extraarags = extraargs if extraargs: self.__guest.installer.extraarags = extraargs
self.__guest.uuid = virtinst.util.uuidToString(virtinst.util.randomUUID()) self.__guest.uuid = virtinst.util.uuidToString(virtinst.util.randomUUID())
if config.get_os_type() != "generic": self.__guest.os_type = config.get_os_type() if config.get_os_type() != "generic": self.__guest.os_type = config.get_os_type()
if config.get_os_variant() != "generic": self.__guest.os_variant = config.get_os_variant() if config.get_os_variant() != "generic": self.__guest.os_variant = config.get_os_variant()
self.__guest._graphics_dev = virtinst.VirtualGraphics(type = virtinst.VirtualGraphics.TYPE_VNC) self.__guest._graphics_dev = virtinst.VirtualGraphics(type = virtinst.VirtualGraphics.TYPE_VNC)
self.__guest.sound_devs = [] self.__guest.sound_devs = []
self.__guest.sound_devs.append(virtinst.VirtualAudio(model = "es1370")) self.__guest.sound_devs.append(virtinst.VirtualAudio(model = "es1370"))
self._setup_nics(config) self._setup_nics(config)
self._setup_disks(config) self._setup_disks(config)
self.__guest.conn = self.__conn self.__guest.conn = self.__conn
self.__domain = self.__guest.start_install(False, meter = meter) self.__domain = self.__guest.start_install(False, meter = meter)
def _setup_nics(self, config): def _setup_nics(self, config):
self.__guest.nics = [] self.__guest.nics = []
nic = virtinst.VirtualNetworkInterface(type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL, nic = virtinst.VirtualNetworkInterface(type = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL,
bridge = config.get_network_bridge(), bridge = config.get_network_bridge(),
network = config.get_network_bridge(), network = config.get_network_bridge(),
macaddr = config.get_mac_address()) macaddr = config.get_mac_address())
self.__guest.nics.append(nic) self.__guest.nics.append(nic)
# ensure the network is running # ensure the network is running
if config.get_network_bridge() not in self.__conn.listNetworks(): if config.get_network_bridge() not in self.__conn.listNetworks():
network = self.__conn.networkLookupByName(config.get_network_bridge()) network = self.__conn.networkLookupByName(config.get_network_bridge())
network.create() network.create()
def _setup_disks(self, config): def _setup_disks(self, config):
self.__guest.disks = [] self.__guest.disks = []
if config.get_enable_storage(): if config.get_enable_storage():
path = None path = None
if config.get_use_local_storage(): if config.get_use_local_storage():
if self.storage_pool_exists("default") is False: if self.storage_pool_exists("default") is False:
self.define_storage_pool("default") self.define_storage_pool("default")
pool = self.__conn.storagePoolLookupByName("default") pool = self.__conn.storagePoolLookupByName("default")
path = virtinst.Storage.StorageVolume.find_free_name(config.get_guest_name(), path = virtinst.Storage.StorageVolume.find_free_name(config.get_guest_name(),
pool_object = pool, pool_object = pool,
suffix = ".img") suffix = ".img")
path = os.path.join(DEFAULT_POOL_TARGET_PATH, path) path = os.path.join(DEFAULT_POOL_TARGET_PATH, path)
else: else:
volume = self.get_storage_volume(config.get_storage_pool(), volume = self.get_storage_volume(config.get_storage_pool(),
config.get_storage_volume()) config.get_storage_volume())
path = volume.path() path = volume.path()
if path is not None: if path is not None:
storage= virtinst.VirtualDisk(conn = self.__conn, storage= virtinst.VirtualDisk(conn = self.__conn,
path = path, path = path,
size = config.get_storage_size()) size = config.get_storage_size())
self.__guest.disks.append(storage) self.__guest.disks.append(storage)
self.__guest.conn = self.__conn self.__guest.conn = self.__conn

View File

@ -1,68 +1,68 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# listdomains.py - Copyright (C) 2009 Red Hat, Inc. # listdomains.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from libvirtworker import LibvirtWorker from libvirtworker import LibvirtWorker
from configscreen import * from configscreen import *
class ListDomainsConfigScreen(DomainListConfigScreen): class ListDomainsConfigScreen(DomainListConfigScreen):
LIST_PAGE = 1 LIST_PAGE = 1
DETAIL_PAGE = 2 DETAIL_PAGE = 2
def __init__(self): def __init__(self):
DomainListConfigScreen.__init__(self, 'List Virtual Machines') DomainListConfigScreen.__init__(self, 'List Virtual Machines')
def page_has_next(self, page): def page_has_next(self, page):
return (page == self.LIST_PAGE) return (page == self.LIST_PAGE)
def page_has_back(self, page): def page_has_back(self, page):
return (page == self.DETAIL_PAGE) return (page == self.DETAIL_PAGE)
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page == self.LIST_PAGE: if page == self.LIST_PAGE:
if self.get_selected_domain() is None: if self.get_selected_domain() is None:
errors.append("Please select a virtual machine to view.") errors.append("Please select a virtual machine to view.")
else: else:
return True return True
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page == self.LIST_PAGE: if page == self.LIST_PAGE:
return self.get_domain_list_page(screen) return self.get_domain_list_page(screen)
elif page == self.DETAIL_PAGE: elif page == self.DETAIL_PAGE:
return self.get_detail_page_elements(screen) return self.get_detail_page_elements(screen)
def get_detail_page_elements(self, screen): def get_detail_page_elements(self, screen):
domain = self.get_libvirt().get_domain(self.get_selected_domain()) domain = self.get_libvirt().get_domain(self.get_selected_domain())
grid = Grid(2, 5) grid = Grid(2, 5)
grid.setField(Label("Name: "), 0, 0, anchorRight = 1) grid.setField(Label("Name: "), 0, 0, anchorRight = 1)
grid.setField(Label(domain.name()), 1, 0, anchorLeft = 1) grid.setField(Label(domain.name()), 1, 0, anchorLeft = 1)
grid.setField(Label("UUID: "), 0, 1, anchorRight = 1) grid.setField(Label("UUID: "), 0, 1, anchorRight = 1)
grid.setField(Label(domain.UUIDString()), 1, 1, anchorLeft = 1) grid.setField(Label(domain.UUIDString()), 1, 1, anchorLeft = 1)
grid.setField(Label("OS Type: "), 0, 2, anchorRight = 1) grid.setField(Label("OS Type: "), 0, 2, anchorRight = 1)
grid.setField(Label(domain.OSType()), 1, 2, anchorLeft = 1) grid.setField(Label(domain.OSType()), 1, 2, anchorLeft = 1)
grid.setField(Label("Max. Memory: "), 0, 3, anchorRight = 1) grid.setField(Label("Max. Memory: "), 0, 3, anchorRight = 1)
grid.setField(Label(str(domain.maxMemory())), 1, 3, anchorLeft = 1) grid.setField(Label(str(domain.maxMemory())), 1, 3, anchorLeft = 1)
grid.setField(Label("Max. VCPUs: "), 0, 4, anchorRight = 1) grid.setField(Label("Max. VCPUs: "), 0, 4, anchorRight = 1)
grid.setField(Label(str(domain.maxVcpus())), 1, 4, anchorLeft = 1) grid.setField(Label(str(domain.maxVcpus())), 1, 4, anchorLeft = 1)
return [grid] return [grid]
def ListDomains(): def ListDomains():
screen = ListDomainsConfigScreen() screen = ListDomainsConfigScreen()
screen.start() screen.start()

View File

@ -1,55 +1,55 @@
# listnetworks.py - Copyright (C) 2009 Red Hat, Inc. # listnetworks.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from configscreen import * from configscreen import *
LIST_PAGE = 1 LIST_PAGE = 1
DETAILS_PAGE = 2 DETAILS_PAGE = 2
class ListNetworksConfigScreen(NetworkListConfigScreen): class ListNetworksConfigScreen(NetworkListConfigScreen):
def __init__(self): def __init__(self):
NetworkListConfigScreen.__init__(self, "List Networks") NetworkListConfigScreen.__init__(self, "List Networks")
def page_has_next(self, page): def page_has_next(self, page):
return (page is LIST_PAGE) and self.has_selectable_networks() return (page is LIST_PAGE) and self.has_selectable_networks()
def page_has_back(self, page): def page_has_back(self, page):
return (page is DETAILS_PAGE) return (page is DETAILS_PAGE)
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_PAGE: return self.get_network_list_page(screen) if page is LIST_PAGE: return self.get_network_list_page(screen)
elif page is DETAILS_PAGE: return self.get_network_details_page(screen) elif page is DETAILS_PAGE: return self.get_network_details_page(screen)
def get_network_details_page(self, screen): def get_network_details_page(self, screen):
network = self.get_libvirt().get_network(self.get_selected_network()) network = self.get_libvirt().get_network(self.get_selected_network())
grid = Grid(2, 3) grid = Grid(2, 3)
grid.setField(Label("Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Name:"), 0, 0, anchorRight = 1)
grid.setField(Label(network.name()), 1, 0, anchorLeft = 1) grid.setField(Label(network.name()), 1, 0, anchorLeft = 1)
grid.setField(Label("Autostart:"), 0, 1, anchorRight = 1) grid.setField(Label("Autostart:"), 0, 1, anchorRight = 1)
label = "No" label = "No"
if network.autostart(): label = "Yes" if network.autostart(): label = "Yes"
grid.setField(Label(label), 1, 1, anchorLeft = 1) grid.setField(Label(label), 1, 1, anchorLeft = 1)
if network.bridgeName() is not "": if network.bridgeName() is not "":
grid.setField(Label("Bridge:"), 0, 2, anchorRight = 1) grid.setField(Label("Bridge:"), 0, 2, anchorRight = 1)
grid.setField(Label(network.bridgeName()), 1, 2, anchorLeft = 1) grid.setField(Label(network.bridgeName()), 1, 2, anchorLeft = 1)
return [Label("Network Interface Details"), return [Label("Network Interface Details"),
grid] grid]
def ListNetworks(): def ListNetworks():
screen = ListNetworksConfigScreen() screen = ListNetworksConfigScreen()
screen.start() screen.start()

View File

@ -1,64 +1,64 @@
# listpools.py - Copyright (C) 2009 Red Hat, Inc. # listpools.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
from utils import * from utils import *
LIST_PAGE = 1 LIST_PAGE = 1
DETAILS_PAGE = 2 DETAILS_PAGE = 2
class ListStoragePoolsConfigScreen(StorageListConfigScreen): class ListStoragePoolsConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "List Storage Pools") StorageListConfigScreen.__init__(self, "List Storage Pools")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_PAGE: return self.get_storage_pool_list_page(screen) if page is LIST_PAGE: return self.get_storage_pool_list_page(screen)
elif page is DETAILS_PAGE: return self.get_pool_details_page(screen) elif page is DETAILS_PAGE: return self.get_pool_details_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is LIST_PAGE and self.has_selectable_pools(): if page is LIST_PAGE and self.has_selectable_pools():
return True return True
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is DETAILS_PAGE: return True if page is DETAILS_PAGE: return True
return False return False
def get_pool_details_page(self, screen): def get_pool_details_page(self, screen):
pool = self.get_libvirt().get_storage_pool(self.get_selected_pool()) pool = self.get_libvirt().get_storage_pool(self.get_selected_pool())
volumes = Listbox(0); volumes = Listbox(0);
for name in pool.listVolumes(): for name in pool.listVolumes():
volume = pool.storageVolLookupByName(name) volume = pool.storageVolLookupByName(name)
volumes.append("%s (%s)" % (name, size_as_mb_or_gb(volume.info()[1])), name) volumes.append("%s (%s)" % (name, size_as_mb_or_gb(volume.info()[1])), name)
grid = Grid(2, 3) grid = Grid(2, 3)
grid.setField(Label("Name:"), 0, 0, anchorRight = 1) grid.setField(Label("Name:"), 0, 0, anchorRight = 1)
grid.setField(Label(pool.name()), 1, 0, anchorLeft = 1) grid.setField(Label(pool.name()), 1, 0, anchorLeft = 1)
grid.setField(Label("Volumes:"), 0, 1, anchorRight = 1) grid.setField(Label("Volumes:"), 0, 1, anchorRight = 1)
grid.setField(volumes, 1, 1, anchorLeft = 1) grid.setField(volumes, 1, 1, anchorLeft = 1)
grid.setField(Label("Autostart:"), 0, 2, anchorRight = 1) grid.setField(Label("Autostart:"), 0, 2, anchorRight = 1)
label = "No" label = "No"
if pool.autostart(): label = "Yes" if pool.autostart(): label = "Yes"
grid.setField(Label(label), 1, 2, anchorLeft = 1) grid.setField(Label(label), 1, 2, anchorLeft = 1)
return [Label("Details For Storage Pool: %s" % self.get_selected_pool()), return [Label("Details For Storage Pool: %s" % self.get_selected_pool()),
grid] grid]
def ListStoragePools(): def ListStoragePools():
screen = ListStoragePoolsConfigScreen() screen = ListStoragePoolsConfigScreen()
screen.start() screen.start()

View File

@ -1,55 +1,55 @@
# mainmenu.py - Copyright (C) 2009 Red Hat, Inc. # mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from menuscreen import MenuScreen from menuscreen import MenuScreen
from nodemenu import NodeMenu from nodemenu import NodeMenu
from netmenu import NetworkMenu from netmenu import NetworkMenu
from storagemenu import StoragePoolMenu from storagemenu import StoragePoolMenu
from hostmenu import HostMenu from hostmenu import HostMenu
import utils import utils
import logging import logging
NODE_MENU = 1 NODE_MENU = 1
NETWORK_MENU = 2 NETWORK_MENU = 2
STORAGE_MENU = 3 STORAGE_MENU = 3
HOST_MENU = 4 HOST_MENU = 4
EXIT_CONSOLE = 99 EXIT_CONSOLE = 99
class MainMenuScreen(MenuScreen): class MainMenuScreen(MenuScreen):
def __init__(self): def __init__(self):
MenuScreen.__init__(self, "Main Menu") MenuScreen.__init__(self, "Main Menu")
def get_menu_items(self): def get_menu_items(self):
return (("Node Administration", NODE_MENU), return (("Node Administration", NODE_MENU),
("Network Administration", NETWORK_MENU), ("Network Administration", NETWORK_MENU),
("Storage Pool Administration", STORAGE_MENU), ("Storage Pool Administration", STORAGE_MENU),
("Host Administration", HOST_MENU)) ("Host Administration", HOST_MENU))
def handle_selection(self, page): def handle_selection(self, page):
if page is NODE_MENU: NodeMenu() if page is NODE_MENU: NodeMenu()
elif page is NETWORK_MENU: NetworkMenu() elif page is NETWORK_MENU: NetworkMenu()
elif page is STORAGE_MENU: StoragePoolMenu() elif page is STORAGE_MENU: StoragePoolMenu()
elif page is HOST_MENU: HostMenu() elif page is HOST_MENU: HostMenu()
def MainMenu(): def MainMenu():
screen = MainMenuScreen() screen = MainMenuScreen()
screen.start() screen.start()

View File

@ -1,57 +1,57 @@
# mainmenu.py - Copyright (C) 2009 Red Hat, Inc. # mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
import utils import utils
import logging import logging
EXIT_MENU = 99 EXIT_MENU = 99
class MenuScreen: class MenuScreen:
def __init__(self, title): def __init__(self, title):
self.__title = title self.__title = title
def start(self): def start(self):
finished = False finished = False
while finished == False: while finished == False:
screen = SnackScreen() screen = SnackScreen()
menu = Listbox(height = 0, width = 0, returnExit = 1) menu = Listbox(height = 0, width = 0, returnExit = 1)
for menu_item in self.get_menu_items(): for menu_item in self.get_menu_items():
menu.append(menu_item[0], menu_item[1]) menu.append(menu_item[0], menu_item[1])
menu.append("Exit Menu", EXIT_MENU) menu.append("Exit Menu", EXIT_MENU)
gridform = GridForm(screen, self.__title, 1, 4) gridform = GridForm(screen, self.__title, 1, 4)
gridform.add(menu, 0, 0) gridform.add(menu, 0, 0)
result = gridform.run(); result = gridform.run();
screen.popWindow() screen.popWindow()
screen.finish() screen.finish()
try: try:
if result.current() == EXIT_MENU: finished = True if result.current() == EXIT_MENU: finished = True
else: self.handle_selection(result.current()) else: self.handle_selection(result.current())
except Exception, error: except Exception, error:
screen = SnackScreen() screen = SnackScreen()
logging.info("An exception occurred: %s" % str(error)) logging.info("An exception occurred: %s" % str(error))
ButtonChoiceWindow(screen, ButtonChoiceWindow(screen,
"An Exception Has Occurred", "An Exception Has Occurred",
str(error) + "\n" + traceback.format_exc(), str(error) + "\n" + traceback.format_exc(),
buttons = ["OK"]) buttons = ["OK"])
screen.popWindow() screen.popWindow()
screen.finish() screen.finish()
finished = True finished = True

View File

@ -1,81 +1,81 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# migratedomain.py - Copyright (C) 2009 Red Hat, Inc. # migratedomain.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from libvirtworker import LibvirtWorker from libvirtworker import LibvirtWorker
from configscreen import * from configscreen import *
LIST_DOMAINS = 1 LIST_DOMAINS = 1
SELECT_TARGET = 2 SELECT_TARGET = 2
CONFIRM_PAGE = 3 CONFIRM_PAGE = 3
class MigrateDomainConfigScreen(DomainListConfigScreen): class MigrateDomainConfigScreen(DomainListConfigScreen):
def __init__(self): def __init__(self):
DomainListConfigScreen.__init__(self, "Migrate Virtual Machine") DomainListConfigScreen.__init__(self, "Migrate Virtual Machine")
self.__configured = False self.__configured = False
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_DOMAINS: return self.get_domain_list_page(screen) if page is LIST_DOMAINS: return self.get_domain_list_page(screen)
elif page is SELECT_TARGET: return self.get_target_page(screen) elif page is SELECT_TARGET: return self.get_target_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is LIST_DOMAINS: return self.has_selectable_domains() if page is LIST_DOMAINS: return self.has_selectable_domains()
else: return page < CONFIRM_PAGE else: return page < CONFIRM_PAGE
def page_has_back(self, page): def page_has_back(self, page):
return page < CONFIRM_PAGE return page < CONFIRM_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_DOMAINS: return self.get_selected_domain() is not None if page is LIST_DOMAINS: return self.get_selected_domain() is not None
elif page is SELECT_TARGET: elif page is SELECT_TARGET:
if self.__targets.current() is None: if self.__targets.current() is None:
errors.append("Please enter a target hostname or IP address.") errors.append("Please enter a target hostname or IP address.")
return False return False
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
if not self.__confirm.value(): if not self.__confirm.value():
errors.append("You must confirm migrating this virtual machine to proceed.") errors.append("You must confirm migrating this virtual machine to proceed.")
return False return False
return True return True
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_PAGE: if page is CONFIRM_PAGE:
self.get_libvirt().migrate_domain(self.get_selected_domain(), self.__targets.current()) self.get_libvirt().migrate_domain(self.get_selected_domain(), self.__targets.current())
self.set_finished() self.set_finished()
def get_target_page(self, screen): def get_target_page(self, screen):
self.__targets = Listbox(0) self.__targets = Listbox(0)
for connection in self.get_virt_manager_config().get_connection_list(): for connection in self.get_virt_manager_config().get_connection_list():
self.__targets.append(connection, connection) self.__targets.append(connection, connection)
return [Label("Select A Target Host"), return [Label("Select A Target Host"),
self.__targets] self.__targets]
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
self.__confirm = Checkbox("Confirm migrating this virtual machine.") self.__confirm = Checkbox("Confirm migrating this virtual machine.")
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm, 0, 0) grid.setField(self.__confirm, 0, 0)
return [grid] return [grid]
def MigrateDomain(): def MigrateDomain():
screen = MigrateDomainConfigScreen() screen = MigrateDomainConfigScreen()
screen.start() screen.start()

View File

@ -1,58 +1,58 @@
# mainmenu.py - Copyright (C) 2009 Red Hat, Inc. # mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from menuscreen import MenuScreen from menuscreen import MenuScreen
from definenet import DefineNetwork from definenet import DefineNetwork
from createnetwork import CreateNetwork from createnetwork import CreateNetwork
from destroynetwork import DestroyNetwork from destroynetwork import DestroyNetwork
from undefinenetwork import UndefineNetwork from undefinenetwork import UndefineNetwork
from listnetworks import ListNetworks from listnetworks import ListNetworks
import utils import utils
import logging import logging
DEFINE_NETWORK = 1 DEFINE_NETWORK = 1
CREATE_NETWORK = 2 CREATE_NETWORK = 2
DESTROY_NETWORK = 3 DESTROY_NETWORK = 3
UNDEFINE_NETWORK = 4 UNDEFINE_NETWORK = 4
LIST_NETWORKS = 5 LIST_NETWORKS = 5
class NetworkMenuScreen(MenuScreen): class NetworkMenuScreen(MenuScreen):
def __init__(self): def __init__(self):
MenuScreen.__init__(self, "Network Administration") MenuScreen.__init__(self, "Network Administration")
def get_menu_items(self): def get_menu_items(self):
return (("Define A Network", DEFINE_NETWORK), return (("Define A Network", DEFINE_NETWORK),
("Create A Network", CREATE_NETWORK), ("Create A Network", CREATE_NETWORK),
("Destroy A Network", DESTROY_NETWORK), ("Destroy A Network", DESTROY_NETWORK),
("Undefine A Network", UNDEFINE_NETWORK), ("Undefine A Network", UNDEFINE_NETWORK),
("List Networks", LIST_NETWORKS)) ("List Networks", LIST_NETWORKS))
def handle_selection(self, item): def handle_selection(self, item):
if item is DEFINE_NETWORK: DefineNetwork() if item is DEFINE_NETWORK: DefineNetwork()
elif item is CREATE_NETWORK: CreateNetwork() elif item is CREATE_NETWORK: CreateNetwork()
elif item is DESTROY_NETWORK: DestroyNetwork() elif item is DESTROY_NETWORK: DestroyNetwork()
elif item is UNDEFINE_NETWORK: UndefineNetwork() elif item is UNDEFINE_NETWORK: UndefineNetwork()
elif item is LIST_NETWORKS: ListNetworks() elif item is LIST_NETWORKS: ListNetworks()
def NetworkMenu(): def NetworkMenu():
screen = NetworkMenuScreen() screen = NetworkMenuScreen()
screen.start() screen.start()

View File

@ -1,99 +1,99 @@
# networkconfig.py - Copyright (C) 2009 Red Hat, Inc. # networkconfig.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from IPy import IP from IPy import IP
import logging import logging
class NetworkConfig: class NetworkConfig:
def __init__(self): def __init__(self):
self.__name = "" self.__name = ""
self.set_ipv4_address("192.168.100.0/24") self.set_ipv4_address("192.168.100.0/24")
self.__isolated_network = True self.__isolated_network = True
self.__physical_device = "" self.__physical_device = ""
def set_name(self, name): def set_name(self, name):
self.__name = name self.__name = name
def get_name(self): def get_name(self):
return self.__name return self.__name
def set_ipv4_address(self, address): def set_ipv4_address(self, address):
self.__ipv4_address = IP(address) self.__ipv4_address = IP(address)
start = int(self.__ipv4_address.len() / 2) start = int(self.__ipv4_address.len() / 2)
end = self.__ipv4_address.len() - 2 end = self.__ipv4_address.len() - 2
self.__ipv4_start = str(self.__ipv4_address[start]) self.__ipv4_start = str(self.__ipv4_address[start])
self.__ipv4_end = str(self.__ipv4_address[end]) self.__ipv4_end = str(self.__ipv4_address[end])
def get_ipv4_address(self): def get_ipv4_address(self):
return self.__ipv4_address.strNormal() return self.__ipv4_address.strNormal()
def get_ipv4_address_raw(self): def get_ipv4_address_raw(self):
return self.__ipv4_address return self.__ipv4_address
def get_ipv4_netmask(self): def get_ipv4_netmask(self):
return self.__ipv4_address.netmask().strNormal() return self.__ipv4_address.netmask().strNormal()
def get_ipv4_broadcast(self): def get_ipv4_broadcast(self):
return self.__ipv4_address.broadcast().strNormal() return self.__ipv4_address.broadcast().strNormal()
def get_ipv4_gateway(self): def get_ipv4_gateway(self):
return str(self.__ipv4_address[1]) return str(self.__ipv4_address[1])
def get_ipv4_max_addresses(self): def get_ipv4_max_addresses(self):
return self.__ipv4_address.len() return self.__ipv4_address.len()
def get_ipv4_network_type(self): def get_ipv4_network_type(self):
return self.__ipv4_address.iptype() return self.__ipv4_address.iptype()
def is_public_ipv4_network(self): def is_public_ipv4_network(self):
if self.__ipv4_address.iptype() is "PUBLIC": if self.__ipv4_address.iptype() is "PUBLIC":
return True return True
return False return False
def set_ipv4_start_address(self, address): def set_ipv4_start_address(self, address):
self.__ipv4_start = address self.__ipv4_start = address
def get_ipv4_start_address(self): def get_ipv4_start_address(self):
return self.__ipv4_start return self.__ipv4_start
def set_ipv4_end_address(self, address): def set_ipv4_end_address(self, address):
self.__ipv4_end = address self.__ipv4_end = address
def get_ipv4_end_address(self): def get_ipv4_end_address(self):
return self.__ipv4_end return self.__ipv4_end
def is_bad_address(self, address): def is_bad_address(self, address):
return not self.__ipv4_address.overlaps(address) return not self.__ipv4_address.overlaps(address)
def set_isolated_network(self, isolated): def set_isolated_network(self, isolated):
self.__isolated_network = isolated self.__isolated_network = isolated
def is_isolated_network(self): def is_isolated_network(self):
return self.__isolated_network return self.__isolated_network
def set_physical_device(self, device): def set_physical_device(self, device):
self.__physical_device = device self.__physical_device = device
def get_physical_device(self): def get_physical_device(self):
return self.__physical_device return self.__physical_device
def get_physical_device_text(self): def get_physical_device_text(self):
if self.__physical_device == "": if self.__physical_device == "":
return "any physical device" return "any physical device"
else: else:
return "physical device %s" % self.__physical_device return "physical device %s" % self.__physical_device

View File

@ -1,29 +1,29 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# node-admin - Copyright (C) 2009 Red Hat, Inc. # node-admin - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import sys import sys
from mainmenu import MainMenu from mainmenu import MainMenu
def NodeAdmin(): def NodeAdmin():
MainMenu() MainMenu()
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(NodeAdmin()) sys.exit(NodeAdmin())

View File

@ -1,67 +1,67 @@
# mainmenu.py - Copyright (C) 2009 Red Hat, Inc. # mainmenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from menuscreen import MenuScreen from menuscreen import MenuScreen
from configscreen import ConfigScreen from configscreen import ConfigScreen
from adddomain import AddDomain from adddomain import AddDomain
from startdomain import StartDomain from startdomain import StartDomain
from stopdomain import StopDomain from stopdomain import StopDomain
from removedomain import RemoveDomain from removedomain import RemoveDomain
from listdomains import ListDomains from listdomains import ListDomains
from migratedomain import MigrateDomain from migratedomain import MigrateDomain
from createuser import CreateUser from createuser import CreateUser
import utils import utils
import logging import logging
ADD_DOMAIN = 1 ADD_DOMAIN = 1
START_DOMAIN = 2 START_DOMAIN = 2
STOP_DOMAIN = 3 STOP_DOMAIN = 3
REMOVE_DOMAIN = 4 REMOVE_DOMAIN = 4
LIST_DOMAINS = 5 LIST_DOMAINS = 5
MIGRATE_DOMAIN = 6 MIGRATE_DOMAIN = 6
CREATE_USER = 7 CREATE_USER = 7
class NodeMenuScreen(MenuScreen): class NodeMenuScreen(MenuScreen):
def __init__(self): def __init__(self):
MenuScreen.__init__(self, "Node Administration") MenuScreen.__init__(self, "Node Administration")
def get_menu_items(self): def get_menu_items(self):
return (("Add A Virtual Machine", ADD_DOMAIN), return (("Add A Virtual Machine", ADD_DOMAIN),
("Start A Virtual Machine", START_DOMAIN), ("Start A Virtual Machine", START_DOMAIN),
("Stop A Virtual Machine", STOP_DOMAIN), ("Stop A Virtual Machine", STOP_DOMAIN),
("Remove A Virtual Machine", REMOVE_DOMAIN), ("Remove A Virtual Machine", REMOVE_DOMAIN),
("List All Virtual Machines", LIST_DOMAINS), ("List All Virtual Machines", LIST_DOMAINS),
("Migrate Virtual Machine", MIGRATE_DOMAIN), ("Migrate Virtual Machine", MIGRATE_DOMAIN),
("Create A User", CREATE_USER)) ("Create A User", CREATE_USER))
def handle_selection(self, item): def handle_selection(self, item):
if item is ADD_DOMAIN: AddDomain() if item is ADD_DOMAIN: AddDomain()
elif item is START_DOMAIN: StartDomain() elif item is START_DOMAIN: StartDomain()
elif item is STOP_DOMAIN: StopDomain() elif item is STOP_DOMAIN: StopDomain()
elif item is REMOVE_DOMAIN: RemoveDomain() elif item is REMOVE_DOMAIN: RemoveDomain()
elif item is LIST_DOMAINS: ListDomains() elif item is LIST_DOMAINS: ListDomains()
elif item is MIGRATE_DOMAIN: MigrateDomain() elif item is MIGRATE_DOMAIN: MigrateDomain()
elif item is CREATE_USER: CreateUser() elif item is CREATE_USER: CreateUser()
def NodeMenu(): def NodeMenu():
screen = NodeMenuScreen() screen = NodeMenuScreen()
screen.start() screen.start()

View File

@ -1,145 +1,145 @@
# poolconfig.py - Copyright (C) 2009 Red Hat, Inc. # poolconfig.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from virtinst import Storage from virtinst import Storage
ROOT_TARGET_PATH="/var/lib/libvirt/images/%s" ROOT_TARGET_PATH="/var/lib/libvirt/images/%s"
class PoolConfig: class PoolConfig:
def __init__(self, libvirt): def __init__(self, libvirt):
self.__libvirt = libvirt self.__libvirt = libvirt
self.__name = "" self.__name = ""
self.set_type(None) self.set_type(None)
self.__format = None self.__format = None
self.__hostname = "" self.__hostname = ""
self.__target_path = "" self.__target_path = ""
self.__source_path = "" self.__source_path = ""
self.__build_pool = False self.__build_pool = False
def get_pool(self): def get_pool(self):
return self.__pool return self.__pool
def set_name(self, name): def set_name(self, name):
self.__name = name self.__name = name
def get_name(self): def get_name(self):
return self.__name return self.__name
def set_type(self, pooltype): def set_type(self, pooltype):
self.__type = pooltype self.__type = pooltype
self.__needs_target_path = False self.__needs_target_path = False
self.__needs_format = False self.__needs_format = False
self.__needs_target_path = False self.__needs_target_path = False
self.__needs_format = False self.__needs_format = False
self.__needs_hostname = False self.__needs_hostname = False
self.__needs_source_path = False self.__needs_source_path = False
self.__needs_build_pool = False self.__needs_build_pool = False
if pooltype is not None: if pooltype is not None:
if pooltype is Storage.StoragePool.TYPE_DIR: if pooltype is Storage.StoragePool.TYPE_DIR:
self.__needs_target_path = True self.__needs_target_path = True
self.__target_path = ROOT_TARGET_PATH % self.__name self.__target_path = ROOT_TARGET_PATH % self.__name
self.__build_pool = True self.__build_pool = True
elif pooltype is Storage.StoragePool.TYPE_DISK: elif pooltype is Storage.StoragePool.TYPE_DISK:
self.__needs_target_path = True self.__needs_target_path = True
self.__needs_format = True self.__needs_format = True
self.__needs_source_path = True self.__needs_source_path = True
self.__needs_build_pool = True self.__needs_build_pool = True
elif pooltype is Storage.StoragePool.TYPE_FS: elif pooltype is Storage.StoragePool.TYPE_FS:
self.__needs_target_path = True self.__needs_target_path = True
self.__needs_format = True self.__needs_format = True
self.__needs_source_path = True self.__needs_source_path = True
self.__build_pool = True self.__build_pool = True
elif pooltype is Storage.StoragePool.TYPE_ISCSI: elif pooltype is Storage.StoragePool.TYPE_ISCSI:
self.__needs_target_path = True self.__needs_target_path = True
self.__needs_hostname = True self.__needs_hostname = True
self.__needs_source_path = True self.__needs_source_path = True
self.__build_pool = False self.__build_pool = False
elif pooltype is Storage.StoragePool.TYPE_LOGICAL: elif pooltype is Storage.StoragePool.TYPE_LOGICAL:
self.__needs_target_path = True self.__needs_target_path = True
self.__needs_source_path = True self.__needs_source_path = True
self.__needs_build_pool = True self.__needs_build_pool = True
elif pooltype is Storage.StoragePool.TYPE_NETFS: elif pooltype is Storage.StoragePool.TYPE_NETFS:
self.__needs_target_path = True self.__needs_target_path = True
self.__needs_format = True self.__needs_format = True
self.__needs_hostname = True self.__needs_hostname = True
self.__needs_source_path = True self.__needs_source_path = True
self.__build_pool = True self.__build_pool = True
# create pool # create pool
pool_class = Storage.StoragePool.get_pool_class(self.__type) pool_class = Storage.StoragePool.get_pool_class(self.__type)
self.__pool = pool_class(name = self.__name, self.__pool = pool_class(name = self.__name,
conn = self.__libvirt.get_connection()) conn = self.__libvirt.get_connection())
if self.__needs_format: if self.__needs_format:
self.__format = self.__pool.formats[0] self.__format = self.__pool.formats[0]
else: else:
self.__type = Storage.StoragePool.get_pool_types()[0] self.__type = Storage.StoragePool.get_pool_types()[0]
def get_type(self): def get_type(self):
return self.__type return self.__type
def needs_target_path(self): def needs_target_path(self):
return self.__needs_target_path return self.__needs_target_path
def needs_format(self): def needs_format(self):
return self.__needs_format return self.__needs_format
def needs_hostname(self): def needs_hostname(self):
return self.__needs_hostname return self.__needs_hostname
def source_must_be_absolute(self): def source_must_be_absolute(self):
if self.__type is Storage.StoragePool.TYPE_ISCSI: if self.__type is Storage.StoragePool.TYPE_ISCSI:
return False return False
return True return True
def needs_source_path(self): def needs_source_path(self):
return self.__needs_source_path return self.__needs_source_path
def needs_build_pool(self): def needs_build_pool(self):
return self.__needs_build_pool return self.__needs_build_pool
def set_target_path(self, path): def set_target_path(self, path):
self.__target_path = path self.__target_path = path
def get_target_path(self): def get_target_path(self):
return self.__target_path return self.__target_path
def get_formats(self): def get_formats(self):
return self.__pool.formats return self.__pool.formats
def set_format(self, format): def set_format(self, format):
self.__format = format self.__format = format
def get_format(self): def get_format(self):
return self.__format return self.__format
def set_hostname(self, hostname): def set_hostname(self, hostname):
self.__hostname = hostname self.__hostname = hostname
def get_hostname(self): def get_hostname(self):
return self.__hostname return self.__hostname
def set_source_path(self, source_path): def set_source_path(self, source_path):
self.__source_path = source_path self.__source_path = source_path
def get_source_path(self): def get_source_path(self):
return self.__source_path return self.__source_path
def set_build_pool(self, build_pool): def set_build_pool(self, build_pool):
self.__build_pool = build_pool self.__build_pool = build_pool
def get_build_pool(self): def get_build_pool(self):
return self.__build_pool return self.__build_pool

View File

@ -1,83 +1,83 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# removedomain.py - Copyright (C) 2009 Red Hat, Inc. # removedomain.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
class RemoveDomainConfigScreen(DomainListConfigScreen): class RemoveDomainConfigScreen(DomainListConfigScreen):
LIST_PAGE = 1 LIST_PAGE = 1
CONFIRM_PAGE = 2 CONFIRM_PAGE = 2
REMOVE_PAGE = 3 REMOVE_PAGE = 3
def __init__(self): def __init__(self):
DomainListConfigScreen.__init__(self, "Remove A Domain") DomainListConfigScreen.__init__(self, "Remove A Domain")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is self.LIST_PAGE: return self.get_domain_list_page(screen) 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.CONFIRM_PAGE: return self.get_confirm_page(screen)
elif page is self.REMOVE_PAGE: return self.get_remove_page(screen) elif page is self.REMOVE_PAGE: return self.get_remove_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is self.LIST_PAGE: return self.has_selectable_domains() if page is self.LIST_PAGE: return self.has_selectable_domains()
elif page is self.CONFIRM_PAGE: return True elif page is self.CONFIRM_PAGE: return True
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is self.CONFIRM_PAGE: return True if page is self.CONFIRM_PAGE: return True
elif page is self.REMOVE_PAGE: return True elif page is self.REMOVE_PAGE: return True
return False return False
def get_back_page(self, page): def get_back_page(self, page):
if page is self.CONFIRM_PAGE: return self.LIST_PAGE if page is self.CONFIRM_PAGE: return self.LIST_PAGE
elif page is self.REMOVE_PAGE: return self.LIST_PAGE elif page is self.REMOVE_PAGE: return self.LIST_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is self.LIST_PAGE: if page is self.LIST_PAGE:
if self.get_selected_domain() is not None: if self.get_selected_domain() is not None:
return True return True
else: else:
errors.append("You must first select a domain.") errors.append("You must first select a domain.")
elif page is self.CONFIRM_PAGE: elif page is self.CONFIRM_PAGE:
if self.__confirm_remove.value(): if self.__confirm_remove.value():
domain = self.get_selected_domain() domain = self.get_selected_domain()
try: try:
self.get_libvirt().undefine_domain(domain) self.get_libvirt().undefine_domain(domain)
return True return True
except Exception, error: except Exception, error:
errors.append("Failed to remove %s." % domain) errors.append("Failed to remove %s." % domain)
errors.append(str(error)) errors.append(str(error))
else: else:
errors.append("You must confirm undefining the domain to proceed.") errors.append("You must confirm undefining the domain to proceed.")
return False return False
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 0) self.__confirm_remove = Checkbox("Check here to confirm undefining %s." % self.get_selected_domain(), 0)
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm_remove, 0, 0) grid.setField(self.__confirm_remove, 0, 0)
return [grid] return [grid]
def get_remove_page(self, screen): def get_remove_page(self, screen):
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(Label("%s has been removed." % self.get_selected_domain()), 0, 0) grid.setField(Label("%s has been removed." % self.get_selected_domain()), 0, 0)
return [grid] return [grid]
def RemoveDomain(): def RemoveDomain():
screen = RemoveDomainConfigScreen() screen = RemoveDomainConfigScreen()
screen.start() screen.start()

View File

@ -1,66 +1,66 @@
# removehost.py - Copyright (C) 2009 Red Hat, Inc. # removehost.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
SELECT_HOST_PAGE = 1 SELECT_HOST_PAGE = 1
CONFIRM_REMOVE_PAGE = 2 CONFIRM_REMOVE_PAGE = 2
class RemoveHostConfigScreen(HostListConfigScreen): class RemoveHostConfigScreen(HostListConfigScreen):
def __init__(self): def __init__(self):
HostListConfigScreen.__init__(self, "Remove Host Connection") HostListConfigScreen.__init__(self, "Remove Host Connection")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is SELECT_HOST_PAGE: return self.get_connection_list_page(screen) if page is SELECT_HOST_PAGE: return self.get_connection_list_page(screen)
elif page is CONFIRM_REMOVE_PAGE: return self.get_confirm_remove_page(screen) elif page is CONFIRM_REMOVE_PAGE: return self.get_confirm_remove_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page is SELECT_HOST_PAGE and self.has_selectable_connections() return page is SELECT_HOST_PAGE and self.has_selectable_connections()
def page_has_back(self, page): def page_has_back(self, page):
return page is CONFIRM_REMOVE_PAGE return page is CONFIRM_REMOVE_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_REMOVE_PAGE return page is CONFIRM_REMOVE_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is SELECT_HOST_PAGE: return True if page is SELECT_HOST_PAGE: return True
elif page is CONFIRM_REMOVE_PAGE: elif page is CONFIRM_REMOVE_PAGE:
if self.__confirm.value(): if self.__confirm.value():
return True return True
else: else:
errors.append("You must confirm removing the connection.") errors.append("You must confirm removing the connection.")
return False return False
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_REMOVE_PAGE: if page is CONFIRM_REMOVE_PAGE:
self.get_virt_manager_config().remove_connection(self.get_selected_connection()) self.get_virt_manager_config().remove_connection(self.get_selected_connection())
self.set_finished() self.set_finished()
def get_confirm_remove_page(self, screen): def get_confirm_remove_page(self, screen):
self.__confirm = Checkbox("Remove this connection: %s" % self.get_selected_connection(), 0) self.__confirm = Checkbox("Remove this connection: %s" % self.get_selected_connection(), 0)
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm, 0, 0) grid.setField(self.__confirm, 0, 0)
return [Label("Remove Host Connection"), return [Label("Remove Host Connection"),
grid] grid]
def RemoveHost(): def RemoveHost():
screen = RemoveHostConfigScreen() screen = RemoveHostConfigScreen()
screen.start() screen.start()

View File

@ -1,72 +1,72 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# removepool.py - Copyright (C) 2009 Red Hat, Inc. # removepool.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_POOLS_PAGE = 1 LIST_POOLS_PAGE = 1
CONFIRM_PAGE = 2 CONFIRM_PAGE = 2
class RemoveStoragePoolConfigScreen(StorageListConfigScreen): class RemoveStoragePoolConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "Remove A Storage Pool") StorageListConfigScreen.__init__(self, "Remove A Storage Pool")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen) if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page is LIST_POOLS_PAGE and self.has_selectable_pools() return page is LIST_POOLS_PAGE and self.has_selectable_pools()
def page_has_back(self, page): def page_has_back(self, page):
return False return False
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_POOLS_PAGE: if page is LIST_POOLS_PAGE:
if self.get_selected_pool() is not None: if self.get_selected_pool() is not None:
return True return True
else: else:
errors.append("Please select a storage pool to be removed.") errors.append("Please select a storage pool to be removed.")
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
if self.__confirm.value(): if self.__confirm.value():
return True return True
else: else:
errors.append("You must confirm removing a storage pool.") errors.append("You must confirm removing a storage pool.")
return False return False
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_PAGE: if page is CONFIRM_PAGE:
self.get_libvirt().destroy_storage_pool(self.get_selected_pool()) self.get_libvirt().destroy_storage_pool(self.get_selected_pool())
self.get_libvirt().undefine_storage_pool(self.get_selected_pool()) self.get_libvirt().undefine_storage_pool(self.get_selected_pool())
self.set_finished() self.set_finished()
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
self.__confirm = Checkbox("Check here to confirm deleting pool: %s" % self.get_selected_pool()) self.__confirm = Checkbox("Check here to confirm deleting pool: %s" % self.get_selected_pool())
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm, 0, 0) grid.setField(self.__confirm, 0, 0)
return [Label("Remove Selected Storage Pool"), return [Label("Remove Selected Storage Pool"),
grid] grid]
def RemoveStoragePool(): def RemoveStoragePool():
screen = RemoveStoragePoolConfigScreen() screen = RemoveStoragePoolConfigScreen()
screen.start() screen.start()

View File

@ -1,76 +1,76 @@
# removevolume.py - Copyright (C) 2009 Red Hat, Inc. # removevolume.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from createmeter import CreateMeter from createmeter import CreateMeter
from configscreen import * from configscreen import *
from volumeconfig import StorageVolumeConfig from volumeconfig import StorageVolumeConfig
from utils import * from utils import *
SELECT_POOL_PAGE = 1 SELECT_POOL_PAGE = 1
SELECT_VOLUME_PAGE = 2 SELECT_VOLUME_PAGE = 2
CONFIRM_PAGE = 3 CONFIRM_PAGE = 3
class RemoveVolumeConfigScreen(StorageListConfigScreen): class RemoveVolumeConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "Add A New Storage Volume") StorageListConfigScreen.__init__(self, "Add A New Storage Volume")
self.__config = StorageVolumeConfig() self.__config = StorageVolumeConfig()
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is SELECT_POOL_PAGE: return self.get_storage_pool_list_page(screen) if page is SELECT_POOL_PAGE: return self.get_storage_pool_list_page(screen)
elif page is SELECT_VOLUME_PAGE: return self.get_storage_volume_list_page(screen) elif page is SELECT_VOLUME_PAGE: return self.get_storage_volume_list_page(screen)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is SELECT_POOL_PAGE: return self.has_selectable_pools() if page is SELECT_POOL_PAGE: return self.has_selectable_pools()
elif page is SELECT_VOLUME_PAGE: return self.has_selectable_volumes() elif page is SELECT_VOLUME_PAGE: return self.has_selectable_volumes()
return False return False
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is SELECT_POOL_PAGE: return self.get_selected_pool() is not None if page is SELECT_POOL_PAGE: return self.get_selected_pool() is not None
elif page is SELECT_VOLUME_PAGE: return self.get_selected_volume() is not None elif page is SELECT_VOLUME_PAGE: return self.get_selected_volume() is not None
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
if self.__confirm.value(): if self.__confirm.value():
return True return True
else: else:
errors.append("You must confirm deleting a storage volume.") errors.append("You must confirm deleting a storage volume.")
return False return False
def process_input(self, page): def process_input(self, page):
if page is CONFIRM_PAGE: if page is CONFIRM_PAGE:
self.get_libvirt().remove_storage_volume(self.get_selected_pool(), self.get_selected_volume()) self.get_libvirt().remove_storage_volume(self.get_selected_pool(), self.get_selected_volume())
self.set_finished() self.set_finished()
def page_has_back(self, page): def page_has_back(self, page):
return page > SELECT_POOL_PAGE return page > SELECT_POOL_PAGE
def page_has_finish(self, page): def page_has_finish(self, page):
return page is CONFIRM_PAGE return page is CONFIRM_PAGE
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
self.__confirm = Checkbox("Check here to confirm deleting volume: %s" % self.get_selected_volume()) self.__confirm = Checkbox("Check here to confirm deleting volume: %s" % self.get_selected_volume())
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm, 0, 0) grid.setField(self.__confirm, 0, 0)
return [Label("Remove Selected Storage Volume"), return [Label("Remove Selected Storage Volume"),
grid] grid]
def RemoveStorageVolume(): def RemoveStorageVolume():
screen = RemoveVolumeConfigScreen() screen = RemoveVolumeConfigScreen()
screen.start() screen.start()

View File

@ -1,47 +1,47 @@
# setup.py - Copyright (C) 2009 Red Hat, Inc. # setup.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup(name = "nodeadmin", setup(name = "nodeadmin",
version = "1.9.3", version = "1.9.3",
package_dir = {'nodeadmin': 'nodeadmin'}, package_dir = {'nodeadmin': 'nodeadmin'},
packages = find_packages('.'), packages = find_packages('.'),
entry_points = { entry_points = {
'console_scripts': [ 'console_scripts': [
'nodeadmin = nodeadmin.nodeadmin:NodeAdmin', 'nodeadmin = nodeadmin.nodeadmin:NodeAdmin',
'addvm = nodeadmin.adddomain:AddDomain', 'addvm = nodeadmin.adddomain:AddDomain',
'startvm = nodeadmin.startdomain:StartDomain', 'startvm = nodeadmin.startdomain:StartDomain',
'stopvm = nodeadmin.stopdomain:StopDomain', 'stopvm = nodeadmin.stopdomain:StopDomain',
'rmvm = nodeadmin.removedomain:RemoveDomain', 'rmvm = nodeadmin.removedomain:RemoveDomain',
'migratevm = nodeadmin.migratedomain:MigradeDomain', 'migratevm = nodeadmin.migratedomain:MigradeDomain',
'createuser = nodeadmin.createuser:CreateUser', 'createuser = nodeadmin.createuser:CreateUser',
'listvms = nodeadmin.listdomains:ListDomains', 'listvms = nodeadmin.listdomains:ListDomains',
'definenet = nodeadmin.definenet:DefineNetwork', 'definenet = nodeadmin.definenet:DefineNetwork',
'createnet = nodeadmin.createnetwork:CreateNetwork', 'createnet = nodeadmin.createnetwork:CreateNetwork',
'destroynet = nodeadmin.destroynetwork:DestroyNetwork', 'destroynet = nodeadmin.destroynetwork:DestroyNetwork',
'undefinenet = nodeadmin.undefinenetwork:UndefineNetwork', 'undefinenet = nodeadmin.undefinenetwork:UndefineNetwork',
'listnets = nodeadmin.listnetworks:ListNetworks', 'listnets = nodeadmin.listnetworks:ListNetworks',
'addpool = nodeadmin.addpool:AddStoragePool', 'addpool = nodeadmin.addpool:AddStoragePool',
'rmpool = nodeadmin.removepool:RemoveStoragePool', 'rmpool = nodeadmin.removepool:RemoveStoragePool',
'startpool = nodeadmin.startpool:StartStoragePool', 'startpool = nodeadmin.startpool:StartStoragePool',
'stoppool = nodeadmin.stoppool:StopStoragePool', 'stoppool = nodeadmin.stoppool:StopStoragePool',
'addvolume = nodeadmin.addvolume:AddStorageVolume', 'addvolume = nodeadmin.addvolume:AddStorageVolume',
'rmvolume = nodeadmin.removevolume:RemoveStorageVolume', 'rmvolume = nodeadmin.removevolume:RemoveStorageVolume',
'listpools = nodeadmin.listpools:ListPools'] 'listpools = nodeadmin.listpools:ListPools']
}) })

View File

@ -1,65 +1,65 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# startdomain.py - Copyright (C) 2009 Red Hat, Inc. # startdomain.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
class StartDomainConfigScreen(DomainListConfigScreen): class StartDomainConfigScreen(DomainListConfigScreen):
LIST_PAGE = 1 LIST_PAGE = 1
START_PAGE = 2 START_PAGE = 2
def __init__(self): def __init__(self):
DomainListConfigScreen.__init__(self, "Start A Domain") DomainListConfigScreen.__init__(self, "Start A Domain")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is self.LIST_PAGE: if page is self.LIST_PAGE:
return self.get_domain_list_page(screen, started = False) return self.get_domain_list_page(screen, started = False)
elif page is self.START_PAGE: elif page is self.START_PAGE:
return self.get_start_domain_page(screen) return self.get_start_domain_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is self.LIST_PAGE: return self.has_selectable_domains() if page is self.LIST_PAGE: return self.has_selectable_domains()
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is self.START_PAGE: return True if page is self.START_PAGE: return True
return False return False
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is self.LIST_PAGE: if page is self.LIST_PAGE:
if self.get_selected_domain() is not None: if self.get_selected_domain() is not None:
domain = self.get_selected_domain() domain = self.get_selected_domain()
try: try:
self.get_libvirt().create_domain(domain) self.get_libvirt().create_domain(domain)
return True return True
except Exception, error: except Exception, error:
errors.append("There was an error creating the domain: %s" % domain) errors.append("There was an error creating the domain: %s" % domain)
errors.append(str(error)) errors.append(str(error))
else: else:
errors.append("You must first select a domain to start.") errors.append("You must first select a domain to start.")
def get_start_domain_page(self, screen): def get_start_domain_page(self, screen):
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(Label("%s was successfully started." % self.get_selected_domain()), 0, 0) grid.setField(Label("%s was successfully started." % self.get_selected_domain()), 0, 0)
return [grid] return [grid]
def StartDomain(): def StartDomain():
screen = StartDomainConfigScreen() screen = StartDomainConfigScreen()
screen.start() screen.start()

View File

@ -1,62 +1,62 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# startpool.py - Copyright (C) 2009 Red Hat, Inc. # startpool.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_POOLS_PAGE = 1 LIST_POOLS_PAGE = 1
FINAL_PAGE = 2 FINAL_PAGE = 2
class StartStoragePoolConfigScreen(StorageListConfigScreen): class StartStoragePoolConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "Start A Storage Pool") StorageListConfigScreen.__init__(self, "Start A Storage Pool")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen, created = False) if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen, created = False)
elif page is FINAL_PAGE: return self.get_final_page(screen) elif page is FINAL_PAGE: return self.get_final_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page is LIST_POOLS_PAGE and self.has_selectable_pools() return page is LIST_POOLS_PAGE and self.has_selectable_pools()
def page_has_back(self, page): def page_has_back(self, page):
return False return False
def page_has_finish(self, page): def page_has_finish(self, page):
return page is FINAL_PAGE return page is FINAL_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_POOLS_PAGE: if page is LIST_POOLS_PAGE:
if self.get_selected_pool() is not None: if self.get_selected_pool() is not None:
return True return True
else: else:
errors.append("Please select a storage pool to be started.") errors.append("Please select a storage pool to be started.")
return False return False
def process_input(self, page): def process_input(self, page):
if page is LIST_POOLS_PAGE: if page is LIST_POOLS_PAGE:
self.get_libvirt().create_storage_pool(self.get_selected_pool()) self.get_libvirt().create_storage_pool(self.get_selected_pool())
self.set_finished() self.set_finished()
def get_final_page(self, screen): def get_final_page(self, screen):
return [Label("Storage pool started: %s" % self.get_selected_pool())] return [Label("Storage pool started: %s" % self.get_selected_pool())]
def StartStoragePool(): def StartStoragePool():
screen = StartStoragePoolConfigScreen() screen = StartStoragePoolConfigScreen()
screen.start() screen.start()

View File

@ -1,66 +1,66 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# stopdomain.py - Copyright (C) 2009 Red Hat, Inc. # stopdomain.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
class StopDomainConfigScreen(DomainListConfigScreen): class StopDomainConfigScreen(DomainListConfigScreen):
LIST_PAGE = 1 LIST_PAGE = 1
STOP_PAGE = 2 STOP_PAGE = 2
def __init__(self): def __init__(self):
DomainListConfigScreen.__init__(self, "Stop A Domain") DomainListConfigScreen.__init__(self, "Stop A Domain")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is self.LIST_PAGE: if page is self.LIST_PAGE:
return self.get_domain_list_page(screen, defined = False) return self.get_domain_list_page(screen, defined = False)
elif page is self.STOP_PAGE: elif page is self.STOP_PAGE:
return self.get_stop_page(screen) return self.get_stop_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
if page is self.LIST_PAGE: return self.has_selectable_domains() if page is self.LIST_PAGE: return self.has_selectable_domains()
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is self.STOP_PAGE: return True if page is self.STOP_PAGE: return True
return False return False
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is self.LIST_PAGE: if page is self.LIST_PAGE:
if self.get_selected_domain() is not None: if self.get_selected_domain() is not None:
domain = self.get_selected_domain() domain = self.get_selected_domain()
try: try:
self.get_libvirt().destroy_domain(domain) self.get_libvirt().destroy_domain(domain)
return True return True
except Exception, error: except Exception, error:
errors.append("There was an error stop the domain: %s" % domain) errors.append("There was an error stop the domain: %s" % domain)
errors.append(str(error)) errors.append(str(error))
else: else:
errors.append("You must first select a domain to stop.") errors.append("You must first select a domain to stop.")
return False return False
def get_stop_page(self, screen): def get_stop_page(self, screen):
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(Label("%s was successfully stoped." % self.get_selected_domain()), 0, 0) grid.setField(Label("%s was successfully stoped." % self.get_selected_domain()), 0, 0)
return [grid] return [grid]
def StopDomain(): def StopDomain():
screen = StopDomainConfigScreen() screen = StopDomainConfigScreen()
screen.start() screen.start()

View File

@ -1,62 +1,62 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# stoppool.py - Copyright (C) 2009 Red Hat, Inc. # stoppool.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_POOLS_PAGE = 1 LIST_POOLS_PAGE = 1
FINAL_PAGE = 2 FINAL_PAGE = 2
class StopStoragePoolConfigScreen(StorageListConfigScreen): class StopStoragePoolConfigScreen(StorageListConfigScreen):
def __init__(self): def __init__(self):
StorageListConfigScreen.__init__(self, "Stop A Storage Pool") StorageListConfigScreen.__init__(self, "Stop A Storage Pool")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen, defined = False) if page is LIST_POOLS_PAGE: return self.get_storage_pool_list_page(screen, defined = False)
elif page is FINAL_PAGE: return self.get_final_page(screen) elif page is FINAL_PAGE: return self.get_final_page(screen)
def page_has_next(self, page): def page_has_next(self, page):
return page is LIST_POOLS_PAGE and self.has_selectable_pools() return page is LIST_POOLS_PAGE and self.has_selectable_pools()
def page_has_back(self, page): def page_has_back(self, page):
return False return False
def page_has_finish(self, page): def page_has_finish(self, page):
return page is FINAL_PAGE return page is FINAL_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_POOLS_PAGE: if page is LIST_POOLS_PAGE:
if self.get_selected_pool() is not None: if self.get_selected_pool() is not None:
return True return True
else: else:
errors.append("Please select a storage pool to be stopped.") errors.append("Please select a storage pool to be stopped.")
return False return False
def process_input(self, page): def process_input(self, page):
if page is LIST_POOLS_PAGE: if page is LIST_POOLS_PAGE:
self.get_libvirt().destroy_storage_pool(self.get_selected_pool()) self.get_libvirt().destroy_storage_pool(self.get_selected_pool())
self.set_finished() self.set_finished()
def get_final_page(self, screen): def get_final_page(self, screen):
return [Label("Storage pool stopped: %s" % self.get_selected_pool())] return [Label("Storage pool stopped: %s" % self.get_selected_pool())]
def StopStoragePool(): def StopStoragePool():
screen = StopStoragePoolConfigScreen() screen = StopStoragePoolConfigScreen()
screen.start() screen.start()

View File

@ -1,63 +1,63 @@
# storagemenu.py - Copyright (C) 2009 Red Hat, Inc. # storagemenu.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
import traceback import traceback
from menuscreen import MenuScreen from menuscreen import MenuScreen
from addpool import AddStoragePool from addpool import AddStoragePool
from startpool import StartStoragePool from startpool import StartStoragePool
from stoppool import StopStoragePool from stoppool import StopStoragePool
from removepool import RemoveStoragePool from removepool import RemoveStoragePool
from addvolume import AddStorageVolume from addvolume import AddStorageVolume
from removevolume import RemoveStorageVolume from removevolume import RemoveStorageVolume
from listpools import ListStoragePools from listpools import ListStoragePools
ADD_POOL = 1 ADD_POOL = 1
START_POOL = 2 START_POOL = 2
STOP_POOL = 3 STOP_POOL = 3
REMOVE_POOL = 4 REMOVE_POOL = 4
ADD_VOLUME = 5 ADD_VOLUME = 5
REMOVE_VOLUME = 6 REMOVE_VOLUME = 6
LIST_POOLS = 7 LIST_POOLS = 7
class StoragePoolMenuScreen(MenuScreen): class StoragePoolMenuScreen(MenuScreen):
def __init__(self): def __init__(self):
MenuScreen.__init__(self, "Storage Pool Administration") MenuScreen.__init__(self, "Storage Pool Administration")
def get_menu_items(self): def get_menu_items(self):
return (("Add A Storage Pool", ADD_POOL), return (("Add A Storage Pool", ADD_POOL),
("Start A Storage Pool", START_POOL), ("Start A Storage Pool", START_POOL),
("Stop A Storage Pool", STOP_POOL), ("Stop A Storage Pool", STOP_POOL),
("Remove A Storage Pool", REMOVE_POOL), ("Remove A Storage Pool", REMOVE_POOL),
("Add A Storage Volume", ADD_VOLUME), ("Add A Storage Volume", ADD_VOLUME),
("Remove A Storage Volume", REMOVE_VOLUME), ("Remove A Storage Volume", REMOVE_VOLUME),
("List Storage Pools", LIST_POOLS)) ("List Storage Pools", LIST_POOLS))
def handle_selection(self, item): def handle_selection(self, item):
if item is ADD_POOL: AddStoragePool() if item is ADD_POOL: AddStoragePool()
elif item is START_POOL: StartStoragePool() elif item is START_POOL: StartStoragePool()
elif item is STOP_POOL: StopStoragePool() elif item is STOP_POOL: StopStoragePool()
elif item is REMOVE_POOL: RemoveStoragePool() elif item is REMOVE_POOL: RemoveStoragePool()
elif item is ADD_VOLUME: AddStorageVolume() elif item is ADD_VOLUME: AddStorageVolume()
elif item is REMOVE_VOLUME: RemoveStorageVolume() elif item is REMOVE_VOLUME: RemoveStorageVolume()
elif item is LIST_POOLS: ListStoragePools() elif item is LIST_POOLS: ListStoragePools()
def StoragePoolMenu(): def StoragePoolMenu():
screen = StoragePoolMenuScreen() screen = StoragePoolMenuScreen()
screen.start() screen.start()

View File

@ -1,88 +1,88 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# undefinenetwork.py - Copyright (C) 2009 Red Hat, Inc. # undefinenetwork.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
from snack import * from snack import *
from configscreen import * from configscreen import *
LIST_PAGE = 1 LIST_PAGE = 1
CONFIRM_PAGE = 2 CONFIRM_PAGE = 2
UNDEFINE_PAGE = 3 UNDEFINE_PAGE = 3
class UndefineNetworkConfigScreen(NetworkListConfigScreen): class UndefineNetworkConfigScreen(NetworkListConfigScreen):
def __init__(self): def __init__(self):
NetworkListConfigScreen.__init__(self, "Undefine A Network") NetworkListConfigScreen.__init__(self, "Undefine A Network")
def get_elements_for_page(self, screen, page): def get_elements_for_page(self, screen, page):
if page is LIST_PAGE: return self.get_network_list_page(screen, created = False) if page is LIST_PAGE: return self.get_network_list_page(screen, created = False)
elif page is CONFIRM_PAGE: return self.get_confirm_page(screen) elif page is CONFIRM_PAGE: return self.get_confirm_page(screen)
elif page is UNDEFINE_PAGE: return self.get_undefine_network_page(screen) elif page is UNDEFINE_PAGE: return self.get_undefine_network_page(screen)
def process_input(self, page, errors): def process_input(self, page, errors):
if page is LIST_PAGE: if page is LIST_PAGE:
network = self.get_selected_network() network = self.get_selected_network()
self.get_libvirt().undefine_network(network) self.get_libvirt().undefine_network(network)
return True return True
def page_has_next(self, page): def page_has_next(self, page):
if page is LIST_PAGE: return self.has_selectable_networks() if page is LIST_PAGE: return self.has_selectable_networks()
if page is CONFIRM_PAGE: return True if page is CONFIRM_PAGE: return True
return False return False
def page_has_back(self, page): def page_has_back(self, page):
if page is CONFIRM_PAGE: return True if page is CONFIRM_PAGE: return True
if page is UNDEFINE_PAGE: return True if page is UNDEFINE_PAGE: return True
return False return False
def get_back_page(self, page): def get_back_page(self, page):
if page is CONFIRM_PAGE: return LIST_PAGE if page is CONFIRM_PAGE: return LIST_PAGE
elif page is UNDEFINE_PAGE: return LIST_PAGE elif page is UNDEFINE_PAGE: return LIST_PAGE
def validate_input(self, page, errors): def validate_input(self, page, errors):
if page is LIST_PAGE: return True if page is LIST_PAGE: return True
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
if self.__confirm_undefine.value(): if self.__confirm_undefine.value():
return True return True
else: else:
errors.append("You must confirm undefining %s." % self.get_selected_network()) errors.append("You must confirm undefining %s." % self.get_selected_network())
elif page is UNDEFINE_PAGE: return True elif page is UNDEFINE_PAGE: return True
return False return False
def process_input(self, page): def process_input(self, page):
if page is LIST_PAGE: return True if page is LIST_PAGE: return True
elif page is CONFIRM_PAGE: elif page is CONFIRM_PAGE:
network = self.get_selected_network() network = self.get_selected_network()
self.get_libvirt().undefine_network(network) self.get_libvirt().undefine_network(network)
return True return True
elif page is UNDEFINE_PAGE: return True elif page is UNDEFINE_PAGE: return True
return False return False
def get_confirm_page(self, screen): def get_confirm_page(self, screen):
self.__confirm_undefine = Checkbox("Check here to confirm undefining %s." % self.get_selected_network(), 0) self.__confirm_undefine = Checkbox("Check here to confirm undefining %s." % self.get_selected_network(), 0)
grid = Grid(1, 1) grid = Grid(1, 1)
grid.setField(self.__confirm_undefine, 0, 0) grid.setField(self.__confirm_undefine, 0, 0)
return [grid] return [grid]
def get_undefine_network_page(self, screen): def get_undefine_network_page(self, screen):
return [Label("Network Is Undefined"), return [Label("Network Is Undefined"),
Label("Network has been undefined: %s" % self.get_selected_network())] Label("Network has been undefined: %s" % self.get_selected_network())]
def UndefineNetwork(): def UndefineNetwork():
screen = UndefineNetworkConfigScreen() screen = UndefineNetworkConfigScreen()
screen.start() screen.start()

View File

@ -1,37 +1,37 @@
# userworker.py - Copyright (C) 2009 Red Hat, Inc. # userworker.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import libuser import libuser
class UserWorker: class UserWorker:
'''Provides APIs for creating, modifying and deleting user accounts.''' '''Provides APIs for creating, modifying and deleting user accounts.'''
def __init__(self): def __init__(self):
self.__admin = libuser.admin() self.__admin = libuser.admin()
def create_user(self, username, password, other_group): def create_user(self, username, password, other_group):
'''Creates a new user account with the provides username, '''Creates a new user account with the provides username,
password. The user is also added to the optional group password. The user is also added to the optional group
if one is specified.''' if one is specified.'''
user = self.__admin.initUser(username) user = self.__admin.initUser(username)
user.set('pw_passwd', password) user.set('pw_passwd', password)
self.__admin.addUser(user) self.__admin.addUser(user)
if other_group is not None: if other_group is not None:
group = self.__admin.lookupGroupByName(other_group) group = self.__admin.lookupGroupByName(other_group)
if group is None: raise Exception("Invalid group specified: %s" % other_group) if group is None: raise Exception("Invalid group specified: %s" % other_group)
user.add('pw_gid', group.get('pw_gid')[0]) user.add('pw_gid', group.get('pw_gid')[0])
self.__admin.modifyUser(user) self.__admin.modifyUser(user)

View File

@ -1,37 +1,37 @@
# definedomain.py - Copyright (C) 2009 Red Hat, Inc. # definedomain.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import re import re
def string_is_not_blank(value): def string_is_not_blank(value):
if len(value) > 0: return True if len(value) > 0: return True
return False return False
def string_has_no_spaces(value): def string_has_no_spaces(value):
if re.match("^[a-zA-Z0-9_]*$", value): if re.match("^[a-zA-Z0-9_]*$", value):
return True return True
return False return False
def size_as_mb_or_gb(size): def size_as_mb_or_gb(size):
'''Takes a size value in bytes and returns it as either a '''Takes a size value in bytes and returns it as either a
value in megabytes or gigabytes.''' value in megabytes or gigabytes.'''
if size / 1024.0**3 < 1.0: if size / 1024.0**3 < 1.0:
result = "%0.2f MB" % (size / 1024.0**2) result = "%0.2f MB" % (size / 1024.0**2)
else: else:
result = "%0.2f GB" % (size / 1024.0**3) result = "%0.2f GB" % (size / 1024.0**3)
return result return result

View File

@ -1,83 +1,83 @@
# volumeconfig.py - Copyright (C) 2009 Red Hat, Inc. # volumeconfig.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@redhat.com> # Written by Darryl L. Pierce <dpierce@redhat.com>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. # the Free Software Foundation; version 2 of the License.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. A copy of the GNU General Public License is # MA 02110-1301, USA. A copy of the GNU General Public License is
# also available at http://www.gnu.org/copyleft/gpl.html. # also available at http://www.gnu.org/copyleft/gpl.html.
import virtinst import virtinst
from virtinst import Storage from virtinst import Storage
class StorageVolumeConfig: class StorageVolumeConfig:
def __init__(self): def __init__(self):
self.__pool = None self.__pool = None
self.__name = "" self.__name = ""
self.__formats = None self.__formats = None
self.__format = None self.__format = None
self.__max_capacity = 10000 self.__max_capacity = 10000
self.__allocation = 0 self.__allocation = 0
def set_pool(self, pool): def set_pool(self, pool):
self.__pool = pool self.__pool = pool
self.__formats = None self.__formats = None
self.__pool_type = virtinst.util.get_xml_path(self.__pool.XMLDesc(0), '/pool/@type') self.__pool_type = virtinst.util.get_xml_path(self.__pool.XMLDesc(0), '/pool/@type')
self.__volume_class = Storage.StoragePool.get_volume_for_pool(self.__pool_type) self.__volume_class = Storage.StoragePool.get_volume_for_pool(self.__pool_type)
def get_pool(self): def get_pool(self):
return self.__pool return self.__pool
def create_volume(self): def create_volume(self):
volume = self.__volume_class(name = self.__name + ".img", volume = self.__volume_class(name = self.__name + ".img",
allocation = self.__allocation * 1024**2, allocation = self.__allocation * 1024**2,
capacity = self.__max_capacity * 1024**2, capacity = self.__max_capacity * 1024**2,
pool = self.__pool) pool = self.__pool)
volume.pool = self.__pool volume.pool = self.__pool
if self.needs_format(): if self.needs_format():
volume.format = self.__format volume.format = self.__format
return volume return volume
def set_name(self, name): def set_name(self, name):
self.__name = name self.__name = name
def get_name(self): def get_name(self):
return self.__name return self.__name
def needs_format(self): def needs_format(self):
if self.__pool.__dict__.keys().count("get_formats_for_pool") > 0: if self.__pool.__dict__.keys().count("get_formats_for_pool") > 0:
return self.__pool.get_formats_for_pool() is not 0 return self.__pool.get_formats_for_pool() is not 0
else: else:
return False return False
def get_formats_for_pool(self): def get_formats_for_pool(self):
if self.__formats is None: if self.__formats is None:
self.__formats = self.__volume_class.formats self.__formats = self.__volume_class.formats
return self.__formats return self.__formats
def set_format(self, format): def set_format(self, format):
self.__format = format self.__format = format
def get_format(self): def get_format(self):
return self.__format return self.__format
def set_max_capacity(self, capacity): def set_max_capacity(self, capacity):
self.__max_capacity = capacity self.__max_capacity = capacity
def get_max_capacity(self): def get_max_capacity(self):
return self.__max_capacity return self.__max_capacity
def set_allocation(self, allocation): def set_allocation(self, allocation):
self.__allocation = allocation self.__allocation = allocation
def get_allocation(self): def get_allocation(self):
return self.__allocation return self.__allocation