コード例 #1
0
ファイル: functions.py プロジェクト: isc-projects/forge
def cfg_write():
    cfg_file = open(world.cfg["cfg_file"], 'w')
    cfg_file.write(world.cfg["conf_time"])
    cfg_file.write("authoritative;\n")

    if "log_facility" in world.cfg:
        cfg_file.write(world.cfg["log_facility"])

    if "custom_lines" in world.cfg:
        cfg_file.write(world.cfg["custom_lines"])

    if "conf_option" in world.cfg:
        cfg_file.write(world.cfg["conf_option"])

    if "conf_vendor" in world.cfg:
        cfg_file.write(world.cfg["conf_vendor"])

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)
        # ddns we can add just to one subnet, for now
        world.subcfg[0][0] += 'ddns-rev-domainname "' + world.ddns_rev_domainname + '";'
        world.subcfg[0][0] += 'ddns-domainname "' + world.ddns_domainname + '";'

    for each_subnet in world.subcfg:
        if each_subnet[0] != "":
            cfg_file.write(each_subnet[0])
            cfg_file.write('}')  # add } for subnet block

    cfg_file.close()
    simple_file_layout()
コード例 #2
0
def cfg_write():
    cfg_file = open(world.cfg["cfg_file"], 'w')
    cfg_file.write(world.cfg["conf_time"])

    if "log_facility" in world.cfg:
        cfg_file.write(world.cfg["log_facility"])

    if "custom_lines" in world.cfg:
        cfg_file.write(world.cfg["custom_lines"])

    if "conf_option" in world.cfg:
        cfg_file.write(world.cfg["conf_option"])

    if "conf_vendor" in world.cfg:
        cfg_file.write(world.cfg["conf_vendor"])

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)
        # ddns we can add just to one subnet, for now
        world.subcfg[0][
            0] += 'ddns-rev-domainname "' + world.ddns_rev_domainname + '";'
        world.subcfg[0][
            0] += 'ddns-domainname "' + world.ddns_domainname + '";'

    for each_subnet in world.subcfg:
        cfg_file.write(each_subnet[0])
        cfg_file.write('}')  # add } for subnet block

    cfg_file.close()
    simple_file_layout()
コード例 #3
0
ファイル: functions.py プロジェクト: godfryd/forge
def cfg_write():
    config_db_backend()
    for number in range(0, len(world.subcfg)):
        if len(world.subcfg[number][2]) > 10:
            world.subcfg[number][
                2] = '"option-data": [' + world.subcfg[number][2] + "]"
        if len(world.subcfg[number][4]) > 10:
            world.subcfg[number][
                4] = '"pools": [' + world.subcfg[number][4] + "]"
        if len(world.subcfg[number][5]) > 10:
            world.subcfg[number][
                5] = '"reservations":[' + world.subcfg[number][5] + "]"
    cfg_file = open(world.cfg["cfg_file"], 'w')
    # add timers
    cfg_file.write(world.cfg["main"])
    if len(world.cfg["server-id"]) > 5:
        cfg_file.write(world.cfg["server-id"])
    # add class definitions
    if len(world.classification) > 0:
        if len(world.classification[0][0]) > 0:
            cfg_file.write('"client-classes": [')
            counter = 0
            for each_class in world.classification:
                if counter > 0:
                    cfg_file.write(',')
                cfg_file.write('{')  # open class
                cfg_file.write('"name":"' + each_class[0] + '"')
                if len(each_class[1]) > 0:
                    cfg_file.write("," + each_class[1])
                if len(each_class[2]) > 0:
                    cfg_file.write(',"option-data": [' + each_class[2] + "]")
                cfg_file.write('}')  # close each class
                counter += 1
            cfg_file.write("],")  # close classes
    # add interfaces
    cfg_file.write('"interfaces-config": { "interfaces": [ ' +
                   world.cfg["interfaces"] + ' ] },')
    # add header for subnets
    if world.subnet_add:
        if "kea6" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet6":[')
        elif "kea4" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet4":[')
        # add subnets
        counter = 0
        comma = 0
        for each_subnet in world.subcfg:
            if counter in world.shared_subnets_tmp:
                # subnets that suppose to go to shared-networks should be omitted here
                counter += 1
                continue
            if counter > 0 and comma == 1:
                cfg_file.write(",")
            tmp = each_subnet[0]
            # we need to be able to add interface-id to config but we want to keep backward compatibility.
            if "interface" not in tmp or "interface-id" not in tmp:
                eth = world.f_cfg.server_iface
                tmp += ', "interface": "{eth}" '.format(**locals())
            counter += 1
            comma = 1
            for each_subnet_config_part in each_subnet[1:]:
                if len(each_subnet_config_part) > 0:
                    tmp += ',' + each_subnet_config_part
            cfg_file.write(tmp + '}')
        cfg_file.write(']')
        # that is ugly hack but kea confing generation is awaiting rebuild anyway
        if "options" in world.cfg:
            cfg_file.write(',' + world.cfg["options"])
            cfg_file.write("]")
            del world.cfg["options"]

    if "options" in world.cfg:
        cfg_file.write(world.cfg["options"])
        cfg_file.write("]")
        del world.cfg["options"]

    if "option_def" in world.cfg:
        cfg_file.write(',' + world.cfg["option_def"])
        cfg_file.write("]")
        del world.cfg["option_def"]

    if len(world.hooks) > 0 or len(world.kea_ha[0]) > 0:
        cfg_file.write(',"hooks-libraries": [')
        test_length_1 = len(world.hooks)
        counter_1 = 1
        for each_hook in world.hooks:
            cfg_file.write('{"library": "' + each_hook[0] + '"')
            if len(each_hook[1]) > 0:
                cfg_file.write(',"parameters": {')
                test_length_2 = len(each_hook[1])
                counter_2 = 1
                for every_parameter in each_hook[1]:
                    cfg_file.write('"' + every_parameter[0] + '":')
                    if every_parameter[1] in [
                            "true", "false"
                    ]:  # TODO add if value is numeric
                        cfg_file.write(every_parameter[1])
                    else:
                        cfg_file.write('"' + every_parameter[1] + '"')
                    if counter_2 < test_length_2:
                        cfg_file.write(',')
                    counter_2 += 1
                cfg_file.write('}')  # closing parameters
            if counter_1 < test_length_1:
                cfg_file.write('},')
            counter_1 += 1
        cfg_file.write('}')  # closing libs
        if len(world.kea_ha[0]) > 0:
            if len(world.hooks) > 0:
                cfg_file.write(',')
            cfg_file.write('{"library": "' + world.kea_ha[0][0] +
                           '","parameters":{"high-availability":[{')
            # add single parameters to main map
            for each_param in world.kea_ha[1]:
                cfg_file.write('"' + each_param[0] + '":' + each_param[1] +
                               ",")
            # add peers
            cfg_file.write('"peers": [')
            for each_ha_peer in world.kea_ha[2]:
                cfg_file.write(each_ha_peer)
                if world.kea_ha[2].index(each_ha_peer) != len(
                        world.kea_ha[2]) - 1:
                    cfg_file.write(",")
            cfg_file.write(']')
            if len(world.kea_ha[3]) > 0:
                cfg_file.write(',"state-machine":{"states":[')
                for each_state in world.kea_ha[3]:
                    cfg_file.write(each_state)
                    if world.kea_ha[3].index(each_state) != len(
                            world.kea_ha[3]) - 1:
                        cfg_file.write(",")
                cfg_file.write(']}')
            cfg_file.write('}]}}')

        cfg_file.write(']')  # closing hooks

    if "simple_options" in world.cfg:
        cfg_file.write(',' + world.cfg["simple_options"])
        del world.cfg["simple_options"]

    if world.ddns_enable:
        cfg_file.write(',' + world.ddns_add + '}')

    if "custom_lines" in world.cfg:
        cfg_file.write(',' + world.cfg["custom_lines"])
        # cfg_file.write("]")
        del world.cfg["custom_lines"]

    if "socket" in world.cfg:
        cfg_file.write(',' + world.cfg["socket"])
        del world.cfg["socket"]

    if len(world.shared_subnets) > 0:
        shared_counter = 0
        last_option = ""
        cfg_file.write(' ,"shared-networks":[')
        for each_shared_subnet in world.shared_subnets:
            counter = 0
            comma = 0
            if shared_counter > 0:
                cfg_file.write(',')
            cfg_file.write('{')

            for each_option in world.shared_subcfg[shared_counter]:
                cfg_file.write(each_option)
                last_option = each_option

            if last_option[:-1] != ",":
                cfg_file.write(",")

            if "kea6" in world.cfg["dhcp_under_test"]:
                cfg_file.write('"subnet6":[')

            elif "kea4" in world.cfg["dhcp_under_test"]:
                cfg_file.write('"subnet4":[')

            for each_subnet in world.subcfg:
                if counter in each_shared_subnet:
                    if counter > 0 and comma == 1:
                        cfg_file.write(",")
                    tmp = each_subnet[0]
                    # we need to be able to add interface-id to config but we want to keep backward compatibility.
                    # if "interface" not in tmp or "interface-id" not in tmp:
                    #     eth = world.f_cfg.server_iface
                    #     tmp += ', "interface": "{eth}" '.format(**locals())
                    counter += 1
                    comma = 1

                    for each_subnet_config_part in each_subnet[1:]:
                        if len(each_subnet_config_part) > 0:
                            tmp += ',' + each_subnet_config_part
                        # tmp += str(each_subnet[-1])
                    cfg_file.write(tmp + '}')
                else:
                    counter += 1
            # shared_counter += 1
            cfg_file.write(']')
            shared_counter += 1
            cfg_file.write('}')  # end of map of each shared network
        cfg_file.write(']')  # end of shared networks list

    cfg_file.write(
        '}'
    )  # end of DHCP part (should be moved if something else will be added after shared-networks

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)

    if "agent" in world.cfg:
        cfg_file.write(',' + world.cfg["agent"])
        del world.cfg["agent"]

    logging_file = world.f_cfg.software_install_path + 'var/kea/kea.log'

    log_type = ''
    if "kea6" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp6'
    elif "kea4" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp4'

    cfg_file.write(',"Logging": {"loggers": [')
    if "logger" not in world.cfg:
        cfg_file.write('{"name": "' + log_type +
                       '","output_options": [{"output": "' + logging_file +
                       '"}')
        cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
        if world.ddns_enable:
            cfg_file.write(
                ',{"name": "kea-dhcp-ddns","output_options": [{"output": "' +
                logging_file + '_ddns"}')
            cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
    else:
        cfg_file.write(world.cfg["logger"])

    cfg_file.write(']}')
    cfg_file.write('}')  # end of the config file
    cfg_file.close()
    # kea ctrl script config file
    cfg_file = open(world.cfg["cfg_file_2"], 'w')
    cfg_file.write(world.cfg["keactrl"])
    cfg_file.close()
    world.subcfg = [["", "", "", "", "", "", ""]]
    config = open(world.cfg["cfg_file"], 'r')
    world.configString = config.read().replace('\n', '').replace(' ', '')
    config.close()
    add_variable("SERVER_CONFIG", world.configString, False)
    json_file_layout()
コード例 #4
0
ファイル: functions.py プロジェクト: isc-projects/forge
def cfg_write():
    config_db_backend()
    checker = 0
    for number in range(len(world.subcfg)):
        if len(world.subcfg[number][2]) > 10:
            world.subcfg[number][2] = '"option-data": [' + world.subcfg[number][2] + "]"
        if len(world.subcfg[number][4]) > 10:
            world.subcfg[number][4] = '"pools": [' + world.subcfg[number][4] + "]"
        if len(world.subcfg[number][5]) > 10:
            world.subcfg[number][5] = '"reservations":[' + world.subcfg[number][5] + "]"
    cfg_file = open(world.cfg["cfg_file"], 'w')
    # add timers
    cfg_file.write(world.cfg["main"])
    if len(world.cfg["server-id"]) > 5:
        cfg_file.write(world.cfg["server-id"])
    # add class definitions
    if len(world.classification) > 0:
        if len(world.classification[0][0]) > 0:
            cfg_file.write('"client-classes": [')
            counter = 0
            for each_class in world.classification:
                if counter > 0:
                    cfg_file.write(',')
                cfg_file.write('{')  # open class
                cfg_file.write('"name":"' + each_class[0] + '"')
                if len(each_class[1]) > 0:
                    cfg_file.write("," + each_class[1])
                if len(each_class[2]) > 0:
                    cfg_file.write(',"option-data": [' + each_class[2] + "]")
                cfg_file.write('}')  # close each class
                counter += 1
            cfg_file.write("],")  # close classes
    # add interfaces
    cfg_file.write('"interfaces-config": { "interfaces": [ ' + world.cfg["interfaces"] + ' ] },')
    # add header for subnets
    if world.subnet_add:
        if "kea6" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet6":[')
        elif "kea4" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet4":[')
        # add subnets
        counter = 0
        comma = 0
        for each_subnet in world.subcfg:
            if counter in world.shared_subnets_tmp:
                # subnets that suppose to go to shared-networks should be omitted here
                checker = 1
                counter += 1
                continue
            if counter > 0 and comma == 1:
                cfg_file.write(",")
            tmp = each_subnet[0]
            # we need to be able to add interface-id to config but we want to keep backward compatibility.
            if "interface" not in tmp or "interface-id" not in tmp:
                eth = world.f_cfg.server_iface
                tmp += ', "interface": "{eth}" '.format(**locals())
            counter += 1
            comma = 1
            for each_subnet_config_part in each_subnet[1:]:
                checker = 1
                if len(each_subnet_config_part) > 0:
                    tmp += ',' + each_subnet_config_part
            cfg_file.write(tmp + '}')
        cfg_file.write(']')
        # that is ugly hack but kea confing generation is awaiting rebuild anyway
        if "options" in world.cfg:
            cfg_file.write(',' + world.cfg["options"])
            cfg_file.write("]")
            del world.cfg["options"]

    if "options" in world.cfg:
        cfg_file.write(world.cfg["options"])
        checker = 1
        cfg_file.write("]")
        del world.cfg["options"]

    if "option_def" in world.cfg:
        cfg_file.write(',' + world.cfg["option_def"])
        cfg_file.write("]")
        del world.cfg["option_def"]

    if len(world.hooks) > 0 or len(world.kea_ha[0]) > 0:
        if checker == 1:
            cfg_file.write(',')
        cfg_file.write('"hooks-libraries": [')
        test_length_1 = len(world.hooks)
        counter_1 = 1
        for each_hook in world.hooks:
            cfg_file.write('{"library": "' + each_hook[0] + '"')
            if len(each_hook[1]) > 0:
                cfg_file.write(',"parameters": {')
                test_length_2 = len(each_hook[1])
                counter_2 = 1
                for every_parameter in each_hook[1]:
                    cfg_file.write('"' + every_parameter[0] + '":')
                    if every_parameter[1] in ["true", "false"]:  # TODO add if value is numeric
                        cfg_file.write(every_parameter[1])
                    else:
                        cfg_file.write('"' + every_parameter[1] + '"')
                    if counter_2 < test_length_2:
                        cfg_file.write(',')
                    counter_2 += 1
                cfg_file.write('}')  # closing parameters
            if counter_1 < test_length_1:
                cfg_file.write('},')
            counter_1 += 1
        cfg_file.write('}')  # closing libs
        if len(world.kea_ha[0]) > 0:
            if len(world.hooks) > 0:
                cfg_file.write(',')
            cfg_file.write('{"library": "' + world.kea_ha[0][0] + '","parameters":{"high-availability":[{')
            # add single parameters to main map
            for each_param in world.kea_ha[1]:
                cfg_file.write('"'+each_param[0]+'":'+each_param[1]+",")
            # add peers
            cfg_file.write('"peers": [')
            for each_ha_peer in world.kea_ha[2]:
                cfg_file.write(each_ha_peer)
                if world.kea_ha[2].index(each_ha_peer) != len(world.kea_ha[2]) - 1:
                    cfg_file.write(",")
            cfg_file.write(']')
            if len(world.kea_ha[3]) > 0:
                cfg_file.write(',"state-machine":{"states":[')
                for each_state in world.kea_ha[3]:
                    cfg_file.write(each_state)
                    if world.kea_ha[3].index(each_state) != len(world.kea_ha[3]) - 1:
                        cfg_file.write(",")
                cfg_file.write(']}')
            cfg_file.write('}]}}')

        cfg_file.write(']')  # closing hooks

    if "simple_options" in world.cfg:
        cfg_file.write(',' + world.cfg["simple_options"])
        del world.cfg["simple_options"]

    if world.ddns_enable:
        cfg_file.write(',' + world.ddns_add + '}')

    if "custom_lines" in world.cfg:
        cfg_file.write(',' + world.cfg["custom_lines"])
        # cfg_file.write("]")
        del world.cfg["custom_lines"]

    if "socket" in world.cfg:
        cfg_file.write(',' + world.cfg["socket"])
        del world.cfg["socket"]

    if len(world.shared_subnets) > 0:
        shared_counter = 0
        last_option = ""
        cfg_file.write(' ,"shared-networks":[')
        for each_shared_subnet in world.shared_subnets:
            counter = 0
            comma = 0
            if shared_counter > 0:
                cfg_file.write(',')
            cfg_file.write('{')

            for each_option in world.shared_subcfg[shared_counter]:
                cfg_file.write(each_option)
                last_option = each_option

            if last_option[:-1] != ",":
                cfg_file.write(",")

            if "kea6" in world.cfg["dhcp_under_test"]:
                cfg_file.write('"subnet6":[')

            elif "kea4" in world.cfg["dhcp_under_test"]:
                cfg_file.write('"subnet4":[')

            for each_subnet in world.subcfg:
                if counter in each_shared_subnet:
                    if counter > 0 and comma == 1:
                        cfg_file.write(",")
                    tmp = each_subnet[0]
                    # we need to be able to add interface-id to config but we want to keep backward compatibility.
                    # if "interface" not in tmp or "interface-id" not in tmp:
                    #     eth = world.f_cfg.server_iface
                    #     tmp += ', "interface": "{eth}" '.format(**locals())
                    counter += 1
                    comma = 1

                    for each_subnet_config_part in each_subnet[1:]:
                        if len(each_subnet_config_part) > 0:
                            tmp += ',' + each_subnet_config_part
                        # tmp += str(each_subnet[-1])
                    cfg_file.write(tmp + '}')
                else:
                    counter += 1
            # shared_counter += 1
            cfg_file.write(']')
            shared_counter += 1
            cfg_file.write('}')  # end of map of each shared network
        cfg_file.write(']')  # end of shared networks list

    cfg_file.write('}')  # end of DHCP part (should be moved if something else will be added after shared-networks

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)

    if "agent" in world.cfg:
        cfg_file.write(',' + world.cfg["agent"])
        del world.cfg["agent"]

    logging_file = os.path.join(world.f_cfg.software_install_path, 'var/kea/kea.log')

    log_type = ''
    if "kea6" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp6'
    elif "kea4" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp4'

    cfg_file.write(',"Logging": {"loggers": [')
    if "logger" not in world.cfg:
        cfg_file.write('{"name": "' + log_type + '","output_options": [{"output": "' + logging_file + '"}')
        cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
        if world.ddns_enable:
            cfg_file.write(',{"name": "kea-dhcp-ddns","output_options": [{"output": "' + logging_file + '_ddns"}')
            cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
    else:
        cfg_file.write(world.cfg["logger"])

    cfg_file.write(']}')
    cfg_file.write('}')  # end of the config file
    cfg_file.close()
    # kea ctrl script config file
    cfg_file = open(world.cfg["cfg_file_2"], 'w')
    cfg_file.write(world.cfg["keactrl"])
    cfg_file.close()
    world.subcfg = [["", "", "", "", "", "", ""]]
    config = open(world.cfg["cfg_file"], 'r')
    world.configString = config.read().replace('\n', '').replace(' ', '')
    config.close()
    add_variable("SERVER_CONFIG", world.configString, False)
    json_file_layout()
コード例 #5
0
ファイル: functions.py プロジェクト: deviousops/forge
def cfg_write():
    config_db_backend()
    for number in range(0, len(world.subcfg)):
        if len(world.subcfg[number][2]) > 10:
            world.subcfg[number][2] = '"option-data": [' + world.subcfg[number][2] + "]"
        if len(world.subcfg[number][4]) > 10:
            world.subcfg[number][4] = '"pools": [' + world.subcfg[number][4] + "]"
        if len(world.subcfg[number][5]) > 10:
            world.subcfg[number][5] = '"reservations":[' + world.subcfg[number][5] + "]"
    cfg_file = open(world.cfg["cfg_file"], 'w')
    ## add timers
    cfg_file.write(world.cfg["main"])
    ## add interfaces
    cfg_file.write('"interfaces-config": { "interfaces": [ ' + world.cfg["interfaces"] + ' ] },')
    ## add header for subnets
    if "kea6" in world.cfg["dhcp_under_test"]:
        cfg_file.write('"subnet6":[')
    elif "kea4" in world.cfg["dhcp_under_test"]:
        cfg_file.write('"subnet4":[')

    ## add subnets
    counter = 0
    for each_subnet in world.subcfg:
        tmp = each_subnet[0]
        counter += 1
        for each_subnet_config_part in each_subnet[1:]:
            if len(each_subnet_config_part) > 0:
                tmp += ',' + each_subnet_config_part
            #tmp += str(each_subnet[-1])
        cfg_file.write(tmp + '}')
        if counter != len(world.subcfg) and len(world.subcfg) > 1:
            cfg_file.write(",")
    cfg_file.write(']')

    if "options" in world.cfg:
        cfg_file.write(',' + world.cfg["options"])
        cfg_file.write("]")
        del world.cfg["options"]

    if "option_def" in world.cfg:
        cfg_file.write(',' + world.cfg["option_def"])
        cfg_file.write("]")
        del world.cfg["option_def"]

    if "hooks" in world.cfg:
        cfg_file.write(',"hooks-libraries": [' + world.cfg["hooks"] + ']')
        del world.cfg["hooks"]

    if "simple_options" in world.cfg:
        cfg_file.write(',' + world.cfg["simple_options"])
        del world.cfg["simple_options"]

    if world.ddns_enable:
        cfg_file.write(',' + world.ddns_add + '}')

    if "custom_lines" in world.cfg:
        cfg_file.write(',' + world.cfg["custom_lines"])
        #cfg_file.write("]")
        del world.cfg["custom_lines"]

    cfg_file.write('}')

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)
        #cfg_file.write("}")

    logging_file = SOFTWARE_INSTALL_DIR + 'var/kea/kea.log'

    log_type = ''
    if "kea6" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp6'
    elif "kea4" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp4'

    cfg_file.write(',"Logging": {"loggers": [')
    cfg_file.write('{"name": "' + log_type + '","output_options": [{"output": "' + logging_file + '",'
                   '"destination": "file"}')
    cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
    if world.ddns_enable:
        cfg_file.write(',{"name": "kea-dhcp-ddns.dhcpddns","output_options": [{"output": "' + logging_file + '_ddns",'
                       '"destination": "file"}')
        cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
    cfg_file.write(']}''')

    cfg_file.write('}')  # end of the config file
    cfg_file.close()
    # kea ctrl script config file
    cfg_file = open(world.cfg["cfg_file_2"], 'w')
    cfg_file.write(world.cfg["keactrl"])
    cfg_file.close()
    json_file_layout()
    world.subcfg = [["", "", "", "", "", ""]]
コード例 #6
0
ファイル: functions_new.py プロジェクト: stephb9959/forge
def cfg_write():
    config_db_backend()
    for number in range(0, len(world.subcfg)):
        if len(world.subcfg[number][2]) > 10:
            world.subcfg[number][
                2] = '"option-data": [' + world.subcfg[number][2] + "]"
        if len(world.subcfg[number][4]) > 10:
            world.subcfg[number][
                4] = '"pools": [' + world.subcfg[number][4] + "]"
        if len(world.subcfg[number][5]) > 10:
            world.subcfg[number][
                5] = '"reservations":[' + world.subcfg[number][5] + "]"
    cfg_file = open(world.cfg["cfg_file"], 'w')
    ## add timers
    cfg_file.write(world.cfg["main"])
    if len(world.cfg["server-id"]) > 5:
        cfg_file.write(world.cfg["server-id"])
    ## add interfaces
    cfg_file.write('"interfaces-config": { "interfaces": [ ' +
                   world.cfg["interfaces"] + ' ] },')
    ## add header for subnets
    if world.subnet_add:
        if "kea6" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet6":[')
        elif "kea4" in world.cfg["dhcp_under_test"]:
            cfg_file.write('"subnet4":[')

        ## add subnets
        counter = 0
        for each_subnet in world.subcfg:
            tmp = each_subnet[0]
            # we need to be able to add interface-id to config but we want to keep backward compatibility.
            if "interface" not in tmp or "interface-id" not in tmp:
                eth = world.f_cfg.server_iface
                tmp += ', "interface": "{eth}" '.format(**locals())
            counter += 1
            for each_subnet_config_part in each_subnet[1:]:
                if len(each_subnet_config_part) > 0:
                    tmp += ',' + each_subnet_config_part
                #tmp += str(each_subnet[-1])
            cfg_file.write(tmp + '}')
            if counter != len(world.subcfg) and len(world.subcfg) > 1:
                cfg_file.write(",")
        cfg_file.write(']')
        #that is ugly hack but kea confing generation is awaiting rebuild anyway
        if "options" in world.cfg:
            cfg_file.write(',' + world.cfg["options"])
            cfg_file.write("]")
            del world.cfg["options"]

    if "options" in world.cfg:
        cfg_file.write(world.cfg["options"])
        cfg_file.write("]")
        del world.cfg["options"]

    if "option_def" in world.cfg:
        cfg_file.write(',' + world.cfg["option_def"])
        cfg_file.write("]")
        del world.cfg["option_def"]

    if "hooks" in world.cfg:
        cfg_file.write(',"hooks-libraries": [' + world.cfg["hooks"] + ']')
        del world.cfg["hooks"]

    if "simple_options" in world.cfg:
        cfg_file.write(',' + world.cfg["simple_options"])
        del world.cfg["simple_options"]

    if world.ddns_enable:
        cfg_file.write(',' + world.ddns_add + '}')

    if "custom_lines" in world.cfg:
        cfg_file.write(',' + world.cfg["custom_lines"])
        #cfg_file.write("]")
        del world.cfg["custom_lines"]

    if "socket" in world.cfg:
        cfg_file.write(',' + world.cfg["socket"])
        del world.cfg["socket"]

    cfg_file.write('}')

    if world.ddns_enable:
        build_ddns_config()
        cfg_file.write(world.ddns)
        #cfg_file.write("}")

    if "agent" in world.cfg:
        cfg_file.write(',' + world.cfg["agent"])
        del world.cfg["agent"]

    logging_file = world.f_cfg.software_install_path + 'var/kea/kea.log'

    log_type = ''
    if "kea6" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp6'
    elif "kea4" in world.cfg["dhcp_under_test"]:
        log_type = 'kea-dhcp4'

    cfg_file.write(',"Logging": {"loggers": [')
    if not "logger" in world.cfg:
        cfg_file.write('{"name": "' + log_type +
                       '","output_options": [{"output": "' + logging_file +
                       '"}')
        cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
        if world.ddns_enable:
            cfg_file.write(
                ',{"name": "kea-dhcp-ddns","output_options": [{"output": "' +
                logging_file + '_ddns"}')
            cfg_file.write('],"debuglevel": 99,"severity": "DEBUG"}')
    else:
        cfg_file.write(world.cfg["logger"])

    cfg_file.write(']}')
    cfg_file.write('}')  # end of the config file
    cfg_file.close()
    # kea ctrl script config file
    cfg_file = open(world.cfg["cfg_file_2"], 'w')
    cfg_file.write(world.cfg["keactrl"])
    cfg_file.close()
    world.subcfg = [["", "", "", "", "", "", ""]]
    config = open(world.cfg["cfg_file"], 'r')
    world.configString = config.read().replace('\n', '').replace(' ', '')
    config.close()
    add_variable("SERVER_CONFIG", world.configString, False)
    json_file_layout()