Ejemplo n.º 1
0
    def find_free_name(name, pool_object=None, pool_name=None, conn=None,
                       suffix="", collidelist=None, start_num=0):
        """
        Finds a name similar (or equal) to passed 'name' that is not in use
        by another pool

        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
        name is in use, it append "-1" to the name and tries again, then "-2",
        continuing to 100000 (which will hopefully never be reached.") If
        suffix is specified, attach it to the (potentially incremented) name
        before checking for collision.

        Ex name="test", suffix=".img" -> name-3.img

        @param collidelist: An extra list of names to check for collision
        @type collidelist: C{list}
        @returns: A free name
        @rtype: C{str}
        """
        collidelist = collidelist or []
        pool_object = StorageVolume.lookup_pool_by_name(
                                                    pool_object=pool_object,
                                                    pool_name=pool_name,
                                                    conn=conn)
        pool_object.refresh(0)

        return util.generate_name(name, pool_object.storageVolLookupByName,
                                   suffix, collidelist=collidelist,
                                   start_num=start_num)
Ejemplo n.º 2
0
 def find_free_name(conn, prefix):
     """
     Generate an unused interface name based on prefix. For example,
     if prefix="br", we find the first unused name such as "br0", "br1",
     etc.
     """
     return util.generate_name(prefix, conn.interfaceLookupByName, sep="",
                               force_num=True)
Ejemplo n.º 3
0
 def find_free_name(conn, basename, **kwargs):
     """
     Finds a name similar (or equal) to passed 'basename' that is not
     in use by another pool. Extra params are passed to generate_name
     """
     return util.generate_name(basename,
                               conn.storagePoolLookupByName,
                               **kwargs)
Ejemplo n.º 4
0
 def find_free_name(pool_object, basename, **kwargs):
     """
     Finds a name similar (or equal) to passed 'basename' that is not
     in use by another volume. Extra params are passed to generate_name
     """
     pool_object.refresh(0)
     return util.generate_name(basename,
                               pool_object.storageVolLookupByName,
                               **kwargs)
Ejemplo n.º 5
0
 def find_free_name(conn, prefix):
     """
     Generate an unused interface name based on prefix. For example,
     if prefix="br", we find the first unused name such as "br0", "br1",
     etc.
     """
     return util.generate_name(prefix,
                               conn.interfaceLookupByName,
                               sep="",
                               force_num=True)
Ejemplo n.º 6
0
def _build_pool(conn, meter, path):
    pool = util.lookup_pool_by_path(conn, path)
    if pool:
        logging.debug("Existing pool '%s' found for %s", pool.name(), path)
        pool.refresh(0)
        return pool

    name = util.generate_name("boot-scratch", conn.storagePoolLookupByName)
    logging.debug("Building storage pool: path=%s name=%s", path, name)
    poolbuild = Storage.DirectoryPool(conn=conn, name=name, target_path=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)
Ejemplo n.º 7
0
def _build_pool(conn, meter, path):
    pool = util.lookup_pool_by_path(conn, path)
    if pool:
        logging.debug("Existing pool '%s' found for %s", pool.name(), path)
        pool.refresh(0)
        return pool

    name = util.generate_name("boot-scratch", conn.storagePoolLookupByName)
    logging.debug("Building storage pool: path=%s name=%s", path, name)
    poolbuild = Storage.DirectoryPool(conn=conn, name=name, target_path=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)