def get_dcs(config): available_implementations = set() for module_name in dcs_modules(): try: module = importlib.import_module(module_name) for name in filter(lambda name: not name.startswith('__'), dir(module)): # iterate through module content item = getattr(module, name) name = name.lower() # try to find implementation of AbstractDCS interface, class name must match with module_name if inspect.isclass(item) and issubclass( item, AbstractDCS ) and __package__ + '.' + name == module_name: available_implementations.add(name) if name in config: # which has configuration section in the config file # propagate some parameters config[name].update({ p: config[p] for p in ('namespace', 'name', 'scope', 'loop_wait', 'patronictl', 'ttl', 'retry_timeout') if p in config }) return item(config[name]) except ImportError: if not config.get('patronictl'): logger.info('Failed to import %s', module_name) raise PatroniException( """Can not find suitable configuration of distributed configuration store Available implementations: """ + ', '.join(available_implementations))
def get_dcs(node_name, config): available_implementations = [] for name in os.listdir(os.path.dirname(__file__)): if name.endswith('.py') and not name.startswith( '__') and name.startswith('etcd'): # find module module = importlib.import_module(__package__ + '.' + name[:-3]) for name in dir(module): # iterate through module content if not name.startswith('__'): # skip internal stuff value = getattr(module, name) name = name.lower() # try to find implementation of AbstractDCS interface if inspect.isclass(value) and issubclass( value, AbstractDCS): available_implementations.append(name) if name in config: # which has configuration section in the config file # propagate some parameters config[name].update({ p: config[p] for p in ('namespace', 'scope', 'ttl') if p in config }) return value(node_name, config[name]) raise PatroniException( """Can not find suitable configuration of distributed configuration store Available implementations: """ + ', '.join(available_implementations))
def get_dcs(config): modules = dcs_modules() for module_name in modules: name = module_name.split('.')[-1] if name in config: # we will try to import only modules which have configuration section in the config file try: module = importlib.import_module(module_name) for key, item in module.__dict__.items(): # iterate through the module content # try to find implementation of AbstractDCS interface, class name must match with module_name if key.lower() == name and inspect.isclass(item) and issubclass(item, AbstractDCS): # propagate some parameters config[name].update({p: config[p] for p in ('namespace', 'name', 'scope', 'loop_wait', 'patronictl', 'ttl', 'retry_timeout') if p in config}) return item(config[name]) except ImportError: logger.debug('Failed to import %s', module_name) available_implementations = [] for module_name in modules: name = module_name.split('.')[-1] try: module = importlib.import_module(module_name) available_implementations.extend(name for key, item in module.__dict__.items() if key.lower() == name and inspect.isclass(item) and issubclass(item, AbstractDCS)) except ImportError: logger.info('Failed to import %s', module_name) raise PatroniException("""Can not find suitable configuration of distributed configuration store Available implementations: """ + ', '.join(sorted(set(available_implementations))))
def get_dcs(config): available_implementations = set() for module in os.listdir(os.path.dirname(__file__)): if module.endswith( '.py') and not module.startswith('__'): # find module module_name = module[:-3].lower() module = importlib.import_module(__package__ + '.' + module[:-3]) for name in filter(lambda name: not name.startswith('__'), dir(module)): # iterate through module content value = getattr(module, name) name = name.lower() # try to find implementation of AbstractDCS interface, class name must match with module_name if inspect.isclass(value) and issubclass( value, AbstractDCS) and name == module_name: available_implementations.add(name) if name in config: # which has configuration section in the config file # propagate some parameters config[name].update({ p: config[p] for p in ('namespace', 'name', 'scope', 'ttl', 'retry_timeout') if p in config }) return value(config[name]) raise PatroniException( """Can not find suitable configuration of distributed configuration store Available implementations: """ + ', '.join(available_implementations))
def __init__(self, postgresql, config): self._postgresql = postgresql self._config_dir = os.path.abspath(config.get('config_dir') or postgresql.data_dir) config_base_name = config.get('config_base_name', 'postgresql') self._postgresql_conf = os.path.join(self._config_dir, config_base_name + '.conf') self._postgresql_conf_mtime = None self._postgresql_base_conf_name = config_base_name + '.base.conf' self._postgresql_base_conf = os.path.join(self._config_dir, self._postgresql_base_conf_name) self._pg_hba_conf = os.path.join(self._config_dir, 'pg_hba.conf') self._pg_ident_conf = os.path.join(self._config_dir, 'pg_ident.conf') self._recovery_conf = os.path.join(postgresql.data_dir, 'recovery.conf') self._recovery_conf_mtime = None self._recovery_signal = os.path.join(postgresql.data_dir, 'recovery.signal') self._standby_signal = os.path.join(postgresql.data_dir, 'standby.signal') self._auto_conf = os.path.join(postgresql.data_dir, 'postgresql.auto.conf') self._auto_conf_mtime = None self._pgpass = os.path.abspath(config.get('pgpass') or os.path.join(os.path.expanduser('~'), 'pgpass')) if os.path.exists(self._pgpass) and not os.path.isfile(self._pgpass): raise PatroniException("'{}' exists and it's not a file, check your `postgresql.pgpass` configuration" .format(self._pgpass)) self._passfile = None self._passfile_mtime = None self._synchronous_standby_names = None self._postmaster_ctime = None self._current_recovery_params = None self._config = {} self._recovery_params = {} self.reload_config(config)
def get_dcs(name, config): if 'etcd' in config: from patroni.etcd import Etcd return Etcd(name, config['etcd']) if 'zookeeper' in config: from patroni.zookeeper import ZooKeeper return ZooKeeper(name, config['zookeeper']) if 'consul' in config: from patroni.consul import Consul return Consul(name, config['consul']) raise PatroniException( 'Can not find suitable configuration of distributed configuration store' )
def inner(): if scope['times'] >= times: pass else: scope['times'] += 1 raise PatroniException('Failed!')