コード例 #1
0
ファイル: server.py プロジェクト: vbellur/UFO
    def __init__(self, path, device, partition, account, container, logger, uid=DEFAULT_UID, gid=DEFAULT_GID):
        if container:
            #self.name = '/'.join((account, container))
            self.name = container
        else:
            self.name = None
        if self.name:
            self.datadir = os.path.join(path, device,
                            storage_directory(DATADIR, partition, self.name))
        else:
            self.datadir = os.path.join(path, device)
            
        #print 'Gaurav DiskDir datadir', account, container, path,\
                                         #device, self.datadir
        self.device_path = os.path.join(path, device)
        self.logger = logger
        self.metadata = {}
        self.uid = int(uid)
        self.gid = int(gid)
        self.dir_exists = os.path.isdir (self.datadir)
        if self.dir_exists:
            self.metadata = read_metadata(self.datadir)
        else:
            return
        if container:
            if not self.metadata:
                #objects, object_count, bytes_used = get_container_details(self.datadir)
                #self.update_container(object_count, bytes_used)
                create_container_metadata(self.datadir)
                self.metadata = read_metadata(self.datadir)
            ret = validate_container(self.metadata)
        else:
            if not self.metadata:
                #containers, container_count = get_account_details(self.datadir)
                #self.update_acocunt(container_count)
                create_account_metadata(self.datadir)
                self.metadata = read_metadata(self.datadir)
            ret = validate_account(self.metadata)

        if not ret:
            self.dir_exists = False
            self.metadata = {}
コード例 #2
0
ファイル: server.py プロジェクト: Gaurav-Gangalwar/UFO
    def __init__(self, path, device, partition, account, container, logger,
                 memcache=None, uid=DEFAULT_UID, gid=DEFAULT_GID):
        if container:
            self.name = container
        else:
            self.name = None
        if self.name:
            self.datadir = os.path.join(path, device,
                            storage_directory(DATADIR, partition, self.name))
        else:
            self.datadir = os.path.join(path, device)
        self.device_path = os.path.join(path, device)
        self.logger = logger
        self.metadata = {}
        self.uid = int(uid)
        self.gid = int(gid)
        self.memcache = memcache
        self.dir_exists = os.path.isdir (self.datadir)
        if self.dir_exists:
            self.metadata = read_metadata(self.datadir)
        else:
            return
        if container:
            if not self.metadata:
                create_container_metadata(self.datadir, memcache=self.memcache)
                self.metadata = read_metadata(self.datadir)
            ret = validate_container(self.metadata)
        else:
            if not self.metadata:
                create_account_metadata(self.datadir, memcache=self.memcache)
                self.metadata = read_metadata(self.datadir)
            ret = validate_account(self.metadata)

        if not ret:
            self.logger.error('Metadata validation failed %s %s' % \
                              (self.datadir, self.metadata))
            self.dir_exists = False
            self.metadata = {}