diff --git a/inventory_provider/config.py b/inventory_provider/config.py index 46c63f8ab268bf89103913562764d1dd553c5a06..9162ab9b29191ba1cc78c6f971a7f939b1bce4bb 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -37,14 +37,9 @@ CONFIG_SCHEMA = { "type": "object", "properties": { "hostname": {"type": "string"}, - "port": {"type": "integer"}, - "databases": { - "type": "array", - "minItems": 1, - "items": {"type": "integer"} - } + "port": {"type": "integer"} }, - "required": ["hostname", "port", "databases"], + "required": ["hostname", "port"], "additionalProperties": False }, "sentinel": { @@ -52,16 +47,16 @@ CONFIG_SCHEMA = { "properties": { "hostname": {"type": "string"}, "port": {"type": "integer"}, - "name": {"type": "string"}, - "databases": { - "type": "array", - "minItems": 1, - "items": {"type": "integer"} - } + "name": {"type": "string"} }, - "required": ["hostname", "port", "name", "databases"], + "required": ["hostname", "port", "name"], "additionalProperties": False }, + "redis-databases": { + "type": "array", + "minItems": 1, + "items": {"type": "integer"} + }, "junosspace": { "api": {"type": "string"}, "username": {"type": "string"}, @@ -74,6 +69,7 @@ CONFIG_SCHEMA = { "ops-db", "ssh", "redis", + "redis-databases", "junosspace"] }, { @@ -81,6 +77,7 @@ CONFIG_SCHEMA = { "ops-db", "ssh", "sentinel", + "redis-databases", "junosspace"] } ], diff --git a/inventory_provider/tasks/common.py b/inventory_provider/tasks/common.py index 4f32d0e2eecf3d52a4f3f8d32e7ed8576f73b07b..5b6b7c7a729e8fc7ae8993118018a7702ba2528a 100644 --- a/inventory_provider/tasks/common.py +++ b/inventory_provider/tasks/common.py @@ -37,15 +37,11 @@ def get_latch(r): def _get_redis(config, dbid=None): - if 'sentinel' in config: - _params = config['sentinel'] - else: - _params = config['redis'] - if dbid is None: - dbid = min(_params['databases']) + logger.debug('no db specified, using minimum as first guess') + dbid = min(config['redis-databases']) - assert dbid in _params['databases'] + assert dbid in config['redis-databases'] kwargs = { 'db': dbid, @@ -82,10 +78,14 @@ def get_current_redis(config): def get_next_redis(config): r = _get_redis(config) latch = get_latch(r) - if not latch: - logger.warning("can't determine next db") - return r - if latch['this'] == latch['next']: + if latch and latch['this'] == latch['next']: return r + + if latch: + next_id = latch['next'] else: - return _get_redis(config, latch['current']) + logger.warning("next db not configured, deriving default value") + db_ids = sorted(set(config['redis-databases'])) + next_id = db_ids[0] if len(db_ids) == 1 else db_ids[1] + + return _get_redis(config, next_id)