mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
storage: Drop unused static function
This allows us to simplify the parameters for find_free_name
This commit is contained in:
parent
01577d3d88
commit
34c502560f
@ -47,7 +47,7 @@ def _findFreePoolName(conn, namebase):
|
|||||||
while True:
|
while True:
|
||||||
poolname = namebase + "-%d" % i
|
poolname = namebase + "-%d" % i
|
||||||
try:
|
try:
|
||||||
StorageVolume.lookup_pool_by_name(conn=conn, pool_name=poolname)
|
conn.storagePoolLookupByName(poolname)
|
||||||
i += 1
|
i += 1
|
||||||
except:
|
except:
|
||||||
return poolname
|
return poolname
|
||||||
|
@ -549,11 +549,9 @@ class vmmCreateInterface(vmmGObjectUI):
|
|||||||
|
|
||||||
name = _("No interface selected")
|
name = _("No interface selected")
|
||||||
if itype == Interface.INTERFACE_TYPE_BRIDGE:
|
if itype == Interface.INTERFACE_TYPE_BRIDGE:
|
||||||
name = Interface.find_free_name(self.conn.get_backend(),
|
name = Interface.find_free_name(self.conn.get_backend(), "br")
|
||||||
"br")
|
|
||||||
elif itype == Interface.INTERFACE_TYPE_BOND:
|
elif itype == Interface.INTERFACE_TYPE_BOND:
|
||||||
name = Interface.find_free_name(self.conn.get_backend(),
|
name = Interface.find_free_name(self.conn.get_backend(), "bond")
|
||||||
"bond")
|
|
||||||
else:
|
else:
|
||||||
ifaces = self.get_config_selected_interfaces()
|
ifaces = self.get_config_selected_interfaces()
|
||||||
if len(ifaces) > 0:
|
if len(ifaces) > 0:
|
||||||
|
@ -104,9 +104,8 @@ class vmmCreateVolume(vmmGObjectUI):
|
|||||||
suffix = self.default_suffix()
|
suffix = self.default_suffix()
|
||||||
ret = ""
|
ret = ""
|
||||||
try:
|
try:
|
||||||
ret = StorageVolume.find_free_name(self.name_hint,
|
ret = StorageVolume.find_free_name(
|
||||||
pool_object=self.parent_pool.get_backend(),
|
self.parent_pool.get_backend(), self.name_hint, suffix=suffix)
|
||||||
suffix=suffix)
|
|
||||||
except:
|
except:
|
||||||
logging.exception("Error finding a default vol name")
|
logging.exception("Error finding a default vol name")
|
||||||
|
|
||||||
|
@ -1174,9 +1174,9 @@ def get_default_path(conn, name, collidelist=None):
|
|||||||
if c and os.path.dirname(c) == pool.get_target_path():
|
if c and os.path.dirname(c) == pool.get_target_path():
|
||||||
newcollidelist.append(os.path.basename(c))
|
newcollidelist.append(os.path.basename(c))
|
||||||
|
|
||||||
path = virtinst.StorageVolume.find_free_name(name,
|
path = virtinst.StorageVolume.find_free_name(
|
||||||
pool_object=pool.get_backend(), suffix=suffix,
|
pool.get_backend(), name,
|
||||||
collidelist=newcollidelist)
|
suffix=suffix, collidelist=newcollidelist)
|
||||||
|
|
||||||
path = os.path.join(target, path)
|
path = os.path.join(target, path)
|
||||||
|
|
||||||
|
@ -1354,11 +1354,8 @@ def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
|
|||||||
|
|
||||||
|
|
||||||
poolobj = guest.conn.storagePoolLookupByName(pool)
|
poolobj = guest.conn.storagePoolLookupByName(pool)
|
||||||
vname = virtinst.StorageVolume.find_free_name(conn=guest.conn,
|
vname = virtinst.StorageVolume.find_free_name(
|
||||||
pool_object=poolobj,
|
poolobj, guest.name, suffix=".img", start_num=_disk_counter.next())
|
||||||
name=guest.name,
|
|
||||||
suffix=".img",
|
|
||||||
start_num=_disk_counter.next())
|
|
||||||
|
|
||||||
volinst = virtinst.VirtualDisk.build_vol_install(
|
volinst = virtinst.VirtualDisk.build_vol_install(
|
||||||
guest.conn, vname, poolobj, size, sparse)
|
guest.conn, vname, poolobj, size, sparse)
|
||||||
|
@ -109,7 +109,7 @@ def _upload_file(conn, meter, destpool, src):
|
|||||||
xmlobj = StoragePool(conn, parsexml=destpool.XMLDesc(0))
|
xmlobj = StoragePool(conn, parsexml=destpool.XMLDesc(0))
|
||||||
poolpath = xmlobj.target_path
|
poolpath = xmlobj.target_path
|
||||||
|
|
||||||
name = StorageVolume.find_free_name(basename, pool_object=destpool)
|
name = StorageVolume.find_free_name(destpool, basename)
|
||||||
if name != basename:
|
if name != basename:
|
||||||
logging.debug("Generated non-colliding volume name %s", name)
|
logging.debug("Generated non-colliding volume name %s", name)
|
||||||
|
|
||||||
|
@ -461,11 +461,11 @@ class StorageVolume(_StorageObject):
|
|||||||
Base class for building and installing libvirt storage volume xml
|
Base class for building and installing libvirt storage volume xml
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_free_name(name, pool_object=None, pool_name=None, conn=None,
|
def find_free_name(pool_object, basename,
|
||||||
suffix="", collidelist=None, start_num=0):
|
suffix="", collidelist=None, start_num=0):
|
||||||
"""
|
"""
|
||||||
Finds a name similar (or equal) to passed 'name' that is not in use
|
Finds a name similar (or equal) to passed 'basename' that is not
|
||||||
by another pool
|
in use by another pool
|
||||||
|
|
||||||
This function scans the list of existing Volumes on the passed or
|
This function scans the list of existing Volumes on the passed or
|
||||||
looked up pool object for a collision with the passed name. If the
|
looked up pool object for a collision with the passed name. If the
|
||||||
@ -482,42 +482,11 @@ class StorageVolume(_StorageObject):
|
|||||||
@rtype: C{str}
|
@rtype: C{str}
|
||||||
"""
|
"""
|
||||||
collidelist = collidelist or []
|
collidelist = collidelist or []
|
||||||
pool_object = StorageVolume.lookup_pool_by_name(
|
|
||||||
pool_object=pool_object,
|
|
||||||
pool_name=pool_name,
|
|
||||||
conn=conn)
|
|
||||||
pool_object.refresh(0)
|
pool_object.refresh(0)
|
||||||
|
|
||||||
return util.generate_name(name, pool_object.storageVolLookupByName,
|
return util.generate_name(basename, pool_object.storageVolLookupByName,
|
||||||
suffix, collidelist=collidelist,
|
suffix, collidelist=collidelist,
|
||||||
start_num=start_num)
|
start_num=start_num)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def lookup_pool_by_name(pool_object=None, pool_name=None, conn=None):
|
|
||||||
"""
|
|
||||||
Returns pool object determined from passed parameters.
|
|
||||||
|
|
||||||
Largely a convenience function for the other static functions.
|
|
||||||
"""
|
|
||||||
if pool_object is None and pool_name is None:
|
|
||||||
raise ValueError(_("Must specify pool_object or pool_name"))
|
|
||||||
|
|
||||||
if pool_name is not None and pool_object is None:
|
|
||||||
if conn is None:
|
|
||||||
raise ValueError(_("'conn' must be specified with 'pool_name'"))
|
|
||||||
if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE):
|
|
||||||
raise ValueError(_("Connection does not support storage "
|
|
||||||
"management."))
|
|
||||||
try:
|
|
||||||
pool_object = conn.storagePoolLookupByName(pool_name)
|
|
||||||
except Exception, e:
|
|
||||||
raise ValueError(_("Couldn't find storage pool '%s': %s" %
|
|
||||||
(pool_name, str(e))))
|
|
||||||
|
|
||||||
if not isinstance(pool_object, libvirt.virStoragePool):
|
|
||||||
raise ValueError(_("pool_object must be a virStoragePool"))
|
|
||||||
|
|
||||||
return pool_object
|
|
||||||
|
|
||||||
TYPE_FILE = getattr(libvirt, "VIR_STORAGE_VOL_FILE", 0)
|
TYPE_FILE = getattr(libvirt, "VIR_STORAGE_VOL_FILE", 0)
|
||||||
TYPE_BLOCK = getattr(libvirt, "VIR_STORAGE_VOL_BLOCK", 1)
|
TYPE_BLOCK = getattr(libvirt, "VIR_STORAGE_VOL_BLOCK", 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user