Пример #1
0
def toggle_device(mac, ip, enabled):
    from apate_redis import ApateRedis
    if not check_ip(ip) or not check_mac(mac):
        return 27

    try:
        with open(CONFIG_FILE) as config:
            data = json.load(config)
    except ValueError as ve:
        print "Could not parse the configuration file"
        print str(ve)
        return 28
    except IOError as ioe:
        print "An error occurred while trying to open the configuration file"
        print str(ioe)
        return 29

    if 'interface' not in data:
        print "The configuration file does not include all necessary options"
        return 30

    network = get_network(data['interface'], check_ip(ip))
    if not network:
        return 31

    try:
        redis = ApateRedis(network, logging.getLogger('config'))
        if enabled:
            redis.enable_device(mac, ip, network)
        else:
            redis.disable_device(mac, ip, network)
    except:
        return 32

    return 0