Esempio n. 1
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 "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("install")
    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()
    else:
        pyfos_util.response_print(l_rsp_obj)

    pyfos_auth.logout(session)
Esempio n. 2
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, 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)

    defined_zone = pyfos_zone.defined_configuration.get(session)
    pyfos_util.response_print(defined_zone)

    effective_zone = pyfos_zone.effective_configuration.get(session)
    pyfos_util.response_print(effective_zone)

    # options = effective_zone.options(session)
    # print(options)

    pyfos_auth.logout(session)
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)

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

    pyfos_auth.logout(session)
Esempio n. 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)

    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)
Esempio n. 5
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)

    defined_zone = pyfos_zone.defined_configuration.get(session)
    pyfos_util.response_print(defined_zone)

    effective_zone = pyfos_zone.effective_configuration.get(session)
    pyfos_util.response_print(effective_zone)

    pyfos_auth.logout(session)
Esempio n. 6
0
def main(argv):
    #myinput=str("-i 10.17.3.70  -n 4/19 ")
    #argv = myinput.split()
    value_dict = dict()
    inputs = dict()
    ret = parse_tunnel(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_tunnel(session, value_dict)
    pyfos_util.response_print(result)
    pyfos_auth.logout(session)
Esempio n. 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)

    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)
Esempio n. 8
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)

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

    pyfos_auth.logout(session)
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)
Esempio n. 10
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']

    diff_object(session, dir_name, pyfos_switch.fibrechannel_switch)
    diff_object_list(session, dir_name, pyfos_switchfcport.fibrechannel)
    diff_object(session, dir_name, pyfos_zone.defined_configuration)
    diff_object(session, dir_name, pyfos_zone.effective_configuration)

    pyfos_auth.logout(session)
Esempio n. 11
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)
        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, __zonedelete)

    pyfos_auth.logout(session)
def example_login(user="******",
                  password="******",
                  ip="10.200.154.63",
                  https=None,
                  throttle=1.1,
                  verbose=0,
                  tokenArg=None,
                  sessionless=False):
    """
    This function is a wrapper function to get a session dictionary for REST
    operation based on the input options specified, all subsequent REST
    operation can be performed by using this session dictionary. The session
    returned is based on inputs for.

    **Regular REST login session**
        *tokenArg* is None
        *sessionless* is False
    **Auth Token based REST login session**
        *tokenArg* is either a Token Manager instance or an Auth token string
        *password* is None
        *sessionless* is False.
    **sessionless  session without any login**
        *tokenArg* must be None
        *password* is mandatory
        *sessionless* is True.
    """
    return pyfos_auth.login(user, password, ip, https, throttle, verbose,
                            tokenArg, sessionless)
Esempio n. 13
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)

    fabric = pyfos_fabric.fabric_switch.get(session)
    if isinstance(fabric, list):
        for switch in fabric:
            pyfos_util.response_print(switch)
    else:
        pyfos_util.response_print(fabric)

    pyfos_auth.logout(session)
Esempio n. 14
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_pmembers_func(session, inputs, usage,
                                                   __pzoneadd)

    pyfos_auth.logout(session)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
0
def main(argv):
    global session
    atexit.register(exit_handler)
    ipaddr = input("Switch IP:")
    login = input("Login:"******"login failed because", session.get('credential')['login-error'])
        sys.exit()
    shell(login)
    pyfos_auth.logout(session)
    session = None
Esempio n. 22
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
            else:
                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
Esempio n. 23
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
Esempio n. 24
0
def main(argv):
    valid_options = ["allaccess"]
    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 "allaccess" not in inputs:
        pyfos_auth.logout(session)
        usage()
        sys.exit()
    allaccess = inputs["allaccess"]

    current_effective = pyfos_zone.effective_configuration.get(session)

    result = defzone(session, allaccess)

    if pyfos_util.is_failed_resp(result):
        pyfos_util.response_print(result)
    else:
        pyfos_util.response_print(result)
        result = cfgsave.cfgsave(session, current_effective.peek_checksum())
        pyfos_util.response_print(result)
        if pyfos_util.is_failed_resp(result):
            print("failed. Aborting transaction.")
            result = cfgabort.cfgabort(session)
            pyfos_util.response_print(result)

    pyfos_auth.logout(session)
Esempio n. 25
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)
Esempio n. 26
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('')
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
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
Esempio n. 30
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