diff --git a/po/POTFILES.in b/po/POTFILES.in index d125b1e3..48545764 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -42,3 +42,4 @@ src/virtManager/domain.py src/virtManager/__init__.py src/virtManager/manager.py src/virtManager/remote.py +src/virtManager/util.py diff --git a/src/virtManager/addhardware.py b/src/virtManager/addhardware.py index ca403453..fb29b672 100644 --- a/src/virtManager/addhardware.py +++ b/src/virtManager/addhardware.py @@ -34,6 +34,7 @@ import logging import dbus import traceback +import virtManager.util as vmmutil from virtManager.asyncjob import vmmAsyncJob from virtManager.error import vmmErrorDialog from virtManager.createmeter import vmmCreateMeter @@ -735,6 +736,9 @@ class vmmAddHardware(gobject.GObject): readonly=True try: + if os.path.dirname(os.path.abspath(path)) == \ + vmmutil.DEFAULT_POOL_PATH: + vmmutil.build_default_pool(self.vm.get_connection().vmm) self._dev = virtinst.VirtualDisk(self.get_config_disk_image(), filesize, type = type, diff --git a/src/virtManager/create.py b/src/virtManager/create.py index 84530380..e7c320c2 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -34,6 +34,7 @@ import logging import dbus import traceback +import virtManager.util as vmmutil from virtManager.asyncjob import vmmAsyncJob from virtManager.error import vmmErrorDialog from virtManager.createmeter import vmmCreateMeter @@ -976,12 +977,11 @@ class vmmCreate(gobject.GObject): self._guest.extraargs = kernel_params else: self._guest.extraargs = "%s %s" % (self._guest.extraargs, kernel_params) - self._guest.extraargs = self._guest.extraargs.strip() + self._guest.extraargs = self._guest.extraargs.strip() elif page_num == PAGE_DISK: - - disk = self.get_config_disk_image() - if disk == None or len(disk) == 0: + path = self.get_config_disk_image() + if path == None or len(path) == 0: return self.err.val_err(_("Storage Address Required"), \ _("You must specify a partition or a file for storage for the guest install")) @@ -995,7 +995,11 @@ class vmmCreate(gobject.GObject): else: type = virtinst.VirtualDisk.TYPE_FILE - self._disk = virtinst.VirtualDisk(self.get_config_disk_image(), + if (os.path.dirname(os.path.abspath(path)) == \ + vmmutil.DEFAULT_POOL_PATH): + vmmutil.build_default_pool(self._guest.conn) + + self._disk = virtinst.VirtualDisk(path, filesize, sparse = self.is_sparse_file(), device = virtinst.VirtualDisk.DEVICE_DISK, @@ -1022,7 +1026,7 @@ class vmmCreate(gobject.GObject): return False if self._disk.is_conflict_disk(self._guest.conn) is True: - res = self.err.yes_no(_('Disk "%s" is already in use by another guest!' % disk), _("Do you really want to use the disk ?")) + res = self.err.yes_no(_('Disk "%s" is already in use by another guest!' % self._disk.path), _("Do you really want to use the disk ?")) return res elif page_num == PAGE_NETWORK: diff --git a/src/virtManager/util.py b/src/virtManager/util.py new file mode 100644 index 00000000..9c5c1869 --- /dev/null +++ b/src/virtManager/util.py @@ -0,0 +1,54 @@ +# +# Copyright (C) 2008 Red Hat, Inc. +# Copyright (C) 2008 Cole Robinson +# +# 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. +# + +import logging + +import libvirt + +import virtinst + +DEFAULT_POOL_NAME = "default" +DEFAULT_POOL_PATH = "/var/lib/libvirt/images" + +def build_default_pool(conn): + """Helper to build the 'default' storage pool""" + if not virtinst.util.is_storage_capable(conn): + # VirtualDisk will raise an error for us + return + pool = None + try: + pool = conn.storagePoolLookupByName(DEFAULT_POOL_NAME) + except libvirt.libvirtError: + pass + + if pool: + return + + try: + logging.debug("Attempting to build default pool with target '%s'" % + DEFAULT_POOL_PATH) + defpool = virtinst.Storage.DirectoryPool(conn=conn, + name=DEFAULT_POOL_NAME, + target_path=DEFAULT_POOL_PATH) + newpool = defpool.install(build=True, create=True) + newpool.setAutostart(True) + except Exception, e: + raise RuntimeError(_("Couldn't create default storage pool '%s': %s") % + (DEFAULT_POOL_PATH, str(e)))