def process_all_zones(session):
    current_defined = pyfos_zone.defined_configuration.get(session)
    current_effective = pyfos_zone.effective_configuration.get(session)

    ns_attributes = pyfos_name_server.fibrechannel_name_server.get(
        session, None)

    hanging_zones = []
    online_zones = []
    current_zones = current_defined.peek_zone()
    for zone in current_zones:
        online_device = 0
        # checking to see if the zone needs to be skipped because it is part
        # of special zones such as TI Zones, RD Zones, etc.
        if zone_to_be_filtered(zone["zone-name"], current_defined):
            online_zones.append(zone["zone-name"])
            continue

        for entry_name in zone["member-entry"]["entry-name"]:
            if pyfos_util.isWWN(entry_name):
                if online_in_name_server_by_wwn(ns_attributes, entry_name):
                    online_device = online_device + 1
            elif pyfos_util.isDCommaI(entry_name):
                if online_in_name_server_by_dcommai(ns_attributes, entry_name):
                    online_device = online_device + 1
            else:
                if online_in_name_server_by_alias(current_defined,
                                                  ns_attributes, entry_name):
                    online_device = online_device + 1
        for entry_name in zone["member-entry"]["principal-entry-name"]:
            if pyfos_util.isWWN(entry_name):
                if online_in_name_server_by_wwn(ns_attributes, entry_name):
                    online_device = online_device + 1
            elif pyfos_util.isDCommaI(entry_name):
                if online_in_name_server_by_dcommai(ns_attributes, entry_name):
                    online_device = online_device + 1
            else:
                if online_in_name_server_by_alias(current_defined,
                                                  ns_attributes, entry_name):
                    online_device = online_device + 1

        if online_device == 0:
            hanging_zones.append(zone["zone-name"])
        else:
            online_zones.append(zone["zone-name"])

    return hanging_zones, online_zones, current_effective.peek_checksum()
def online_in_name_server_by_alias(current_defined, ns_attributes,
                                   device_alias):
    current_aliases = current_defined.peek_alias()
    for alias in current_aliases:
        if alias["alias-name"] == device_alias:
            for alias_entry_name in alias["member-entry"]["alias-entry-name"]:
                if pyfos_util.isWWN(alias_entry_name):
                    if online_in_name_server_by_wwn(ns_attributes,
                                                    alias_entry_name):
                        return True
                elif pyfos_util.isDCommaI(alias_entry_name):
                    if online_in_name_server_by_dcommai(
                            ns_attributes, alias_entry_name):
                        return True

    return False
Esempio n. 3
0
def base_generic_input(argv, usage, valid_options, sessionless):
    ret_dict = dict()

    # default value that should be added here
    ret_dict["secured"] = None
    ret_dict["verbose"] = 0
    ret_dict['utilusage'] = ""

    try:
        opts, args = getopt.getopt(argv, "hi:f:s:L:P:avz", [
            "activate",
            "allaccess=",
            "authtoken=",
            "acceptEULA",
            "compare=",
            "device=",
            "disable",
            "displayEULA",
            "enable",
            "filename=",
            "help",
            "hbaid=",
            "hostname=",
            "banner=",
            "hostport=",
            "ipaddr=",
            "login="******"members=",
            "name=",
            "password="******"pmembers=",
            "portid=",
            "protocol=",
            "messageid=",
            "reffcport=",
            "secured=",
            "speed=",
            "stage",
            "template=",
            "targetname=",
            "targetport=",
            "type=",
            "usepeer=",
            "username="******"userpassword="******"verbose",
            "vfid=",
            "xlsapply=",
            "xlscheck=",
            "json",
            "nosession",
            "nocredential",
        ])
    except getopt.GetoptError as err:
        print("getopt error", str(err))
        full_usage(usage, valid_options, sessionless)
        sys.exit(2)

    if len(args) > 0:
        print("*** Contains invalid options:", args[0])
        full_usage(usage, valid_options, sessionless)
        sys.exit(3)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            full_usage(usage, valid_options, sessionless)
            sys.exit()
        elif opt == "--activate":
            ret_dict["activate"] = True
        elif opt == "--allaccess":
            if not pyfos_util.isInt(arg):
                print("*** Invalid allacess:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["allaccess"] = int(arg)
        elif opt == "--acceptEULA":
            ret_dict["acceptEULA"] = "accept-eula"
        elif opt in "--compare":
            ret_dict["compare"] = arg
        elif opt in "--disable":
            ret_dict["disable"] = True
        elif opt in "--displayEULA":
            ret_dict["displayEULA"] = "display-eula"
        elif opt in "--device":
            if not pyfos_util.isWWN(arg):
                print("*** Invalid device:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["device"] = arg
        elif opt in "--enable":
            ret_dict["enable"] = True
        elif opt in ("-f", "--vfid"):
            if not pyfos_util.isInt(arg):
                print("*** Invalid vfid:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["vfid"] = int(arg)
        elif opt in "--filename":
            ret_dict["filename"] = arg
        elif opt in "--hbaid":
            ret_dict["hbaid"] = arg
        elif opt in "--hostname":
            ret_dict["hostname"] = arg
        elif opt in "--banner":
            ret_dict["banner"] = arg
        elif opt in "--hostport":
            if not pyfos_util.isWWN(arg):
                print("*** Invalid hostport:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["hostport"] = arg
        elif opt in ("-i", "--ipaddr"):
            if not pyfos_util.isIPAddr(arg):
                print("*** Invalid ipaddr:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["ipaddr"] = arg
        elif opt in "--json":
            ret_dict["json"] = True
        elif opt in ("-L", "--login"):
            ret_dict["login"] = arg
        elif opt in "--members":
            ret_dict["members"] = arg.split(";")
        elif opt in "--name":
            ret_dict["name"] = arg
        elif opt in "--pmembers":
            ret_dict["pmembers"] = arg.split(";")
        elif opt in ("-P", "--password"):
            ret_dict["password"] = arg
        elif opt in "--portid":
            ret_dict["portid"] = arg
        elif opt in "--protocol":
            ret_dict["protocol"] = arg
        elif opt in "--messageid":
            ret_dict["messageid"] = arg
        elif opt in "--reffcport":
            if not pyfos_util.isSlotPort(arg):
                print("*** Invalid reffcport:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["reffcport"] = arg
        elif opt in ("-s", "--secured"):
            if arg == "self":
                ret_dict["secured"] = "self"
            elif arg == "CA":
                ret_dict["secured"] = "CA"
            else:
                print("defaults to CA")
                ret_dict["secured"] = "CA"
        elif opt in "--show":
            ret_dict["show"] = 1
        elif opt in "--speed":
            if not pyfos_util.isInt(arg):
                print("*** Invalid speed:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["speed"] = int(arg)
        elif opt in "--stage":
            ret_dict["stage"] = True
        elif opt in "--template":
            ret_dict["template"] = arg
        elif opt in "--targetname":
            ret_dict["targetname"] = arg
        elif opt in "--targetport":
            if not pyfos_util.isWWN(arg):
                print("*** Invalid targetport:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["targetport"] = arg
        elif opt in "--type":
            ret_dict["type"] = arg
        elif opt in "--username":
            ret_dict["username"] = arg
        elif opt in "--userpassword":
            ret_dict["userpassword"] = arg
        elif opt in "--usepeer":
            if arg not in ('WWN', ''):
                print("*** Invalid userpeer:", arg)
                full_usage(usage, valid_options, sessionless)
                sys.exit(5)

            ret_dict["usepeer"] = arg
        elif opt in ("-v", "--verbose"):
            ret_dict["verbose"] = 1
        elif opt in ("-z", "--nosession"):
            ret_dict["sessionless"] = True
        elif opt in "--nocredential":
            ret_dict["nocredential"] = True
        elif opt in ("-a", "--authtoken"):
            if len(arg) == 0:
                ret_dict['authtoken'] = None
            else:
                ret_dict['authtoken'] = arg
        elif opt in "--xlscheck":
            ret_dict["xlscheck"] = arg
        elif opt in "--xlsapply":
            ret_dict["xlsapply"] = arg
        else:
            print("unknown", opt)
            full_usage(usage, valid_options, sessionless)
            sys.exit(5)

    if "ipaddr" not in ret_dict:
        print("Missing IP address input")
        print("")
        full_usage(usage, valid_options, sessionless)
        sys.exit(6)

    if "login" not in ret_dict.keys():
        login = input("Login:"******"login"] = login

    if "password" not in ret_dict.keys():
        if 'authtoken' not in ret_dict.keys() and\
           'nocredential' not in ret_dict.keys():
            password = getpass.getpass()
            ret_dict["password"] = password

    if valid_options is not None:
        # pylint: disable=W0612
        for k, v in ret_dict.items():
            if k not in ('login', 'password', 'ipaddr', 'secured', 'vfid',
                         'verbose', 'authtoken', 'sessionless', 'utilusage',
                         'nocredential'):
                found = False
                for valid_option in valid_options:
                    if valid_option == k:
                        found = True
                        break
                if not found:
                    print("*** Invalid option given:", k)
                    full_usage(usage, valid_options, sessionless)
                    sys.exit(4)

    return ret_dict
Esempio n. 4
0
def base_generic_input(argv, usage, valid_options):
    if len(argv) == 0:
        full_usage(usage)
        sys.exit()

    ret_dict = dict()

    # default value that should be added here
    ret_dict["secured"] = None
    ret_dict["verbose"] = 0

    try:
        opts, args = getopt.getopt(argv, "hi:f:s:L:P:v", [
            "allaccess=",
            "compare=",
            "device=",
            "disable",
            "enable",
            "filename=",
            "help",
            "hostname=",
            "hostport=",
            "ipaddr=",
            "login="******"members=",
            "name=",
            "password="******"pmembers=",
            "reffcport=",
            "secured=",
            "speed=",
            "template=",
            "targetname=",
            "targetport=",
            "usepeer=",
            "username="******"verbose",
            "vfid=",
            "xlsapply=",
            "xlscheck=",
        ])
    except getopt.GetoptError as err:
        print("getopt error", str(err))
        full_usage(usage)
        sys.exit(2)

    if len(args) > 0:
        print("*** Contains invalid options:", args[0])
        full_usage(usage)
        sys.exit(3)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            full_usage(usage)
            sys.exit()
        elif opt in ("--allaccess"):
            if not pyfos_util.isInt(arg):
                print("*** Invalid allacess:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["allaccess"] = int(arg)
        elif opt in ("--compare"):
            ret_dict["compare"] = arg
        elif opt in ("--disable"):
            ret_dict["disable"] = True
        elif opt in ("--device"):
            if not pyfos_util.isWWN(arg):
                print("*** Invalid device:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["device"] = arg
        elif opt in ("--enable"):
            ret_dict["enable"] = True
        elif opt in ("-f", "--vfid"):
            if not pyfos_util.isInt(arg):
                print("*** Invalid vfid:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["vfid"] = int(arg)
        elif opt in ("--filename"):
            ret_dict["filename"] = arg
        elif opt in ("--hostname"):
            ret_dict["hostname"] = arg
        elif opt in ("--hostport"):
            if not pyfos_util.isWWN(arg):
                print("*** Invalid hostport:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["hostport"] = arg
        elif opt in ("-i", "--ipaddr"):
            if not pyfos_util.isIPAddr(arg):
                print("*** Invalid ipaddr:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["ipaddr"] = arg
        elif opt in ("-L", "--login"):
            ret_dict["login"] = arg
        elif opt in ("--members"):
            ret_dict["members"] = arg.split(";")
        elif opt in ("--name"):
            ret_dict["name"] = arg
        elif opt in ("--pmembers"):
            ret_dict["pmembers"] = arg.split(";")
        elif opt in ("-P", "--password"):
            ret_dict["password"] = arg
        elif opt in ("--reffcport"):
            if not pyfos_util.isSlotPort(arg):
                print("*** Invalid reffcport:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["reffcport"] = arg
        elif opt in ("-s", "--secured"):
            if arg == "self":
                ret_dict["secured"] = "self"
            elif arg == "CA":
                ret_dict["secured"] = "CA"
            else:
                print("defaults to CA")
                ret_dict["secured"] = "CA"
        elif opt in ("--show"):
            ret_dict["show"] = 1
        elif opt in ("--speed"):
            if not pyfos_util.isInt(arg):
                print("*** Invalid speed:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["speed"] = int(arg)
        elif opt in ("--template"):
            ret_dict["template"] = arg
        elif opt in ("--targetname"):
            ret_dict["targetname"] = arg
        elif opt in ("--targetport"):
            if not pyfos_util.isWWN(arg):
                print("*** Invalid targetport:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["targetport"] = arg
        elif opt in ("--username"):
            ret_dict["username"] = arg
        elif opt in ("--usepeer"):
            if arg != "WWN" and arg != "":
                print("*** Invalid userpeer:", arg)
                full_usage(usage)
                sys.exit(5)

            ret_dict["usepeer"] = arg
        elif opt in ("-v", "--verbose"):
            ret_dict["verbose"] = 1
        elif opt in ("--xlscheck"):
            ret_dict["xlscheck"] = arg
        elif opt in ("--xlsapply"):
            ret_dict["xlsapply"] = arg
        else:
            print("unknown", opt)
            full_usage(usage)
            sys.exit(5)

    if "login" not in ret_dict.keys():
        login = input("Login:"******"login"] = login

    if "password" not in ret_dict.keys():
        password = getpass.getpass()
        ret_dict["password"] = password

    if valid_options is not None:
        for k, v in ret_dict.items():
            if (k != "login" and k != "password" and k != "ipaddr"
                    and k != "secured" and k != "vfid" and k != "verbose"):
                found = False
                for valid_option in valid_options:
                    if valid_option == k:
                        found = True
                        break
                if not found:
                    print("*** Invalid option given:", k)
                    full_usage(usage)
                    sys.exit(4)

    if "ipaddr" not in ret_dict:
        print("*** IP address must be given:")
        full_usage(usage)
        sys.exit(6)

    return ret_dict