示例#1
0
    def _sync_domain(self, domain, new_domain_flag=False):
        """ Sync a single domain's zone file """
        LOG.debug('Synchronising Domain: %s' % domain['id'])

        servers = self.central_service.get_servers(self.admin_context)

        records = self.central_service.get_records(self.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_op = 'reconfig' if new_domain_flag else 'reload'

        rndc_call = self._rndc_base() + [rndc_op]

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

        LOG.debug('Calling RNDC with: %s' % " ".join(rndc_call))
        utils.execute(*rndc_call)
示例#2
0
    def _sync_domain(self, domain, new_domain_flag=False):
        """ Sync a single domain's zone file """
        LOG.debug('Synchronising Domain: %s' % domain['id'])

        servers = self.central_service.get_servers(self.admin_context)

        records = self.central_service.get_records(self.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_op = 'reconfig' if new_domain_flag else 'reload'

        rndc_call = self._rndc_base() + [rndc_op]

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

        LOG.debug('Calling RNDC with: %s' % " ".join(rndc_call))
        utils.execute(*rndc_call)
示例#3
0
    def _write_zonefile(self, domain):
        records = self.central_service.get_records(self.admin_context,
                                                   domain['id'])

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

        utils.render_template_to_file('dnsmasq-zone.jinja2',
                                      filename,
                                      records=records)
示例#4
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')

        domains = self.central_service.get_domains(self.admin_context)

        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 = [
            'rndc',
            '-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'])

        utils.execute(*rndc_call)
示例#5
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)
示例#6
0
    def render_template_to_file(self):
        output_path = tempfile.mktemp()

        template = Template("Hello {{name}}")

        utils.render_template_to_file(template, output_path=output_path, name="World")

        self.assertTrue(os.path.exists(output_path))

        try:
            with open(output_path, "r") as fh:
                self.assertEqual("Hello World", fh.read())
        finally:
            os.unlink(output_path)
示例#7
0
    def render_template_to_file(self):
        output_path = tempfile.mktemp()

        template = Template("Hello {{name}}")

        utils.render_template_to_file(template,
                                      output_path=output_path,
                                      name="World")

        self.assertTrue(os.path.exists(output_path))

        try:
            with open(output_path, 'r') as fh:
                self.assertEqual('Hello World', fh.read())
        finally:
            os.unlink(output_path)
示例#8
0
    def _sync_domains(self):
        """ Sync the list of domains this server handles """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising domains')

        domains = self.central_service.get_domains(self.admin_context)

        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)

        utils.render_template_to_file('bind9-config.jinja2',
                                      output_path,
                                      domains=domains,
                                      state_path=abs_state_path)
示例#9
0
    def _sync_domains(self):
        """ Sync the list of domains this server handles """
        # TODO: Rewrite this entire thing ASAP
        LOG.debug('Synchronising domains')

        domains = self.central_service.get_domains(self.admin_context)

        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)

        utils.render_template_to_file('bind9-config.jinja2',
                                      output_path,
                                      domains=domains,
                                      state_path=abs_state_path)
示例#10
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)