Merge lp:~niedbalski/ubuntu/precise/serverstack-dns/add-current-instances into lp:~openstack-charmers/ubuntu/precise/serverstack-dns/trunk

Proposed by Jorge Niedbalski on 2015-11-18
Status: Merged
Merged at revision: 14
Proposed branch: lp:~niedbalski/ubuntu/precise/serverstack-dns/add-current-instances
Merge into: lp:~openstack-charmers/ubuntu/precise/serverstack-dns/trunk
Diff against target: 73 lines (+25/-0)
2 files modified
dns.conf (+2/-0)
serverstack-tenant-dns (+23/-0)
To merge this branch: bzr merge lp:~niedbalski/ubuntu/precise/serverstack-dns/add-current-instances
Reviewer Review Type Date Requested Status
Liam Young 2015-11-18 Approve on 2015-12-01
Review via email: mp+277836@code.launchpad.net

Description of the change

Dear Maintainer:

- This patch adds the ability to populate the dnsmasq
file with the instances for the current tenant.
- It modifies the configuration to add a new entry called
'add_current_instances' which defaults to False.
- It modifies the logic for adding entries based on the
current tenant available instances and adds them to the
dnsmasq host file.

To post a comment you must log in.
15. By Jorge Niedbalski on 2015-11-18

Defaults to false, non invasive change

Liam Young (gnuoy) wrote :

thanks for the feature! approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dns.conf'
2--- dns.conf 2014-02-19 16:24:28 +0000
3+++ dns.conf 2015-11-18 14:31:30 +0000
4@@ -6,6 +6,8 @@
5 hosts_file = /etc/serverstack-dns/tenant_hosts
6 # domain name associated with tenant network
7 domain = openstacklocal
8+#add current tenant instances to the hosts
9+add_current_instances=False
10
11 # connection info for serverstack's rabbit server. these settings
12 # should match neutron's
13
14=== modified file 'serverstack-tenant-dns'
15--- serverstack-tenant-dns 2014-03-01 14:37:41 +0000
16+++ serverstack-tenant-dns 2015-11-18 14:31:30 +0000
17@@ -36,6 +36,7 @@
18 'rabbit_host': _get('rabbit_host'),
19 'rabbit_vhost': _get('rabbit_vhost'),
20 'rabbit_exchange': _get('rabbit_exchange'),
21+ 'add_current_instances': _get('add_current_instances'),
22 'rabbit_topic': _get('rabbit_topic'),
23 'include_tenants': _get('include_tenants'),
24 'hosts_file': _get('hosts_file'),
25@@ -68,6 +69,7 @@
26
27 with open(config['hosts_file']) as hosts:
28 hostnames = hosts.readlines()
29+
30 hostnames = [host.strip() for host in hostnames
31 if not host.startswith('#')]
32
33@@ -127,6 +129,21 @@
34 instance_id)
35
36
37+def get_current_instances():
38+ client = get_nova_client()
39+ tenant_name = config['os_tenant_name']
40+
41+ for instance in client.servers.list():
42+ networks = instance.networks.get('%s_admin_net' % tenant_name, None)
43+ if networks:
44+ yield get_instance_hostname(instance.id), networks[0]
45+
46+
47+def add_current_instances():
48+ for hostname, ip_addr in get_current_instances():
49+ add_host_entry(hostname, ip_addr, "")
50+
51+
52 def manage_dns(body, message):
53 tenant_ids = [body['_context_tenant_id']]
54 try:
55@@ -206,6 +223,7 @@
56 cmd = ['kill', '-HUP', pid]
57 check_call(cmd)
58 return
59+
60 logging.info('Starting new dnsmasq: %s' % ' '.join(cmd))
61 check_call(cmd)
62
63@@ -214,5 +232,10 @@
64 if not os.path.isfile(config['hosts_file']):
65 with open(config['hosts_file'], 'wb'):
66 pass
67+
68+ add_current = config.get('add_current_instances', False)
69+ if add_current:
70+ add_current_instances()
71+
72 ensure_dnsmasq()
73 listen()

Subscribers

People subscribed via source and target branches

to status/vote changes: