|
|
|
@ -227,6 +227,13 @@ class Ns1Provider(BaseProvider): |
|
|
|
'NA': ('US-CENTRAL', 'US-EAST', 'US-WEST'), |
|
|
|
} |
|
|
|
|
|
|
|
# Necessary for handling unsupported continents in _CONTINENT_TO_REGIONS |
|
|
|
_CONTINENT_TO_LIST_OF_COUNTRIES = { |
|
|
|
'OC': {'FJ', 'NC', 'PG', 'SB', 'VU', 'AU', 'NF', 'NZ', 'FM', 'GU', |
|
|
|
'KI', 'MH', 'MP', 'NR', 'PW', 'AS', 'CK', 'NU', 'PF', 'PN', |
|
|
|
'TK', 'TO', 'TV', 'WF', 'WS'}, |
|
|
|
} |
|
|
|
|
|
|
|
def __init__(self, id, api_key, retry_count=4, monitor_regions=None, *args, |
|
|
|
**kwargs): |
|
|
|
self.log = getLogger('Ns1Provider[{}]'.format(id)) |
|
|
|
@ -351,11 +358,37 @@ class Ns1Provider(BaseProvider): |
|
|
|
for georegion in meta.get('georegion', []): |
|
|
|
geos.add(self._REGION_TO_CONTINENT[georegion]) |
|
|
|
|
|
|
|
# Countries are easy enough to map, we just have ot find their |
|
|
|
# Countries are easy enough to map, we just have to find their |
|
|
|
# continent |
|
|
|
# |
|
|
|
# NOTE: Special handling for Oceania |
|
|
|
# NS1 doesn't support Oceania as a region. So the Oceania countries |
|
|
|
# will be present in meta['country']. If all the countries in the |
|
|
|
# Oceania countries list are found, set the region to OC and remove |
|
|
|
# individual oceania country entries |
|
|
|
|
|
|
|
oc_countries = set() |
|
|
|
for country in meta.get('country', []): |
|
|
|
con = country_alpha2_to_continent_code(country) |
|
|
|
geos.add('{}-{}'.format(con, country)) |
|
|
|
# country_alpha2_to_continent_code fails for Pitcairn ('PN') |
|
|
|
if country == 'PN': |
|
|
|
con = 'OC' |
|
|
|
else: |
|
|
|
con = country_alpha2_to_continent_code(country) |
|
|
|
|
|
|
|
if con == 'OC': |
|
|
|
oc_countries.add(country) |
|
|
|
else: |
|
|
|
# Adding only non-OC countries here to geos |
|
|
|
geos.add('{}-{}'.format(con, country)) |
|
|
|
|
|
|
|
if oc_countries: |
|
|
|
if oc_countries == self._CONTINENT_TO_LIST_OF_COUNTRIES['OC']: |
|
|
|
# All OC countries found, so add 'OC' to geos |
|
|
|
geos.add('OC') |
|
|
|
else: |
|
|
|
# Partial OC countries found, just add them as-is to geos |
|
|
|
for c in oc_countries: |
|
|
|
geos.add('{}-{}'.format('OC', c)) |
|
|
|
|
|
|
|
# States are easy too, just assume NA-US (CA providences aren't |
|
|
|
# supported by octoDNS currently) |
|
|
|
@ -782,7 +815,15 @@ class Ns1Provider(BaseProvider): |
|
|
|
country.add(geo[-2:]) |
|
|
|
else: |
|
|
|
# Continent, e.g. AS |
|
|
|
georegion.update(self._CONTINENT_TO_REGIONS[geo]) |
|
|
|
if geo in self._CONTINENT_TO_REGIONS: |
|
|
|
georegion.update(self._CONTINENT_TO_REGIONS[geo]) |
|
|
|
else: |
|
|
|
# No maps for geo in _CONTINENT_TO_REGIONS. |
|
|
|
# Use the country list |
|
|
|
self.log.debug('Converting geo {} to country list'. |
|
|
|
format(geo)) |
|
|
|
for c in self._CONTINENT_TO_LIST_OF_COUNTRIES[geo]: |
|
|
|
country.add(c) |
|
|
|
|
|
|
|
meta = { |
|
|
|
'note': self._encode_notes(notes), |
|
|
|
|