Example #1
0
def _get_volume(vol_name, vol_size, instance_name, user):
    path = _get_volume_dir(vol_name, user)
    if os.path.exists(path):
        volume_uuid = _get_volume_uuid(path)
        create = False
        if volume_uuid == "":
            log.warning("Found volume directory but cannot find related \
                    volume! Create one")
            create = True

        assert _get_volume_instance_name(path) == instance_name

        if not create:
            mount_dir = os.path.join(path, volume_uuid)
            if not service.mounted(mount_dir,
                                   Config.volmgr_mount_namespace_fd()):
                v.mount_volume(volume_uuid, mount_dir, False,
                               Config.volmgr_mount_namespace_fd())
            return mount_dir

    volume_uuid = v.create_volume(vol_size)
    v.add_volume_to_blockstore(volume_uuid, blockstore_uuid)
    mount_dir = os.path.join(path, volume_uuid)
    os.makedirs(mount_dir)
    f = open(os.path.join(path, INSTANCE_TAG_FILE), "w")
    try:
        f.write(instance_name)
    finally:
        f.close()
    v.mount_volume(volume_uuid, mount_dir, True,
                   Config.volmgr_mount_namespace_fd())
    return mount_dir
Example #2
0
def _get_volume(vol_name, vol_size, instance_name, user):
    path = _get_volume_dir(vol_name, user)
    if os.path.exists(path):
        volume_uuid = _get_volume_uuid(path)
        create = False
        if volume_uuid == "":
            log.warning("Found volume directory but cannot find related \
                    volume! Create one")
            create = True

        assert _get_volume_instance_name(path) == instance_name

        if not create:
            mount_dir = os.path.join(path, volume_uuid)
            if not service.mounted(mount_dir,
                                   Config.volmgr_mount_namespace_fd()):
                v.mount_volume(volume_uuid, mount_dir, False,
                               Config.volmgr_mount_namespace_fd())
            return mount_dir

    volume_uuid = v.create_volume(vol_size)
    v.add_volume_to_blockstore(volume_uuid, blockstore_uuid)
    mount_dir = os.path.join(path, volume_uuid)
    os.makedirs(mount_dir)
    f = open(os.path.join(path, INSTANCE_TAG_FILE), "w")
    try:
        f.write(instance_name)
    finally:
        f.close()
    v.mount_volume(volume_uuid, mount_dir, True,
                   Config.volmgr_mount_namespace_fd())
    return mount_dir
Example #3
0
def volume_exists(path):
    if not enabled():
        return False
    if not path.startswith(Config.volmgr_mount_dir()):
        return False
    if not os.path.exists(path):
        return False
    return service.mounted(path, Config.volmgr_mount_namespace_fd())
Example #4
0
def volume_exists(path):
    if not enabled():
        return False
    if not path.startswith(Config.volmgr_mount_dir()):
        return False
    if not os.path.exists(path):
        return False
    return service.mounted(path, Config.volmgr_mount_namespace_fd())