Ejemplo n.º 1
0
def password_patch(login, password, fos_ip_addr, fos_version, is_https, auth,
                       vfid, result, new_password, ssh_hostkeymust):
    """
        update existing user config configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_PASSWORD)

    xml_str = password_xml_str(result, new_password)

    result["patch_password_str"] = xml_str

    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_url, xml_str)
Ejemplo n.º 2
0
def system_patch(login, password, fos_ip_addr, fos_version, is_https, auth,
                    vfid, result, diff_attributes):
    """
        update existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of switch configurations
        :rtype: dict
    """
    l_diffs = diff_attributes.copy()

    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_SNMP_SYSTEM)

    return (url_patch_single_object(fos_ip_addr, is_https, auth,
                                    vfid, result, full_url,
                                    "system", l_diffs))
def fabric_get(login, password, fos_ip_addr, fos_version, is_https, auth, vfid,
               result, ssh_hostkeymust):
    """
        retrieve existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of fabric configurations
        :rtype: dict
    """
    full_fabric_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                   REST_FABRIC)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                   full_fabric_url)
    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None

    rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr,
                                     ssh_hostkeymust, "iodshow", "showcommand")
    if rssh == 0:
        if "IOD is not set" in sshstr:
            rdict["Response"]["fabric"]["in-order-delivery-enabled"] = "false"
        elif "IOD is set" in sshstr:
            rdict["Response"]["fabric"]["in-order-delivery-enabled"] = "true"
        else:
            result["failed"] = True
            result["msg"] = "IOD returned unknown string. " + sshstr
            return -1, None

    enabled_err, enabled, priority_err, priority = fabric_principal(
        login, password, fos_ip_addr, ssh_hostkeymust)
    if enabled_err == None:
        if enabled:
            rdict["Response"]["fabric"]["fabric-principal-enabled"] = "true"
        else:
            rdict["Response"]["fabric"]["fabric-principal-enabled"] = "false"
    else:
        result["failed"] = True
        result["msg"] = enabled_err
        return -1, None

    if priority_err == None:
        rdict["Response"]["fabric"]["fabric-principal-priority"] = priority
    else:
        result["failed"] = True
        result["msg"] = priority_err
        return -1, None

    return 0, rdict
Ejemplo n.º 4
0
def system_get(login, password, fos_ip_addr, fos_version, is_https, auth, vfid, result):
    """
        retrieve existing snmp system configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of switch configurations
        :rtype: dict
    """
    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_SNMP_SYSTEM)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid,
                           result, full_url)

    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None

    return 0, rdict
Ejemplo n.º 5
0
def list_delete(login, password, fos_ip_addr, module_name, list_name,
                fos_version, is_https, auth, vfid, result, entries,
                ssh_hostkeymust, timeout):
    """
        update existing user config configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_url, validate_certs = full_url_get(
        is_https, fos_ip_addr, REST_PREFIX + module_name + "/" + list_name)

    xml_str = list_xml_str(result, module_name, list_name, entries)

    result["delete_str"] = xml_str

    return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_url,
                      xml_str, timeout)
Ejemplo n.º 6
0
def cfg_enable(fos_ip_addr, is_https, auth, vfid,
               result, checksum, active_cfg):
    """
        enable a particular cfg

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param checksum: current checksum of the database
        :type checksum: str
        :param active_cfg: cfg to be enabled
        :type active_cfg: str
        :return: code to indicate failure or success
        :rtype: int
    """
    full_effective_url, validate_certs = full_url_get(is_https,
                                                      fos_ip_addr,
                                                      REST_EFFECTIVE)

    save_str = "<effective-configuration><checksum>" + checksum +\
        "</checksum><cfg-name>" + active_cfg +\
        "</cfg-name></effective-configuration>"
    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_effective_url, save_str)
Ejemplo n.º 7
0
def cfg_disable(fos_ip_addr, is_https, auth, vfid, result, checksum, timeout):
    """
        disable zoning transaction

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param vfid: vfid of the switch to be executed
        :type vfid: int
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param checksum: current checksum of the database
        :type checksum: str
        :return: code to indicate failure or success
        :rtype: int
    """
    full_effective_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                      REST_EFFECTIVE)

    disable_str = "<effective-configuration><cfg-action>"\
        "2</cfg-action><checksum>" + checksum +\
        "</checksum></effective-configuration>"
    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_effective_url, disable_str, timeout)
Ejemplo n.º 8
0
def ipfilter_rule_patch(fos_ip_addr, is_https, auth,
                       vfid, result, rules):
    """
        update existing ip filter configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_IPFILTER_RULE)

    xml_str = ipfilter_rule_xml_str(result, rules)

    result["patch_ipfilter_str"] = xml_str

    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_url, xml_str)
Ejemplo n.º 9
0
def effective_patch(fos_ip_addr, is_https, auth,
                    vfid, result, diff_attributes):
    """
        update existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of effective configurations
        :rtype: dict
    """
    full_effective_url, validate_certs = full_url_get(is_https,
                                                      fos_ip_addr,
                                                      REST_EFFECTIVE)

    return (url_patch_single_object(fos_ip_addr, is_https, auth,
            vfid, result, full_effective_url,
            "effective-configuration", diff_attributes))
Ejemplo n.º 10
0
def user_config_delete(fos_ip_addr, is_https, auth,
                       vfid, result, users):
    """
        delete existing user config configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_USER_CONFIG)

    xml_str = user_config_xml_str(result, users)

    result["delete_user_config_str"] = xml_str

    return url_delete(fos_ip_addr, is_https, auth, vfid, result,
                     full_url, xml_str)
Ejemplo n.º 11
0
def singleton_get(login, password, fos_ip_addr, module_name, obj_name, fos_version, is_https, auth, vfid, result, ssh_hostkeymust):
    """
        retrieve existing user config configuration 

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of ipfilter policy configurations
        :rtype: dict
    """
    full_url, validate_certs = full_url_get(is_https,
                                            fos_ip_addr,
                                            REST_PREFIX + module_name + "/" + obj_name)

    ret, resp = url_get_to_dict(fos_ip_addr, is_https, auth, vfid,
                                result, full_url)

    if ret == -2:
        # return empty dict. GET isn't supported
        result["daniel1"] = "here"
        return 0, ({"Response" : {obj_name: {}}})

    result["daniel2"] = "why"
    return ret, resp
Ejemplo n.º 12
0
def clock_server_patch(fos_ip_addr, is_https, auth,
                       vfid, result, diff_attributes):
    """
        update existing clock-server configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_cs_url, validate_certs = full_url_get(is_https,
                                               fos_ip_addr,
                                               REST_CLOCK_SERVER)

    return (url_patch_single_object(fos_ip_addr, is_https, auth,
                                    vfid, result, full_cs_url,
                                    "clock-server", diff_attributes, longer_timeout = 300))
Ejemplo n.º 13
0
def alias_set(fos_ip_addr, is_https, auth, vfid, result, aliases, method):
    """
        set aliases in Zone Database

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param aliases: list of aliases to set
        :type aliases: list
        :param method: "POST", "PATCH", or "DELETE"
        :type method: str
        :return: code to indicate failure or success
        :rtype: int
    """
    full_defined_url, validate_certs = full_url_get(is_https,
                                                    fos_ip_addr,
                                                    REST_DEFINED)

    alias_str = "<defined-configuration>"

    for alias in aliases:
        alias_str = alias_str + "<alias><alias-name>" +\
            alias["name"] + "</alias-name>"
        if "members" in alias:
            alias_str = alias_str + "<member-entry>"
            for member in alias["members"]:
                alias_str = alias_str + "<alias-entry-name>" +\
                    member + "</alias-entry-name>"
            alias_str = alias_str + "</member-entry>"
        alias_str = alias_str + "</alias>"

    alias_str = alias_str + "</defined-configuration>"

    result["alias_str"] = alias_str
    result["method"] = method

    if method == "POST":
        return url_post(fos_ip_addr, is_https, auth, vfid, result,
                        full_defined_url, alias_str)
    elif method == "PATCH":
        return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                         full_defined_url, alias_str)
    elif method == "DELETE":
        return url_delete(fos_ip_addr, is_https, auth, vfid, result,
                          full_defined_url, alias_str)
    else:
        result["invalid method"] = method
        result["failed"] = True
        result["msg"] = "url_get_to_dict failed"
        return -1
Ejemplo n.º 14
0
def fc_switch_get(login, password, fos_ip_addr, fos_version, is_https, auth,
                  vfid, result, ssh_hostkeymust, timeout):
    """
        retrieve existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of switch configurations
        :rtype: dict
    """
    full_fc_switch_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                      REST_SWITCH)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                   full_fc_switch_url, timeout)

    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None

    result["fos_version"] = fos_version
    result["fos_version_check"] = fos_version < "v9.0"
    if fos_version < "v9.0":
        rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr,
                                         ssh_hostkeymust, "dlsshow",
                                         "showcommand")
        if rssh == 0:
            if "DLS is not set with Lossless disabled" in sshstr or "Error: This command is not supported in AG mode" in sshstr:
                rdict["Response"]["fibrechannel-switch"][
                    "dynamic-load-sharing"] = "disabled"
            elif "DLS is set with Lossless disabled" in sshstr:
                rdict["Response"]["fibrechannel-switch"][
                    "dynamic-load-sharing"] = "dls"
            elif "DLS is set with Lossless enabled, Two-hop Lossless disabled" in sshstr:
                rdict["Response"]["fibrechannel-switch"][
                    "dynamic-load-sharing"] = "lossless-dls"
            elif "DLS is set with Two-hop Lossless enabled" in sshstr:
                rdict["Response"]["fibrechannel-switch"][
                    "dynamic-load-sharing"] = "two-hop-lossless-dls"
            else:
                result["failed"] = True
                result["msg"] = "DLS returned unknown string"
                return -1, None

    return 0, rdict
Ejemplo n.º 15
0
def cfg_set(fos_ip_addr, is_https, auth, vfid, result, cfgs, method):
    """
        set cfgs in Zone Database

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param cfgs: list of cfgs to set
        :type cfgs: list
        :param method: "POST", "PATCH", or "DELETE"
        :type method: str
        :return: code to indicate failure or success
        :rtype: int
    """
    full_defined_url, validate_certs = full_url_get(is_https,
                                                    fos_ip_addr,
                                                    REST_DEFINED)

    cfg_str = "<defined-configuration>"

    for cfg in cfgs:
        cfg_str = cfg_str + "<cfg><cfg-name>" + cfg["name"] + "</cfg-name>"
        if "members" in cfg:
            cfg_str = cfg_str + "<member-zone>"
            for member in cfg["members"]:
                cfg_str = cfg_str + "<zone-name>" + member + "</zone-name>"
            cfg_str = cfg_str + "</member-zone>"

        cfg_str = cfg_str + "</cfg>"

    cfg_str = cfg_str + "</defined-configuration>"

#    result["cfg_str"] = cfg_str

    if method == "POST":
        return url_post(fos_ip_addr, is_https, auth, vfid, result,
                        full_defined_url, cfg_str)
    elif method == "PATCH":
        return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                         full_defined_url, cfg_str)
    elif method == "DELETE":
        return url_delete(fos_ip_addr, is_https, auth, vfid, result,
                          full_defined_url, cfg_str)
    else:
        result["invalid method"] = method
        result["failed"] = True
        result["msg"] = "url_get_to_dict failed"
        return -1
Ejemplo n.º 16
0
def singleton_get(login, password, fos_ip_addr, module_name, obj_name,
                  fos_version, is_https, auth, vfid, result, ssh_hostkeymust,
                  timeout):
    """
        retrieve existing user config configuration 

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of ipfilter policy configurations
        :rtype: dict
    """
    if module_name == "brocade_chassis" and obj_name == "chassis":
        return chassis_get(login, password, fos_ip_addr, fos_version, is_https,
                           auth, vfid, result, ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "fabric":
        return fabric_get(login, password, fos_ip_addr, fos_version, is_https,
                          auth, vfid, result, ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "port_configuration":
        return port_configuration_get(login, password, fos_ip_addr,
                                      fos_version, is_https, auth, vfid,
                                      result, ssh_hostkeymust, timeout)

    # get is not support for these modules. Just return empty
    if module_name == "brocade_security" and obj_name == "security_certificate_action":
        return 0, ({"Response": {str_to_yang(obj_name): {}}})
    if module_name == "brocade_security" and obj_name == "security_certificate_generate":
        return 0, ({"Response": {str_to_yang(obj_name): {}}})
    if module_name == "brocade_security" and obj_name == "sshutil_public_key_action":
        return 0, ({"Response": {str_to_yang(obj_name): {}}})

    full_url, validate_certs = full_url_get(
        is_https, fos_ip_addr, REST_PREFIX + module_name + "/" + obj_name)

    ret, resp = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                full_url, timeout)

    if ret == ERROR_LIST_EMPTY:
        # return empty dict. GET isn't supported
        return 0, ({"Response": {str_to_yang(obj_name): {}}})

    return ret, resp
Ejemplo n.º 17
0
def singleton_patch(login, password, fos_ip_addr, module_name, obj_name,
                    fos_version, is_https, auth, vfid, result, new_attributes,
                    ssh_hostkeymust, timeout):
    """
        update existing user config configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    if module_name == "brocade_chassis" and obj_name == "chassis":
        return chassis_patch(login, password, fos_ip_addr, fos_version,
                             is_https, auth, vfid, result, new_attributes,
                             ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "fabric":
        return fabric_patch(login, password, fos_ip_addr, fos_version,
                            is_https, auth, vfid, result, new_attributes,
                            ssh_hostkeymust, timeout)

    if module_name == "brocade_fibrechannel_configuration" and obj_name == "port_configuration":
        return port_configuration_patch(login, password, fos_ip_addr,
                                        fos_version, is_https, auth, vfid,
                                        result, new_attributes,
                                        ssh_hostkeymust, timeout)

    full_url, validate_certs = full_url_get(
        is_https, fos_ip_addr, REST_PREFIX + module_name + "/" + obj_name)

    xml_str = singleton_xml_str(result, obj_name, new_attributes)

    result["patch_obj_str"] = xml_str

    if module_name == "brocade_security" and obj_name == "security_certificate_generate":
        return url_post(fos_ip_addr, is_https, auth, vfid, result, full_url,
                        xml_str, timeout)

    return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_url,
                     xml_str, timeout)
def port_configuration_get(login, password, fos_ip_addr, fos_version, is_https,
                           auth, vfid, result, ssh_hostkeymust, timeout):
    """
        retrieve existing port configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of fabric configurations
        :rtype: dict
    """
    full_port_config_url, validate_certs = full_url_get(
        is_https, fos_ip_addr, REST_PORT_CONFIGURATION)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                   full_port_config_url, timeout)
    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None

    rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr,
                                     ssh_hostkeymust, "creditrecovmode --show",
                                     "showcommand")
    if rssh == 0:
        if "Internal port credit recovery is Disabled" in sshstr:
            rdict["Response"]["port-configuration"][
                "credit-recovery-mode"] = "off"
        elif "Internal port credit recovery is Enabled with LrOnly" in sshstr:
            rdict["Response"]["port-configuration"][
                "credit-recovery-mode"] = "onLrOnly"
        elif "Internal port credit recovery is Enabled with LrThresh" in sshstr:
            rdict["Response"]["port-configuration"][
                "credit-recovery-mode"] = "onLrThresh"
        elif "Not supported on this platform" in sshstr:
            result["credit_recovery_mode"] = "Not supported on this platform"
        else:
            result["failed"] = True
            result["msg"] = "credit-recovery-mode returned unknown string"
            return -1, None

    return 0, rdict
Ejemplo n.º 19
0
def system_get(login, password, fos_ip_addr, fos_version, is_https, auth, vfid,
               result):
    """
        retrieve existing snmp system configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of switch configurations
        :rtype: dict
    """
    full_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                            REST_SNMP_SYSTEM)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                   full_url)

    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None


#    result["fos_version"] = fos_version
#    result["fos_version_check"] = fos_version < "v9.0"
#    if fos_version < "v9.0":
#        rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, False, "dlsshow", "showcommand")
#        if rssh == 0:
#            if "DLS is set with Lossless disabled" in sshstr:
#                rdict["Response"]["fibrechannel-switch"]["dynamic-load-sharing"] = "disabled"
#            elif "DLS is set with Lossless enabled, Two-hop Lossless disabled" in sshstr:
#                rdict["Response"]["fibrechannel-switch"]["dynamic-load-sharing"] = "lossless-dls"
#            elif "DLS is set with Two-hop Lossless enabled" in sshstr:
#                rdict["Response"]["fibrechannel-switch"]["dynamic-load-sharing"] = "two-hop-lossless-dls"
#            else:
#                result["failed"] = True
#                result["msg"] = "DLS returned unknown string"
#                return -1, None

    return 0, rdict
Ejemplo n.º 20
0
def chassis_get(login, password, fos_ip_addr, fos_version, is_https, auth,
                vfid, result, ssh_hostkeymust, timeout):
    """
        retrieve existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of chassis configurations
        :rtype: dict
    """
    full_chassis_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                    REST_CHASSIS)

    rtype, rdict = url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                                   full_chassis_url, timeout)
    if rtype != 0:
        result["failed"] = True
        result["msg"] = "API failed to return data"
        return -1, None

    rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr,
                                     ssh_hostkeymust, "timeout", "showcommand")
    if rssh == 0:
        if "Current IDLE Timeout is " in sshstr:
            text = sshstr[len("Current IDLE Timeout is "):]
            timeout = text.split(" ")
            rdict["Response"]["chassis"]["telnet-timeout"] = timeout[0]
        elif "Shell Idle Timeout is " in sshstr:
            text = sshstr[len("Shell Idle Timeout is "):]
            timeout = text.split(" ")
            rdict["Response"]["chassis"]["telnet-timeout"] = timeout[0]
        else:
            result["failed"] = True
            result["msg"] = "telnet_timeout returned unknown string"
            return -1, None

    return 0, rdict
Ejemplo n.º 21
0
def logout(fos_ip_addr, is_https, auth, result):
    """
        logout from the fos switch at ip address specified

        :param fos_ip_addr: fos switch ip address
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTPS or HTTP
        :type fos_password: Bool
        :param auth: return authorization struct at the time of login
        :type auth: dict
        :return: 0 for success or -1 for failure
        :rtype: int
    """
    full_logout_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                   REST_LOGOUT)

    return url_post(fos_ip_addr, is_https, auth, None, result, full_logout_url,
                    None)
Ejemplo n.º 22
0
def chassis_patch(login, password, fos_ip_addr, fos_version, is_https, auth,
                  vfid, result, diff_attributes, ssh_hostkeymust, timeout):
    """
        update existing switch configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    l_diffs = diff_attributes.copy()

    if "telnet-timeout" in l_diffs:
        rssh, sshstr = ssh_and_configure(
            login, password, fos_ip_addr, ssh_hostkeymust,
            "timeout " + str(l_diffs["telnet-timeout"]),
            "Timeout will be in effect after NEXT login")
        if rssh != 0:
            result["failed"] = True
            result["msg"] = "Failed to set telnet-timeout. " + sshstr
        else:
            result["changed"] = True
            result["messages"] = "telnet-timeout set"
        l_diffs.pop("telnet-timeout")

    if len(l_diffs) == 0:
        return 0

    full_chassis_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                    REST_CHASSIS)

    return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result,
                                    full_chassis_url, "chassis", l_diffs,
                                    timeout))
Ejemplo n.º 23
0
def fc_port_patch(fos_ip_addr, is_https, auth, vfid, result, ports, timeout):
    """
        update existing port configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param ports: list of ports and associated attributes for update
        :type ports: list
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of port configurations
        :rtype: list
    """
    full_fc_port_url, validate_certs = full_url_get(is_https,
                                                    fos_ip_addr,
                                                    REST_FC)

    fc_port_str = ""

    for port in ports:
        fc_port_str = fc_port_str + "<fibrechannel>"

        fc_port_str = fc_port_str + "<name>" + port["name"] + "</name>"

        for k, v in port.items():
            if k != "name":
                k = k.replace("_", "-")
                fc_port_str = fc_port_str + "<" + k + ">" +\
                    str(v) + "</" + k + ">"

        fc_port_str = fc_port_str + "</fibrechannel>"

    result["fc_port_str"] = fc_port_str

    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_fc_port_url, fc_port_str, timeout)
Ejemplo n.º 24
0
def syslog_server_patch(fos_ip_addr, is_https, auth, vfid, result, servers):
    """
        update existing syslog-server configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :param diff_attributes: list of attributes for update
        :type ports: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of chassis configurations
        :rtype: list
    """
    full_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                            REST_LOGGING_SYSLOG_SERVER)

    syslog_str = ""

    for server in servers:
        syslog_str = syslog_str + "<syslog-server>"

        syslog_str = syslog_str + "<server>" + server["server"] + "</server>"

        for k, v in server.items():
            if k != "server":
                k = k.replace("_", "-")
                syslog_str = syslog_str + "<" + k + ">" +\
                    str(v) + "</" + k + ">"

        syslog_str = syslog_str + "</syslog-server>"

    result["patch_syslog_str"] = syslog_str

    return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_url,
                     syslog_str)
Ejemplo n.º 25
0
def audit_get(fos_ip_addr, is_https, auth, vfid, result):
    """
        retrieve existing audit configurations

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of clock server configurations
        :rtype: dict
    """
    full_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                            REST_LOGGING_AUDIT)

    return url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result, full_url)
Ejemplo n.º 26
0
def fc_port_stats_get(fos_ip_addr, is_https, auth, vfid, result):
    """
        retrieve existing port stats

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: list of dict of port stats
        :rtype: list
    """
    full_fc_port_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                    REST_FC_STATS)

    return url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                           full_fc_port_url)
Ejemplo n.º 27
0
def ipfilter_policy_get(fos_ip_addr, is_https, auth, vfid, result, timeout):
    """
        retrieve existing ipfilter policy configuration 

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type struct: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of ipfilter policy configurations
        :rtype: dict
    """
    full_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                            REST_IPFILTER_POLICY)

    return (url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                            full_url, timeout))
Ejemplo n.º 28
0
def cfg_abort(fos_ip_addr, is_https, auth, vfid, result):
    """
        abort zoning transacdtion

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
    """
    full_effective_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                      REST_EFFECTIVE)

    abort_str = "<effective-configuration><cfg-action>"\
        "4</cfg-action></effective-configuration>"
    return url_patch(fos_ip_addr, is_https, auth, vfid, result,
                     full_effective_url, abort_str)
Ejemplo n.º 29
0
def cfg_get(fos_ip_addr, is_https, auth, vfid, result):
    """
        retrieve existing cfgs

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of cfg content
        :rtype: dict
    """
    full_defined_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                    REST_DEFINED + "/cfg")

    return url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                           full_defined_url)
Ejemplo n.º 30
0
def effective_get(fos_ip_addr, is_https, auth, vfid, result):
    """
        retrieve all of effective Zone Database

        :param fos_ip_addr: ip address of FOS switch
        :type fos_ip_addr: str
        :param is_https: indicate to use HTTP or HTTPS
        :type is_https: bool
        :param auth: authorization struct from login
        :type auth: dict
        :param result: dict to keep track of execution msgs
        :type result: dict
        :return: code to indicate failure or success
        :rtype: int
        :return: dict of full effective Zone DB content
        :rtype: dict
    """
    full_effective_url, validate_certs = full_url_get(is_https, fos_ip_addr,
                                                      REST_EFFECTIVE)

    return url_get_to_dict(fos_ip_addr, is_https, auth, vfid, result,
                           full_effective_url)