From ad6e39bac5c31da3a0bc5003866505e4ae9da14c Mon Sep 17 00:00:00 2001 From: Steve Leon Date: Wed, 11 Dec 2013 14:32:40 -0800 Subject: [PATCH] Make use of IP filtering when creating DNS records Previously, the return list from get_ip_address in trove.instance.views was not filtering by the CONF.ip_regex. (See blueprint add-ip-addr-filter-to-instance-view for more information). DNS uses this method to get the IP. Therefore it was not creating record with the right IP. Moving the filtering logic to the get_ip_address method will ensure that both DNS and instance view will obtain the right IP. Change-Id: I4ce7c65e24f6d105f555e6c36d788558daa25f12 Closes-Bug: #1260089 --- etc/trove/trove-taskmanager.conf.sample | 4 ++++ trove/dns/manager.py | 2 +- trove/instance/views.py | 9 ++++----- trove/taskmanager/models.py | 10 ++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/etc/trove/trove-taskmanager.conf.sample b/etc/trove/trove-taskmanager.conf.sample index 92445767ae..300106100d 100644 --- a/etc/trove/trove-taskmanager.conf.sample +++ b/etc/trove/trove-taskmanager.conf.sample @@ -88,6 +88,10 @@ agent_call_high_timeout = 150 # Whether to use nova's contrib api for create server with volume use_nova_server_volume = False +# Config option for filtering the IP address that DNS uses +network_label_regex = ^private$ +#ip_regex = ^(15.|123.) + # Datastore templates template_path = /etc/trove/templates/ diff --git a/trove/dns/manager.py b/trove/dns/manager.py index 6e6a791803..75aa1fa421 100644 --- a/trove/dns/manager.py +++ b/trove/dns/manager.py @@ -52,7 +52,7 @@ class DnsManager(object): """ entry = self.entry_factory.create_entry(instance_id) if entry: - entry.content = content[0] + entry.content = content LOG.debug("Creating entry address %s." % str(entry)) self.driver.create_entry(entry) else: diff --git a/trove/instance/views.py b/trove/instance/views.py index 2786929f5a..1d633a9bab 100644 --- a/trove/instance/views.py +++ b/trove/instance/views.py @@ -34,6 +34,9 @@ def get_ip_address(addresses): if (re.search(CONF.network_label_regex, label) and len(addresses[label]) > 0): IPs.extend([addr.get('addr') for addr in addresses[label]]) + # Includes ip addresses that match the regexp pattern + if CONF.ip_regex: + IPs = filter_ips(IPs, CONF.ip_regex) return IPs @@ -99,11 +102,7 @@ class InstanceDetailView(InstanceView): if CONF.add_addresses: ip = get_ip_address(self.instance.addresses) if ip is not None and len(ip) > 0: - # Includes ip addresses that match the regexp pattern - if CONF.ip_regex: - ip = filter_ips(ip, CONF.ip_regex) - if len(ip) > 0: - result['instance']['ip'] = ip + result['instance']['ip'] = ip if (isinstance(self.instance, models.DetailInstance) and self.instance.volume_used): diff --git a/trove/taskmanager/models.py b/trove/taskmanager/models.py index 9b353e87f6..192f592b0a 100644 --- a/trove/taskmanager/models.py +++ b/trove/taskmanager/models.py @@ -559,8 +559,10 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): server = self.nova_client.servers.get( self.db_info.compute_instance_id) LOG.info(_("Creating dns entry...")) - dns_client.create_instance_entry(self.id, - get_ip_address(server.addresses)) + ip = get_ip_address(server.addresses) + if not ip: + raise TroveError('Error creating DNS. No IP available.') + dns_client.create_instance_entry(self.id, ip.pop) else: LOG.debug(_("%(gt)s: DNS not enabled for instance: %(id)s") % {'gt': greenthread.getcurrent(), 'id': self.id}) @@ -615,8 +617,8 @@ class BuiltInstanceTasks(BuiltInstance, NotifyMixin, ConfigurationMixin): dns_api = create_dns_client(self.context) dns_api.delete_instance_entry(instance_id=self.db_info.id) except Exception as ex: - LOG.exception(_("Error during dns entry of instance %(id)s: %(ex)") - % {'id': self.db_info.id, 'ex': ex}) + LOG.exception(_("Error during dns entry of instance %(id)s: " + "%(ex)s") % {'id': self.db_info.id, 'ex': ex}) # Poll until the server is gone. def server_is_finished():