From 9b62c2260d445fef10c5bc63bae14c86753b092b Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 6 Dec 2014 13:04:59 -0500 Subject: [PATCH] devicedisk: Catch --disk /dev/idontexist,size=2 --- virtinst/cli.py | 13 +++++++------ virtinst/devicedisk.py | 10 +++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/virtinst/cli.py b/virtinst/cli.py index dfaf23af..06384ba7 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1568,16 +1568,17 @@ class ParserDisk(VirtCLIParser): StoragePool.build_default_pool(self.guest.conn) poolobj = self.guest.conn.storagePoolLookupByName(poolname) - if inst.wants_storage_creation(): - newvolname = os.path.basename(inst.path) - poolobj = inst.get_parent_pool() - elif volname: + if volname: vol_object = poolobj.storageVolLookupByName(volname) inst.set_vol_object(vol_object) poolobj = None - if poolobj and (fmt or size or sparse or backing_store): - if not fmt: + if ((poolobj or inst.wants_storage_creation()) and + (fmt or size or sparse or backing_store)): + if not poolobj: + poolobj = inst.get_parent_pool() + newvolname = os.path.basename(inst.path) + if poolobj and not fmt: fmt = _get_default_image_format(self.guest.conn, poolobj) if newvolname is None: newvolname = _generate_new_volume_name(self.guest, poolobj, diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py index 582941ed..e0bac1ee 100644 --- a/virtinst/devicedisk.py +++ b/virtinst/devicedisk.py @@ -410,6 +410,12 @@ class VirtualDisk(VirtualDevice): raise ValueError(_("Size must be specified for non " "existent volume '%s'" % volname)) + # This catches --disk /dev/idontexist,size=1 if /dev is unmanaged + if not poolobj: + raise RuntimeError(_("Don't know how to create storage for " + "path '%s'. Use libvirt APIs to manage the parent directory " + "as a pool first.") % volname) + logging.debug("Creating volume '%s' on pool '%s'", volname, poolobj.name()) @@ -710,9 +716,7 @@ class VirtualDisk(VirtualDevice): If true, this disk needs storage creation parameters or things will error. """ - return (self.path and - not self._storage_backend.exists() and - self.get_parent_pool()) + return self.path and not self._storage_backend.exists() def __managed_storage(self): """