コード例 #1
0
def set_dns_servers(dns_server_info):
    field = {1: 'primary', 2: 'secondary'}

    with ConfigurationManager('dns_server') as dnx:
        dns_server_settings = dnx.load_configuration()

        public_resolvers = dns_server_settings['dns_server']['resolvers']

        for i, (server_name, ip_address) in enumerate(dns_server_info.items(), 1):
            if (not server_name and ip_address):
                continue

            public_resolvers[field[i]].update({
                'name': server_name,
                'ip_address': ip_address
            })

        dnx.write_configuration(dns_server_settings)

    wan_information = load_configuration('config')['settings']
    interface = wan_information['interfaces']
    wan_dhcp = interface['wan']['dhcp']
    wan_int = interface['wan']['ident']
    if (not wan_dhcp):
        wan_ip = interface.get_ip_address(wan_int)

        wan_dfg = Interface.default_gateway(wan_int)
        cidr = System.standard_to_cidr(wan_netmask)

        # TODO: convert this to new module
        wan_netmask = Interface.netmask(wan_int)

        set_wan_interface({
            'ip_address': wan_ip, 'cidr': cidr, 'default_gateway': wan_dfg
        })
コード例 #2
0
def set_dns_servers(dns_server_info):
    with ConfigurationManager('dns_server') as dnx:
        dns_server_settings = dnx.load_configuration()

        dns = dns_server_settings['dns_server']['resolvers']
        for i, (server_name, ip_address) in enumerate(dns_server_info.items(),
                                                      1):
            if (server_name and ip_address):
                server = dns[f'server{i}']
                server.update({'name': server_name, 'ip_address': ip_address})

        dnx.write_configuration(dns_server_settings)

    wan_information = load_configuration('config')
    interface = wan_information['settings']['interface']
    wan_dhcp = interface['wan']['dhcp']
    wan_int = interface['outside']
    if (not wan_dhcp):
        wan_ip = interface.get_ip_address(wan_int)
        wan_netmask = Interface.netmask(wan_int)
        wan_dfg = Interface.default_gateway(wan_int)

        cidr = System.standard_to_cidr(wan_netmask)

        wan_settings = {
            'ip_address': wan_ip,
            'cidr': cidr,
            'default_gateway': wan_dfg
        }
        set_wan_interface(wan_settings)