Esempio n. 1
0
def getIPS():
    """
    Prompts to enter SID/location of IPS.
    """
    while True:
        try:
            ips = input("Enter the IPS ID: ").lower().strip()
            if NWdevice(ips).is_ips():
                ips = NWdevice(ips)
                break
            else:
                print("ERROR: SERVICE ID INVALID\n")
        except AttributeError:
            print('ERROR: SERVICE ID INVALID\n')
    while True:
        try:
            ipsloc = Loccode(input("Enter the location code of "+ips+": "))
            if ipsloc.is_NWloc():
                if ipsloc.site == ips.site():
                    break
                else:
                    print('ERROR: SITE MISMATCH DETECTED\n')
            else:
                print("ERROR: INVALID LOCATION\n")
        except AttributeError:
            print("ERROR: INVALID LOCATION\n")
    return [ips,ipsloc]
Esempio n. 2
0
def getDevices(devicetype):
    """
    devicetype must be either 'firewall' or 'loadbalancer.'
    Prompts to enter SIDs/speed/locations of Stand-alone gear & IPS (w/ their error handlings).
    Only accepts the devicetype you specify.
    Returns the provided data as a list for use in main().
    
    nwdevice = newtwork device ID (firewall or loadbalancer)
    speed = 1000 or 100 (int)
    nwdeviceloc = network device location
    ips = IPS ID or 'none'
    """
    while True:
        try:
            nwdevice = NWdevice(input("Enter the "+devicetype+" ID: ").lower().strip())
            if nwdevice.is_fw_or_lb(devicetype) and nwdevice.is_solo():
                break
            else:
                print("ERROR: SERVICE ID INVALID\n")
        except AttributeError:
            print('ERROR: SERVICE ID INVALID\n')
    while devicetype == 'firewall':
        try:
            speed = input('Enter the interface speed (Mbps)[1000]: ').strip() or '1000'
            if not re.match(r"^10{2,3}$",speed):
                print('ERROR: DATA INVALID')
            else:
                print('OK - speed = '+speed+'Mbps')
                break
        except ValueError:
            print('ERROR: DATA INVALID')
    speed = speed if devicetype == 'firewall' else '1000'
    while True:
        try:
            nwdeviceloc = Loccode(input("Enter the location code of "+nwdevice+": "))
            if nwdeviceloc.is_NWloc():
                if nwdeviceloc.site == nwdevice.site():
                    break
                else:
                    print('ERROR: SITE MISMATCH DETECTED\n')
            else:
                print("ERROR: INVALID LOCATION FOR MASTER\n")
        except AttributeError:
            print("ERROR: INVALID LOCATION\n")
    while True:
        try:
            ips = input("Enter an IPS ID that monitors the "+devicetype+" segment(s), or type 'none': ").lower().strip().replace("'","")

            if ips == 'none' or NWdevice(ips).is_ips():
                break
            else:
                print('ERROR: INVALID SID FORMAT\n')
        except AttributeError:
            print('ERROR: SERVICE ID INVALID\n')
    if ips != 'none':
        while True:
            try:
                ipsloc = Loccode(input("Enter the location code of "+ips+": "))
                if ipsloc.is_NWloc() and (nwdeviceloc.srr == ipsloc.srr and nwdeviceloc.rack_noa == ipsloc.rack_noa) and nwdeviceloc != ipsloc:
                    print("OK")
                    break
                elif nwdeviceloc == ipsloc:
                    print("ERROR: The "+devicetype+" and IPS cannot take the same slot!\n")
                elif not (nwdeviceloc.srr == ipsloc.srr and nwdeviceloc.rack_noa == ipsloc.rack_noa):
                    print("ERROR: The "+devicetype+" and IPS must be in the same rack\n")
                else:
                    print("ERROR: INVALID LOCATION\n")
            except AttributeError:
                print("ERROR: SYNTAX INVALID\n")
    else:
        ipsloc = ''
        print("OK no IPS!")
    return [nwdevice,speed,nwdeviceloc,ips,ipsloc]
Esempio n. 3
0
def getHAdevices(devicetype):
    """
    devicetype must be either 'firewall' or 'loadbalancer.'
    Prompts to enter SIDs/speed/locations of HA pair & IPS (w/ their error handlings).
    Only accepts the devicetype you specify.
    Returns the provided data as a list for use in main().
    
    mfw = master device ID (firewall or loadbalancer)
    speed = 1000 or 100 (int)
    mfwloc = master device location
    sfw = secondary device ID (firewall or loadbalancer)
    sfwloc = secondary device location
    ips = IPS ID or 'none'
    """
    #import re
    #from networksid import NWdevice
    #from locationcode import Loccode
    while True:
        try:
            mfw = input("Enter the master "+devicetype+" ID: ").lower().strip()
            if NWdevice(mfw).is_master() and NWdevice(mfw).is_fw_or_lb(devicetype):
                mfw = NWdevice(mfw)
                break
            else:
                print("ERROR: SERVICE ID INVALID\n")
        except AttributeError:
            print('ERROR: SERVICE ID INVALID\n')
    while devicetype == 'firewall':
        try:
            speed = input('Enter the interface speed (Mbps)[1000]: ').strip() or '1000'
            if not re.match(r"^10{2,3}$",speed):
                print('ERROR: DATA INVALID')
            else:
                print('OK - speed = '+speed+'Mbps')
                break
        except ValueError:
            print('ERROR: DATA INVALID')
    speed = speed if devicetype == 'firewall' else '1000'
    while True:
        try:
            mfwloc = Loccode(input("Enter the location code of "+mfw+": "))
            if mfwloc.is_masterloc():
                if mfwloc.site == mfw.site():
                    break
                else:
                    print('ERROR: SITE MISMATCH DETECTED\n')
            else:
                print("ERROR: INVALID LOCATION FOR MASTER\n")
        except AttributeError:
            print("ERROR: INVALID LOCATION\n")
    while True:
        try:
            sfw = mfw.peersid()
            break
        except UnboundLocalError:
            print('\nThis case requires you to provide a secondary '+devicetype+' ID manually.')
            sfw = input('Enter the secondary '+devicetype+' ID: ').lower().strip()
            if re.match(r"^(netsvc)+(\d{5})$", sfw) and NWdevice(sfw) != mfw:
                break
            elif re.match(r"^(netsvc)+(\d{5})$", sfw) and NWdevice(sfw) == mfw:
                print('ERROR: Master and secondary cannot share the same ID!')
    sfwloc = mfwloc.peerloc()
    print('OK')
    print("The location of secondary "+sfw+" is {0}.".format(sfwloc))
    while True:
        try:
            ips = input("Enter an IPS ID that goes to the master segment, or type 'none': ").lower().strip().replace("'","")

            if ips == 'none' or NWdevice(ips).is_ips():
                break
            else:
                print('ERROR: INVALID SID FORMAT\n')
        except AttributeError:
            print('ERROR: SERVICE ID INVALID\n')
    if ips != 'none':
        while True:
            try:
                ipsloc = Loccode(input("Enter the location code of "+ips+": "))
                if ipsloc.is_NWloc() and (mfwloc.srr == ipsloc.srr and mfwloc.rack_noa == ipsloc.rack_noa) and mfwloc != ipsloc:
                    print("OK")
                    break
                elif mfwloc == ipsloc:
                    print("ERROR: Master "+devicetype+" and IPS cannot take the same slot!\n")
                elif not (mfwloc.srr == ipsloc.srr and mfwloc.rack_noa == ipsloc.rack_noa):
                    print("ERROR: Master "+devicetype+" and IPS must be in the same rack\n")
                else:
                    print("ERROR: INVALID LOCATION\n")
            except AttributeError:
                print("ERROR: SYNTAX INVALID\n")
    else:
        ipsloc = ''
        print("OK no IPS!")
    return [mfw,speed,mfwloc,sfw,sfwloc,ips,ipsloc]