Ejemplo n.º 1
0
def changeResilienceStateOfPort(session, name, enabled):
    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_credit_recovery_enabled(enabled)
    port.set_fec_enabled(enabled)
    result = port.patch(session)
    pyfos_util.response_print(result)
    #   Wait for few secs to allow the new value to be negotiated
    time.sleep(3)
    newport = pyfos_switchfcport.fibrechannel.get(session, name)
    return (newport)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def main(argv):
    valid_options = ["name", "username"]
    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 "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)
Ejemplo n.º 4
0
def main(argv):
    global session

    atexit.register(exit_handler)

    args_file = sys.argv[1]
    args_data = open(args_file).read()

    vfid = None

    arguments = shlex.split(args_data)
    for arg in arguments:
        if "=" in arg:
            (key, value) = arg.split("=")

            if key == "switch_ip":
                ip_addr = value
            elif key == "user":
                user = value
            elif key == "password":
                password = value
            elif key == "checkmode":
                checkmode = ast.literal_eval(value)
            elif key == "name":
                name = value
            elif key == "mode":
                mode = ast.literal_eval(value)
            elif key == "vfid":
                vfid = ast.literal_eval(value)


#        print json.dumps({
#                "ip_addr" : ip_addr,
#                "user" : user,
#                "password" : password,
#                "checkmode" : checkmode
#        })

    session = pyfos_auth.login(user, password, ip_addr, isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            json.dumps({
                "changed":
                False,
                "login failed reason":
                session.get(
                    pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY]
            }))
        sys.exit()

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

    changed = False
    result = pyfos_switchfcport.fibrechannel.get(session, name)
    if pyfos_util.is_failed_resp(result):
        print(
            json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            }))
        sys.exit()

    if result.peek_g_port_locked() != int(mode):
        changed = True
        if checkmode is False:
            port = pyfos_switchfcport.fibrechannel()
            port.set_name(name)
            port.set_g_port_locked(int(mode))
            result = port.patch(session)
            if pyfos_util.is_failed_resp(result):
                print((json.dumps({
                    "changed": False,
                    "line": inspect.currentframe().f_lineno,
                    "error": result
                })))
                sys.exit()

    pyfos_auth.logout(session)

    print(json.dumps({
        "changed": changed,
    }))
Ejemplo n.º 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:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    name = inputs["name"]

    # PUT - Disable one port
    print("disable " + name)
    port = pyfos_switchfcport.fibrechannel({
        "name":
        name,
        "enabled-state":
        pyfos_switchfcport.ENABLED_STATE_TYPE.OFFLINE
    })
    result = port.patch(session)
    if pyfos_util.is_failed_resp(result):
        print("Failed to disable port", name)
        pyfos_auth.logout(session)
        pyfos_util.response_print(result)
        usage()
        sys.exit()

    pyfos_util.response_print(result)

    # PUT - D-Port mode set
    print("disable dport " + name)
    port = pyfos_switchfcport.fibrechannel({"name": name, "d-port-enable": 0})
    result = port.patch(session)
    pyfos_util.response_print(result)

    # PUT - D-Port mode set
    print("enable dport " + name)
    port = pyfos_switchfcport.fibrechannel({"name": name, "d-port-enable": 1})
    result = port.patch(session)
    pyfos_util.response_print(result)

    # PUT - Re-enable the port
    print("enable " + name)
    port = pyfos_switchfcport.fibrechannel({
        "name":
        name,
        "enabled-state":
        pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE
    })
    result = port.patch(session)
    pyfos_util.response_print(result)

    # GET state of the test. As default mode is auto,
    # it will start the test once port is enabled
    print("auto started dport testing")
    wait_diag_completion(session, name)

    diag_info = pyfos_diag.fibrechannel_diagnostics({
        "name": name,
        "payload-pattern": {
            "payload": "0x30540242"
        }
    })
    print("set new payload")
    result = diag_info.patch(session)
    pyfos_util.response_print(result)

    diag_info = pyfos_diag.fibrechannel_diagnostics({
        "name":
        name,
        "diagnostic-control":
        pyfos_diag.DIAG_RESTART
    })
    print("restart diag")
    result = diag_info.patch(session)
    pyfos_util.response_print(result)

    # Wait for few secs to complete tests.
    print("restart dport with new parameters " + name)
    wait_diag_completion(session, name)

    print("SET new attributes and start the diagnostics test in the same call")
    diag_info = pyfos_diag.fibrechannel_diagnostics()
    diag_info.set_name(name)
    diag_info.set_payload_pattern_payload("0x02423054")
    diag_info.set_diagnostic_control(pyfos_diag.DIAG_START)
    result = diag_info.patch(session)
    pyfos_util.response_print(result)

    # Wait for few secs to complete tests.
    print("start dport with new parameters " + name)
    wait_diag_completion(session, name)

    # PUT - Disable one port
    print("disable " + name)
    port = pyfos_switchfcport.fibrechannel({
        "name":
        name,
        "enabled-state":
        pyfos_switchfcport.ENABLED_STATE_TYPE.OFFLINE
    })
    result = port.patch(session)
    pyfos_util.response_print(result)

    # PUT - D-Port mode set
    print("disable dport " + name)
    port = pyfos_switchfcport.fibrechannel({"name": name, "d-port-enable": 0})
    result = port.patch(session)
    pyfos_util.response_print(result)

    # PUT - Re-enable the port
    print("enable " + name)
    port = pyfos_switchfcport.fibrechannel({
        "name":
        name,
        "enabled-state":
        pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE
    })
    result = port.patch(session)
    pyfos_util.response_print(result)

    pyfos_auth.logout(session)
Ejemplo n.º 6
0
def main(argv):
    global session

    atexit.register(exit_handler)

    args_file = sys.argv[1]
    args_data = open(args_file).read()

    vfid = None

    arguments = shlex.split(args_data)
    for arg in arguments:
        if "=" in arg:
            (key, value) = arg.split("=")

            if key == "switch_ip":
                ip_addr = value
            elif key == "user":
                user = value
            elif key == "password":
                password = value
            elif key == "checkmode":
                checkmode = ast.literal_eval(value)
            elif key == "name":
                name = value
            elif key == "speed":
                speed = value
            elif key == "vfid":
                vfid = ast.literal_eval(value)


#        print json.dumps({
#                "ip_addr" : ip_addr,
#                "user" : user,
#                "password" : password,
#                "checkmode" : checkmode
#        })

    session = pyfos_auth.login(user, password, ip_addr, isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            json.dumps({
                "changed":
                False,
                "login failed reason":
                session.get(
                    pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY]
            }))
        sys.exit()

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

    changed = False

    current_port_info = pyfos_switchfcport.fibrechannel.get(session, name)
    if pyfos_util.is_failed_resp(current_port_info):
        print(
            json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": current_port_info
            }))
        sys.exit()

    if speed == "0":
        new_speed = pyfos_switchfcport.SPEED_TYPE.AUTO
    elif speed == "1":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G1FC
    elif speed == "2":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G2FC
    elif speed == "4":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G4FC
    elif speed == "8":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G8FC
    elif speed == "10":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G10FC
    elif speed == "16":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G16FC
    elif speed == "32":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G32FC
    elif speed == "128":
        new_speed = pyfos_switchfcport.SPEED_TYPE.G128FC

    old_speed = current_port_info.peek_speed()
    if (new_speed == pyfos_switchfcport.SPEED_TYPE.AUTO
            and current_port_info.peek_auto_negotiate() != 1) or (
                new_speed != pyfos_switchfcport.SPEED_TYPE.AUTO
                and current_port_info.peek_speed() != new_speed
                and current_port_info.peek_auto_negotiate() != 1) or (
                    new_speed != pyfos_switchfcport.SPEED_TYPE.AUTO
                    and current_port_info.peek_auto_negotiate() == 1):
        changed = True
        if checkmode is False:
            port = pyfos_switchfcport.fibrechannel()
            port.set_name(name)
            port.set_speed(new_speed)
            result = port.patch(session)
            if pyfos_util.is_failed_resp(result):
                print((json.dumps({
                    "changed": False,
                    "line": inspect.currentframe().f_lineno,
                    "error": result
                })))
                sys.exit()

    pyfos_auth.logout(session)

    if changed:
        if new_speed == pyfos_switchfcport.SPEED_TYPE.AUTO:
            print(json.dumps({"changed": changed, "speed": "auto negotiate"}))
        else:
            if current_port_info.peek_auto_negotiate() == 1:
                print(
                    json.dumps({
                        "changed": changed,
                        "old speed": "auto negotiate",
                        "new speed": str(new_speed),
                    }))
            else:
                print(
                    json.dumps({
                        "changed": changed,
                        "old speed": old_speed,
                        "new speed": str(new_speed),
                    }))
    else:
        print(json.dumps({
            "changed": changed,
        }))
Ejemplo n.º 7
0
def main(argv):
    global session

    atexit.register(exit_handler)

    args_file = sys.argv[1]
    args_data = open(args_file).read()

    vfid = None

    arguments = shlex.split(args_data)
    for arg in arguments:
        if "=" in arg:
            (key, value) = arg.split("=")

            if key == "switch_ip":
                ip_addr = value
            elif key == "user":
                user = value
            elif key == "password":
                password = value
            elif key == "checkmode":
                checkmode = ast.literal_eval(value)
            elif key == "name":
                name = value
            elif key == "mode":
                mode = ast.literal_eval(value)
            elif key == "vfid":
                vfid = ast.literal_eval(value)


#        print json.dumps({
#                "ip_addr" : ip_addr,
#                "user" : user,
#                "password" : password,
#                "checkmode" : checkmode
#        })

    session = pyfos_auth.login(user, password, ip_addr, isHttps)
    if pyfos_auth.is_failed_login(session):
        print(
            json.dumps({
                "changed":
                False,
                "login failed reason":
                session.get(
                    pyfos_auth.CREDENTIAL_KEY)[pyfos_auth.LOGIN_ERROR_KEY]
            }))
        sys.exit()

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

    changed = False

    current_port_info = pyfos_switchfcport.fibrechannel.get(session, name)
    if pyfos_util.is_failed_resp(current_port_info):
        print(
            json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": current_port_info
            }))
        sys.exit()

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.OFFLINE)
    result = port.patch(session)
    if pyfos_util.is_failed_resp(result):
        if same_config_error not in result['client-errors']['errors']['error'][
                'error-message']:
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_d_port_enable(0)
    result = port.patch(session)
    if pyfos_util.is_failed_resp(result):
        if same_config_error not in result['client-errors']['errors']['error'][
                'error-message']:
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_d_port_enable(1)
    result = port.patch(session)
    if pyfos_util.is_failed_resp(result):
        if same_config_error not in result['client-errors']['errors']['error'][
                'error-message']:
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    port = pyfos_switchfcport.fibrechannel()
    port.set_name(name)
    port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE)
    result = port.patch(session)
    if pyfos_util.is_failed_resp(result):
        if same_config_error not in result['client-errors']['errors']['error'][
                'error-message']:
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    count = 0
    diag_info = pyfos_diag.brocade_fibrechannel_diagnostics.get(session, name)
    if pyfos_util.is_failed_resp(diag_info):
        print((json.dumps({
            "changed": False,
            "line": inspect.currentframe().f_lineno,
            "d_port_result": "NOT STARTED",
            "error": result
        })))
        sys.exit()

    time.sleep(10)
    diag_state = diag_info.peek_state()
    while "IN PROGRESS" in diag_state or "NOT STARTED" in diag_state or "RESPONDER" in diag_state or "STOPPED" in diag_state:
        count += 1
        if count > 12:
            break
        time.sleep(10)

        diag_info = pyfos_diag.brocade_fibrechannel_diagnostics.get(
            session, name)
        diag_state = diag_info.peek_state()

    diag_info = pyfos_diag.brocade_fibrechannel_diagnostics.get(session, name)
    diag_state = diag_info.peek_state()

    # if dport was disabled to begin with. turn back.
    if current_port_info.peek_d_port_enable() == 0:
        port = pyfos_switchfcport.fibrechannel()
        port.set_name(name)
        port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.OFFLINE)
        result = port.patch(session)
        if pyfos_util.is_failed_resp(result):
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

        port = pyfos_switchfcport.fibrechannel()
        port.set_name(name)
        port.set_d_port_enable(0)
        result = port.patch(session)
        if pyfos_util.is_failed_resp(result):
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    if current_port_info.peek_enabled_state(
    ) == pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE:
        port = pyfos_switchfcport.fibrechannel()
        port.set_name(name)
        port.set_enabled_state(pyfos_switchfcport.ENABLED_STATE_TYPE.ONLINE)
        result = port.patch(session)
        if pyfos_util.is_failed_resp(result):
            print((json.dumps({
                "changed": False,
                "line": inspect.currentframe().f_lineno,
                "error": result
            })))
            sys.exit()

    pyfos_auth.logout(session)

    print(json.dumps({
        "changed": changed,
        "d_port_result": diag_state,
    }))