Merge "Make use of IP filtering when creating DNS records"

This commit is contained in:
Jenkins 2014-01-22 02:01:47 +00:00 committed by Gerrit Code Review
commit 62c3a203ba
4 changed files with 15 additions and 10 deletions

View File

@ -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/

View File

@ -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:

View File

@ -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):

View File

@ -564,8 +564,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})
@ -612,8 +614,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():