2008-08-15 23:22:20 +08:00
|
|
|
#
|
2014-06-11 19:36:28 +08:00
|
|
|
# Copyright (C) 2008, 2013, 2014 Red Hat, Inc.
|
2008-08-15 23:22:20 +08:00
|
|
|
# Copyright (C) 2008 Cole Robinson <crobinso@redhat.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
2012-05-14 21:24:56 +08:00
|
|
|
from gi.repository import Gdk
|
2015-04-10 02:42:25 +08:00
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2014-09-13 04:10:45 +08:00
|
|
|
from .baseclass import vmmGObjectUI
|
|
|
|
from .asyncjob import vmmAsyncJob
|
|
|
|
from . import uiutil
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
from virtinst import StoragePool
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
PAGE_NAME = 0
|
|
|
|
PAGE_FORMAT = 1
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
class vmmCreatePool(vmmGObjectUI):
|
2015-04-10 02:42:25 +08:00
|
|
|
__gsignals__ = {
|
|
|
|
"pool-created": (GObject.SignalFlags.RUN_FIRST, None, [str]),
|
|
|
|
}
|
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
def __init__(self, conn):
|
2013-09-23 04:10:16 +08:00
|
|
|
vmmGObjectUI.__init__(self, "createpool.ui", "vmm-create-pool")
|
2008-08-15 23:22:20 +08:00
|
|
|
self.conn = conn
|
|
|
|
|
|
|
|
self._pool = None
|
|
|
|
|
2013-02-17 02:31:46 +08:00
|
|
|
self.builder.connect_signals({
|
2008-08-15 23:22:20 +08:00
|
|
|
"on_pool_forward_clicked" : self.forward,
|
|
|
|
"on_pool_back_clicked" : self.back,
|
|
|
|
"on_pool_cancel_clicked" : self.close,
|
|
|
|
"on_vmm_create_pool_delete_event" : self.close,
|
|
|
|
"on_pool_finish_clicked" : self.forward,
|
|
|
|
"on_pool_pages_change_page" : self.page_changed,
|
2013-09-28 00:13:01 +08:00
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
"on_pool_source_button_clicked" : self.browse_source_path,
|
|
|
|
"on_pool_target_button_clicked" : self.browse_target_path,
|
2009-01-26 04:41:44 +08:00
|
|
|
|
2009-12-15 05:26:46 +08:00
|
|
|
"on_pool_name_activate": self.forward,
|
2009-10-21 21:48:12 +08:00
|
|
|
"on_pool_hostname_activate" : self.hostname_changed,
|
2011-07-24 07:42:41 +08:00
|
|
|
"on_pool_iqn_chk_toggled": self.iqn_toggled,
|
2008-08-15 23:22:20 +08:00
|
|
|
})
|
2011-04-18 23:25:28 +08:00
|
|
|
self.bind_escape_key_close()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
self.set_initial_state()
|
2013-11-27 23:10:34 +08:00
|
|
|
self.set_page(PAGE_NAME)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2011-04-14 20:47:42 +08:00
|
|
|
def show(self, parent):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Showing new pool wizard")
|
2008-08-15 23:22:20 +08:00
|
|
|
self.reset_state()
|
2011-04-14 20:47:42 +08:00
|
|
|
self.topwin.set_transient_for(parent)
|
2008-08-15 23:22:20 +08:00
|
|
|
self.topwin.present()
|
|
|
|
|
|
|
|
def close(self, ignore1=None, ignore2=None):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Closing new pool wizard")
|
2008-08-15 23:22:20 +08:00
|
|
|
self.topwin.hide()
|
|
|
|
return 1
|
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
def _cleanup(self):
|
2011-04-13 21:27:02 +08:00
|
|
|
self.conn = None
|
|
|
|
self._pool = None
|
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
def set_initial_state(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-pages").set_show_tabs(False)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-28 00:13:01 +08:00
|
|
|
blue = Gdk.Color.parse("#0072A8")[1]
|
|
|
|
self.widget("header").modify_bg(Gtk.StateType.NORMAL, blue)
|
|
|
|
|
2011-07-15 01:13:13 +08:00
|
|
|
type_list = self.widget("pool-type")
|
2012-05-14 21:24:56 +08:00
|
|
|
type_model = Gtk.ListStore(str, str)
|
2008-08-15 23:22:20 +08:00
|
|
|
type_list.set_model(type_model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(type_list, 1)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2011-07-15 01:13:13 +08:00
|
|
|
format_list = self.widget("pool-format")
|
2012-05-14 21:24:56 +08:00
|
|
|
format_model = Gtk.ListStore(str, str)
|
2008-08-15 23:22:20 +08:00
|
|
|
format_list.set_model(format_model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(format_list, 1)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2009-10-21 09:12:35 +08:00
|
|
|
# Target path combo box entry
|
2011-07-15 01:13:13 +08:00
|
|
|
target_list = self.widget("pool-target-path")
|
2009-10-21 09:12:35 +08:00
|
|
|
# target_path, Label, pool class instance
|
2012-05-14 21:24:56 +08:00
|
|
|
target_model = Gtk.ListStore(str, str, object)
|
|
|
|
target_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
2009-10-21 09:12:35 +08:00
|
|
|
target_list.set_model(target_model)
|
2013-01-13 05:13:53 +08:00
|
|
|
target_list.set_entry_text_column(0)
|
2009-10-21 09:12:35 +08:00
|
|
|
|
2009-10-20 03:55:19 +08:00
|
|
|
# Source path combo box entry
|
2011-07-15 01:13:13 +08:00
|
|
|
source_list = self.widget("pool-source-path")
|
2009-10-21 08:20:59 +08:00
|
|
|
# source_path, Label, pool class instance
|
2012-05-14 21:24:56 +08:00
|
|
|
source_model = Gtk.ListStore(str, str, object)
|
|
|
|
source_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
|
2009-10-20 03:55:19 +08:00
|
|
|
source_list.set_model(source_model)
|
2013-01-13 05:13:53 +08:00
|
|
|
source_list.set_entry_text_column(0)
|
2009-10-20 03:55:19 +08:00
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
self.populate_pool_type()
|
|
|
|
|
|
|
|
def reset_state(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-pages").set_current_page(0)
|
|
|
|
self.widget("pool-forward").show()
|
|
|
|
self.widget("pool-finish").hide()
|
|
|
|
self.widget("pool-back").set_sensitive(False)
|
|
|
|
|
|
|
|
self.widget("pool-name").set_text("")
|
|
|
|
self.widget("pool-name").grab_focus()
|
|
|
|
self.widget("pool-type").set_active(0)
|
2012-05-14 21:24:56 +08:00
|
|
|
self.widget("pool-target-path").get_child().set_text("")
|
|
|
|
self.widget("pool-source-path").get_child().set_text("")
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-hostname").set_text("")
|
2011-07-24 07:42:41 +08:00
|
|
|
self.widget("pool-iqn-chk").set_active(False)
|
|
|
|
self.widget("pool-iqn-chk").toggled()
|
|
|
|
self.widget("pool-iqn").set_text("")
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-format").set_active(-1)
|
|
|
|
self.widget("pool-build").set_sensitive(True)
|
|
|
|
self.widget("pool-build").set_active(False)
|
2013-09-28 00:13:01 +08:00
|
|
|
self.widget("pool-details-grid").set_visible(False)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
|
2009-10-21 21:48:12 +08:00
|
|
|
def hostname_changed(self, ignore):
|
|
|
|
# If a hostname was entered, try to lookup valid pool sources.
|
|
|
|
self.populate_pool_sources()
|
|
|
|
|
2011-07-24 07:42:41 +08:00
|
|
|
def iqn_toggled(self, src):
|
|
|
|
self.widget("pool-iqn").set_sensitive(src.get_active())
|
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
def populate_pool_type(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
model = self.widget("pool-type").get_model()
|
2008-08-15 23:22:20 +08:00
|
|
|
model.clear()
|
2013-09-20 08:18:12 +08:00
|
|
|
types = StoragePool.get_pool_types()
|
2008-08-15 23:22:20 +08:00
|
|
|
types.sort()
|
2008-11-19 04:42:51 +08:00
|
|
|
for typ in types:
|
2011-07-15 01:13:13 +08:00
|
|
|
model.append([typ, "%s: %s" %
|
2013-09-20 08:18:12 +08:00
|
|
|
(typ, StoragePool.get_pool_type_desc(typ))])
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2010-05-06 04:16:15 +08:00
|
|
|
def populate_pool_format(self, formats):
|
2011-07-15 01:13:13 +08:00
|
|
|
model = self.widget("pool-format").get_model()
|
2008-08-15 23:22:20 +08:00
|
|
|
model.clear()
|
|
|
|
for f in formats:
|
|
|
|
model.append([f, f])
|
|
|
|
|
2009-10-21 09:12:35 +08:00
|
|
|
def populate_pool_sources(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
source_list = self.widget("pool-source-path")
|
2009-10-21 09:12:35 +08:00
|
|
|
source_model = source_list.get_model()
|
|
|
|
source_model.clear()
|
|
|
|
|
2011-07-15 01:13:13 +08:00
|
|
|
target_list = self.widget("pool-target-path")
|
2009-10-21 09:12:35 +08:00
|
|
|
target_model = target_list.get_model()
|
|
|
|
target_model.clear()
|
2009-10-20 03:55:19 +08:00
|
|
|
|
2009-10-21 09:12:35 +08:00
|
|
|
use_list = source_list
|
|
|
|
use_model = source_model
|
2009-10-20 03:55:19 +08:00
|
|
|
entry_list = []
|
2013-09-20 08:18:12 +08:00
|
|
|
if self._pool.type == StoragePool.TYPE_SCSI:
|
2009-10-20 03:55:19 +08:00
|
|
|
entry_list = self.list_scsi_adapters()
|
2009-10-21 09:12:35 +08:00
|
|
|
use_list = source_list
|
|
|
|
use_model = source_model
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
elif self._pool.type == StoragePool.TYPE_LOGICAL:
|
2009-10-21 09:12:35 +08:00
|
|
|
pool_list = self.list_pool_sources()
|
2013-04-12 04:32:00 +08:00
|
|
|
entry_list = [[p.target_path, p.target_path, p]
|
|
|
|
for p in pool_list]
|
2009-10-21 09:12:35 +08:00
|
|
|
use_list = target_list
|
|
|
|
use_model = target_model
|
2009-10-20 03:55:19 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
elif self._pool.type == StoragePool.TYPE_DISK:
|
2011-07-24 04:37:30 +08:00
|
|
|
entry_list = self.list_disk_devs()
|
|
|
|
use_list = source_list
|
|
|
|
use_model = source_model
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
elif self._pool.type == StoragePool.TYPE_NETFS:
|
2009-10-21 21:48:12 +08:00
|
|
|
host = self.get_config_host()
|
|
|
|
if host:
|
|
|
|
pool_list = self.list_pool_sources(host=host)
|
2013-04-12 04:32:00 +08:00
|
|
|
entry_list = [[p.source_path, p.source_path, p]
|
|
|
|
for p in pool_list]
|
2009-10-21 21:48:12 +08:00
|
|
|
use_list = source_list
|
|
|
|
use_model = source_model
|
|
|
|
|
2009-10-20 03:55:19 +08:00
|
|
|
for e in entry_list:
|
2009-10-21 09:12:35 +08:00
|
|
|
use_model.append(e)
|
2009-10-20 03:55:19 +08:00
|
|
|
|
|
|
|
if entry_list:
|
2009-10-21 09:12:35 +08:00
|
|
|
use_list.set_active(0)
|
2009-10-20 03:55:19 +08:00
|
|
|
|
|
|
|
def list_scsi_adapters(self):
|
2015-04-10 21:37:03 +08:00
|
|
|
scsi_hosts = self.conn.filter_nodedevs("scsi_host")
|
2015-04-08 02:12:00 +08:00
|
|
|
host_list = [dev.xmlobj.host for dev in scsi_hosts]
|
2009-10-20 03:55:19 +08:00
|
|
|
|
|
|
|
clean_list = []
|
|
|
|
for h in host_list:
|
|
|
|
name = "host%s" % h
|
2013-09-20 08:18:12 +08:00
|
|
|
tmppool = self._make_stub_pool()
|
2009-10-21 08:20:59 +08:00
|
|
|
tmppool.source_path = name
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
entry = [name, name, tmppool]
|
2013-04-12 04:32:00 +08:00
|
|
|
if name not in [l[0] for l in clean_list]:
|
2009-10-20 03:55:19 +08:00
|
|
|
clean_list.append(entry)
|
|
|
|
|
|
|
|
return clean_list
|
|
|
|
|
2011-07-24 04:37:30 +08:00
|
|
|
def list_disk_devs(self):
|
2015-04-10 21:37:03 +08:00
|
|
|
devs = self.conn.filter_nodedevs("storage")
|
2011-07-24 04:37:30 +08:00
|
|
|
devlist = []
|
|
|
|
for dev in devs:
|
2015-04-08 02:12:00 +08:00
|
|
|
if dev.xmlobj.drive_type != "disk" or not dev.xmlobj.block:
|
2011-07-24 04:37:30 +08:00
|
|
|
continue
|
2015-04-08 02:12:00 +08:00
|
|
|
devlist.append(dev.xmlobj.block)
|
2011-07-24 04:37:30 +08:00
|
|
|
|
|
|
|
devlist.sort()
|
|
|
|
clean_list = []
|
|
|
|
for dev in devlist:
|
2013-09-20 08:18:12 +08:00
|
|
|
tmppool = self._make_stub_pool()
|
2011-07-24 04:37:30 +08:00
|
|
|
tmppool.source_path = dev
|
|
|
|
|
|
|
|
entry = [dev, dev, tmppool]
|
2013-04-12 04:32:00 +08:00
|
|
|
if dev not in [l[0] for l in clean_list]:
|
2011-07-24 04:37:30 +08:00
|
|
|
clean_list.append(entry)
|
|
|
|
|
|
|
|
return clean_list
|
|
|
|
|
2009-10-21 21:48:12 +08:00
|
|
|
def list_pool_sources(self, host=None):
|
2009-10-21 09:12:35 +08:00
|
|
|
pool_type = self._pool.type
|
|
|
|
|
|
|
|
plist = []
|
|
|
|
try:
|
2013-09-20 08:18:12 +08:00
|
|
|
plist = StoragePool.pool_list_from_sources(
|
2013-07-05 20:59:58 +08:00
|
|
|
self.conn.get_backend(),
|
2013-09-20 08:18:12 +08:00
|
|
|
pool_type,
|
2013-07-05 20:59:58 +08:00
|
|
|
host=host)
|
2009-10-29 08:35:13 +08:00
|
|
|
except Exception:
|
2009-10-21 09:12:35 +08:00
|
|
|
logging.exception("Pool enumeration failed")
|
|
|
|
|
|
|
|
return plist
|
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
def show_options_by_pool(self):
|
2011-07-24 04:22:02 +08:00
|
|
|
def show_row(base, do_show):
|
2013-09-28 00:13:01 +08:00
|
|
|
widget = self.widget(base + "-label")
|
2014-01-27 07:15:50 +08:00
|
|
|
uiutil.set_grid_row_visible(widget, do_show)
|
2011-07-24 04:22:02 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
src = self._pool.supports_property("source_path")
|
|
|
|
src_b = src and not self.conn.is_remote()
|
|
|
|
tgt = self._pool.supports_property("target_path")
|
|
|
|
tgt_b = tgt and not self.conn.is_remote()
|
2014-12-10 05:05:02 +08:00
|
|
|
host = self._pool.supports_property("hosts")
|
2013-09-20 08:18:12 +08:00
|
|
|
fmt = self._pool.supports_property("formats")
|
|
|
|
iqn = self._pool.supports_property("iqn")
|
2011-07-24 04:22:02 +08:00
|
|
|
builddef, buildsens = self.get_build_default()
|
2009-10-21 04:53:13 +08:00
|
|
|
|
2014-12-10 05:05:02 +08:00
|
|
|
# We don't show source_name for logical pools, since we use
|
|
|
|
# pool-sources to avoid the need for it
|
|
|
|
src_name = (self._pool.supports_property("source_name") and
|
|
|
|
self._pool.type != self._pool.TYPE_LOGICAL)
|
|
|
|
|
2014-06-11 19:36:28 +08:00
|
|
|
# Source path browsing is meaningless for net pools
|
2013-09-20 08:18:12 +08:00
|
|
|
if self._pool.type in [StoragePool.TYPE_NETFS,
|
|
|
|
StoragePool.TYPE_ISCSI,
|
2014-12-10 05:05:02 +08:00
|
|
|
StoragePool.TYPE_SCSI,
|
|
|
|
StoragePool.TYPE_GLUSTER]:
|
2009-10-21 04:53:13 +08:00
|
|
|
src_b = False
|
|
|
|
|
2011-07-24 04:22:02 +08:00
|
|
|
show_row("pool-target", tgt)
|
|
|
|
show_row("pool-source", src)
|
|
|
|
show_row("pool-hostname", host)
|
|
|
|
show_row("pool-format", fmt)
|
|
|
|
show_row("pool-build", buildsens)
|
2011-07-24 07:42:41 +08:00
|
|
|
show_row("pool-iqn", iqn)
|
2014-02-12 18:52:46 +08:00
|
|
|
show_row("pool-source-name", src_name)
|
2011-07-24 04:22:02 +08:00
|
|
|
|
2014-04-03 23:19:03 +08:00
|
|
|
if iqn:
|
|
|
|
self.widget("pool-source-label").set_label(_("_Source IQN:"))
|
|
|
|
else:
|
|
|
|
self.widget("pool-source-label").set_label(_("_Source Path:"))
|
|
|
|
|
2014-02-12 17:29:22 +08:00
|
|
|
if tgt:
|
|
|
|
self.widget("pool-target-path").get_child().set_text(
|
|
|
|
self._pool.target_path)
|
|
|
|
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-target-button").set_sensitive(tgt_b)
|
|
|
|
self.widget("pool-source-button").set_sensitive(src_b)
|
2011-07-24 04:22:02 +08:00
|
|
|
self.widget("pool-build").set_active(builddef)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2014-02-12 18:52:46 +08:00
|
|
|
if src_name:
|
2014-06-11 19:30:15 +08:00
|
|
|
self.widget("pool-source-name").set_text(self._pool.source_name)
|
2014-02-12 18:52:46 +08:00
|
|
|
|
2011-07-24 04:22:02 +08:00
|
|
|
self.widget("pool-format").set_active(-1)
|
2009-10-21 04:53:13 +08:00
|
|
|
if fmt:
|
2013-09-20 08:18:12 +08:00
|
|
|
self.populate_pool_format(self._pool.list_formats("formats"))
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-format").set_active(0)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2009-10-21 09:12:35 +08:00
|
|
|
self.populate_pool_sources()
|
2009-10-20 03:55:19 +08:00
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def get_config_type(self):
|
2014-01-27 09:21:12 +08:00
|
|
|
return uiutil.get_list_selection(self.widget("pool-type"), 0)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def get_config_name(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
return self.widget("pool-name").get_text()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def get_config_target_path(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
src = self.widget("pool-target-path")
|
2012-11-09 19:13:22 +08:00
|
|
|
if not src.get_sensitive():
|
2009-10-21 09:12:35 +08:00
|
|
|
return None
|
|
|
|
|
2014-01-27 09:21:12 +08:00
|
|
|
ret = uiutil.get_list_selection(src, 1)
|
|
|
|
if ret is not None:
|
|
|
|
return ret
|
2012-05-14 21:24:56 +08:00
|
|
|
return src.get_child().get_text()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def get_config_source_path(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
src = self.widget("pool-source-path")
|
2012-11-09 19:13:22 +08:00
|
|
|
if not src.get_sensitive():
|
2009-10-20 03:55:19 +08:00
|
|
|
return None
|
|
|
|
|
2014-01-27 09:21:12 +08:00
|
|
|
ret = uiutil.get_list_selection(src, 1)
|
|
|
|
if ret is not None:
|
|
|
|
return ret
|
2012-05-14 21:24:56 +08:00
|
|
|
return src.get_child().get_text().strip()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def get_config_host(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
host = self.widget("pool-hostname")
|
2012-11-09 19:13:22 +08:00
|
|
|
if host.get_sensitive():
|
2011-02-03 00:47:01 +08:00
|
|
|
return host.get_text().strip()
|
2008-08-15 23:22:20 +08:00
|
|
|
return None
|
|
|
|
|
2014-02-12 18:52:46 +08:00
|
|
|
def get_config_source_name(self):
|
|
|
|
name = self.widget("pool-source-name")
|
|
|
|
if name.get_sensitive():
|
|
|
|
return name.get_text().strip()
|
|
|
|
return None
|
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
def get_config_format(self):
|
2014-01-27 09:21:12 +08:00
|
|
|
return uiutil.get_list_selection(self.widget("pool-format"), 0)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2011-07-24 07:42:41 +08:00
|
|
|
def get_config_iqn(self):
|
|
|
|
iqn = self.widget("pool-iqn")
|
2013-09-09 23:02:34 +08:00
|
|
|
if iqn.get_sensitive() and iqn.get_visible():
|
2011-07-24 07:42:41 +08:00
|
|
|
return iqn.get_text().strip()
|
|
|
|
return None
|
|
|
|
|
2008-08-26 04:28:17 +08:00
|
|
|
def get_build_default(self):
|
|
|
|
""" Return (default value, whether build option can be changed)"""
|
|
|
|
if not self._pool:
|
|
|
|
return (False, False)
|
2013-09-20 08:18:12 +08:00
|
|
|
if self._pool.type in [StoragePool.TYPE_DIR,
|
|
|
|
StoragePool.TYPE_FS,
|
|
|
|
StoragePool.TYPE_NETFS]:
|
2008-08-26 04:28:17 +08:00
|
|
|
# Building for these simply entails creating a directory
|
|
|
|
return (True, False)
|
2013-09-20 08:18:12 +08:00
|
|
|
elif self._pool.type in [StoragePool.TYPE_LOGICAL,
|
|
|
|
StoragePool.TYPE_DISK]:
|
2008-08-26 04:28:17 +08:00
|
|
|
# This is a dangerous operation, anything (False, True)
|
|
|
|
# should be assumed to be one.
|
|
|
|
return (False, True)
|
|
|
|
else:
|
|
|
|
return (False, False)
|
|
|
|
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def browse_source_path(self, ignore1=None):
|
|
|
|
source = self._browse_file(_("Choose source path"),
|
|
|
|
startfolder="/dev", foldermode=False)
|
|
|
|
if source:
|
2012-05-14 21:24:56 +08:00
|
|
|
self.widget("pool-source-path").get_child().set_text(source)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def browse_target_path(self, ignore1=None):
|
2015-05-03 07:54:14 +08:00
|
|
|
startfolder = StoragePool.get_default_dir(self.conn.get_backend())
|
2008-08-15 23:22:20 +08:00
|
|
|
target = self._browse_file(_("Choose target directory"),
|
2015-05-03 07:54:14 +08:00
|
|
|
startfolder=startfolder,
|
2008-08-15 23:22:20 +08:00
|
|
|
foldermode=True)
|
|
|
|
if target:
|
2012-05-14 21:24:56 +08:00
|
|
|
self.widget("pool-target-path").get_child().set_text(target)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
def forward(self, ignore=None):
|
2011-07-15 01:13:13 +08:00
|
|
|
notebook = self.widget("pool-pages")
|
2008-08-15 23:22:20 +08:00
|
|
|
try:
|
2013-09-28 00:13:01 +08:00
|
|
|
if self.validate(notebook.get_current_page()) is not True:
|
2008-08-15 23:22:20 +08:00
|
|
|
return
|
|
|
|
if notebook.get_current_page() == PAGE_FORMAT:
|
|
|
|
self.finish()
|
|
|
|
else:
|
|
|
|
notebook.next_page()
|
|
|
|
except Exception, e:
|
2011-04-06 23:22:03 +08:00
|
|
|
self.err.show_err(_("Uncaught error validating input: %s") % str(e))
|
2008-08-15 23:22:20 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
def back(self, ignore=None):
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("pool-pages").prev_page()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2015-04-10 02:42:25 +08:00
|
|
|
def _signal_pool_added(self, src, connkey, created_name):
|
|
|
|
ignore = src
|
|
|
|
if connkey == created_name:
|
|
|
|
self.emit("pool-created", connkey)
|
|
|
|
|
2013-09-07 08:59:01 +08:00
|
|
|
def _finish_cb(self, error, details):
|
2008-08-15 23:22:20 +08:00
|
|
|
self.topwin.set_sensitive(True)
|
2013-09-07 08:59:01 +08:00
|
|
|
self.topwin.get_window().set_cursor(
|
|
|
|
Gdk.Cursor.new(Gdk.CursorType.TOP_LEFT_ARROW))
|
2009-04-04 02:15:15 +08:00
|
|
|
|
2010-12-10 22:57:42 +08:00
|
|
|
if error:
|
|
|
|
error = _("Error creating pool: %s") % error
|
2011-04-06 23:22:03 +08:00
|
|
|
self.err.show_err(error,
|
2011-04-06 23:52:26 +08:00
|
|
|
details=details)
|
2010-12-10 22:57:42 +08:00
|
|
|
else:
|
2015-04-10 02:42:25 +08:00
|
|
|
self.conn.connect_once("pool-added", self._signal_pool_added,
|
|
|
|
self._pool.name)
|
2013-07-07 23:06:15 +08:00
|
|
|
self.conn.schedule_priority_tick(pollpool=True)
|
2009-04-04 02:15:15 +08:00
|
|
|
self.close()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-07 08:59:01 +08:00
|
|
|
def finish(self):
|
|
|
|
self.topwin.set_sensitive(False)
|
|
|
|
self.topwin.get_window().set_cursor(
|
|
|
|
Gdk.Cursor.new(Gdk.CursorType.WATCH))
|
|
|
|
build = self.widget("pool-build").get_active()
|
|
|
|
|
|
|
|
progWin = vmmAsyncJob(self._async_pool_create, [build],
|
|
|
|
self._finish_cb, [],
|
|
|
|
_("Creating storage pool..."),
|
|
|
|
_("Creating the storage pool may take a "
|
|
|
|
"while..."),
|
|
|
|
self.topwin)
|
|
|
|
progWin.run()
|
|
|
|
|
2012-02-11 03:07:51 +08:00
|
|
|
def _async_pool_create(self, asyncjob, build):
|
2012-02-10 23:24:43 +08:00
|
|
|
meter = asyncjob.get_meter()
|
2010-12-10 22:57:42 +08:00
|
|
|
|
|
|
|
logging.debug("Starting backround pool creation.")
|
|
|
|
poolobj = self._pool.install(create=True, meter=meter, build=build)
|
|
|
|
poolobj.setAutostart(True)
|
2011-04-14 20:47:42 +08:00
|
|
|
logging.debug("Pool creation succeeded")
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-11-27 23:10:34 +08:00
|
|
|
def set_page(self, page_number):
|
2013-09-28 00:13:01 +08:00
|
|
|
# Update page number
|
|
|
|
page_lbl = ("<span color='#59B0E2'>%s</span>" %
|
|
|
|
_("Step %(current_page)d of %(max_page)d") %
|
|
|
|
{'current_page': page_number + 1,
|
|
|
|
'max_page': PAGE_FORMAT + 1})
|
|
|
|
self.widget("header-pagenum").set_markup(page_lbl)
|
|
|
|
|
|
|
|
isfirst = (page_number == PAGE_NAME)
|
|
|
|
islast = (page_number == PAGE_FORMAT)
|
|
|
|
|
|
|
|
self.widget("pool-back").set_sensitive(not isfirst)
|
|
|
|
self.widget("pool-finish").set_visible(islast)
|
|
|
|
self.widget("pool-forward").set_visible(not islast)
|
|
|
|
self.widget(islast and "pool-finish" or "pool-forward").grab_focus()
|
|
|
|
|
|
|
|
self.widget("pool-details-grid").set_visible(islast)
|
|
|
|
if islast:
|
2010-06-15 01:21:13 +08:00
|
|
|
self.show_options_by_pool()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-11-27 23:10:34 +08:00
|
|
|
def page_changed(self, notebook_ignore, page_ignore, page_number):
|
|
|
|
self.set_page(page_number)
|
|
|
|
|
2009-10-21 08:20:59 +08:00
|
|
|
def get_pool_to_validate(self):
|
|
|
|
"""
|
|
|
|
Return a pool instance to use for parameter assignment validation.
|
|
|
|
For most pools this will be the one we built after step 1, but for
|
|
|
|
pools we find via FindPoolSources, this will be different
|
|
|
|
"""
|
2011-07-15 01:13:13 +08:00
|
|
|
source_list = self.widget("pool-source-path")
|
|
|
|
target_list = self.widget("pool-target-path")
|
2009-10-21 08:20:59 +08:00
|
|
|
|
2014-01-27 09:21:12 +08:00
|
|
|
pool = uiutil.get_list_selection(source_list, 2)
|
|
|
|
if pool is None:
|
|
|
|
pool = uiutil.get_list_selection(target_list, 2)
|
2009-10-21 08:20:59 +08:00
|
|
|
|
|
|
|
return pool
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
def _make_stub_pool(self):
|
|
|
|
pool = StoragePool(self.conn.get_backend())
|
|
|
|
pool.type = self.get_config_type()
|
|
|
|
return pool
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
def _validate_page_name(self, usepool=None):
|
|
|
|
try:
|
|
|
|
if usepool:
|
|
|
|
self._pool = usepool
|
|
|
|
else:
|
|
|
|
self._pool = self._make_stub_pool()
|
|
|
|
self._pool.name = self.get_config_name()
|
|
|
|
except ValueError, e:
|
|
|
|
return self.err.val_err(_("Pool Parameter Error"), e)
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
return True
|
2008-08-15 23:22:20 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
def _validate_page_format(self):
|
|
|
|
target = self.get_config_target_path()
|
|
|
|
host = self.get_config_host()
|
|
|
|
source = self.get_config_source_path()
|
|
|
|
fmt = self.get_config_format()
|
|
|
|
iqn = self.get_config_iqn()
|
2014-02-12 18:52:46 +08:00
|
|
|
source_name = self.get_config_source_name()
|
2013-09-20 08:18:12 +08:00
|
|
|
|
|
|
|
if not self._validate_page_name(self.get_pool_to_validate()):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
self._pool.target_path = target
|
|
|
|
if host:
|
2014-12-10 05:05:02 +08:00
|
|
|
self._pool.add_host(host)
|
2013-09-20 08:18:12 +08:00
|
|
|
if source:
|
|
|
|
self._pool.source_path = source
|
|
|
|
if fmt:
|
|
|
|
self._pool.format = fmt
|
|
|
|
if iqn:
|
|
|
|
self._pool.iqn = iqn
|
2014-02-12 18:52:46 +08:00
|
|
|
if source_name:
|
|
|
|
self._pool.source_name = source_name
|
2013-09-20 08:18:12 +08:00
|
|
|
|
|
|
|
self._pool.validate()
|
|
|
|
except ValueError, e:
|
|
|
|
return self.err.val_err(_("Pool Parameter Error"), e)
|
|
|
|
|
|
|
|
buildval = self.widget("pool-build").get_active()
|
|
|
|
buildsen = (self.widget("pool-build").get_sensitive() and
|
2013-09-28 00:13:01 +08:00
|
|
|
self.widget("pool-build").get_visible())
|
2013-09-20 08:18:12 +08:00
|
|
|
if buildsen and buildval:
|
|
|
|
ret = self.err.yes_no(_("Building a pool of this type will "
|
|
|
|
"format the source device. Are you "
|
|
|
|
"sure you want to 'build' this pool?"))
|
|
|
|
if not ret:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def validate(self, page):
|
|
|
|
if page == PAGE_NAME:
|
|
|
|
return self._validate_page_name()
|
2008-08-15 23:22:20 +08:00
|
|
|
elif page == PAGE_FORMAT:
|
2013-09-20 08:18:12 +08:00
|
|
|
return self._validate_page_format()
|
2008-08-15 23:22:20 +08:00
|
|
|
|
|
|
|
def _browse_file(self, dialog_name, startfolder=None, foldermode=False):
|
2012-05-14 21:24:56 +08:00
|
|
|
mode = Gtk.FileChooserAction.OPEN
|
2008-08-15 23:22:20 +08:00
|
|
|
if foldermode:
|
2012-05-14 21:24:56 +08:00
|
|
|
mode = Gtk.FileChooserAction.SELECT_FOLDER
|
2009-03-09 03:14:00 +08:00
|
|
|
|
2014-01-27 06:59:09 +08:00
|
|
|
return self.err.browse_local(self.conn, dialog_name,
|
|
|
|
dialog_type=mode, start_folder=startfolder)
|