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)
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
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
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)
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)
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)
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)
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))
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)
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
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))
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
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
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
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
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
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
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
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)
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))
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)
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)
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)
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)
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))
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)
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)
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)