def unlink_clone_vol(vol_uuid):
    cbd = curvefs.CBDClient()
    rc = cbd.Init("./client.conf")
    if rc != 0:
        raise AssertionError
    filename = "/" + vol_uuid
    user = curvefs.UserInfo_t()
    user.owner = "test"
    logger2.debug("filename is %s"%filename)
    cbd.Unlink(str(filename), user)
    cbd.UnInit()
Beispiel #2
0
def check_clone_vol_exist(clonevol_uuid):
    cbd = curvefs.CBDClient()
    rc = cbd.Init("./client.conf")
    if rc != 0:
        raise AssertionError
    filename = "volume-" + clonevol_uuid
    user = curvefs.UserInfo_t()
    user.owner = "cinder"
    dirs = cbd.Listdir("/cinder", user)
    for d in dirs:
        logger2.info("dir is %s,filename is %s"%(d,filename))
        if d == filename:
            cbd.UnInit()
            return True
    cbd.UnInit()
    return False
def get_vol_md5(vol_uuid):
    cbd = curvefs.CBDClient()
    rc = cbd.Init("./client.conf")
    if rc != 0:
        raise AssertionError
    filename = "/" + vol_uuid
    user = curvefs.UserInfo_t()
    user.owner = "test"
#    user.password = ""
    logger2.info("file name is %s,type is %s"%(filename,type(filename)))
    logger2.info("user is %s,type is %s"%(user,type(user)))
    fd = cbd.Open(str(filename), user)
    buf = ''
    md5_obj = hashlib.md5()
    for i in range(1,2560):
        j = i - 1
        context = cbd.Read(fd, buf, 4096*1024*j,4096*1024)
        md5_obj.update(context)
    hash_code = md5_obj.hexdigest()
    md5 = str(hash_code).lower()
    cbd.Close(fd)
    cbd.UnInit()
    logger2.info("md5 is %s"%md5)
    return md5
#!/usr/bin/env python
# -*- coding: utf8 -*-

from curvefs_python import curvefs
from config import config
from logger.logger import *

cbdClient = curvefs.CBDClient()


class LibCurve:
    def __init__(self):
        rc = cbdClient.Init(config.client_conf)
        logger.info("init success.")
        if rc != 0:
            print("init client fail! rc=%s" % rc)
            logger.debug("init client fail! rc=%s" % rc)
            raise AssertionError

    def libcurve_create(self, file_path, user_name, size, pass_word=""):
        user_info_t = curvefs.UserInfo_t()
        user_info_t.owner = user_name
        user_info_t.password = pass_word
        rc = cbdClient.Create(file_path, user_info_t, size)
        if rc != 0:
            #            print("create file %s fail! rc=%s" %(file_path,rc))
            logger.debug("create file %s fail! rc=%s" % (file_path, rc))
            return rc
            #raise AssertionError
        else:
            return rc