Example #1
0
    def _sync_domains(self):
        """ Sync the list of domains this server handles """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising domains')

        admin_context = get_admin_context()

        domains = central_api.get_domains(admin_context)

        template_path = os.path.join(os.path.abspath(cfg.CONF.templates_path),
                                     'bind9-config.jinja2')

        output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),
                                     'bind9')

        # Create the output folder tree if necessary
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)

        output_path = os.path.join(output_folder, 'zones.config')

        self._render_template(template_path,
                              output_path,
                              domains=domains,
                              state_path=os.path.abspath(cfg.CONF.state_path))
Example #2
0
def get_domains():
    context = flask.request.environ.get('context')

    try:
        domains = central_api.get_domains(context)
    except exceptions.Forbidden:
        return flask.Response(status=401)

    domains = domains_schema.filter(domains)

    return flask.jsonify(domains=domains)
Example #3
0
    def start(self):
        super(Bind9Backend, self).start()

        # TODO: This is a hack to ensure the data dir is 100% up to date
        admin_context = MonikerContext.get_admin_context()

        domains = central_api.get_domains(admin_context)

        for domain in domains:
            self._sync_domain(domain)

        self._sync_domains()
Example #4
0
    def __init__(self, *args, **kwargs):
        kwargs.update(host=cfg.CONF.host, topic=cfg.CONF.agent_topic)

        super(Service, self).__init__(*args, **kwargs)

        # TODO: This is a hack to ensure the data dir is 100% up to date
        admin_context = get_admin_context()

        domains = central_api.get_domains(admin_context)

        for domain in domains:
            self._sync_domain(domain)

        self._sync_domains()
Example #5
0
    def __init__(self, *args, **kwargs):
        kwargs.update(
            host=cfg.CONF.host,
            topic=cfg.CONF.agent_topic
        )

        super(Service, self).__init__(*args, **kwargs)

        # TODO: This is a hack to ensure the data dir is 100% up to date
        admin_context = get_admin_context()

        domains = central_api.get_domains(admin_context)

        for domain in domains:
            self._sync_domain(domain)

        self._sync_domains()
Example #6
0
    def _sync_domains(self):
        """ Sync the list of domains this server handles """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising domains')

        admin_context = get_admin_context()

        domains = central_api.get_domains(admin_context)

        template_path = os.path.join(os.path.abspath(
            cfg.CONF.templates_path), 'bind9-config.jinja2')

        output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),
                                     'bind9')

        # Create the output folder tree if necessary
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)

        output_path = os.path.join(output_folder, 'zones.config')

        self._render_template(template_path, output_path, domains=domains,
                              state_path=os.path.abspath(cfg.CONF.state_path))
Example #7
0
    def _sync_domains(self):
        """
        Update the zone file and reconfig rndc to update bind.
        Unike regular bind, this only needs to be done upon adding
        or deleting domains as mysqlbind takes care of updating
        bind upon regular record changes
        """
        LOG.debug('Synchronising domains')

        admin_context = MonikerContext.get_admin_context()
        LOG.debug("admin_context: %r" % admin_context)

        domains = central_api.get_domains(admin_context)
        LOG.debug("domains: %r" % domains)

        output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),
                                     'bind9')

        # Create the output folder tree if necessary
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)

        output_path = os.path.join(output_folder, 'zones.config')

        abs_state_path = os.path.abspath(cfg.CONF.state_path)

        LOG.debug("Getting ready to write zones.config at %s" % output_path)

        # NOTE(CapTofu): Might have to adapt this later on?
        url = self.get_url_data()
        utils.render_template_to_file('mysql-bind9-config.jinja2',
                                      output_path,
                                      domains=domains,
                                      state_path=abs_state_path,
                                      dns_server_type=cfg.CONF[self.name].
                                      dns_server_type,
                                      dns_db_schema=url['database'],
                                      dns_db_table=cfg.CONF[self.name].
                                      database_dns_table,
                                      dns_db_host=url['host'],
                                      dns_db_user=url['username'],
                                      dns_db_password=url['password'])

        # only do this if domain create, domain delete
        rndc_call = [
            'sudo',
            cfg.CONF[self.name].rndc_path,
            '-s', cfg.CONF[self.name].rndc_host,
            '-p', str(cfg.CONF[self.name].rndc_port),
        ]

        if cfg.CONF[self.name].rndc_config_file:
            rndc_call.extend(['-c', self.config.rndc_config_file])

        if cfg.CONF[self.name].rndc_key_file:
            rndc_call.extend(['-k', self.config.rndc_key_file])

        rndc_call.extend(['reconfig'])

        LOG.warn(rndc_call)

        subprocess.call(rndc_call)