From 15a81095c53f613bc7ccad8ca7adffd076a8048f Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Sat, 28 Mar 2015 17:41:45 +0000 Subject: [PATCH] Add also-notifies support to Pool Manager Change-Id: I2bf72390fde1fc0296df684074260cfe5ff1d883 --- designate/objects/__init__.py | 1 + designate/objects/pool.py | 14 ++++++++++ designate/objects/pool_also_notifies.py | 28 +++++++++++++++++++ designate/pool_manager/__init__.py | 1 + designate/pool_manager/service.py | 17 +++++++++++ .../tests/test_pool_manager/test_service.py | 1 + etc/designate/designate.conf.sample | 1 + 7 files changed, 63 insertions(+) create mode 100644 designate/objects/pool_also_notifies.py diff --git a/designate/objects/__init__.py b/designate/objects/__init__.py index 79e6b0a5..6924d8e6 100644 --- a/designate/objects/__init__.py +++ b/designate/objects/__init__.py @@ -24,6 +24,7 @@ from designate.objects.domain_attribute import DomainAttribute, DomainAttributeL from designate.objects.floating_ip import FloatingIP, FloatingIPList # noqa from designate.objects.pool_manager_status import PoolManagerStatus, PoolManagerStatusList # noqa from designate.objects.pool import Pool, PoolList # noqa +from designate.objects.pool_also_notifies import PoolAlsoNotifies, PoolAlsoNotifiesList # noqa from designate.objects.pool_attribute import PoolAttribute, PoolAttributeList # noqa from designate.objects.pool_ns_record import PoolNsRecord, PoolNsRecordList # noqa from designate.objects.pool_nameserver import PoolNameserver, PoolNameserverList # noqa diff --git a/designate/objects/pool.py b/designate/objects/pool.py index 6b1fd161..010d4f1c 100644 --- a/designate/objects/pool.py +++ b/designate/objects/pool.py @@ -68,6 +68,10 @@ class Pool(base.DictObjectMixin, base.PersistentObjectMixin, 'relation': True, 'relation_cls': 'PoolTargetList' }, + 'also_notifies': { + 'relation': True, + 'relation_cls': 'PoolAlsoNotifiesList' + }, } @classmethod @@ -76,6 +80,7 @@ class Pool(base.DictObjectMixin, base.PersistentObjectMixin, pool_target_ids = CONF['pool:%s' % pool_id].targets pool_nameserver_ids = CONF['pool:%s' % pool_id].nameservers + pool_also_notifies = CONF['pool:%s' % pool_id].also_notifies # Build Base Pool pool = { @@ -83,8 +88,17 @@ class Pool(base.DictObjectMixin, base.PersistentObjectMixin, 'description': 'Pool built from configuration on %s' % CONF.host, 'targets': [], 'nameservers': [], + 'also_notifies': [], } + # Build Pool Also Notifies + for pool_also_notify in pool_also_notifies: + host, port = utils.split_host_port(pool_also_notify) + pool['also_notifies'].append({ + 'host': host, + 'port': port, + }) + # Build Pool Targets for pool_target_id in pool_target_ids: pool_target_group = 'pool_target:%s' % pool_target_id diff --git a/designate/objects/pool_also_notifies.py b/designate/objects/pool_also_notifies.py new file mode 100644 index 00000000..3f52d8d7 --- /dev/null +++ b/designate/objects/pool_also_notifies.py @@ -0,0 +1,28 @@ +# Copyright (c) 2014 Rackspace Hosting +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from designate.objects import base + + +class PoolAlsoNotifies(base.DictObjectMixin, base.PersistentObjectMixin, + base.DesignateObject): + FIELDS = { + 'pool_id': {}, + 'host': {}, + 'port': {}, + } + + +class PoolAlsoNotifiesList(base.ListObjectMixin, base.DesignateObject): + LIST_ITEM_TYPE = PoolAlsoNotifies diff --git a/designate/pool_manager/__init__.py b/designate/pool_manager/__init__.py index 5db7ff43..413b91a9 100644 --- a/designate/pool_manager/__init__.py +++ b/designate/pool_manager/__init__.py @@ -71,6 +71,7 @@ def register_dynamic_pool_options(): pool_opts = [ cfg.ListOpt('targets', default=[]), cfg.ListOpt('nameservers', default=[]), + cfg.ListOpt('also_notifies', default=[]), ] CONF.register_group(pool_group) diff --git a/designate/pool_manager/service.py b/designate/pool_manager/service.py index f727256e..db7d3945 100644 --- a/designate/pool_manager/service.py +++ b/designate/pool_manager/service.py @@ -251,6 +251,10 @@ class Service(service.RPCService, service.Service): return + # Send a NOTIFY to each also-notifies + for also_notify in self.pool.also_notifies: + self._update_domain_on_also_notify(context, also_notify, domain) + # Send a NOTIFY to each nameserver for nameserver in self.pool.nameservers: create_status = self._build_status_object( @@ -308,6 +312,10 @@ class Service(service.RPCService, service.Service): return + # Send a NOTIFY to each also-notifies + for also_notify in self.pool.also_notifies: + self._update_domain_on_also_notify(context, also_notify, domain) + # Send a NOTIFY to each nameserver for nameserver in self.pool.nameservers: # See if there is already another update in progress @@ -342,6 +350,15 @@ class Service(service.RPCService, service.Service): {'domain': domain.name, 'target': target.id}) return False + def _update_domain_on_also_notify(self, context, also_notify, domain): + LOG.info(_LI('Updating domain %(domain)s on also_notify %(server)s.') % + {'domain': domain.name, + 'server': self._get_destination(also_notify)}) + + self.mdns_api.notify_zone_changed( + context, domain, also_notify, self.timeout, self.retry_interval, + self.max_retries, 0) + def _update_domain_on_nameserver(self, context, nameserver, domain): LOG.info(_LI('Updating domain %(domain)s on nameserver %(server)s.') % {'domain': domain.name, diff --git a/designate/tests/test_pool_manager/test_service.py b/designate/tests/test_pool_manager/test_service.py index 01ca0dec..d0feadc5 100644 --- a/designate/tests/test_pool_manager/test_service.py +++ b/designate/tests/test_pool_manager/test_service.py @@ -55,6 +55,7 @@ class PoolManagerServiceNoopTest(PoolManagerTestCase): 'c5d64303-4cba-425a-9f3c-5d708584dde4', 'c67cdc95-9a9e-4d2a-98ed-dc78cbd85234', ]), + cfg.ListOpt('also_notifies', default=[]), ] cfg.CONF.register_group(cfg.OptGroup(name=section_name)) cfg.CONF.register_opts(section_opts, group=section_name) diff --git a/etc/designate/designate.conf.sample b/etc/designate/designate.conf.sample index dae2bc72..43541cb1 100644 --- a/etc/designate/designate.conf.sample +++ b/etc/designate/designate.conf.sample @@ -252,6 +252,7 @@ debug = False #[pool:794ccc2c-d751-44fe-b57f-8894c9f5c842] #nameservers = 0f66b842-96c2-4189-93fc-1dc95a08b012 #targets = f26e0b32-736f-4f0a-831b-039a415c481e +#also_notifies = 192.0.2.1:53, 192.0.2.2:53 #[pool_nameserver:0f66b842-96c2-4189-93fc-1dc95a08b012] #port = 53