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 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 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 time_zone_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 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 = (HTTPS if is_https else HTTP) +\ fos_ip_addr + REST_TIME_ZONE return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result, full_cs_url, "time-zone", diff_attributes))
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_switch_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() if fos_version < "v9.0": if "dynamic-load-sharing" in l_diffs: if l_diffs["dynamic-load-sharing"] == "disabled": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, False, "dlsset --disable -lossless", "Lossless is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to disable DLS lossless" else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, False, "dlsset --disable -twohop", "Two-hop lossless is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to disable DLS twohop" else: result["changed"] = True elif l_diffs["dynamic-load-sharing"] == "lossless-dls": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, False, "dlsset --enable -lossless", "Lossless is set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to enable DLS lossless" else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, False, "dlsset --disable -twohop", [ "Two-hop lossless disabled successfully", "Two-hop lossless is not set" ]) if rssh != 0: result["failed"] = True result["msg"] = "Failed to disable DLS twohop" else: result["changed"] = True result["messages"] = "disabled DSL twohop" elif l_diffs["dynamic-load-sharing"] == "two-hop-lossless-dls": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, False, "dlsset --enable -lossless", "Lossless is set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to enable DLS lossless" else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, False, "dlsset --enable -twohop", "Two-hop lossless enabled successfully") if rssh != 0: result["failed"] = True result["msg"] = "Failed to enable DLS twohop" else: result["changed"] = True result["messages"] = "enable DSL two-hop-lossless-dls" else: result["failed"] = True result["msg"] = "Unkown DLS mode" l_diffs.pop("dynamic-load-sharing") # should be only key for the switch if nothing else if len(l_diffs) <= 1: return 0 full_fc_switch_url = (HTTPS if is_https else HTTP) +\ fos_ip_addr + REST_SWITCH return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result, full_fc_switch_url, "fibrechannel-switch", l_diffs))
def port_configuration_patch(login, password, fos_ip_addr, fos_version, is_https, auth, vfid, result, diff_attributes, ssh_hostkeymust): """ :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 port-configuration configurations :rtype: dict """ l_diffs = diff_attributes.copy() if "credit-recovery-mode" in l_diffs: if l_diffs["credit-recovery-mode"] == "off": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "creditrecovmode --cfg off", "") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to set credit-recovery-mode to off. " + sshstr else: result["changed"] = True result["messages"] = "credit-recovery-mode set to off" elif l_diffs["credit-recovery-mode"] == "onLrOnly": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "creditrecovmode --cfg onLrOnly", "") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to credit-recovery-mode to onLrOnly. " + sshstr else: result["changed"] = True result["messages"] = "credit-recovery-mode set to onLrOnly" elif l_diffs["credit-recovery-mode"] == "onLrThresh": rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "creditrecovmode --cfg onLrThresh", "") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to credit-recovery-mode to onLrThresh. " + sshstr else: result["changed"] = True result["messages"] = "credit-recovery-mode set to onLrThresh" else: result["failed"] = True result["msg"] = "unknown credit-recovery-mode value" l_diffs.pop("credit-recovery-mode") if len(l_diffs) == 0: return 0 full_port_config_url, validate_certs = full_url_get( is_https, fos_ip_addr, REST_PORT_CONFIGURATION) return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result, full_port_config_url, "port-configuration", l_diffs))
def fabric_patch(login, password, fos_ip_addr, fos_version, is_https, auth, vfid, result, diff_attributes, ssh_hostkeymust): """ :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 fabric configurations :rtype: dict """ l_diffs = diff_attributes.copy() if "in-order-delivery-enabled" in l_diffs: if l_diffs["in-order-delivery-enabled"] == "true": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "iodset", "IOD is set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to set IOD. " + sshstr else: result["changed"] = True result["messages"] = "in-order-delivery-enabled set" elif l_diffs["in-order-delivery-enabled"] == "false": rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "iodreset", "IOD is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to reset IOD. " + sshstr else: result["changed"] = True result["messages"] = "in-order-delivery-enabled reset" else: result["failed"] = True result["msg"] = "Failed to reset IOD. Invalid input." l_diffs.pop("in-order-delivery-enabled") if "fabric-principal-priority" in l_diffs and "fabric-principal-enabled" in l_diffs: # if both are given, execute the CLI if l_diffs["fabric-principal-enabled"] == "true": rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "fabricprincipal --enable -p " + l_diffs["fabric-principal-priority"] + " -f", "Principal Selection Mode enabled") if rssh != 0: result["failed"] = True result["msg"] = "Failed to set fabric-principal. " + sshstr else: result["changed"] = True result["messages"] = "fabric-principal-enabled set" elif l_diffs["fabric-principal-enabled"] == "false": #if disabling, must set the priority to 0 if l_diffs["fabric-principal-priority"] != "0": result["failed"] = True result["msg"] = "Priority must be 0 when disabling" else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "fabricprincipal --disable", "Principal Selection Mode disabled") if rssh != 0: result["failed"] = True result["msg"] = "Failed to set fabric-principal. " + sshstr else: result["changed"] = True result["messages"] = "fabric-principal-enabled reset" else: result["failed"] = True result["msg"] = "Failed to set fabric-principal. Invalid input." l_diffs.pop("fabric-principal-enabled") l_diffs.pop("fabric-principal-priority") else: if "fabric-principal-priority" in l_diffs: enabled_err, enabled, priority_err, priority = fabric_principal( login, password, fos_ip_addr, ssh_hostkeymust) if enabled_err is None and enabled: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "fabricprincipal --enable -p " + l_diffs["fabric-principal-priority"] + " -f", "Principal Selection Mode enabled") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to set fabric-principal-priority. " + sshstr else: result["changed"] = True result["messages"] = "fabric-principal-priority set" else: result["failed"] = True result[ "msg"] = "fabric-principal-priority must be accompanied by fabric-principal-enabled" l_diffs.pop("fabric-principal-priority") if "fabric-principal-enable" in l_diffs: result["failed"] = True result[ "msg"] = "fabric-principal-enabled must be accompanied by fabric-principal-priority" l_diffs.pop("fabric-principal-enabled") if len(l_diffs) == 0: return 0 full_fabric_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_FABRIC) return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result, full_fabric_url, "fabric", l_diffs))
def fc_switch_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: dict of switch configurations :rtype: dict """ l_diffs = diff_attributes.copy() if fos_version < "v9.0": in_mode_3 = False rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "aptpolicy", "showcommand") if rssh == 0: if "Current Policy: 3" in sshstr: in_mode_3 = True result["aptpolicy 3"] = in_mode_3 if "dynamic-load-sharing" in l_diffs: if l_diffs["dynamic-load-sharing"] == "disabled": if in_mode_3: result["failed"] = True result["msg"] = "Unsupported mode for policy." else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --disable -lossless", "Lossless is not set") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to disable DLS lossless. " + sshstr else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --disable -twohop", "Two-hop lossless is not set") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to disable DLS twohop. " + sshstr else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsreset", "DLS is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to reset. " + sshstr else: result["changed"] = True elif l_diffs["dynamic-load-sharing"] == "lossless-dls": rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --enable -lossless", ["Lossless is set", "DLS and Lossless are set"]) if rssh != 0: result["failed"] = True result["msg"] = "Failed to enable DLS lossless. " + sshstr else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --disable -twohop", [ "Two-hop lossless disabled successfully", "Two-hop lossless is not set" ]) if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to disable DLS twohop. " + sshstr else: result["changed"] = True result["messages"] = "disabled DSL twohop" elif l_diffs["dynamic-load-sharing"] == "two-hop-lossless-dls": rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --enable -lossless", ["Lossless is set", "DLS and Lossless are set"]) if rssh != 0: result["failed"] = True result["msg"] = "Failed to enable DLS lossless. " + sshstr else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --enable -twohop", "Two-hop lossless enabled successfully") if rssh != 0: result["failed"] = True result[ "msg"] = "Failed to enable DLS twohop. " + sshstr else: result["changed"] = True result["messages"] = "enable DSL two-hop-lossless-dls" elif l_diffs["dynamic-load-sharing"] == "dls": if in_mode_3: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset --disable -lossless", "Lossless is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to dlsset. " + sshstr else: result["changed"] = True result["messages"] = "enable DSL dls" else: rssh, sshstr = ssh_and_configure(login, password, fos_ip_addr, ssh_hostkeymust, "dlsreset", "DLS is not set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to dlsreset. " + sshstr else: rssh, sshstr = ssh_and_configure( login, password, fos_ip_addr, ssh_hostkeymust, "dlsset", "DLS is set") if rssh != 0: result["failed"] = True result["msg"] = "Failed to dlsset. " + sshstr else: result["changed"] = True result["messages"] = "enable DSL dls" else: result["failed"] = True result["msg"] = "Unkown DLS mode" l_diffs.pop("dynamic-load-sharing") # should be only key for the switch if nothing else if len(l_diffs) <= 1: return 0 full_fc_switch_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_SWITCH) return (url_patch_single_object(fos_ip_addr, is_https, auth, vfid, result, full_fc_switch_url, "fibrechannel-switch", l_diffs, timeout))