#!/usr/bin/env python

import json
import os
import re
import sys
import shlex
import string
import ipaddress
# WANT_JSON

# Regular expressions to identify comments and blank lines
comment = re.compile("^\s*#")
blank = re.compile("^\s*$")

#####
# Parsers
#
# Parses are methods that take the form 'parse_<keyword>', where the keyword
# is the first word on a line in file. The purpose of the parser is to
# evaluate the line tna update the interface model accordingly.
####

# Compares the current and desired network configuration to see if there
# is a change and returns:
# 0 if no change
# -1 if the change has no semantic value (i.e. comments differ)
# 1 if there is a semantic change (i.e. its meaningful)
# the highest priority of change is returned, i.e. if there is both
# a semantic and non-semantic change a 1 is returned indicating a
# semantic change.
def value_equal(left, right):
    if type(left) == type(right):
        return left == right
    return str(left) == str(right)

def compare(have, want):
    result = 0
    for key in list(set().union(have.keys(), want.keys())):
        if key in have.keys() and key in want.keys():
            if not value_equal(have[key], want[key]):
                if key in ["description"]:
                    result = -1
                else:
                    return 1
        else:
            if key in ["description"]:
                result = -1
            else:
                return 1
    return result

# Creates an interface definition in the model and sets the auto
# configuration to true
def parse_auto(data, current, words, description):
    if words[1] in data.keys():
        iface = data[words[1]]
    else:
        iface = {}

    if len(description) > 0:
        iface["description"] = description

    iface["auto"] = True
    data[words[1]] = iface
    return words[1]

# Creates an interface definition in the model if one does not exist and
# sets the type and configuation method
def parse_iface(data, current, words, description):
    if words[1] in data.keys():
        iface = data[words[1]]
    else:
        iface = {}

    if len(description) > 0:
        iface["description"] = description

    iface["type"] = words[2]
    iface["config"] = words[3]
    data[words[1]] = iface
    return words[1]

allow_lists = ["pre-up", "post-up", "pre-down", "post-down"]

# Used to evaluate attributes and add a generic name / value pair to the interface
# model
def parse_add_attr(data, current, words, description):
    global allow_lists
    if current == "":
        raise SyntaxError("Attempt to add attribute '%s' without an interface" % words[0])

    if current in data.keys():
        iface = data[current]
    else:
        iface = {}

    if len(description) > 0:
        iface["description"] = description

    if words[0] in iface and words[0] in allow_lists:
        have = iface[words[0]]
        if type(have) is list:
            iface[words[0]].append(" ".join(words[1:]))
        else:
            iface[words[0]] = [have, " ".join(words[1:])]
    else:
        iface[words[0]] = " ".join(words[1:])

    data[current] = iface
    return current

#####
# Writers
#
# Writers take the form of 'write_<keyword>` where keyword is an interface
# attribute. The role of the writer is to output the attribute to the
# output stream, i.e. the new interface file.
#####

# Writes a generic name / value pair indented
def write_attr(out, name, value):
    if isinstance(value, list):
        for line in value:
            out.write("  %s %s\n" % (name, line))
    else:
        out.write("  %s %s\n" % (name, value))

# Writes an interface definition to the output stream
def write_iface(out, name, iface):
    if "description" in iface.keys():
        val = iface["description"]
        if len(val) > 0 and val[0] != "#":
            val = "# " + val
        out.write("%s\n" % (val))
    if "auto" in iface.keys() and iface["auto"]:
        out.write("auto %s\n" % (name))
    out.write("iface %s %s %s\n" % (name, iface["type"], iface["config"]))
    for attr in sorted(iface.keys(), key=lambda x:x in write_sort_order.keys() and write_sort_order[x] or 100):
        if attr in write_ignore:
            continue
        writer = "write_%s" % (attr)
        if writer in all_methods:
            globals()[writer](out, attr, iface[attr])
        else:
            write_attr(out, attr, iface[attr])
    out.write("\n")

# Writes the new interface file
def write(out, data):
#    out.write("# This file describes the network interfaces available on your system\n")
#    out.write("# and how to activate them. For more information, see interfaces(5).\n\n")
    # First to loopback
    for name, iface in data.items():
        if iface["config"] != "loopback":
            continue
        write_iface(out, name, iface)

    for iface in sorted(data.keys(), key=lambda x:x in write_iface_sort_order.keys() and write_iface_sort_order[x] or x):
        if data[iface]["config"] == "loopback":
            continue
        write_iface(out, iface, data[iface])

# The defaults for the netfile task
src_file = "/etc/network/interfaces"
dest_file = None
merge_comments = False
state = "present"
name = ""
force = False
values = {
    "config": "manual",
    "type": "inet"
}

# read the argument string from the arguments file
args_file = sys.argv[1]
args_data = file(args_file).read()

# parse the task options
arguments = json.loads(args_data)
for key, value in arguments.iteritems():
    if key == "src":
        src_file = value
    elif key == "dest":
        dest_file = value
    elif key == "name":
        name = value
    elif key == "state":
        state = value
    elif key == "force":
        force = value.lower() in ['true', 't', 'yes', 'y']
    elif key == "description":
        values["description"] = value
    elif key == "merge-comments":
        merge_comments = value.lower() in ['true', 't', 'yes', 'y']
    elif key == "address":
        if string.find(value, "/") != -1:
            parts = value.split('/')
            addr = ipaddress.ip_network(value, strict=False)
            values["address"] = parts[0]
            values["network"] = addr.network_address.exploded.encode('ascii','ignore')
            values["netmask"] = addr.netmask.exploded.encode('ascii','ignore')
            values["broadcast"] = addr.broadcast_address.exploded.encode('ascii','ignore')
        else:
            values["address"] = value
    elif key[0] != '_':
        values[key] = value

# If name is not set we need to error out
if name == "":
    result = {
        "changed": False,
        "failed": True,
        "msg": "Name is a mansitory parameter",
    }
    print json.dumps(result)
    sys.stdout.flush()
    exit(1)

# If no destination file was specified, write it back to the same file
if not dest_file:
    dest_file = src_file

# all methods is used to check if parser or writer methods exist
all_methods = dir()

# which attributes should be ignored and not be written as single
# attributes values against and interface
write_ignore = ["auto", "type", "config", "description"]

# specifies the order in which attributes are written against an
# interface. Any attribute note in this list is sorted by default
# order after the attributes specified.
write_sort_order = {
    "address"   :  1,
    "network"   :  2,
    "netmask"   :  3,
    "broadcast" :  4,
    "gateway"   :  5,
    "pre-up"    : 10,
    "post-up"   : 11,
    "pre-down"  : 12,
    "post-down" : 13
}

write_iface_sort_order = {
    "fabric" : "y",
    "mgmtbr" : "z"
}

# Read and parse the specified interface file
file = open(src_file, "r")
ifaces = {}
current = "" # The current interface being parsed
description = ""
for line in file.readlines():
    line = line.rstrip('\n')

    if comment.match(line):
        if len(description) > 0:
            description = description + '\n' + line
        else:
            description = line

    if len(description) > 0 and blank.match(line):
        description = description + '\n'

    # Drop any comment of blank line
    if comment.match(line) or blank.match(line):
        continue

    # Parse the line
    words = line.split()
    parser = "parse_" + words[0].replace("-", "_")
    if parser in all_methods:
        current = globals()[parser](ifaces, current, words, description)
    else:
        current = parse_add_attr(ifaces, current, words, description)

    description = ""

file.close()

# Assume no change unless we discover otherwise
result = {
    "changed" : False
}
change_type = 0

# if the interface specified and state is present then either add
# it to the model or replace it if it already exists.
if state == "query":
    if name in ifaces.keys():
        result["interface"] = ifaces[name]
        result["found"] = True
    else:
        result["found"] = False
elif state == "present":
    if name in ifaces.keys():
        have = ifaces[name]
        change_type = compare(have, values)
        result["change_type"] = change_type
        if change_type != 0:
            ifaces[name] = values
            if merge_comments and "description" in have.keys() and len(have["description"]) > 0:
                result["merge_comments"] = True
                if "description" in values.keys() and len(values["description"]) > 0:
                    ifaces[name]["description"] = values["description"] + "\n" + have["description"]
                else:
                    ifaces[name]["description"] = have["description"]
            result["changed"] = (change_type == 1)
    else:
        ifaces[name] = values
        result["changed"] = True


# if state is absent then remove it from the model
elif state == "absent" and name in ifaces.keys():
    del ifaces[name]
    result["changed"] = True

# Only write the output file if something has changed or if the
# task requests a forced write.
if force or result["changed"] or change_type != 0:
    file = open(dest_file, "w+")
    write(file, ifaces)
    file.close()

# Output the task result
print json.dumps(result)
