예제 #1
0
파일: gfapi.py 프로젝트: rollandf/vdsm
def checkVolumeEmpty(volumeId,
                     host=GLUSTER_VOL_HOST,
                     port=GLUSTER_VOL_PORT,
                     protocol=GLUSTER_VOL_PROTOCOL):
    data = ctypes.POINTER(DirentStruct)()
    fs = glfsInit(volumeId, host, port, protocol)

    fd = _glfs_opendir(fs, "/")

    if fd is None:
        glfsFini(fs, volumeId)
        raise ge.GlusterVolumeEmptyCheckFailedException(
            err=['glfs_opendir() failed'])

    entry = "."
    flag = False

    while entry in [".", "..", ".trashcan"]:
        data = _glfs_readdir(fd)
        if data is None:
            glfsFini(fs, volumeId)
            raise ge.GlusterVolumeEmptyCheckFailedException(
                err=['glfs_readdir() failed'])

        # When there are no more entries in directory _glfs_readdir()
        # will return a null pointer. bool of null pointer will be false
        # Using this to conclude that no more entries in volume.
        if not bool(data):
            flag = True
            break

        entry = data.contents.d_name
    else:
        flag = False

    glfsFini(fs, volumeId)
    return flag
예제 #2
0
파일: gfapi.py 프로젝트: xiaojiongming/vdsm
def volumeEmptyCheck(volumeName, host=GLUSTER_VOL_HOST,
                     port=GLUSTER_VOL_PORT,
                     protocol=GLUSTER_VOL_PROTOCOL):
    module = "gluster.gfapi"
    command = [sys.executable, '-m', module, '-v', volumeName,
               '-p', str(port), '-H', host, '-t', protocol, '-c', 'readdir']

    # to include /usr/share/vdsm in python path
    env = os.environ.copy()
    env['PYTHONPATH'] = "%s:%s" % (
        env.get("PYTHONPATH", ""), constants.P_VDSM)
    env['PYTHONPATH'] = ":".join(map(os.path.abspath,
                                     env['PYTHONPATH'].split(":")))

    rc, out, err = commands.execCmd(command, raw=True, env=env)
    if rc != 0:
        raise ge.GlusterVolumeEmptyCheckFailedException(rc, [out], [err])
    return out.upper() == "TRUE"