Beispiel #1
0
def update_host_md5(named_conf_md5):
    try:
        DnsdbApi.update_host_md5(CONF.host_ip, named_conf_md5)
    except Exception as e:
        send_alarm_email(u'主机%s更新named.conf文件成功,更新数据库失败\n原因%s' % (_get_local_hostname(), e))
        log.exception(e)
    return
Beispiel #2
0
    def run(self):
        msg = ''
        is_success = True
        try:
            if self.group_name != CONF.host_group:
                raise UpdaterErr(u'Host %s group not match: local %s, param: %s' %
                                 (CONF.host_ip, CONF.host_group, self.group_name))
            if self.update_type == 'named.conf':
                self.update_named()
            elif self.update_type == 'acl':
                self.update_acl()
            elif self.update_type == 'zone':
                self.init_zone()
            else:
                raise UpdaterErr('No worker for this type of update: %s' % self.update_type)

        except Exception as e:
            send_alarm_email(u'更新文件失败\n主机: %s\n, 类型: %s, 原因: %s' % (_get_local_hostname(), self.update_type, e))
            log.exception(e)
            msg = str(e)
            is_success = False

        deploy_id = self.kwargs.get('deploy_id', None)
        if deploy_id:
            DnsdbApi.update_deploy_info(deploy_id, is_success, msg)
Beispiel #3
0
def update_host_md5(named_conf_md5):
    try:
        DnsdbApi.update_host_md5(CONF.host_ip, named_conf_md5)
    except Exception as e:
        send_alarm_email(u'主机%s更新named.conf文件成功,更新数据库失败\n原因%s' % (_get_local_hostname(), e))
        log.exception(e)
    return
Beispiel #4
0
    def run(self):
        msg = ''
        is_success = True
        try:
            if self.group_name != CONF.host_group:
                raise UpdaterErr(
                    u'Host %s group not match: local %s, param: %s' %
                    (CONF.host_ip, CONF.host_group, self.group_name))
            if self.update_type == 'named.conf':
                self.update_named()
            elif self.update_type == 'acl':
                self.update_acl()
            elif self.update_type == 'zone':
                self.init_zone()
            else:
                raise UpdaterErr('No worker for this type of update: %s' %
                                 self.update_type)

        except Exception as e:
            send_alarm_email(u'更新文件失败\n主机: %s\n, 类型: %s, 原因: %s' %
                             (_get_local_hostname(), self.update_type, e))
            log.exception(e)
            msg = str(e)
            is_success = False

        deploy_id = self.kwargs.get('deploy_id', None)
        if deploy_id:
            DnsdbApi.update_deploy_info(deploy_id, is_success, msg)
Beispiel #5
0
    def update_acl(self):
        acl_dir = _get_acl_dir()
        acl_files = self.kwargs.get('acl_files', [])
        filenames = {filename: os.path.join(acl_dir, filename) for filename in acl_files}

        for acl_file, acl_path in filenames.items():
            # 生成新的配置文件
            content = DnsdbApi.get_acl_content(acl_file)['data']
            with open('{}.tmp'.format(acl_path), 'w') as f:
                f.write(content)

        # 重新加载配置
        if can_reload(self.group_name):
            tmp_conf_dict = {}
            for acl_file in filenames.values():
                # 备份原来配置文件
                backup_file('acl', acl_file)
                back = acl_file + '.bak'
                shutil.copy(acl_file, back)
                # 拷贝新的配置文件
                shutil.copy('{}.tmp'.format(acl_file), acl_file)
                tmp_conf_dict[acl_file] = back

            # 检查文件语法
            try:
                check_named_conf(_get_named_path())
            except UpdaterErr as e:
                # 配置文件还原
                for conf_file, back in tmp_conf_dict.items():
                    shutil.copy(back, conf_file)
                raise
            reload_conf()
Beispiel #6
0
def update_named_conf(group_name):
    named_conf = DnsdbApi.get_named_conf(group_name)['data']

    named_dir = _get_named_dir()
    new_name_path = os.path.join(named_dir, group_name)
    to_use_file = '{0}_used'.format(new_name_path)
    with open(new_name_path, 'w') as f:
        f.write(named_conf)
    shutil.copy(new_name_path, to_use_file)
    # 如果是local dns  检查前先获取本机ip 将listen-on {ip};添加到option中
    if _is_local_dns():
        output, status = os.system(
            "ifconfig | grep inet | awk '{print $2}' | awk -F '/' '{print $1}' | grep  -E '(^127\.|^192\.|^10\.)'")
        iplist = [ip.strip() for ip in output.split('\n')]
        if len(iplist) <= 1:
            raise UpdaterErr('listen ip %s replace failed' % ','.join(iplist))
        log.info('listen ip: %s' % iplist)
        with open(to_use_file) as f:
            content = f.read()
        content = content.replace('#localdns_listen_mark', 'listen-on {%s;};' % (';'.join(iplist)))
        open(to_use_file, 'w').write(content)

    check_named_conf(to_use_file)
    if can_reload(group_name):
        copy_named_conf(to_use_file)
        reload_conf()
Beispiel #7
0
    def update_acl(self):
        acl_dir = _get_acl_dir()
        acl_files = self.kwargs.get('acl_files', [])
        filenames = {
            filename: os.path.join(acl_dir, filename)
            for filename in acl_files
        }

        for acl_file, acl_path in filenames.items():
            # 生成新的配置文件
            content = DnsdbApi.get_acl_content(acl_file)['data']
            with open('{}.tmp'.format(acl_path), 'w') as f:
                f.write(content)

        # 重新加载配置
        if can_reload(self.group_name):
            tmp_conf_dict = {}
            for acl_file in filenames.values():
                # 备份原来配置文件
                backup_file('acl', acl_file)
                back = acl_file + '.bak'
                shutil.copy(acl_file, back)
                # 拷贝新的配置文件
                shutil.copy('{}.tmp'.format(acl_file), acl_file)
                tmp_conf_dict[acl_file] = back

            # 检查文件语法
            try:
                check_named_conf(_get_named_path())
            except UpdaterErr as e:
                # 配置文件还原
                for conf_file, back in tmp_conf_dict.items():
                    shutil.copy(back, conf_file)
                raise
            reload_conf()
Beispiel #8
0
def update_named_conf(group_name):
    named_conf = DnsdbApi.get_named_conf(group_name)['data']

    named_dir = _get_named_dir()
    new_name_path = os.path.join(named_dir, group_name)
    to_use_file = '{0}_used'.format(new_name_path)
    with open(new_name_path, 'w') as f:
        f.write(named_conf)
    shutil.copy(new_name_path, to_use_file)
    # 如果是local dns  检查前先获取本机ip 将listen-on {ip};添加到option中
    if _is_local_dns():
        output, status = os.system(
            "ifconfig | grep inet | awk '{print $2}' | awk -F '/' '{print $1}' | grep  -E '(^127\.|^192\.|^10\.)'"
        )
        iplist = [ip.strip() for ip in output.split('\n')]
        if len(iplist) <= 1:
            raise UpdaterErr('listen ip %s replace failed' % ','.join(iplist))
        log.info('listen ip: %s' % iplist)
        with open(to_use_file) as f:
            content = f.read()
        content = content.replace('#localdns_listen_mark',
                                  'listen-on {%s;};' % (';'.join(iplist)))
        open(to_use_file, 'w').write(content)

    check_named_conf(to_use_file)
    if can_reload(group_name):
        copy_named_conf(to_use_file)
        reload_conf()
Beispiel #9
0
 def handler(self):
     log.info('%s worker start' % self.queue_name)
     try:
         zones = DnsdbApi.get_update_zones(self.queue_name)
         if zones:
             self.zone_handler(zones)
     except Exception as e:
         log.exception(e)
         send_alarm_email(u"[CRITICAL] Failed to handle zone update of %s, because: %s" %
                          (self.queue_name, e.message))
Beispiel #10
0
    def run(self):
        msg = ''
        is_success = True
        try:
            if self.update_type == 'named.conf':
                self.update_named()
            elif self.update_type == 'acl':
                self.update_acl()

        except Exception as e:
            send_alarm_email(u'更新文件失败\n主机: %s\n原因: %s' %
                             (_get_local_hostname(), e))
            log.exception(e)
            msg = str(e)
            is_success = False

        deploy_id = self.kwargs.get('deploy_id', None)
        if deploy_id:
            DnsdbApi.update_deploy_info(deploy_id, is_success, msg)
Beispiel #11
0
def setup_config(app_env, app_kind, conf_dir):
    common_config_file = os.path.join(conf_dir, "etc/{}/common.conf".format(app_env))
    default_config_files = [common_config_file]
    app_config_file = os.path.join(conf_dir, "etc/{}/{}.conf".format(app_env, app_kind))
    default_config_files.append(app_config_file)
    CONF(default_config_files=default_config_files, args=[])

    from dns_updater.utils.updater_util import (DnsdbApi, get_self_ip)
    CONF.host_ip = get_self_ip()
    CONF.host_group = DnsdbApi.get_host_group()['data']
    setattr(CONF, 'bind_conf', CONF.bind_default)

    if getattr(CONF, CONF.host_group, None):
        for k, v in CONF[CONF.host_group].items():
            if v is not None:
                setattr(CONF.bind_conf, k, v)
Beispiel #12
0
def setup_config(app_env, app_kind, conf_dir):
    common_config_file = os.path.join(conf_dir,
                                      "etc/{}/common.conf".format(app_env))
    default_config_files = [common_config_file]
    app_config_file = os.path.join(conf_dir,
                                   "etc/{}/{}.conf".format(app_env, app_kind))
    default_config_files.append(app_config_file)
    CONF(default_config_files=default_config_files, args=[])

    from dns_updater.utils.updater_util import (DnsdbApi, get_self_ip)
    CONF.host_ip = get_self_ip()
    CONF.host_group = DnsdbApi.get_host_group()['data']
    setattr(CONF, 'bind_conf', CONF.bind_default)

    if getattr(CONF, CONF.host_group, None):
        for k, v in CONF[CONF.host_group].items():
            if v is not None:
                setattr(CONF.bind_conf, k, v)
Beispiel #13
0
def can_reload(group_name):
    return DnsdbApi.can_reload(group_name)['data']
Beispiel #14
0
def can_reload(group_name):
    return DnsdbApi.can_reload(group_name)['data']