예제 #1
0
def main(argv):
    valid_options = []
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage)
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    current_effective = pyfos_zone.effective_configuration.get(session)
    result = cfgsave(session, current_effective.peek_checksum())
    pyfos_util.response_print(result)

    pyfos_auth.logout(session)
예제 #2
0
def main(argv):
    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print("login failed because",
              session.get(pyfos_auth.CREDENTIAL_KEY)
              [pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    ret_code, details = zone_allow_pair_to_peer(
            session, ZONE_PREFIX, inputs["hostport"],
            inputs["targetname"], inputs["targetport"], CFG_NAME, False)

    if ret_code > 0:
        print("zone db updated", ret_code)
    else:
        print("zone db remains", ret_code)

    print(details)

    pyfos_auth.logout(session)
예제 #3
0
def main(argv):
    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    brcd_zone_util.zone_name_members_func(session, inputs, usage,
                                          __aliasremove)

    pyfos_auth.logout(session)
예제 #4
0
def main(argv):
    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    switch = pyfos_switch.fibrechannel_switch.get(session)
    pyfos_util.response_print(switch)

    pyfos_auth.logout(session)
예제 #5
0
def main(argv):
    valid_options = ["name"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in inputs:
        ports = pyfos_switchfcport.fibrechannel_statistics.get(session)
        for port in ports:
            pyfos_util.response_print(port)
    else:
        name = inputs["name"]
        port = pyfos_switchfcport.fibrechannel_statistics.get(session, name)
        pyfos_util.response_print(port)

    pyfos_auth.logout(session)
예제 #6
0
def main(argv):
    valid_options = ["name"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage, valid_options)
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    brcd_zone_util.zone_name_func(session, inputs, usage, __pzonedelete)

    pyfos_auth.logout(session)
예제 #7
0
def main(argv):
    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print("login failed because",
              session.get(pyfos_auth.CREDENTIAL_KEY)
              [pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    name = inputs["name"]

    current_effective = pyfos_zone.effective_configuration.get(session)
    result = cfgenable(session, name, current_effective.peek_checksum())
    pyfos_util.response_print(result)

    pyfos_auth.logout(session)
예제 #8
0
def main(argv):
    isHttps = "0"

    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if 'compare' not in inputs or inputs['compare'] is None:
        usage()
        sys.exit()

    dir_name = inputs['compare']

    apply_to_object(session, dir_name, pyfos_switch.fibrechannel_switch)
    apply_to_object_list(session, dir_name, pyfos_switchfcport.fibrechannel)
    apply_to_object(session, dir_name, pyfos_zone.defined_configuration)
    apply_to_object(session, dir_name, pyfos_zone.effective_configuration)

    pyfos_auth.logout(session)
예제 #9
0
def main(argv):
    #myinput=str("-i 10.17.3.70  -n 4/19 -c 0 ")
    #argv = myinput.split()
    value_dict = dict()
    inputs = dict()
    ret = parse_circuit(argv, inputs, value_dict)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["switch"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in value_dict:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    result = _delete_extension_circuit(session, value_dict)
    pyfos_util.response_print(result)
    pyfos_auth.logout(session)
예제 #10
0
def main(argv):
    valid_options = ["hbaid"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    # Login to switch
    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print("login failed because",
              session.get(pyfos_auth.CREDENTIAL_KEY)
              [pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage, valid_options)
        sys.exit()

    brcd_util.exit_register(session)

    # Set VF ID, if necessary
    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']
    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    # Call fdmishow
    fdmishow(session, inputs)

    # Log out
    pyfos_auth.logout(session)
예제 #11
0
def get_uptime_from_fabric(fabric_switch_ips):

    # Define a dictionary
    fabric_uptime = {}
    # Get uptime from all the fabric switches
    for ip in fabric_switch_ips:
        session = get_session(ip)
        if pyfos_auth.is_failed_login(session):
            print(
                "Login failed due to",
                session.get(
                    pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
            continue

        switch = fibrechannel_switch.get(session)
        if pyfos_util.is_failed_resp(switch):
            pyfos_util.response_print(switch)
            continue

        # Peek uptime from fabric switch
        if isinstance(switch, list):
            for entry in switch:
                uptime = entry.peek_up_time()
        else:
            uptime = switch.peek_up_time()

        # Update dictionary
        fabric_uptime[ip] = uptime

        pyfos_auth.logout(session)

    return fabric_uptime
예제 #12
0
def main(argv):
    valid_options = ["hostname", "hostport", "targetname", "targetport"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage)
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "hostname" not in inputs:
        print("--hostname is mandatory")
        brcd_util.full_usage(usage)
        sys.exit()

    if "hostport" not in inputs:
        print("--hostport is mandatory")
        brcd_util.full_usage(usage)
        sys.exit()

    if "targetname" not in inputs:
        print("--targetname is mandatory")
        brcd_util.full_usage(usage)
        sys.exit()

    if "targetport" not in inputs:
        print("--targetport is mandatory")
        brcd_util.full_usage(usage)
        sys.exit()

    ret_code, details = zone_allow_pair(session, ZONE_PREFIX,
                                        inputs["hostname"], inputs["hostport"],
                                        inputs["targetname"],
                                        inputs["targetport"], CFG_NAME, False)

    if ret_code > 0:
        print("zone db updated")
    else:
        print("zone db remains")

    print(details)

    pyfos_auth.logout(session)
예제 #13
0
def main(argv):
    valid_options = ["compare", "template", "reffcport"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if 'compare' not in inputs or inputs['compare'] is None:
        usage()
        sys.exit()

    dir_name = inputs['compare']

    template = None
    if 'template' in inputs:
        template = switch_config_util.get_template(inputs['template'])

    switch_config_util.process_object(session, dir_name,
                                      pyfos_switch.fibrechannel_switch, True,
                                      template)
    if 'template' in inputs and 'reffcport' in inputs:
        switch_config_util.process_object(session, dir_name,
                                          pyfos_switchfcport.fibrechannel,
                                          True, template,
                                          [{
                                              "name": inputs['reffcport']
                                          }])
    else:
        switch_config_util.process_object(session, dir_name,
                                          pyfos_switchfcport.fibrechannel,
                                          True, template)
    switch_config_util.process_object(session, dir_name,
                                      pyfos_zone.defined_configuration, True,
                                      template)
    switch_config_util.process_object(session, dir_name,
                                      pyfos_zone.effective_configuration, True,
                                      template)

    pyfos_auth.logout(session)
예제 #14
0
    def reinitsession(cls, arg, session):
        """
        Callback Handler to reinit the session.
        """
        arg = None
        print("Dup Session start")
        cls.log(1, "Dup Session start")
        ret, username = cls.getsessionuser(session)
        if ret is False:
            print("Unable to reinit the session", session, arg)
            cls.log(3, "Unable to reinit the session", session, arg)
            return False
        ret, passwd = cls.getsessionpasswd(session)
        if ret is False:
            print("Unable to reinit the session", session, arg)
            cls.log(3, "Unable to reinit the session", session, arg)
            return False

        IP = session["ip_addr"]
        # vfid = session["vfid"]
        https = session["ishttps"]
        # debug = session["debug"]
        # throttle_delay = session["throttle_delay"]
        newsession = None
        retry = 0
        for i in range(10):
            retry = i
            newsession = auth.login(username, passwd, IP, https)
            if auth.is_failed_login(newsession):
                cls.sleep(20, session)
                continue
            break
        if not auth.is_failed_login(newsession):
            # print('old', cls.sessionkey(session), 'New',
            #       cls.sessionkey(newsession))
            session['credential'] = newsession['credential']
            session["version"] = newsession["version"]
            print("Dup Session Completed after Iterations:", retry)
            cls.log(1, "Dup Session Completed after Iterations:", retry)
            return True
        print("Dup Session Failed.")
        cls.log(2, "Dup Session Failed.")
        sys.exit('Exiting as session dup didn\'t work')
        return False
예제 #15
0
def main(argv):
    """
    This function shows the following sequence of operation.

    **Support for login/logout sequence for Sessionless**
        *login* returns a pseudo session without actual Login.
        *REST operation support* for GET Examples.
        *logout* no-operation logout.

    **Dummy session creation and operations**
        *Pseudo session* using dummy function without login.
        *REST operation support* for GET/PATCH examples.

    """
    # Login to the switch
    login_sessionless = example_login(sessionless=True)
    if pyfos_auth.is_failed_login(login_sessionless):
        print(
            "login failed because",
            login_sessionless.get(
                pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        sys.exit(3)
    print("Login to Switch with session-less option, Actually there is no ",
          "login done to switch.")

    # Using sessionless Session for operation
    print("\nGet the swithshow with session-less")
    fcobj = fibrechannel_switch.get(login_sessionless)
    pyfos_util.response_print(fcobj)

    # Sessionless Session logout(No-operation)
    pyfos_auth.logout(login_sessionless)
    print("\nLogout session-less based login session no-op.")

    # Dummy session to the switch
    pseudosession = dummy_session()
    print("\nGet swithshow using pseudo-session with session-less [Allowed].")
    fcobj = fibrechannel_switch.get(pseudosession)
    pyfos_util.response_print(fcobj)

    # Patch operation example.
    print("\nPatch using pseudo-session for session-less [Forbidden]")
    fcobjnew = fibrechannel_switch()
    fcobjnew.set_name(fcobj.peek_name())
    fcobjnew.set_user_friendly_name("mybanner")
    print("Patch with banner :", fcobjnew.peek_user_friendly_name())
    ret = fcobjnew.patch(pseudosession)
    pyfos_util.response_print(ret)

    # Revert the banner to original
    print("\nPatch using pseudo-session for session-less[Forbidden]")
    print("Revert Patch with banner :", fcobj.peek_user_friendly_name())
    fcobjnew.set_user_friendly_name(fcobj.peek_user_friendly_name())
    ret = fcobjnew.patch(pseudosession)
    pyfos_util.response_print(ret)
    print("No logout required for pseudo-session")
예제 #16
0
def main(argv):
    #myinput=str("-i 10.17.3.70  -n 4/17 -d 0 -s 154.10.10.0 " +\
    #            "-g 134.10.10.125 -p 24 ")
    #argv = myinput.split()
    value_dict = dict()
    inputs = dict()
    ret = parse_iproute(argv, inputs, value_dict)
    if ret != 0:
        usage()
        sys.exit()

    #print(inputs, value_dict)
    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["switch"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in value_dict:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    if "ip-address" not in value_dict:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    if "ip-prefix-length" not in value_dict:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    if "dp-id" not in value_dict:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    result = _modify_extension_iproute(session, value_dict)
    pyfos_util.response_print(result)
    pyfos_auth.logout(session)
예제 #17
0
def main(argv):
    valid_options = ["filename", "usepeer", "xlscheck", "xlsapply"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage)
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "filename" not in inputs:
        print("filename missing")
        brcd_util.full_usage(usage)
        sys.exit()

    filename = inputs["filename"]
    if filename.endswith("txt"):
        process_txt(session, filename)
    elif filename.endswith("xlsx"):
        usepeer = False
        usepeer_wwn = False
        if "usepeer" in inputs:
            usepeer = True
            if inputs["usepeer"] == "WWN":
                usepeer_wwn = True
            else:
                usepeer_wwn = False

        if "xlscheck" in inputs:
            process_xlsx_direct_generic(session, filename, inputs["xlscheck"],
                                        False, usepeer, usepeer_wwn)
        elif "xlsapply" in inputs:
            process_xlsx_direct_generic(session, filename, inputs["xlsapply"],
                                        True, usepeer, usepeer_wwn)

    pyfos_auth.logout(session)
예제 #18
0
def main(argv):
    valid_options = ["name", "enable", "disable"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    name = inputs["name"]

    if "enable" not in inputs and "disable" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()

    if "enable" in inputs:
        enabled = 1
    if "disable" in inputs:
        enabled = 0

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    if enabled:
        port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE)
    else:
        port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.OFFLINE)
    result = port.patch(session)
    pyfos_util.response_print(result)

    pyfos_auth.logout(session)
예제 #19
0
def main(argv):
    valid_options = ["json", "compare", "template", "reffcport"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if 'compare' not in inputs or inputs['compare'] is None:
        usage()
        sys.exit()

    envelope_name = inputs['compare']

    in_json = False
    if 'json' in inputs:
        in_json = True

    if in_json:
        fmtfile = 'JSON'
        fmtobj = 'json'
        # ext = '.json'
    else:
        fmtfile = 'XLSX'
        fmtobj = 'attributes'
        # ext = '.xlsx'
    clsmanager.addsession(session, inputs["login"], inputs["password"])
    mgr = config_manager(fmtfile, fmtobj)
    fcmodechange = config_manager()
    fcmodechange.applygoldenobject(session, envelope_name,
                                   "fibrechannel-switch", 6)
    mgr.applydiff(envelope_name, session)
    pyfos_auth.logout(session)
예제 #20
0
def Connect(Username, Password, IP):
    #Accepts Brocade IP, Username and Password.
    #Creates a connection to a switch.
    #Returns the header for that switch and the session created.
    import pyfos.pyfos_auth as auth

    Connection = auth.login(Username, Password, IP, "None")

    if auth.is_failed_login(Connection):
        return 66, None
    else:
        Header = Connection.get('credential')
        Header.update({'Accept': 'application/yang-data+xml'})
        Header.update({'Content-Type': 'application/yang-data+xml'})

        return Connection, Header
예제 #21
0
def main(argv):
    valid_options = ["name"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" in inputs:
        name = inputs["name"]
        result = pyfos_switchfcport.fibrechannel.get(session, name)
    else:
        result = pyfos_switchfcport.fibrechannel.get(session)

    if not pyfos_util.is_failed_resp(result):
        available_ports = []
        if isinstance(result, list):
            for port in result:
                id_avail_port(port, available_ports)
        else:
            id_avail_port(result, available_ports)

        pyfos_util.response_print(available_ports)
    else:
        if "name" in inputs:
            print("failed to get information on", inputs["name"])
        else:
            print("failed to get information on ports")

    pyfos_auth.logout(session)
예제 #22
0
def main():
    ip_address = '10.0.0.1'  # ip address of switch - edit for IP of switch
    username = '******'  # username of switch - edit for username of switch
    password = '******'  # password of switch - edit for password of switch

    # logs into the switch and creates an active session with the switch
    session = pyfos_auth.login(username=username,
                               password=password,
                               ip_addr=ip_address,
                               isHttps=True)
    if pyfos_auth.is_failed_login(
            session):  # if there is a login fail.... please print why...
        '''
            this is where you can put your logging and error handling
        '''
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])

        sys.exit()

    switch = pyfos_switch.fibrechannel_switch.get(
        session)  # creates the switch variable (and its info)
    '''
    pyfos_util.response_print(switch) # Prints out the switch json..... same as the below:
    
    # alternative: I use the below... as I'm trying to change it out to dump into an actual dictionary to play with it.
    print('Switch info:')
    print(switch)
    '''

    #  pyfos_util.response_print(switch)  #  command not used, but could be used to print out switch variable

    pyfos_auth.logout(
        session
    )  # logs out of the session to prevent maxing out Rest Sessions....

    print(
        'Switch info:'
    )  # prints switch info.... drop out point to dump into a json dump then dictionary
    print(switch)

    # used as a script pause point (for PyCharm or python editor.... comment this out if running as a script from CLI
    print('script pause')
    print('')
예제 #23
0
def main(argv):
    valid_options = ["json", "compare"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    in_json = False
    if 'json' in inputs:
        in_json = inputs['json']

    if in_json:
        fmtfile = 'JSON'
        fmtobj = 'json'
        ext = '.json'
    else:
        fmtfile = 'XLSX'
        fmtobj = 'attributes'
        ext = '.xlsx'
    envelope_name = get_envelope_name(inputs['ipaddr'])
    envelope_name += ext
    mgr = config_manager(fmtfile, fmtobj)
    mgr.dumptofile(session, envelope_name)
    print("done")

    pyfos_auth.logout(session)
예제 #24
0
def get_fabric_from_seedswitch():

    fabric = []
    # Get session from input seed switch
    session = get_session(IPADDRESS)
    if pyfos_auth.is_failed_login(session):
        print(
            "Login failed due to",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        sys.exit()
    else:
        pyfos_auth.vfid_set(session, VFID)

        # Get fabric from seed switch
        fabric = pyfos_fabric.fabric_switch.get(session)

        pyfos_auth.logout(session)

    return fabric
예제 #25
0
def getsession(inputs):
    global session
    tokenManager = None
    ishttps = None
    if 'authtoken' in inputs.keys():
        # Always need to use the Default Token Manager config
        # if user wants to use a different configuration then user
        # config store should be set as default store using the set
        # default store option.
        if inputs['authtoken'] is None or \
           auth_token_manager.isvalidconfig(inputs['authtoken']):
            tokenManager = auth_token_manager(inputs['authtoken'])
        else:
            tokenManager = inputs['authtoken']
        # tokenManager.show()

    # Get the password or else None
    ip = inputs.get("ipaddr", None)
    user = inputs.get("login", None)
    password = inputs.get("password", None)
    sessionless = inputs.get('sessionless', False)
    nocred = inputs.get('nocredential', False)

    if 'secured' in inputs.keys():
        ishttps = inputs['secured']

    # Default DEFAULT_THROTTLE_DELAY 1.1
    session = pyfos_auth.login(user, password, ip, ishttps, 1.1, 0,
                               tokenManager, sessionless, nocred)

    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        print(inputs['utilusage'])
        sys.exit(3)
    exit_register(session)
    if 'vfid' in inputs:
        pyfos_auth.vfid_set(session, inputs['vfid'])
    if 'verbose' in inputs and inputs['verbose'] != 0:
        pyfos_auth.debug_set(session, 1)
    inputs['session'] = session
    return session
예제 #26
0
def main(argv):
    valid_options = ["name"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage, valid_options)
        sys.exit()

    brcd_util.exit_register(session)

    if "FOS-" in inputs["name"]:
        err_str = "Invalid license format. "
        print(err_str + "Please specify only key based license.")
        brcd_util.full_usage(usage, valid_options)
        sys.exit()

    if "name" not in inputs:
        print("License key is required")
        brcd_util.full_usage(usage, valid_options)
        sys.exit()
    l_obj = license_parameters()
    l_obj.set_action("remove")
    l_obj.set_name(inputs["name"])
    l_rsp_obj = l_obj.post(session)
    if ("info-message" in l_rsp_obj and l_rsp_obj["info-message"]
            == "Switch version is lower than the object"):
        pyfos_util.response_print(l_rsp_obj)
        pyfos_auth.logout(session)
        sys.exit()
    if pyfos_util.is_failed_resp(l_rsp_obj):
        pyfos_util.response_print(l_rsp_obj)
    else:
        pyfos_util.response_print(l_rsp_obj)

    pyfos_auth.logout(session)
예제 #27
0
def getsession(inputs):
    ishttps = None
    if 'secured' in inputs.keys():
        ishttps = inputs['secured']
    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], ishttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        print(inputs['utilusage'])
        sys.exit(3)
    exit_register(session)
    if 'vfid' in inputs:
        pyfos_auth.vfid_set(session, inputs['vfid'])
    if 'verbose' in inputs:
        pyfos_auth.debug_set(session, 1)
    inputs['session'] = session
    return session
def main(argv):
    # pylint: disable=W0603
    global g_session
    valid_options = ["hostport", "targetname", "targetport"]
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    g_session = pyfos_auth.login(inputs["login"],
                                 inputs["password"],
                                 inputs["ipaddr"],
                                 inputs["secured"],
                                 verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(g_session):
        print(
            "login failed because",
            g_session.get(
                pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        brcd_util.full_usage(usage, valid_options)
        sys.exit()

    brcd_util.exit_register(g_session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(g_session, vfid)

    ret_code, details = zone_allow_pair_to_peer(g_session, ZONE_PREFIX,
                                                inputs["hostport"],
                                                inputs["targetname"],
                                                inputs["targetport"], CFG_NAME,
                                                False)

    if ret_code > 0:
        print("zone db updated", ret_code)
    else:
        print("zone db remains", ret_code)

    print(details)

    pyfos_auth.logout(g_session)
예제 #29
0
def main(argv):
    inputs = brcd_util.generic_input(argv, usage)

    session = pyfos_auth.login(inputs["login"], inputs["password"],
                               inputs["ipaddr"], isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    if "name" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    name = inputs["name"]

    if "username" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    username = inputs["username"]

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_user_friendly_name(username)
    result = port.patch(session)
    pyfos_util.response_print(result)

    pyfos_auth.logout(session)
예제 #30
0
def main(argv):
    valid_options = []
    inputs = brcd_util.generic_input(argv, usage, valid_options)

    session = pyfos_auth.login(inputs["login"],
                               inputs["password"],
                               inputs["ipaddr"],
                               inputs["secured"],
                               verbose=inputs["verbose"])
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        usage()
        sys.exit()

    brcd_util.exit_register(session)

    vfid = None
    if 'vfid' in inputs:
        vfid = inputs['vfid']

    if vfid is not None:
        pyfos_auth.vfid_set(session, vfid)

    dir_name = switch_config_util.get_dirname(inputs['ipaddr'])
    try:
        os.stat(dir_name)
    except OSError:
        os.mkdir(dir_name)

    dump_object(session, dir_name, pyfos_switch.fibrechannel_switch)
    dump_object(session, dir_name, pyfos_switchfcport.fibrechannel)
    dump_object(session, dir_name, pyfos_fabric.fabric_switch)
    dump_object(session, dir_name, pyfos_zone.defined_configuration)
    dump_object(session, dir_name, pyfos_zone.effective_configuration)

    print("done")

    pyfos_auth.logout(session)