#!/usr/bin/python
import sys,argparse,json,time,yaml
import re

def GetArgs():
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('--server', '-s', type=str, action='store')
    parser.add_argument('--vCenter', '-v', type=str, action='store')
    return (parser.parse_args())

args = GetArgs()

with open("./exemptions.yml", "r") as exemptionJobData:
    try:
        exemptionJobData = yaml.load(exemptionJobData, Loader=yaml.FullLoader)
    except:
        print("Unable to load exemptions file.")

    exemptServers = []

    for i in exemptionJobData:
        for e in exemptionJobData[i]['vms']:
            exemptServers.append([exemptionJobData[i]['id'],e.lower()])

    for entry in exemptServers:
        parent = entry[0]
        pattern = entry[1]

        if (parent == int(args.vCenter) and re.search(pattern, args.server)):
            print("Found match with pattern: " + pattern)
