Andrew Bogott has uploaded a new change for review. https://gerrit.wikimedia.org/r/199926
Change subject: Initial totally untested project commit ...................................................................... Initial totally untested project commit Change-Id: I507d716d04a6f0ccb4a133f31fae765a8e92c282 --- A README A nova_fixed_multi/__init__.py A nova_fixed_multi/base.py A nova_fixed_multi/novamulti.py A setup.py 5 files changed, 224 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/sink_nova_fixed_multi refs/changes/26/199926/1 diff --git a/README b/README new file mode 100644 index 0000000..5f44f33 --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +I'm using 'stdeb' to build debian packages here. To build: + +$ sudo apt-get install python-stdeb +$ python setup.py --command-packages=stdeb.command bdist_deb +$ ls deb_dist/*.deb + +Note that due to file-system weirdness, stddeb errors out on labs +boxes. I'm running it on a VirtualBox VM without any trouble. diff --git a/nova_fixed_multi/__init__.py b/nova_fixed_multi/__init__.py new file mode 100644 index 0000000..711e39e --- /dev/null +++ b/nova_fixed_multi/__init__.py @@ -0,0 +1,18 @@ +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# 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. + +import gettext +import logging diff --git a/nova_fixed_multi/base.py b/nova_fixed_multi/base.py new file mode 100644 index 0000000..a6e5d9b --- /dev/null +++ b/nova_fixed_multi/base.py @@ -0,0 +1,85 @@ +# Copyright 2015 Andrew Bogott for the Wikimedia Foundation +# 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. + + +# This is a slight form of the designate source file found at +# designate/notification_handler/base.py + +import abc +from oslo.config import cfg +from designate import exceptions +from designate.openstack.common import log as logging +from designate.central import rpcapi as central_rpcapi +from designate.context import DesignateContext +from designate.plugin import ExtensionPlugin + +from designate.notification_handler.base import BaseAddressHandler + +LOG = logging.getLogger(__name__) + + +class BaseAddressMultiHandler(BaseAddressHandler): + def _create(self, addresses, extra, managed=True, + resource_type=None, resource_id=None): + """ + Create a a record from addresses + + :param addresses: Address objects like + {'version': 4, 'ip': '10.0.0.1'} + :param extra: Extra data to use when formatting the record + :param managed: Is it a managed resource + :param resource_type: The managed resource type + :param resource_id: The managed resource ID + """ + LOG.debug('Using DomainID: %s' % cfg.CONF[self.name].domain_id) + domain = self.get_domain(cfg.CONF[self.name].domain_id) + LOG.debug('Domain: %r' % domain) + + data = extra.copy() + LOG.debug('Event data: %s' % data) + data['domain'] = domain['name'] + + context = DesignateContext.get_admin_context(all_tenants=True) + + for addr in addresses: + event_data = data.copy() + event_data.update(get_ip_data(addr)) + + for fmt in cfg.CONF[self.name].get('format'): + recordset_values = { + 'domain_id': domain['id'], + 'name': fmt % event_data, + 'type': 'A' if addr['version'] == 4 else 'AAAA'} + + recordset = self._find_or_create_recordset( + context, **recordset_values) + + record_values = { + 'data': addr['address']} + + if managed: + record_values.update({ + 'managed': managed, + 'managed_plugin_name': self.get_plugin_name(), + 'managed_plugin_type': self.get_plugin_type(), + 'managed_resource_type': resource_type, + 'managed_resource_id': resource_id}) + + LOG.debug('Creating record in %s / %s with values %r', + domain['id'], recordset['id'], record_values) + central_api.create_record(context, + domain['id'], + recordset['id'], + record_values) diff --git a/nova_fixed_multi/novamulti.py b/nova_fixed_multi/novamulti.py new file mode 100644 index 0000000..f6d8cf2 --- /dev/null +++ b/nova_fixed_multi/novamulti.py @@ -0,0 +1,69 @@ +# Copyright 2015 Andrew Bogott for the Wikimedia Foundation +# 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. + + +# This file is a slight modification of the nova notification driver found +# in the designate source at designate/notification_handler/nova.py + +from oslo.config import cfg +from designate.openstack.common import log as logging +from sink_nova_fixed_multi.base import BaseAddressMultiHandler + +LOG = logging.getLogger(__name__) + +cfg.CONF.register_group(cfg.OptGroup( + name='handler:nova_fixed_multi', + title="Configuration for Nova Notification Handler" +)) + +cfg.CONF.register_opts([ + cfg.ListOpt('notification-topics', default=['monitor']), + cfg.StrOpt('control-exchange', default='nova'), + cfg.StrOpt('domain-id', default=None), + cfg.MultiStrOpt('format', default=None) +], group='handler:nova_fixed') + + +class NovaFixedHandler(BaseAddressHandler): + """ Handler for Nova's notifications """ + __plugin_name__ = 'nova_fixed' + + def get_exchange_topics(self): + exchange = cfg.CONF[self.name].control_exchange + + topics = [topic + ".info" + for topic in cfg.CONF[self.name].notification_topics] + + return (exchange, topics) + + def get_event_types(self): + return [ + 'compute.instance.create.end', + 'compute.instance.delete.start', + ] + + def process_notification(self, event_type, payload): + LOG.debug('NovaFixedHandler received notification - %s' % event_type) + + if event_type == 'compute.instance.create.end': + self._create(payload['fixed_ips'], payload, + resource_id=payload['instance_id'], + resource_type='instance') + + elif event_type == 'compute.instance.delete.start': + self._delete(resource_id=payload['instance_id'], + resource_type='instance') + else: + raise ValueError('NovaFixedHandler received an invalid event type') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7a1b363 --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +# Copyright 2015 Andrew Bogott for the Wikimedia Foundation +# 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. +import setuptools + +requirements = ["mwclient"] + +setuptools.setup( + name="nova_fixed_multi", + version="2015.1", + author="Wikimedia Foundation", + author_email="abog...@wikimedia.org", + description="Designate sink handler that supports multiple arecords per instance", + license="Apache License, Version 2.0", + url="https://gerrit.wikimedia.org/r/sink_nova_fixed_multi" + packages=setuptools.find_packages(exclude=['tests', 'tests.*']), + install_requires=requirements, + tests_require=["nose", "mock"], + test_suite="nose.collector", + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python" + ], + entry_points={ + "designate.notification.handler": ["nova_fixed_multi=sink_nova_fixed_multi.novamulti:NovaFixedMultiHandler"] + }, + py_modules=[] +) -- To view, visit https://gerrit.wikimedia.org/r/199926 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I507d716d04a6f0ccb4a133f31fae765a8e92c282 Gerrit-PatchSet: 1 Gerrit-Project: sink_nova_fixed_multi Gerrit-Branch: master Gerrit-Owner: Andrew Bogott <abog...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits