#!/usr/bin/env python

from mixcoatl.network.network import Network
import argparse
import sys

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--networkid', '-i', type=int, help='Network ID')
    parser.add_argument('--reason', '-r', help='The reason for deleting the network.')

    cmd_args = parser.parse_args()

    if cmd_args.networkid is None:
        parser.print_help()
        sys.exit(1)

    network = Network(cmd_args.networkid)

    if network.load() is not None:
        print("Cannot find the network.")
        sys.exit(1)

    if cmd_args.reason:
        result = network.destroy(reason=cmd_args.reason)
    else:
        result = network.destroy()

    if isinstance(result, dict):
        print(result['jobs'][0]['jobId'])
    elif isinstance(result, unicode):
        print(result)
        sys.exit(1)
