1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

enum for status flag of pool values

This commit is contained in:
Viranch Mehta
2021-09-21 01:54:55 -07:00
parent e737161c76
commit 43e02c916c
6 changed files with 24 additions and 23 deletions

View File

@@ -457,7 +457,7 @@ class AzureProvider(BaseProvider):
'''
SUPPORTS_GEO = False
SUPPORTS_DYNAMIC = True
SUPPORTS_POOL_VALUE_UP = True
SUPPORTS_POOL_VALUE_STATUS = True
SUPPORTS_MULTIVALUE_PTR = True
SUPPORTS = set(('A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NS', 'PTR', 'SRV',
'TXT'))
@@ -808,14 +808,14 @@ class AzureProvider(BaseProvider):
defaults.add(val)
ep_name = ep_name[:-len('--default--')]
up = None
status = 'obey'
if pool_ep.endpoint_status == 'Disabled':
up = False
status = 'down'
values.append({
'value': val,
'weight': pool_ep.weight or 1,
'up': up,
'status': status,
})
return values
@@ -905,7 +905,7 @@ class AzureProvider(BaseProvider):
return data
def _process_desired_zone(self, desired):
# check for support of force up/down values
# check for status=up values
for record in desired.records:
if not getattr(record, 'dynamic', False):
continue
@@ -913,14 +913,14 @@ class AzureProvider(BaseProvider):
up_pools = []
for name, pool in record.dynamic.pools.items():
for value in pool.data['values']:
if value['up']:
# Azure only supports up=None & up=False, not up=True
if value['status'] == 'up':
# Azure only supports obey and down, not up
up_pools.append(name)
if not up_pools:
continue
up_pools = ','.join(up_pools)
msg = f'up=True is not supported for pools {up_pools} in ' \
msg = f'status=up is not supported for pools {up_pools} in ' \
f'{record.fqdn}'
fallback = 'will ignore it and respect the healthcheck'
self.supports_warn_or_except(msg, fallback)
@@ -928,8 +928,8 @@ class AzureProvider(BaseProvider):
record = record.copy()
for pool in record.dynamic.pools.values():
for value in pool.data['values']:
if value['up']:
value['up'] = None
if value['status'] == 'up':
value['status'] = 'obey'
desired.add_record(record, replace=True)
return super()._process_desired_zone(desired)
@@ -1075,7 +1075,7 @@ class AzureProvider(BaseProvider):
# mark default
ep_name += '--default--'
default_seen = True
ep_status = 'Disabled' if val['up'] is False else \
ep_status = 'Disabled' if val['status'] == 'down' else \
'Enabled'
endpoints.append(Endpoint(
name=ep_name,

View File

@@ -59,13 +59,13 @@ class BaseProvider(BaseSource):
desired.remove_record(record)
elif getattr(record, 'dynamic', False):
if self.SUPPORTS_DYNAMIC:
if self.SUPPORTS_POOL_VALUE_UP:
if self.SUPPORTS_POOL_VALUE_STATUS:
continue
# drop unsupported up flag
unsupported_pools = []
for _id, pool in record.dynamic.pools.items():
for value in pool.data['values']:
if isinstance(value['up'], bool):
if value['status'] != 'obey':
unsupported_pools.append(_id)
if not unsupported_pools:
continue
@@ -77,7 +77,7 @@ class BaseProvider(BaseSource):
record = record.copy()
for pool in record.dynamic.pools.values():
for value in pool.data['values']:
value['up'] = None
value['status'] = 'obey'
desired.add_record(record, replace=True)
else:
msg = f'dynamic records not supported for {record.fqdn}'

View File

@@ -306,7 +306,7 @@ class Ns1Provider(BaseProvider):
'''
SUPPORTS_GEO = True
SUPPORTS_DYNAMIC = True
SUPPORTS_POOL_VALUE_UP = True
SUPPORTS_POOL_VALUE_STATUS = True
SUPPORTS_MULTIVALUE_PTR = True
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'NAPTR',
'NS', 'PTR', 'SPF', 'SRV', 'TXT', 'URLFWD'))
@@ -593,7 +593,7 @@ class Ns1Provider(BaseProvider):
'weight': int(meta.get('weight', 1)),
}
if isinstance(meta['up'], bool):
value_dict['up'] = meta['up']
value_dict['status'] = 'up' if meta['up'] else 'down'
if value_dict not in pool['values']:
# If we haven't seen this value before add it to the pool
@@ -1148,7 +1148,7 @@ class Ns1Provider(BaseProvider):
if answer['feed_id']:
up = {'feed': answer['feed_id']}
else:
up = answer['up']
up = answer['status'] == 'up'
answer = {
'answer': answer['answer'],
'meta': {
@@ -1279,10 +1279,11 @@ class Ns1Provider(BaseProvider):
for pool_name, pool in sorted(pools.items()):
for value in pool.data['values']:
weight = value['weight']
up = value['up']
status = value['status']
value = value['value']
feed_id = None
if up is None:
if status == 'obey':
# state is not forced, let's find a monitor
feed_id = value_feed.get(value)
# check for identical monitor and skip creating one if
@@ -1298,7 +1299,7 @@ class Ns1Provider(BaseProvider):
'answer': [value],
'weight': weight,
'feed_id': feed_id,
'up': up,
'status': status,
})
if record._type == 'CNAME':

View File

@@ -104,7 +104,7 @@ class YamlProvider(BaseProvider):
'''
SUPPORTS_GEO = True
SUPPORTS_DYNAMIC = True
SUPPORTS_POOL_VALUE_UP = True
SUPPORTS_POOL_VALUE_STATUS = True
SUPPORTS_MULTIVALUE_PTR = True
SUPPORTS = set(('A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'DNAME', 'LOC', 'MX',
'NAPTR', 'NS', 'PTR', 'SSHFP', 'SPF', 'SRV', 'TXT',

View File

@@ -418,7 +418,7 @@ class _DynamicPool(object):
{
'value': d['value'],
'weight': d.get('weight', 1),
'up': d.get('up'), # TODO: add validation on this field
'status': d.get('status', 'obey'), # TODO: add validation on this field
} for d in data['values']
]
values.sort(key=lambda d: d['value'])

View File

@@ -9,7 +9,7 @@ from __future__ import absolute_import, division, print_function, \
class BaseSource(object):
SUPPORTS_MULTIVALUE_PTR = False
SUPPORTS_POOL_VALUE_UP = False
SUPPORTS_POOL_VALUE_STATUS = False
def __init__(self, id):
self.id = id