def to_fos_system(system_config, result): human_to_yang(system_config) for k, v in system_config.items(): if isinstance(v, bool): if v == True: system_config[k] = "true" else: system_config[k] = "false" return 0
def to_fos_singleton(module_name, obj_name, attributes, result): human_to_yang(attributes) for k, v in attributes.items(): if isinstance(v, bool): if v == True: attributes[k] = "true" else: attributes[k] = "false" # if going to fos, we need to encode password if module_name == "brocade-security" and obj_name == "password" and k == "old-password": attributes[k] = base64.b64encode(attributes[k].encode('ascii')).decode('utf-8') if module_name == "brocade-security" and obj_name == "password" and k == "new-password": attributes[k] = base64.b64encode(attributes[k].encode('ascii')).decode('utf-8') return 0
def to_fos_list(module_name, list_name, attributes_list, result): for attributes in attributes_list: human_to_yang(attributes) for k, v in attributes.items(): if isinstance(v, bool): if v == True: attributes[k] = "true" else: attributes[k] = "false" if module_name == "brocade-snmp" and list_name == "v3-account": if k == "authentication-password" or k == "privacy-password": if str(v) != "None": attributes[k] = base64.b64encode( v.encode('ascii')).decode('utf-8') return 0
def to_fos_zoning(zoning_config, result): human_to_yang(zoning_config) if "default-zone-access" in zoning_config: if zoning_config["default-zone-access"] == "allaccess": zoning_config["default-zone-access"] = "1" elif zoning_config["default-zone-access"] == "noaccess": zoning_config["default-zone-access"] = "0" else: result["failed"] = True result["msg"] = "default-zone-access converted to unknown value" return -1 for k, v in zoning_config.items(): if isinstance(v, bool): if v == True: zoning_config[k] = "true" else: zoning_config[k] = "false" return 0
def to_fos_operation(op_name, in_name, attributes, result): human_to_yang(attributes) for k, v in attributes.items(): # if going to fos, we need to encode password if op_name == "supportsave" and in_name == "connection": if k == "password": attributes[k] = base64.b64encode( attributes[k].encode('ascii')).decode('utf-8') if op_name == "firmwaredownload" and in_name == "firmwaredownload_parameters": if k == "password": attributes[k] = base64.b64encode( attributes[k].encode('ascii')).decode('utf-8') for k, v in attributes.items(): if isinstance(v, bool): if v == True: attributes[k] = "true" else: attributes[k] = "false" return 0
def to_fos_list(module_name, list_name, attributes_list, result): for attributes in attributes_list: human_to_yang(attributes) if module_name == "brocade_snmp" and list_name == "v3_account": if "authentication-password" in attributes: pword = attributes["authentication-password"] if str(pword) != "None": attributes["authentication-password"] = base64.b64encode( pword.encode('ascii')).decode('utf-8') if "privacy-password" in attributes: pword = attributes["privacy-password"] if str(pword) != "None": attributes["privacy-password"] = base64.b64encode( pword.encode('ascii')).decode('utf-8') if module_name == "brocade_interface" and list_name == "fibrechannel": to_fos_fc(attributes, result) if module_name == "brocade_fibrechannel_switch" and list_name == "fibrechannel_switch": to_fos_switch(attributes, result) if module_name == "brocade_security" and list_name == "user_config": if "password" in attributes: pword = attributes["password"] if str(pword) != "None": attributes["password"] = base64.b64encode( pword.encode('ascii')).decode('utf-8') for k, v in attributes.items(): if isinstance(v, bool): if v == True: attributes[k] = "true" else: attributes[k] = "false" return 0
def to_fos_switch(switch_config, result): human_to_yang(switch_config) if "enabled-state" in switch_config: if isinstance(switch_config["enabled-state"], bool): if switch_config["enabled-state"] == False: switch_config["enabled-state"] = "3" else: switch_config["enabled-state"] = "2" else: result["failed"] = True result["msg"] = "enabled-state converted to unknown" return -1 # convert the boolean to integers first # then convert the rest of the booleans to bool string for k, v in switch_config.items(): if isinstance(v, bool): if v == True: switch_config[k] = "true" else: switch_config[k] = "false" return 0
def to_fos_fc(port_config, result): human_to_yang(port_config) # convert boolean to non 0/1 integer # convert boolean to 0/1 integer # convert the rest to boolean string if "enabled-state" in port_config: if port_config["enabled-state"] == True: port_config["enabled-state"] = "2" elif port_config["enabled-state"] == False: port_config["enabled-state"] = "6" else: result["failed"] = True result["msg"] = "enabled-state converted to unknown value" return -1 for attrib in zero_one_attributes: if attrib in port_config: if isinstance(port_config[attrib], bool): if port_config[attrib] == False: port_config[attrib] = "0" else: port_config[attrib] = "1" else: result["failed"] = True result["msg"] = attrib + " converted non-bool value" return -1 for k, v in port_config.items(): if isinstance(v, bool): if v == True: port_config[k] = "true" else: port_config[k] = "false" if "los-tov-mode-enabled" in port_config: if port_config["los-tov-mode-enabled"] == "Disabled": port_config["los-tov-mode-enabled"] = "0" elif port_config["los-tov-mode-enabled"] == "Fixed": port_config["los-tov-mode-enabled"] = "1" elif port_config["los-tov-mode-enabled"] == "FixedAuto": port_config["los-tov-mode-enabled"] = "2" else: result["failed"] = True result["msg"] = "los-tov-mode-enabled converted to unknown value" return -1 if "long-distance" in port_config: if port_config["long-distance"] == "Disabled": port_config["long-distance"] = "0" elif port_config["long-distance"] == "L0": port_config["long-distance"] = "1" elif port_config["long-distance"] == "L1": port_config["long-distance"] = "2" elif port_config["long-distance"] == "L2": port_config["long-distance"] = "3" elif port_config["long-distance"] == "LE": port_config["long-distance"] = "4" elif port_config["long-distance"] == "L0.5": port_config["long-distance"] = "5" elif port_config["long-distance"] == "LD": port_config["long-distance"] = "6" elif port_config["long-distance"] == "LS": port_config["long-distance"] = "7" else: result["failed"] = True result["msg"] = "long-distance converted to unknown value" return -1 if "speed" in port_config: if port_config["speed"] == "32Gig": port_config["speed"] = "32000000000" elif port_config["speed"] == "16Gig": port_config["speed"] = "16000000000" elif port_config["speed"] == "8Gig": port_config["speed"] = "8000000000" elif port_config["speed"] == "10Gig": port_config["speed"] = "10000000000" elif port_config["speed"] == "4Gig": port_config["speed"] = "4000000000" elif port_config["speed"] == "2Gig": port_config["speed"] = "2000000000" elif port_config["speed"] == "1Gig": port_config["speed"] = "1000000000" elif port_config["speed"] == "Auto": port_config["speed"] = "0" else: result["failed"] = True result["msg"] = "speed converted to unknown value" return -1 return 0