Create the default pool if user requests '/var/lib/libvirt/images' as a storage dir.

This commit is contained in:
Cole Robinson 2008-09-07 18:56:30 -04:00
parent 04d82dbe20
commit 76cd8f3dda
4 changed files with 69 additions and 6 deletions

View File

@ -42,3 +42,4 @@ src/virtManager/domain.py
src/virtManager/__init__.py
src/virtManager/manager.py
src/virtManager/remote.py
src/virtManager/util.py

View File

@ -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,

View File

@ -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:

54
src/virtManager/util.py Normal file
View File

@ -0,0 +1,54 @@
#
# Copyright (C) 2008 Red Hat, Inc.
# 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.
#
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)))