Beispiel #1
0
def refresh_if_config(ip, mask, gw, dns, type):
    logging.basicConfig()
    logger = logging.getLogger(get_server_logging_name())
    logger.setLevel(logging.DEBUG)
    logger.debug("Attempting to refresh if configuration of the host")
    do_persist = False  # flag indicate that the configuration should be persisted

    try:
        logger.debug("Retrieving current ip configuration")
        default_if = route.get_default_if()
        eth = Interface(default_if)
        current_ip = eth.get_ip()
        current_gw = route.get_default_gw()

        # handling ip modification
        if current_ip != ip:
            logger.debug("Need to update the ip address of the default network interface [%s]" % (default_if))
            # eth.set_ip(ip)
            do_persist = True
        else:
            logger.debug("No need to update configuration of the interface")

        # handling mask modification
        tmp_mask = IPAddress(mask)
        requested_mask = int(tmp_mask)
        if requested_mask != eth.get_netmask():
            logger.debug("Need to update the netmask")
            # eth.set_netmask(requested_mask)
            do_persist = True
        else:
            logger.debug("No need to update netmask configuration")

        # persist if necessary
        if do_persist:
            logger.debug("Persisting configuration ...")
            new_config = {}
            new_config["eth"] = default_if
            new_config["ip"] = ip
            new_config["mask"] = mask
            new_config["dns"] = dns
            new_config["gw"] = current_gw
            new_config["type"] = type  # type of configuration (static or dynamic)

            # TODO : need to check the distrib to choose the right method to persist data
            persist_config_debian_like(new_config)
            logger.debug("Network interface configuration successfully updated")
            restart_network(default_if)
        else:
            logger.debug("No need to persist the configuration")

    except Exception, ex:
        logger.error("Unable to refresh if configuration [%s]" % (ex))
Beispiel #2
0
	fhdl = open('/etc/simkiosk/url.conf', 'r')
	old_url = fhdl.readline()
	fhdl.close()
	return old_url

def format_netmask(ip_str, netmask_int):
    try :
        plain_ip = "%s/%s" % (ip_str,  netmask_int)
        ip = IPNetwork(plain_ip)
        return str(ip.netmask)
    except Exception :
        return '0.0.0.0'

try :
    default_if = route.get_default_if();
    eth0 = Interface(default_if)
    ip = eth0.get_ip()
    mask = format_netmask(ip, eth0.get_netmask())
    gw = route.get_default_gw()
except Exception :
    ip = '0.0.0.0'
    mask = '0.0.0.0'
    gw = '0.0.0.0'

resolver = Resolver()
# load only the first dns but we may have up to 3 entries
dns = resolver.nameservers[0]
url = get_old_url()
response = { 'statusCode' : 0, 'statusMessage' : 'SUCCESS', 'body' : { 'ip' : ip, 'mask' : mask, 'gw' : gw, 'dns' : dns, 'url' : url.rstrip('\n') ,  'message' :  'Configuration successfully loaded' } }

# after processing sending back response as json ...