Fix remote URL installs

We need to make sure the pool cache is invalidated if we create
the boot-scratch pool. Also share code that builds a volinstall instance.
This commit is contained in:
Cole Robinson 2013-07-25 16:21:30 -04:00
parent 03bd6f024e
commit 85f1e1d4b1
5 changed files with 24 additions and 16 deletions

View File

@ -82,8 +82,10 @@ def _build_pool(conn, meter, path):
# Explicitly don't build? since if we are creating this directory
# we probably don't have correct perms
return poolbuild.install(meter=meter, create=True, build=False,
autostart=True)
ret = poolbuild.install(meter=meter, create=True, build=False,
autostart=True)
conn.clear_cache()
return ret
def _upload_file(conn, meter, destpool, src):
@ -108,10 +110,12 @@ def _upload_file(conn, meter, destpool, src):
if name != basename:
logging.debug("Generated non-colliding volume name %s", name)
vol_install = VirtualDisk.build_vol_install(conn, name, destpool,
(float(size) / 1024.0 / 1024.0 / 1024.0), True)
disk = VirtualDisk(conn)
disk.path = os.path.join(poolpath, name)
disk.set_create_storage(size=(float(size) / 1024.0 / 1024.0 / 1024.0),
sparse=True)
disk.set_create_storage(vol_install=vol_install)
disk.validate()
disk.setup(meter=meter)

View File

@ -385,7 +385,9 @@ class VirtualDisk(VirtualDevice):
except Exception, e:
raise ValueError(_("Couldn't lookup volume object: %s" % str(e)))
@staticmethod
def build_vol_install(*args, **kwargs):
return diskbackend.build_vol_install(*args, **kwargs)
_XML_PROP_ORDER = [

View File

@ -334,6 +334,7 @@ def build_default_pool(guest):
name=DEFAULT_POOL_NAME,
target_path=DEFAULT_POOL_PATH)
defpool.install(build=True, create=True, autostart=True)
guest.conn.clear_cache()
except Exception, e:
raise RuntimeError(_("Couldn't create default storage pool '%s': %s") %
(DEFAULT_POOL_PATH, str(e)))
@ -1405,25 +1406,23 @@ def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
raise ValueError(_("Size must be specified with all 'pool='"))
if pool == DEFAULT_POOL_NAME:
build_default_pool(guest)
vc = virtinst.Storage.StorageVolume.get_volume_for_pool(pool_name=pool,
conn=guest.conn)
poolobj = guest.conn.storagePoolLookupByName(pool)
vname = virtinst.Storage.StorageVolume.find_free_name(conn=guest.conn,
pool_name=pool,
pool_object=poolobj,
name=guest.name,
suffix=".img",
start_num=_disk_counter.next())
volinst = vc(pool_name=pool, name=vname, conn=guest.conn,
allocation=0, capacity=(size and
size * 1024 * 1024 * 1024))
volinst = virtinst.VirtualDisk.build_vol_install(
guest.conn, vname, poolobj, size, sparse)
if fmt:
if not hasattr(volinst, "format"):
raise ValueError(_("Format attribute not supported for this "
"volume type"))
setattr(volinst, "format", fmt)
if not sparse:
volinst.allocation = volinst.capacity
elif vol:
if not vol.count("/"):
raise ValueError(_("Storage volume must be specified as "

View File

@ -216,6 +216,9 @@ class VirtualConnection(object):
self._fetch_cache[key] = ret
return ret
def clear_cache(self):
self._fetch_cache = {}
#########################
# Libvirt API overrides #

View File

@ -134,7 +134,7 @@ def check_if_path_managed(conn, path):
return vol, pool, path_is_pool
def _build_vol_install(conn, path, pool, size, sparse):
def build_vol_install(conn, path, pool, size, sparse):
# Path wasn't a volume. See if base of path is a managed
# pool, and if so, setup a StorageVolume object
if size is None:
@ -186,7 +186,7 @@ class StorageCreator(_StorageBase):
self.fake = False
if not self._vol_install and self._pool:
self._vol_install = _build_vol_install(conn, path, pool,
self._vol_install = build_vol_install(conn, path, pool,
size, sparse)
self._set_format(fmt)
if self._vol_install: