Skip to content
Snippets Groups Projects
Commit 76c114ab authored by Erik Reid's avatar Erik Reid
Browse files

derive next id, if none specified

parent 33270080
No related branches found
No related tags found
No related merge requests found
......@@ -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"]
}
],
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment