diff --git a/designate/backend/__init__.py b/designate/backend/__init__.py index c17feda2..d4338c4a 100644 --- a/designate/backend/__init__.py +++ b/designate/backend/__init__.py @@ -15,20 +15,20 @@ # under the License. from oslo_log import log as logging -from designate.backend.base import PoolBackend +from designate.backend.base import Backend LOG = logging.getLogger(__name__) def get_backend(backend_driver, backend_options): LOG.debug("Loading backend driver: %s" % backend_driver) - cls = PoolBackend.get_driver(backend_driver) + cls = Backend.get_driver(backend_driver) return cls(backend_options) def get_server_object(backend_driver, server_id): LOG.debug("Loading backend driver: %s" % backend_driver) - cls = PoolBackend.get_driver(backend_driver) + cls = Backend.get_driver(backend_driver) return cls.get_server_object(backend_driver, server_id) diff --git a/designate/backend/base.py b/designate/backend/base.py index c6d4e7f6..78764106 100644 --- a/designate/backend/base.py +++ b/designate/backend/base.py @@ -19,8 +19,7 @@ import copy from oslo.config import cfg from oslo_log import log as logging -from designate.i18n import _LW -from designate import exceptions +from designate.i18n import _LI from designate.context import DesignateContext from designate.plugin import DriverPlugin from designate import objects @@ -34,125 +33,20 @@ class Backend(DriverPlugin): __plugin_type__ = 'backend' __plugin_ns__ = 'designate.backend' - def __init__(self, central_service): + def __init__(self, backend_options): super(Backend, self).__init__() - self.central_service = central_service + self.backend_options = backend_options + self.admin_context = DesignateContext.get_admin_context() self.admin_context.all_tenants = True def start(self): - pass + LOG.info(_LI('Starting %s backend'), self.get_canonical_name()) def stop(self): - pass + LOG.info(_LI('Stopped %s backend'), self.get_canonical_name()) - def create_tsigkey(self, context, tsigkey): - """Create a TSIG Key""" - raise exceptions.NotImplemented( - 'TSIG is not supported by this backend') - - def update_tsigkey(self, context, tsigkey): - """Update a TSIG Key""" - raise exceptions.NotImplemented( - 'TSIG is not supported by this backend') - - def delete_tsigkey(self, context, tsigkey): - """Delete a TSIG Key""" - raise exceptions.NotImplemented( - 'TSIG is not supported by this backend') - - @abc.abstractmethod - def create_domain(self, context, domain): - """Create a DNS domain""" - - @abc.abstractmethod - def update_domain(self, context, domain): - """Update a DNS domain""" - - @abc.abstractmethod - def delete_domain(self, context, domain): - """Delete a DNS domain""" - - @abc.abstractmethod - def create_recordset(self, context, domain, recordset): - """Create a DNS recordset""" - - @abc.abstractmethod - def update_recordset(self, context, domain, recordset): - """Update a DNS recordset""" - - @abc.abstractmethod - def delete_recordset(self, context, domain, recordset): - """Delete a DNS recordset""" - - @abc.abstractmethod - def create_record(self, context, domain, recordset, record): - """Create a DNS record""" - - @abc.abstractmethod - def update_record(self, context, domain, recordset, record): - """Update a DNS record""" - - @abc.abstractmethod - def delete_record(self, context, domain, recordset, record): - """Delete a DNS record""" - - def sync_domain(self, context, domain, rdata): - """ - Re-Sync a DNS domain - - This is the default, naive, domain synchronization implementation. - """ - # First up, delete the domain from the backend. - try: - self.delete_domain(context, domain) - except exceptions.DomainNotFound as e: - # NOTE(Kiall): This means a domain was missing from the backend. - # Good thing we're doing a sync! - LOG.warn(_LW("Failed to delete domain '%(domain)s' during sync. " - "Message: %(message)s") % - {'domain': domain['id'], 'message': str(e)}) - - # Next, re-create the domain in the backend. - self.create_domain(context, domain) - - # Finally, re-create the records for the domain. - for recordset, records in rdata: - # Re-create the record in the backend. - self.create_recordset(context, domain, recordset) - for record in records: - self.create_record(context, domain, recordset, record) - - def sync_record(self, context, domain, recordset, record): - """ - Re-Sync a DNS record. - - This is the default, naive, record synchronization implementation. - """ - # First up, delete the record from the backend. - try: - self.delete_record(context, domain, recordset, record) - except exceptions.RecordNotFound as e: - # NOTE(Kiall): This means a record was missing from the backend. - # Good thing we're doing a sync! - LOG.warn(_LW("Failed to delete record '%(record)s' " - "in domain '%(domain)s' during sync. " - "Message: %(message)s") % - {'record': record['id'], 'domain': domain['id'], - 'message': str(e)}) - - # Finally, re-create the record in the backend. - self.create_record(context, domain, recordset, record) - - def ping(self, context): - """Ping the Backend service""" - - return { - 'status': None - } - - -class PoolBackend(Backend): + # Config Methods @classmethod def get_cfg_opts(cls): group = cfg.OptGroup( @@ -217,10 +111,15 @@ class PoolBackend(Backend): def _get_server_cfg_opts(cls): return [] - def __init__(self, backend_options): - super(PoolBackend, self).__init__(None) - self.backend_options = backend_options + def get_backend_option(self, key): + """ + Get the backend option value using the backend option key. + """ + for backend_option in self.backend_options: + if backend_option['key'] == key: + return backend_option['value'] + # Pool Mgr Object Creation @classmethod def _create_server_object(cls, backend, server_id, backend_options, server_section_name): @@ -286,23 +185,7 @@ class PoolBackend(Backend): return cls._create_server_object( backend, server_id, backend_options, server_section_name) - def get_backend_option(self, key): - """ - Get the backend option value using the backend option key. - """ - for backend_option in self.backend_options: - if backend_option['key'] == key: - return backend_option['value'] - - def create_tsigkey(self, context, tsigkey): - pass - - def update_tsigkey(self, context, tsigkey): - pass - - def delete_tsigkey(self, context, tsigkey): - pass - + # Core Backend Interface @abc.abstractmethod def create_domain(self, context, domain): """ @@ -324,29 +207,9 @@ class PoolBackend(Backend): :param domain: the DNS domain. """ - def create_recordset(self, context, domain, recordset): - pass - - def update_recordset(self, context, domain, recordset): - pass - - def delete_recordset(self, context, domain, recordset): - pass - - def create_record(self, context, domain, recordset, record): - pass - - def update_record(self, context, domain, recordset, record): - pass - - def delete_record(self, context, domain, recordset, record): - pass - - def sync_domain(self, context, domain, records): - pass - - def sync_record(self, context, domain, record): - pass - def ping(self, context): - pass + """Ping the Backend service""" + + return { + 'status': None + } diff --git a/designate/backend/impl_bind9.py b/designate/backend/impl_bind9.py index 3150205a..14d4d755 100644 --- a/designate/backend/impl_bind9.py +++ b/designate/backend/impl_bind9.py @@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__) DEFAULT_MASTER_PORT = 5354 -class Bind9Backend(base.PoolBackend): +class Bind9Backend(base.Backend): __plugin_name__ = 'bind9' @classmethod diff --git a/designate/backend/impl_fake.py b/designate/backend/impl_fake.py index 44ad5eb3..21709df7 100644 --- a/designate/backend/impl_fake.py +++ b/designate/backend/impl_fake.py @@ -22,7 +22,7 @@ from designate.backend import base LOG = logging.getLogger(__name__) -class FakeBackend(base.PoolBackend): +class FakeBackend(base.Backend): __plugin_name__ = 'fake' def create_domain(self, context, domain): diff --git a/designate/backend/impl_powerdns/__init__.py b/designate/backend/impl_powerdns/__init__.py index 6e98ea21..80c41223 100644 --- a/designate/backend/impl_powerdns/__init__.py +++ b/designate/backend/impl_powerdns/__init__.py @@ -34,7 +34,7 @@ def _map_col(keys, col): return dict([(keys[i], col[i]) for i in range(len(keys))]) -class PowerDNSBackend(base.PoolBackend): +class PowerDNSBackend(base.Backend): __plugin_name__ = 'powerdns' @classmethod