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

import urwid
import urwid.raw_display
import urwid.web_display
import logging
import sys
import re
import copy
import socket
import struct
import netaddr
import dhcp_checker.api
import netifaces
import subprocess
from fuelmenu.settings import *
from fuelmenu.common import network, puppet, replace, nailyfactersettings, \
    dialog
from fuelmenu.common.urwidwrapper import *
log = logging.getLogger('fuelmenu.pxe_setup')
blank = urwid.Divider()

#Need to define fields in order so it will render correctly
#fields = ["hostname", "domain", "mgmt_if","dhcp_start","dhcp_end",
#          "blank","ext_if","ext_dns"]
fields = ["static_label",
          "ADMIN_NETWORK/static_pool_start", "ADMIN_NETWORK/static_pool_end",
          "blank", "dynamic_label", "ADMIN_NETWORK/dhcp_pool_start",
          "ADMIN_NETWORK/dhcp_pool_end"]
facter_translate = {
    "ADMIN_NETWORK/interface":     "internal_interface",
    "ADMIN_NETWORK/ipaddress":        "internal_ipaddress",
    "ADMIN_NETWORK/netmask":       "internal_netmask",
    "ADMIN_NETWORK/dhcp_pool_start":         "dhcp_pool_start",
    "ADMIN_NETWORK/dhcp_pool_end":          "dhcp_pool_end",
    "ADMIN_NETWORK/static_pool_start":  "static_pool_start",
    "ADMIN_NETWORK/static_pool_end":    "static_pool_end",
}

DEFAULTS = {
    "ADMIN_NETWORK/dhcp_pool_start": {"label": "DHCP Pool Start",
                                      "tooltip": "Used for defining IPs for \
hosts and instance public addresses",
                                      "value":   "10.0.0.130"},
    "ADMIN_NETWORK/dhcp_pool_end": {"label": "DHCP Pool End",
                                    "tooltip": "Used for defining IPs for \
hosts and instance public addresses",
                                    "value":  "10.0.0.254"},
    "static_label": {"label": "Static pool for installed nodes:",
                     "tooltip": "",
                     "value":   "label"},
    "ADMIN_NETWORK/static_pool_start": {"label": "Static Pool Start",
                                        "tooltip": "Static pool for installed \
nodes",
                                        "value":   "10.0.0.10"},
    "ADMIN_NETWORK/static_pool_end": {"label": "Static Pool End",
                                      "tooltip": "Static pool for installed \
nodes",
                                      "value":   "10.0.0.120"},
    "dynamic_label": {"label": "DHCP pool for node discovery:",
                      "tooltip": "",
                      "value":   "label"},
    #"ADMIN_NETWORK/dynamic_start" : { "label"  : "Static Pool Start",
    #                 "tooltip": "DHCP pool for node discovery",
    #                 "value"  : "10.0.0.10"},
    #"ADMIN_NETWORK/dynamic_end": { "label"  : "Static Pool End",
    #                 "tooltip": "DHCP pool for node discovery",
    #                 "value"  : "10.0.0.120"},
}


class cobblerconf(urwid.WidgetWrap):
    def __init__(self, parent):
        self.name = "PXE Setup"
        self.priority = 20
        self.visible = True
        self.netsettings = dict()
        self.parent = parent
        self.deployment = "pre"
        self.getNetwork()
        self.gateway = self.get_default_gateway_linux()
        self.activeiface = sorted(self.netsettings.keys())[0]
        self.parent.managediface = self.activeiface
        self.extdhcp = True
        self.oldsettings = self.load()
        self.screen = None

    def check(self, args):
        """Validates all fields have valid values and some sanity checks"""
        self.parent.footer.set_text("Checking data...")
        self.parent.refreshScreen()

        #Get field information
        responses = dict()

        for index, fieldname in enumerate(fields):
            if fieldname == "blank" or "label" in fieldname:
                pass
            else:
                responses[fieldname] = self.edits[index].get_edit_text()

        ###Validate each field
        errors = []

        #Set internal_{ipaddress,netmask,interface}
        responses["ADMIN_NETWORK/interface"] = self.activeiface
        responses["ADMIN_NETWORK/netmask"] = self.netsettings[
            self.activeiface]["netmask"]
        responses["ADMIN_NETWORK/ipaddr"] = self.netsettings[
            self.activeiface]["addr"]

        #ensure management interface is valid
        if responses["ADMIN_NETWORK/interface"] not in self.netsettings.keys():
            errors.append("Management interface not valid")
        else:
            self.parent.footer.set_text("Scanning for DHCP servers. \
Please wait...")
            self.parent.refreshScreen()

            ###Start DHCP check on this interface
            #dhcp_server_data=[{'server_id': '192.168.200.2', 'iface': 'eth2',
            #                   'yiaddr': '192.168.200.15', 'mac':
            #                '52:54:00:12:35:02', 'server_ip': '192.168.200.2',
            #                   'dport': 67, 'message': 'offer',
            #                   'gateway': '0.0.0.0'}]
            dhcp_server_data = dhcp_checker.api.check_dhcp_on_eth(
                self.activeiface, timeout=5)

            num_dhcp = len(dhcp_server_data)
            if num_dhcp == 0:
                log.debug("No DHCP servers found")
            else:
                #Problem exists, but permit user to continue
                log.error("%s foreign DHCP server(s) found: %s" %<commit_msg>fix yaml entry for ipaddress<commit_after>#!/usr/bin/env python

import urwid
import urwid.raw_display
import urwid.web_display
import logging
import sys
import re
import copy
import socket
import struct
import netaddr
import dhcp_checker.api
import netifaces
import subprocess
from fuelmenu.settings import *
from fuelmenu.common import network, puppet, replace, nailyfactersettings, \
    dialog
from fuelmenu.common.urwidwrapper import *
log = logging.getLogger('fuelmenu.pxe_setup')
blank = urwid.Divider()

#Need to define fields in order so it will render correctly
#fields = ["hostname", "domain", "mgmt_if","dhcp_start","dhcp_end",
#          "blank","ext_if","ext_dns"]
fields = ["static_label",
          "ADMIN_NETWORK/static_pool_start", "ADMIN_NETWORK/static_pool_end",
          "blank", "dynamic_label", "ADMIN_NETWORK/dhcp_pool_start",
          "ADMIN_NETWORK/dhcp_pool_end"]
facter_translate = {
    "ADMIN_NETWORK/interface":     "internal_interface",
    "ADMIN_NETWORK/ipaddress":        "internal_ipaddress",
    "ADMIN_NETWORK/netmask":       "internal_netmask",
    "ADMIN_NETWORK/dhcp_pool_start":         "dhcp_pool_start",
    "ADMIN_NETWORK/dhcp_pool_end":          "dhcp_pool_end",
    "ADMIN_NETWORK/static_pool_start":  "static_pool_start",
    "ADMIN_NETWORK/static_pool_end":    "static_pool_end",
}

DEFAULTS = {
    "ADMIN_NETWORK/dhcp_pool_start": {"label": "DHCP Pool Start",
                                      "tooltip": "Used for defining IPs for \
hosts and instance public addresses",
                                      "value":   "10.0.0.130"},
    "ADMIN_NETWORK/dhcp_pool_end": {"label": "DHCP Pool End",
                                    "tooltip": "Used for defining IPs for \
hosts and instance public addresses",
                                    "value":  "10.0.0.254"},
    "static_label": {"label": "Static pool for installed nodes:",
                     "tooltip": "",
                     "value":   "label"},
    "ADMIN_NETWORK/static_pool_start": {"label": "Static Pool Start",
                                        "tooltip": "Static pool for installed \
nodes",
                                        "value":   "10.0.0.10"},
    "ADMIN_NETWORK/static_pool_end": {"label": "Static Pool End",
                                      "tooltip": "Static pool for installed \
nodes",
                                      "value":   "10.0.0.120"},
    "dynamic_label": {"label": "DHCP pool for node discovery:",
                      "tooltip": "",
                      "value":   "label"},
    #"ADMIN_NETWORK/dynamic_start" : { "label"  : "Static Pool Start",
    #                 "tooltip": "DHCP pool for node discovery",
    #                 "value"  : "10.0.0.10"},
    #"ADMIN_NETWORK/dynamic_end": { "label"  : "Static Pool End",
    #                 "tooltip": "DHCP pool for node discovery",
    #                 "value"  : "10.0.0.120"},
}


class cobblerconf(urwid.WidgetWrap):
    def __init__(self, parent):
        self.name = "PXE Setup"
        self.priority = 20
        self.visible = True
        self.netsettings = dict()
        self.parent = parent
        self.deployment = "pre"
        self.getNetwork()
        self.gateway = self.get_default_gateway_linux()
        self.activeiface = sorted(self.netsettings.keys())[0]
        self.parent.managediface = self.activeiface
        self.extdhcp = True
        self.oldsettings = self.load()
        self.screen = None

    def check(self, args):
        """Validates all fields have valid values and some sanity checks"""
        self.parent.footer.set_text("Checking data...")
        self.parent.refreshScreen()

        #Get field information
        responses = dict()

        for index, fieldname in enumerate(fields):
            if fieldname == "blank" or "label" in fieldname:
                pass
            else:
                responses[fieldname] = self.edits[index].get_edit_text()

        ###Validate each field
        errors = []

        #Set internal_{ipaddress,netmask,interface}
        responses["ADMIN_NETWORK/interface"] = self.activeiface
        responses["ADMIN_NETWORK/netmask"] = self.netsettings[
            self.activeiface]["netmask"]
        responses["ADMIN_NETWORK/ipaddress"] = self.netsettings[
            self.activeiface]["addr"]

        #ensure management interface is valid
        if responses["ADMIN_NETWORK/interface"] not in self.netsettings.keys():
            errors.append("Management interface not valid")
        else:
            self.parent.footer.set_text("Scanning for DHCP servers. \
Please wait...")
            self.parent.refreshScreen()

            ###Start DHCP check on this interface
            #dhcp_server_data=[{'server_id': '192.168.200.2', 'iface': 'eth2',
            #                   'yiaddr': '192.168.200.15', 'mac':
            #                '52:54:00:12:35:02', 'server_ip': '192.168.200.2',
            #                   'dport': 67, 'message': 'offer',
            #                   'gateway': '0.0.0.0'}]
            dhcp_server_data = dhcp_checker.api.check_dhcp_on_eth(
                self.activeiface, timeout=5)

            num_dhcp = len(dhcp_server_data)
            if num_dhcp == 0:
                log.debug("No DHCP servers found")
            else:
                #Problem exists, but permit user to continue
                log.error("%s foreign DHCP server(s) found: %s" %
{'fraction_non_alphanumeric': 0.12105554530356154, 'fraction_numerical': 0.0175309097619487, 'mean_word_length': 2.0609997175939, 'pattern_counts': {'":': 68, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 20, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5701512', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3131, 'n_words': 698}