Added central backend changes and rpc plugin. Added write_database flag to mysqlbind agent.

Change-Id: I6097536958648128372a54facb0f73e0e53b3673
This commit is contained in:
Patrick Galbraith 2012-12-02 15:17:53 +00:00
parent 52c7dd4fb3
commit ac596c2e0d
5 changed files with 77 additions and 21 deletions

View File

@ -26,5 +26,6 @@ cfg.CONF.register_opts([
def get_backend(conf): def get_backend(conf):
LOG.debug("backend_driver: %s" % cfg.CONF.backend_driver)
return Plugin.get_plugin(cfg.CONF.backend_driver, ns=__name__, return Plugin.get_plugin(cfg.CONF.backend_driver, ns=__name__,
conf=conf, invoke_on_load=True) conf=conf, invoke_on_load=True)

View File

@ -43,7 +43,12 @@ class MySQLBind9Backend(base.Backend):
cfg.StrOpt('rndc-config-file', cfg.StrOpt('rndc-config-file',
default=None, help='RNDC Config File'), default=None, help='RNDC Config File'),
cfg.StrOpt('rndc-key-file', default=None, help='RNDC Key File'), cfg.StrOpt('rndc-key-file', default=None, help='RNDC Key File'),
cfg.StrOpt('database-connection', default=None, cfg.StrOpt('dns-server-type', default='master',
help='slave or master DNS server?'),
cfg.BoolOpt('write-database', default=True,
help='Write to the DNS mysqlbind database?'),
cfg.StrOpt('database-connection',
default=cfg.CONF.database_connection,
help='SQL Connection'), help='SQL Connection'),
cfg.StrOpt('database-dns-table', cfg.StrOpt('database-dns-table',
default='dns_domains', default='dns_domains',
@ -67,9 +72,8 @@ class MySQLBind9Backend(base.Backend):
def start(self): def start(self):
super(MySQLBind9Backend, self).start() super(MySQLBind9Backend, self).start()
LOG.debug("DB_CONN %s" % cfg.CONF[self.name].database_connection) if cfg.CONF[self.name].write_database:
self._db = SqlSoup(cfg.CONF[self.name].database_connection)
self._db = SqlSoup(cfg.CONF[self.name].database_connection)
self._sync_domains() self._sync_domains()
@ -230,33 +234,39 @@ class MySQLBind9Backend(base.Backend):
def create_domain(self, context, domain): def create_domain(self, context, domain):
LOG.debug('create_domain()') LOG.debug('create_domain()')
self._add_soa_record(domain) if cfg.CONF[self.name].write_database:
self._add_ns_records(domain) self._add_soa_record(domain)
self._add_ns_records(domain)
self._sync_domains() self._sync_domains()
def update_domain(self, context, domain): def update_domain(self, context, domain):
LOG.debug('update_domain()') LOG.debug('update_domain()')
self._update_soa_record(domain) if cfg.CONF[self.name].write_database:
self._update_ns_records(domain) self._update_soa_record(domain)
self._update_ns_records(domain)
def delete_domain(self, context, domain): def delete_domain(self, context, domain):
LOG.debug('delete_domain()') LOG.debug('delete_domain()')
self._delete_db_domain_records(domain['id']) if cfg.CONF[self.name].write_database:
self._delete_db_domain_records(domain['id'])
self._sync_domains() self._sync_domains()
def create_record(self, context, domain, record): def create_record(self, context, domain, record):
LOG.debug('create_record()') LOG.debug('create_record()')
self._insert_db_record(domain['id'], record) if cfg.CONF[self.name].write_database:
self._insert_db_record(domain['id'], record)
def update_record(self, context, domain, record): def update_record(self, context, domain, record):
LOG.debug('update_record()') LOG.debug('update_record()')
self._update_db_record(record) if cfg.CONF[self.name].write_database:
self._update_db_record(record)
def delete_record(self, context, domain, record): def delete_record(self, context, domain, record):
LOG.debug('Delete Record') LOG.debug('Delete Record')
self._delete_db_record(record) if cfg.CONF[self.name].write_database:
self._delete_db_record(record)
def _sync_domains(self): def _sync_domains(self):
""" """
@ -292,6 +302,8 @@ class MySQLBind9Backend(base.Backend):
output_path, output_path,
domains=domains, domains=domains,
state_path=abs_state_path, state_path=abs_state_path,
dns_server_type=cfg.CONF[self.name].
dns_server_type,
dns_db_schema=url['database'], dns_db_schema=url['database'],
dns_db_table=cfg.CONF[self.name]. dns_db_table=cfg.CONF[self.name].
database_dns_table, database_dns_table,

View File

@ -0,0 +1,37 @@
# Copyright 2012 Managed I.T.
#
# Author: Kiall Mac Innes <kiall@managedit.ie>
#
# 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 moniker.backend import base
from moniker.agent import api as agent_api
class RPCBackend(base.Backend):
def create_domain(self, *args, **kw):
return agent_api.create_domain(*args, **kw)
def update_domain(self, *args, **kw):
return agent_api.update_domain(*args, **kw)
def delete_domain(self, *args, **kw):
return agent_api.delete_domain(*args, **kw)
def create_record(self, *args, **kw):
return agent_api.create_record(*args, **kw)
def update_record(self, *args, **kw):
return agent_api.update_record(*args, **kw)
def delete_record(self, *args, **kw):
return agent_api.delete_record(*args, **kw)

View File

@ -18,10 +18,10 @@ from moniker.openstack.common import log as logging
from moniker.openstack.common import rpc from moniker.openstack.common import rpc
from moniker.openstack.common.rpc import service as rpc_service from moniker.openstack.common.rpc import service as rpc_service
from stevedore.named import NamedExtensionManager from stevedore.named import NamedExtensionManager
from moniker import policy
from moniker import storage from moniker import storage
from moniker import utils from moniker import utils
from moniker import policy from moniker import backend
from moniker.agent import api as agent_api
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -35,9 +35,12 @@ cfg.CONF.register_opts([
class Service(rpc_service.Service): class Service(rpc_service.Service):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.backend = backend.get_backend(cfg.CONF)
kwargs.update( kwargs.update(
host=cfg.CONF.host, host=cfg.CONF.host,
topic=cfg.CONF.central_topic topic=cfg.CONF.central_topic,
) )
policy.init_policy() policy.init_policy()
@ -71,6 +74,7 @@ class Service(rpc_service.Service):
return [] return []
def start(self): def start(self):
self.backend.start()
super(Service, self).start() super(Service, self).start()
if self.handlers: if self.handlers:
@ -88,6 +92,7 @@ class Service(rpc_service.Service):
pass pass
super(Service, self).stop() super(Service, self).stop()
self.backend.stop()
def _setup_subscriptions(self): def _setup_subscriptions(self):
""" """
@ -187,7 +192,7 @@ class Service(rpc_service.Service):
domain = self.storage_conn.create_domain(context, values) domain = self.storage_conn.create_domain(context, values)
agent_api.create_domain(context, domain) self.backend.create_domain(context, domain)
utils.notify(context, 'api', 'domain.create', domain) utils.notify(context, 'api', 'domain.create', domain)
return domain return domain
@ -219,7 +224,7 @@ class Service(rpc_service.Service):
domain = self.storage_conn.update_domain(context, domain_id, values) domain = self.storage_conn.update_domain(context, domain_id, values)
agent_api.update_domain(context, domain) self.backend.update_domain(context, domain)
utils.notify(context, 'api', 'domain.update', domain) utils.notify(context, 'api', 'domain.update', domain)
return domain return domain
@ -230,7 +235,7 @@ class Service(rpc_service.Service):
target = {'domain_id': domain_id, 'tenant_id': domain['tenant_id']} target = {'domain_id': domain_id, 'tenant_id': domain['tenant_id']}
policy.check('delete_domain', context, target) policy.check('delete_domain', context, target)
agent_api.delete_domain(context, domain) self.backend.delete_domain(context, domain)
utils.notify(context, 'api', 'domain.delete', domain) utils.notify(context, 'api', 'domain.delete', domain)
return self.storage_conn.delete_domain(context, domain_id) return self.storage_conn.delete_domain(context, domain_id)
@ -244,7 +249,7 @@ class Service(rpc_service.Service):
record = self.storage_conn.create_record(context, domain_id, values) record = self.storage_conn.create_record(context, domain_id, values)
agent_api.create_record(context, domain, record) self.backend.create_record(context, domain, record)
utils.notify(context, 'api', 'record.create', record) utils.notify(context, 'api', 'record.create', record)
return record return record
@ -277,7 +282,7 @@ class Service(rpc_service.Service):
record = self.storage_conn.update_record(context, record_id, values) record = self.storage_conn.update_record(context, record_id, values)
agent_api.update_record(context, domain, record) self.backend.update_record(context, domain, record)
utils.notify(context, 'api', 'record.update', record) utils.notify(context, 'api', 'record.update', record)
return record return record
@ -294,7 +299,7 @@ class Service(rpc_service.Service):
record = self.storage_conn.get_record(context, record_id) record = self.storage_conn.get_record(context, record_id)
agent_api.delete_record(context, domain, record) self.backend.delete_record(context, domain, record)
utils.notify(context, 'api', 'record.delete', record) utils.notify(context, 'api', 'record.delete', record)
return self.storage_conn.delete_record(context, record_id) return self.storage_conn.delete_record(context, record_id)

View File

@ -69,6 +69,7 @@ setup(
[moniker.backend] [moniker.backend]
bind9 = moniker.backend.impl_bind9:Bind9Backend bind9 = moniker.backend.impl_bind9:Bind9Backend
mysqlbind9 = moniker.backend.impl_mysqlbind9:MySQLBind9Backend mysqlbind9 = moniker.backend.impl_mysqlbind9:MySQLBind9Backend
rpc = moniker.backend.impl_rpc:RPCBackend
fake = moniker.backend.impl_fake:FakeBackend fake = moniker.backend.impl_fake:FakeBackend
[moniker.manage] [moniker.manage]