Beispiel #1
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")
def show_switch_ip_config(session):
    filters = [
        'ip_address_ip_address', 'ip_static_gateway_list_ip_static_gateway',
        'subnet_mask'
    ]
    result = fibrechannel_switch.get(session, None, filters)
    return result
Beispiel #3
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
Beispiel #4
0
def _modify_dns_config_params(session, swobject):
    if swobject.peek_name() is None:
        current_swobj = fibrechannel_switch.get(session)
        if isinstance(current_swobj, fibrechannel_switch):
            swobject.set_name(current_swobj.peek_name())
        else:
            return current_swobj
    result = swobject.patch(session)
    return result
Beispiel #5
0
def set_ag_mode(session, ag_mode):
    sw_obj = fibrechannel_switch()
    current_sw = fibrechannel_switch.get(session)
    if pyfos_util.is_failed_resp(current_sw):
        return current_sw

    sw_obj.set_name(current_sw.peek_name())
    sw_obj.set_ag_mode(ag_mode)
    # print(settings_obj)
    return sw_obj.patch(session)
Beispiel #6
0
def _modify_switch_ip_config_params(session, swobject):
    if swobject.peek_name() is None:
        current_swobj = fibrechannel_switch.get(session)
        swobject.set_name(current_swobj.peek_name())
    result = swobject.patch(session)
    return result
def main(argv):
    # Login to the switch
    print("\nLogin to the switch")
    session = example_login()
    if pyfos_auth.is_failed_login(session):
        print(
            "login failed because",
            session.get(pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        sys.exit(3)
    # Get an instance of auth token manager
    print("Get Auth Token Manager instance")
    examplemgrauthtoken = exampleTokenManager()

    # Display authtoken manager details
    print("Display the Auth Token Manager details.")
    examplemgrauthtoken.show()

    # Delete any existing authtoken
    ret = examplemgrauthtoken.delete(session)
    print("Delete Auth Token from the switch\nRet:")
    pyfos_util.response_print(ret)

    # Display authtoken manager details
    print("Display the Auth Token Manager details.")
    examplemgrauthtoken.show()

    # Generate the authtoken
    ret = examplemgrauthtoken.generateToken(session)
    print("Generate Auth Token from the switch\nRet:")
    pyfos_util.response_print(ret)

    # Display authtoken manager details
    print("Display the Auth Token Manager details.")
    examplemgrauthtoken.show()

    print("Get the swithshow with regular session")
    ret = fibrechannel_switch.get(session)
    pyfos_util.response_print(ret)

    # Session Logout
    pyfos_auth.logout(session)

    # Token based authentication session error scenario with default
    # password used and not None.
    print("AuthToken Login error scenario")
    tokensession = example_login(tokenArg=examplemgrauthtoken)
    if pyfos_auth.is_failed_login(tokensession):
        print(
            "Token based login failed because",
            tokensession.get(
                pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])

    print("AuthToken Login Success scenario.")
    # Token based authentication session Success scenario
    tokensession = example_login(password=None, tokenArg=examplemgrauthtoken)
    if pyfos_auth.is_failed_login(tokensession):
        print(
            "Token based login failed because",
            tokensession.get(
                pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY])
        sys.exit(3)

    # Using Token Session for operation
    print("Get the swithshow with authToken based login session.")
    fcobj = fibrechannel_switch.get(tokensession)
    pyfos_util.response_print(fcobj)

    # Patch operation example.
    fcobjnew = fibrechannel_switch()
    fcobjnew.set_name(fcobj.peek_name())
    fcobjnew.set_user_friendly_name("mybanner")
    print("AuthToken login session patch with banner :",
          fcobjnew.peek_user_friendly_name())
    ret = fcobjnew.patch(tokensession)
    pyfos_util.response_print(ret)

    # Revert the banner to original
    print("AuthToken login session patch revert banner :",
          fcobj.peek_user_friendly_name())
    fcobjnew.set_user_friendly_name(fcobj.peek_user_friendly_name())
    ret = fcobjnew.patch(tokensession)
    pyfos_util.response_print(ret)

    print("AuthToken login session Logout")
    # Token Session logout
    pyfos_auth.logout(tokensession)
Beispiel #8
0
def show_dns_config(session):
    filters = ['dns_servers_dns_server', 'domain_name']
    result = fibrechannel_switch.get(session, None, filters)
    return result