def __init__(self): self.__nibbler = None self.__api_list = [] self.__config = Config() self.__status = CS_STOPPED self.__ms_mgr = get_media_storage_manager() self.__check_kss_thrd = None self.__last_ks_type = None self.__last_ks_path = None self.__events = [] self.__webdav_mount = WebdavMounter() events_provider.append_listener(Event.ET_CRITICAL, self.on_critical_event) self.__set_log_level()
class IdepositboxClient(object): def __init__(self): self.__nibbler = None self.__api_list = [] self.__config = Config() self.__status = CS_STOPPED self.__ms_mgr = get_media_storage_manager() self.__check_kss_thrd = None self.__last_ks_type = None self.__last_ks_path = None self.__events = [] self.__webdav_mount = WebdavMounter() events_provider.append_listener(Event.ET_CRITICAL, self.on_critical_event) self.__set_log_level() def __set_log_level(self): log_level = self.__config.log_level.lower() ll_map = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARNING, 'error': logging.ERROR} l_level = ll_map.get(log_level, None) if l_level == None: logger.error('Unknown log level "%s"'%log_level) logger.setLevel(l_level) nimbus_logger.setLevel(l_level) @IDEventLock def on_critical_event(self, event): self.__events.append(event) @IDEventLock def get_events(self): events = self.__events self.__events = [] return events @IDEventLock def get_events_count(self): return len(self.__events) def get_version(self): return VERSION @IDLock def get_nibbler(self): return self.__nibbler @IDLock def get_status(self): return self.__status @IDLock def get_mount_point(self): return self.__webdav_mount.get_mount_point() @IDLock def get_last_key_storage_type(self): return self.__last_ks_type @IDLock def get_last_key_storage_path(self): return self.__last_ks_path @IDLock def start(self, ks_type, ks_path, ks_passwd): if self.__status == CS_STARTED: raise Exception('IdepositboxClient is already started') self.__config.refresh() config = self.__config try: sm_class = SM_TYPES_MAP.get(ks_type, None) if not sm_class: raise Exception('Unsupported key chain type: "%s"'%ks_type) security_provider = sm_class(ks_path, ks_passwd) self.__last_ks_path = ks_path self.__last_ks_type = ks_type self.__nibbler = Nibbler(config.fabnet_hostname, security_provider, \ config.parallel_put_count, config.parallel_get_count, \ config.data_dir, config.cache_size) try: registered = self.__nibbler.is_registered() except Exception, err: logger.error(err) raise Exception('Service %s does not respond! Please, '\ 'ensure that network is configured correctly'%config.fabnet_hostname) if not registered: try: self.__nibbler.register_user() #FIXME: this is dangerous call! user should accept this case... except Exception, err: logger.error('Register user error: %s'%err) raise Exception('User does not registered in service') self.__nibbler.start() #init API instances self.__api_list = [] if config.mount_type == MOUNT_LOCAL: ext_host = '127.0.0.1' else: ext_host = config.webdav_bind_host log_level = logger.getEffectiveLevel() webdav_server = WebDavAPI(self.__nibbler, ext_host, config.webdav_bind_port, log_level) self.__api_list.append(webdav_server) for api_instance in self.__api_list: logger.debug('starting %s...'%api_instance.get_name()) api_instance.start() logger.debug('waiting while %s is started...'%api_instance.get_name()) for i in xrange(api_instance.get_start_waittime()): time.sleep(1) if api_instance.is_ready(): break else: raise Exception('%s does not started!'%api_instance.get_name()) logger.info('%s is started!'%api_instance.get_name()) if config.mount_type == MOUNT_LOCAL: time.sleep(1) ret_code = self.__webdav_mount.mount(ext_host, config.webdav_bind_port) mount_point = self.__webdav_mount.get_mount_point() if not mount_point: mount_point = 'UnknownMountPoint' if ret_code: logger.error('WebDav resource does not mounted at %s!'%mount_point) else: logger.info('WebDav resource is mounted at %s'%mount_point) self.__check_kss_thrd = CheckKSStatusThread(self) self.__check_kss_thrd.start() logger.info('IdepositboxClient is started')
class IdepositboxClient(object): def __init__(self): self.__nibbler = None self.__api_list = [] self.__config = Config() self.__status = CS_STOPPED self.__ms_mgr = get_media_storage_manager() self.__check_kss_thrd = None self.__last_ks_type = None self.__last_ks_path = None self.__events = [] self.__webdav_mount = WebdavMounter() events_provider.append_listener(Event.ET_CRITICAL, self.on_critical_event) self.__set_log_level() def __set_log_level(self): log_level = self.__config.log_level.lower() ll_map = { 'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARNING, 'error': logging.ERROR } l_level = ll_map.get(log_level, None) if l_level == None: logger.error('Unknown log level "%s"' % log_level) logger.setLevel(l_level) nimbus_logger.setLevel(l_level) @IDEventLock def on_critical_event(self, event): self.__events.append(event) @IDEventLock def get_events(self): events = self.__events self.__events = [] return events @IDEventLock def get_events_count(self): return len(self.__events) def get_version(self): return VERSION @IDLock def get_nibbler(self): return self.__nibbler @IDLock def get_status(self): return self.__status @IDLock def get_mount_point(self): return self.__webdav_mount.get_mount_point() @IDLock def get_last_key_storage_type(self): return self.__last_ks_type @IDLock def get_last_key_storage_path(self): return self.__last_ks_path @IDLock def start(self, ks_type, ks_path, ks_passwd): if self.__status == CS_STARTED: raise Exception('IdepositboxClient is already started') self.__config.refresh() config = self.__config try: sm_class = SM_TYPES_MAP.get(ks_type, None) if not sm_class: raise Exception('Unsupported key chain type: "%s"' % ks_type) security_provider = sm_class(ks_path, ks_passwd) self.__last_ks_path = ks_path self.__last_ks_type = ks_type self.__nibbler = Nibbler(config.fabnet_hostname, security_provider, \ config.parallel_put_count, config.parallel_get_count, \ config.data_dir, config.cache_size) try: registered = self.__nibbler.is_registered() except Exception, err: logger.error(err) raise Exception('Service %s does not respond! Please, '\ 'ensure that network is configured correctly'%config.fabnet_hostname) if not registered: try: self.__nibbler.register_user( ) #FIXME: this is dangerous call! user should accept this case... except Exception, err: logger.error('Register user error: %s' % err) raise Exception('User does not registered in service') self.__nibbler.start() #init API instances self.__api_list = [] if config.mount_type == MOUNT_LOCAL: ext_host = '127.0.0.1' else: ext_host = config.webdav_bind_host log_level = logger.getEffectiveLevel() webdav_server = WebDavAPI(self.__nibbler, ext_host, config.webdav_bind_port, log_level) self.__api_list.append(webdav_server) for api_instance in self.__api_list: logger.debug('starting %s...' % api_instance.get_name()) api_instance.start() logger.debug('waiting while %s is started...' % api_instance.get_name()) for i in xrange(api_instance.get_start_waittime()): time.sleep(1) if api_instance.is_ready(): break else: raise Exception('%s does not started!' % api_instance.get_name()) logger.info('%s is started!' % api_instance.get_name()) if config.mount_type == MOUNT_LOCAL: time.sleep(1) ret_code = self.__webdav_mount.mount(ext_host, config.webdav_bind_port) mount_point = self.__webdav_mount.get_mount_point() if not mount_point: mount_point = 'UnknownMountPoint' if ret_code: logger.error('WebDav resource does not mounted at %s!' % mount_point) else: logger.info('WebDav resource is mounted at %s' % mount_point) self.__check_kss_thrd = CheckKSStatusThread(self) self.__check_kss_thrd.start() logger.info('IdepositboxClient is started')
def __init_logger(self): config = Config() wsgi_logger = init_logger(os.path.join(config.data_dir, 'logs', 'webdav.log'),\ BASE_LOGGER_NAME) wsgi_logger.setLevel(self.log_level)
if os.path.exists(mount_point): p = Subprocess('umount %s' % mount_point) out, err = p.communicate() if p.returncode: logger.debug('"umount %s" output: %s %s' % (mount_point, out, err)) if __name__ == '__main__': if len(sys.argv) != 2: sys.stderr.write('usage: webdav_mount mount|umount\n') sys.exit(1) from id_client.config import Config wdm = WebdavMounter(nofork=True) config = Config() cmd = sys.argv[1] if cmd == 'mount': err = '' try: ret_code = wdm.mount('127.0.0.1', config.webdav_bind_port) except Exception, err: ret_code = 1 if ret_code: sys.stderr.write('Webdav does not mounted locally! %s\n' % err) sys.exit(1) elif cmd == 'umount': wdm.update_linux_mountpoint('127.0.0.1:%s' % config.webdav_bind_port) wdm.unmount() else: sys.stderr.write('unknown command "%s"!\n' % cmd)