~smoser/ubuntu/wily/maas/lp1474417

« back to all changes in this revision

Viewing changes to src/provisioningserver/dns/config.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Raphaël Badin, Andres Rodriguez
  • Date: 2015-07-03 00:11:50 UTC
  • mfrom: (1.4.2)
  • Revision ID: package-import@ubuntu.com-20150703001150-mszsmaakg1mw3fkb
Tags: 1.7.6+bzr3376-0ubuntu1
* New upstream release 1.7.6 bzr3376:
  - Accept list of forwarders for upstream_dns rather than just
    one. (LP: #1470585)
  - Fix upgrade issue where it would remove custom DNS config,
    potentially breaking DNS. (LP: #1413388)

[ Raphaël Badin ]
* Drop dependency on python-iscpy: the code has been integrated into
  MAAS. (LP: #1413388).

[ Andres Rodriguez ]
* Refactor maas-dns upgrade code so it doesn't break local DNS config
  and it gets migrated (LP: #1413388)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from provisioningserver.utils import locate_config
33
33
from provisioningserver.utils.fs import atomic_write
 
34
from provisioningserver.utils.isc import read_isc_file
34
35
from provisioningserver.utils.shell import call_and_check
35
36
import tempita
36
37
 
37
38
 
 
39
NAMED_CONF_OPTIONS = 'named.conf.options'
38
40
MAAS_NAMED_CONF_NAME = 'named.conf.maas'
39
41
MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME = 'named.conf.options.inside.maas'
40
42
MAAS_NAMED_RNDC_CONF_NAME = 'named.conf.rndc.maas'
53
55
        return setting
54
56
 
55
57
 
 
58
def get_bind_config_dir():
 
59
    """Location of bind configuration files."""
 
60
    setting = os.getenv(
 
61
        "MAAS_BIND_CONFIG_DIR",
 
62
        locate_config(os.path.pardir, "bind"))
 
63
    if isinstance(setting, bytes):
 
64
        fsenc = sys.getfilesystemencoding()
 
65
        return setting.decode(fsenc)
 
66
    else:
 
67
        return setting
 
68
 
 
69
 
56
70
def get_dns_rndc_port():
57
71
    """RNDC port to be configured by MAAS to communicate with BIND."""
58
72
    setting = os.getenv("MAAS_DNS_RNDC_PORT", "954")
192
206
    # specify it. If it's not set, the substitution will fail with the default
193
207
    # template that uses this value.
194
208
    kwargs.setdefault("upstream_dns")
 
209
 
 
210
    # Parse the options file and make sure MAAS doesn't define any options
 
211
    # that the user has already customized.
 
212
    allow_user_override_options = [
 
213
        "allow-query",
 
214
        "allow-recursion",
 
215
        "allow-query-cache",
 
216
    ]
 
217
 
 
218
    try:
 
219
        parsed_options = read_isc_file(
 
220
            compose_bind_config_path(NAMED_CONF_OPTIONS))
 
221
    except IOError:
 
222
        parsed_options = {}
 
223
 
 
224
    options = parsed_options.get('options', {})
 
225
    for option in allow_user_override_options:
 
226
        kwargs['upstream_' + option.replace('-', '_')] = option in options
 
227
 
195
228
    try:
196
229
        rendered = template.substitute(kwargs)
197
230
    except NameError as error:
206
239
    return os.path.join(get_dns_config_dir(), filename)
207
240
 
208
241
 
 
242
def compose_bind_config_path(filename):
 
243
    """Return the full path for a DNS config or zone file."""
 
244
    return os.path.join(get_bind_config_dir(), filename)
 
245
 
 
246
 
209
247
def render_dns_template(template_name, *parameters):
210
248
    """Generate contents for a DNS configuration or zone file.
211
249