Beispiel #1
0
class Nibbler:
    def __init__(self, fabnet_host, security_provider, parallel_put=3, parallel_get=3):
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)
        self.metadata = None
        self.put_manager = PutDataManager(self.fabnet_gateway, self.__finish_file_put, parallel_put)
        self.get_manager = GetDataManager(self.fabnet_gateway, parallel_get)

        user_id = self.security_provider.get_client_cert()
        self.metadata_key = hashlib.sha1(user_id).hexdigest()

        self.put_manager.start()
        self.get_manager.start()

    def stop(self):
        self.put_manager.stop()
        self.get_manager.stop()

    def __get_metadata(self, reload_force=False, metadata_key=None):
        if self.metadata and not reload_force:
            return self.metadata

        if not metadata_key:
            metadata_key = self.metadata_key

        metadata = self.fabnet_gateway.get(metadata_key)
        if metadata is None:
            raise Exception("No metadata found!")

        mdf = MetadataFile()
        mdf.load(metadata)
        self.metadata = mdf
        return self.metadata

    def __save_metadata(self):
        version_key = self.metadata.make_new_version(self.metadata_key)
        metadata = self.metadata.dump()
        try:
            self.fabnet_gateway.put(metadata, key=version_key)
        except Exception, err:
            self.metadata.remove_version(version_key)
            raise err

        try:
            self.fabnet_gateway.put(metadata, key=self.metadata_key)
        except Exception, err:
            self.__get_metadata(reload_force=True)
            raise err
Beispiel #2
0
    def __init__(self, fabnet_host, security_provider, parallel_put=3, parallel_get=3):
        self.security_provider = security_provider
        self.fabnet_gateway = FabnetGateway(fabnet_host, security_provider)
        self.metadata = None
        self.put_manager = PutDataManager(self.fabnet_gateway, self.__finish_file_put, parallel_put)
        self.get_manager = GetDataManager(self.fabnet_gateway, parallel_get)

        user_id = self.security_provider.get_client_cert()
        self.metadata_key = hashlib.sha1(user_id).hexdigest()

        self.put_manager.start()
        self.get_manager.start()