Merge lp:~thomnico/charms/precise/dns/openstack-support into lp:~lazypower/charms/precise/dns/trunk

Proposed by Nicolas Thomas
Status: Merged
Merged at revision: 9
Proposed branch: lp:~thomnico/charms/precise/dns/openstack-support
Merge into: lp:~lazypower/charms/precise/dns/trunk
Diff against target: 208 lines (+111/-9)
9 files modified
contrib/bind/provider.py (+5/-3)
contrib/bind/templates/named.conf.options.jinja2 (+22/-0)
hooks/dns-client-relation-changed (+55/-0)
hooks/install (+16/-0)
hooks/programmable-relation-changed (+2/-2)
hooks/programmable-relation-departed (+3/-3)
lib/common.py (+5/-1)
metadata.yaml (+2/-0)
requirements.txt (+1/-0)
To merge this branch: bzr merge lp:~thomnico/charms/precise/dns/openstack-support
Reviewer Review Type Date Requested Status
Charles Butler Pending
Review via email: mp+233715@code.launchpad.net

Description of the change

Fix that enable non EC2 environment (OpenStack/MAAS) to work with clearwater project.

To post a comment you must log in.
10. By Nicolas Thomas

 OpenStack support

11. By Nicolas Thomas

Allow dns to use the provider dns as fowarder

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/bind/provider.py'
2--- contrib/bind/provider.py 2014-07-07 12:10:07 +0000
3+++ contrib/bind/provider.py 2014-09-12 15:12:25 +0000
4@@ -54,9 +54,11 @@
5 'update-retry': '15m',
6 'expiry': '3w',
7 'minimum': '3h'})
8- parser.dict_to_zone({'rr': 'NS', 'alias': '@', 'ttl': 1600,
9- 'addr': 'ns.%s.' % domain})
10- parser.dict_to_zone({'rr': 'A', 'alias': 'ns', 'addr': addr,
11+ parser.dict_to_zone({'rr': 'NS', 'alias': '@',
12+ 'addr': 'ns1.%s.' % domain})
13+ parser.dict_to_zone({'rr': 'A', 'alias': '@', 'addr': addr,
14+ 'ttl': 300})
15+ parser.dict_to_zone({'rr': 'A', 'alias': 'ns1', 'addr': addr,
16 'ttl': 300})
17
18 def reload_config(self):
19
20=== added file 'contrib/bind/templates/named.conf.options.jinja2'
21--- contrib/bind/templates/named.conf.options.jinja2 1970-01-01 00:00:00 +0000
22+++ contrib/bind/templates/named.conf.options.jinja2 2014-09-12 15:12:25 +0000
23@@ -0,0 +1,22 @@
24+acl "trusted" {
25+ localhost;
26+ localnets;
27+ any;
28+ };
29+
30+options {
31+ directory "/var/cache/bind";
32+
33+ forwarders {
34+ {{ forwarder }} ;
35+ 8.8.8.8 ;
36+ };
37+ dnssec-enable yes;
38+ dnssec-validation yes;
39+ auth-nxdomain no; # conform to RFC1035
40+ listen-on-v6 { any; };
41+ allow-query { any; };
42+ allow-recursion { trusted; };
43+ allow-query-cache { trusted; };
44+
45+};
46
47=== added file 'hooks/dns-client-relation-changed'
48--- hooks/dns-client-relation-changed 1970-01-01 00:00:00 +0000
49+++ hooks/dns-client-relation-changed 2014-09-12 15:12:25 +0000
50@@ -0,0 +1,55 @@
51+#!/usr/bin/python
52+import os
53+import sys
54+# Add charmhelpers to the system path.
55+try:
56+ sys.path.insert(0, os.path.abspath(os.path.join(os.environ['CHARM_DIR'],
57+ 'lib')))
58+ sys.path.insert(0, os.path.abspath(os.path.join(os.environ['CHARM_DIR'],
59+ 'contrib')))
60+except:
61+ sys.path.insert(0, os.path.abspath(os.path.join('..', 'lib')))
62+ sys.path.insert(0, os.path.abspath(os.path.join('..', 'contrib')))
63+
64+
65+from bind.provider import BindProvider
66+
67+from charmhelpers.core.hookenv import (
68+ config,
69+ unit_get,
70+ relation_get,
71+ relation_set,
72+ relation_id,
73+)
74+
75+from common import trim_empty_array_elements as trim
76+from common import resolve_hostname_to_ip as getip
77+
78+
79+class ProgrammableChanged(object):
80+
81+ def __init__(self):
82+ self.config = config()
83+ relid = relation_id()
84+ relation_set(relid, {'public-address':
85+ getip(unit_get('public-address'))})
86+ self.add_resource()
87+
88+ def add_resource(self):
89+ domain = relation_get('domain')
90+ # Do nothing if we didn't receive a RR to process
91+ if not relation_get('resources'):
92+ return
93+
94+ resources = trim(relation_get('resources').split('\n'))
95+
96+ if not domain:
97+ domain = config()['domain']
98+
99+ if self.config['provider'] == 'bind':
100+ bp = BindProvider()
101+ bp.add_record(resources, domain)
102+
103+
104+if __name__ == '__main__':
105+ c = ProgrammableChanged()
106
107=== modified file 'hooks/install'
108--- hooks/install 2014-06-06 01:39:07 +0000
109+++ hooks/install 2014-09-12 15:12:25 +0000
110@@ -52,6 +52,22 @@
111 def install_provider(self):
112 if config()['provider'] == 'bind':
113 ProviderInstaller()
114+ ## use the nameserver in /etc/resolv.conf as a forwarder ...
115+ import DNS
116+ DNS.ParseResolvConf("/etc/resolv.conf")
117+ nameserver = DNS.defaults['server'][0]
118+ log('Setting dns to be forwarder to :'+nameserver)
119+ import jinja2
120+ templateLoader = jinja2.FileSystemLoader( searchpath= os.environ['CHARM_DIR'] )
121+ #use Jinja2 template to enable bind forwarding
122+ templateEnv=jinja2.Environment( loader=templateLoader );
123+ template=templateEnv.get_template('contrib/bind/templates/named.conf.options.jinja2')
124+ output_from_parsed_template = template.render(forwarder=nameserver)
125+ # to save the results
126+ with open("/etc/bind/named.conf.options", "wb") as fh:
127+ fh.write(output_from_parsed_template)
128+ ## use jinja2 templates..
129+
130
131 if __name__ == '__main__':
132 i = Install()
133
134=== modified file 'hooks/programmable-relation-changed'
135--- hooks/programmable-relation-changed 2014-06-06 01:39:07 +0000
136+++ hooks/programmable-relation-changed 2014-09-12 15:12:25 +0000
137@@ -37,9 +37,9 @@
138 domain = relation_get('domain')
139 alias = relation_get('alias')
140 addr = relation_get('addr')
141- rr = relation_get('rr').upper()
142+ #off#rr = relation_get('rr').upper()
143
144- parsed = {'domain': domain, 'alias': alias, 'addr': addr, 'rr': rr}
145+ parsed = {'domain': domain, 'alias': alias, 'addr': addr}
146
147 if self.config['provider'] == 'bind':
148 bp = BindProvider()
149
150=== modified file 'hooks/programmable-relation-departed'
151--- hooks/programmable-relation-departed 2014-06-06 01:39:07 +0000
152+++ hooks/programmable-relation-departed 2014-09-12 15:12:25 +0000
153@@ -32,9 +32,9 @@
154 domain = relation_get('domain')
155 alias = relation_get('alias')
156 addr = relation_get('addr')
157- rr = relation_get('rr').upper()
158+ ##rr = relation_get('rr').upper()
159
160- parsed = {'domain': domain, 'alias': alias, 'addr': addr, 'rr': rr}
161+ parsed = {'domain': domain, 'alias': alias, 'addr': addr}
162
163 if self.config['provider'] == 'bind':
164 bp = BindProvider()
165@@ -43,4 +43,4 @@
166
167
168 if __name__ == '__main__':
169- c = ProgrammableBroken()
170\ No newline at end of file
171+ c = ProgrammableBroken()
172
173=== modified file 'lib/common.py'
174--- lib/common.py 2014-07-07 12:10:07 +0000
175+++ lib/common.py 2014-09-12 15:12:25 +0000
176@@ -47,7 +47,11 @@
177 hostname = hostname.strip()
178 out = subprocess.check_output(['dig', '+short', hostname]).rstrip('\n')
179 # required to obtain the IP from MAAS output. See test_common - line 83
180- return out.split('\n')[-1]
181+ if out:
182+ return out.split('\n')[-1]
183+ else:
184+ # got an empty resp means hostname=IP return it
185+ return hostname
186
187
188 # Parse existing nameservers from resolv.conf
189
190=== modified file 'metadata.yaml'
191--- metadata.yaml 2014-06-06 01:39:07 +0000
192+++ metadata.yaml 2014-09-12 15:12:25 +0000
193@@ -14,3 +14,5 @@
194 interface: dns-multi
195 auto-generated:
196 interface: dns-auto
197+ dns-client:
198+ interface: dns-client
199\ No newline at end of file
200
201=== modified file 'requirements.txt'
202--- requirements.txt 2014-07-07 12:10:07 +0000
203+++ requirements.txt 2014-09-12 15:12:25 +0000
204@@ -3,3 +3,4 @@
205 mock
206 coverage
207 jinja2
208+pydns

Subscribers

People subscribed via source and target branches

to all changes: