<commit_before>#!/usr/local/bin/python

import os
import datetime
import re

import docker
from jinja2 import Template
from yaml import load

TEMPLATES_DIRECTORY = os.environ['TEMPLATE_DIRECTORY']
CONFIG_DIRECTORY = os.environ['CONFIG_DIRECTORY']

SERVICE_NAMES = {
    'dns': os.environ.get('DNS_SERVICE_NAME', 'dns'),
    'dhcp': os.environ.get('DHCP_SERVICE_NAME', '{domain}-dhcp')
}

DNS_IMAGE = os.environ.get('DNS_IMAGE')
DHCP_IMAGE = os.environ.get('DHCP_IMAGE')

DNS_TTL = {
    'default': 86400,
    'short': 300
}

DHCP_LEASE_TIME = {
    'default': 600,
    'max': 7200
}

DHCP_FILENAME_TEMPLATE = 'dhcp.{domain}.conf'


def get_configurations():
    with open('/opt/conf') as config_file:
        return load(config_file)

route_ip_regex = re.compile('src[ ](?P<ip>[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)[ ]')
def get_interfaces_ip_maps(configurations):
    interfaces_ip_maps = {}
    client = docker.from_env()
    route_outputs = client.containers.run(
        "magnitus/network-setup_setup:latest", 
        "ip route",
        network_mode="host",
        remove=True
    ).decode('utf-8').strip().split('\n')

    for name in configurations['networks']:
        interface = configurations['networks'][name]['interface']
        for route_output in route_outputs:
            if not route_output.startswith('default via') and 'dev {interface}'.format(interface=interface) in route_output:
                match = route_ip_regex.search(route_output)
                if match is not None:
                    interfaces_ip_maps[interface] = match.group('ip')

    return interfaces_ip_maps

def generate_dns_config(configurations):
    with open(os.path.join(TEMPLATES_DIRECTORY, 'dns.conf.j2'), 'r') as template_file:<commit_msg>Bug fix<commit_after>#!/usr/local/bin/python

import os
import datetime
import re

import docker
from jinja2 import Template
from yaml import load

TEMPLATES_DIRECTORY = os.environ['TEMPLATE_DIRECTORY']
CONFIG_DIRECTORY = os.environ['CONFIG_DIRECTORY']

SERVICE_NAMES = {
    'dns': os.environ.get('DNS_SERVICE_NAME', 'dns'),
    'dhcp': os.environ.get('DHCP_SERVICE_NAME', '{domain}-dhcp')
}

DNS_IMAGE = os.environ.get('DNS_IMAGE')
DHCP_IMAGE = os.environ.get('DHCP_IMAGE')

DNS_TTL = {
    'default': 86400,
    'short': 300
}

DHCP_LEASE_TIME = {
    'default': 600,
    'max': 7200
}

DHCP_FILENAME_TEMPLATE = 'dhcp.{domain}.conf'


def get_configurations():
    with open('/opt/conf') as config_file:
        return load(config_file)

route_ip_regex = re.compile('src[ ](?P<ip>[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)[ ]')
def get_interfaces_ip_maps(configurations):
    interfaces_ip_maps = {}
    client = docker.from_env()
    route_outputs = client.containers.run(
        "magnitus/network-setup:latest", 
        "ip route",
        network_mode="host",
        remove=True
    ).decode('utf-8').strip().split('\n')

    for name in configurations['networks']:
        interface = configurations['networks'][name]['interface']
        for route_output in route_outputs:
            if not route_output.startswith('default via') and 'dev {interface}'.format(interface=interface) in route_output:
                match = route_ip_regex.search(route_output)
                if match is not None:
                    interfaces_ip_maps[interface] = match.group('ip')

    return interfaces_ip_maps

def generate_dns_config(configurations):
    with open(os.path.join(TEMPLATES_DIRECTORY, 'dns.conf.j2'), 'r') as template_file:
{'fraction_non_alphanumeric': 0.1447520184544406, 'fraction_numerical': 0.014994232987312572, 'mean_word_length': 3.752054794520548, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5986439', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1193, 'n_words': 212}