Esempio n. 1
0
def get_records(domain_id):
    context = flask.request.environ.get('context')

    try:
        records = central_api.get_records(context, domain_id)
    except exceptions.Forbidden:
        return flask.Response(status=401)

    return flask.jsonify(records=records)
Esempio n. 2
0
def get_records(domain_id):
    context = flask.request.environ.get('context')

    try:
        records = central_api.get_records(context, domain_id)
    except exceptions.Forbidden:
        return flask.Response(status=401)

    return flask.jsonify(records=records)
Esempio n. 3
0
    def _sync_domain(self, domain, new_domain_flag=False):
        """ Sync a single domain's zone file """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising Domain: %s' % domain['id'])

        admin_context = MonikerContext.get_admin_context()

        servers = central_api.get_servers(admin_context)

        if len(servers) == 0:
            LOG.critical('No servers configured. Please create at least one '
                         'server via the REST API')
            return

        records = central_api.get_records(admin_context, domain['id'])

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

        output_path = os.path.join(output_folder, '%s.zone' % domain['id'])

        utils.render_template_to_file('bind9-zone.jinja2',
                                      output_path,
                                      servers=servers,
                                      domain=domain,
                                      records=records)

        self._sync_domains()

        rndc_call = [
            'sudo',
            cfg.CONF.rndc_path,
            '-s', cfg.CONF.rndc_host,
            '-p', str(cfg.CONF.rndc_port),
        ]

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

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

        rndc_op = 'reconfig' if new_domain_flag else 'reload'
        rndc_call.extend([rndc_op])

        if not new_domain_flag:
            rndc_call.extend([domain['name']])

        LOG.debug('Calling RNDC with: %s' % " ".join(rndc_call))
        subprocess.call(rndc_call)
Esempio n. 4
0
    def _sync_domain(self, domain):
        """ Sync a single domain's zone file """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising Domain: %s' % domain['id'])

        admin_context = get_admin_context()

        servers = central_api.get_servers(admin_context)
        records = central_api.get_records(admin_context, domain['id'])

        template_path = os.path.join(os.path.abspath(cfg.CONF.templates_path),
                                     'bind9-zone.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, '%s.zone' % domain['id'])

        self._render_template(template_path,
                              output_path,
                              servers=servers,
                              domain=domain,
                              records=records)

        self._sync_domains()

        rndc_call = [
            'sudo',
            cfg.CONF.rndc_path,
            '-s',
            cfg.CONF.rndc_host,
            '-p',
            str(cfg.CONF.rndc_port),
        ]

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

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

        rndc_call.extend(['reload', domain['name']])

        LOG.warn(rndc_call)

        subprocess.call(rndc_call)
Esempio n. 5
0
def get_records(domain_id):
    context = flask.request.environ.get('context')

    try:
        records = central_api.get_records(context, domain_id)
    except exceptions.Forbidden:
        return flask.Response(status=401)
    except exceptions.DomainNotFound:
        return flask.Response(status=404)
    except rpc_common.Timeout:
        return flask.Response(status=504)

    records = records_schema.filter({'records': records})

    return flask.jsonify(records)
Esempio n. 6
0
    def _sync_domain(self, domain):
        """ Sync a single domain's zone file """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising Domain: %s' % domain['id'])

        admin_context = get_admin_context()

        servers = central_api.get_servers(admin_context)
        records = central_api.get_records(admin_context, domain['id'])

        template_path = os.path.join(os.path.abspath(
            cfg.CONF.templates_path), 'bind9-zone.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, '%s.zone' % domain['id'])

        self._render_template(template_path, output_path, servers=servers,
                              domain=domain, records=records)

        self._sync_domains()

        rndc_call = [
            'sudo',
            cfg.CONF.rndc_path,
            '-s', cfg.CONF.rndc_host,
            '-p', str(cfg.CONF.rndc_port),
        ]

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

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

        rndc_call.extend(['reload', domain['name']])

        LOG.warn(rndc_call)

        subprocess.call(rndc_call)