def create_a_mtu_object_from_a_json(context) -> None: """ JSON file data structure must be as follow: spine01: global_mtu: 1500 interfaces: lo0: 1514 :param context: :param mtu_data: Data to create a MTU object :param hostname: Device hostname :return: """ mtu_data = open_file(path=f"{FEATURES_SRC_PATH}mtu_tests.yml") hostname = list(mtu_data.keys())[0] interface_mtu_lst = ListInterfaceMTU(list()) if hostname in mtu_data.keys(): if MTU_INTER_YAML_KEY in mtu_data.get(hostname): for interface_name in mtu_data.get(hostname).get( MTU_INTER_YAML_KEY): interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU( interface_name=_mapping_interface_name(interface_name), mtu_size=mtu_data.get(hostname).get( MTU_INTER_YAML_KEY).get(interface_name, NOT_SET))) context.object_02 = MTU(hostname=hostname, mtu_global=mtu_data.get(hostname).get( MTU_GLOBAL_YAML_KEY, NOT_SET), interface_mtu_lst=interface_mtu_lst)
def step_impl(context, nb_int_01): """ Create a MTU object and store it in context object. :param context: :param nb_int_01: :return None: """ i = 0 interface_mtu_lst = ListInterfaceMTU(list()) while i < nb_int_01: interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU( interface_name=_mapping_interface_name(f"Gi0/{i}"), mtu_size=(2000 + (200 * i)), )) i += 1 context.object_01 = MTU(hostname="spine01", mtu_global=1500, interface_mtu_lst=interface_mtu_lst)
def _extreme_vsp_mtu_converter(hostname: str(), cmd_output: dict) -> MTU: if cmd_output is None: return None interface_mtu_lst = ListInterfaceMTU(list()) for interface in cmd_output: interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU(interface_name=_mapping_interface_name(interface[0]), mtu_size=interface[5])) return MTU(hostname=hostname, interface_mtu_lst=interface_mtu_lst)
def _cumulus_mtu_converter(hostname: str(), cmd_output: json) -> MTU: if cmd_output is None: return None interface_mtu_lst = ListInterfaceMTU(list()) for interface in cmd_output: if "swp" in interface or "eth" in interface: interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU( interface_name=_mapping_interface_name(interface), mtu_size=cmd_output.get(interface).get('iface_obj').get( 'mtu', NOT_SET))) return MTU(hostname=hostname, interface_mtu_lst=interface_mtu_lst)
def _arista_mtu_converter(hostname: str(), cmd_output: json) -> MTU: if cmd_output is None: return None interface_mtu_lst = ListInterfaceMTU(list()) if "interfaces" in cmd_output.keys(): for interface in cmd_output.get("interfaces"): if "Ethernet" in interface or "Management" in interface: interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU( interface_name=_mapping_interface_name(interface), mtu_size=cmd_output.get("interfaces").get( interface).get('mtu', NOT_SET))) return MTU(hostname=hostname, interface_mtu_lst=interface_mtu_lst)
def _nexus_mtu_converter(hostname: str(), cmd_output: json) -> MTU: if cmd_output is None: return None interface_mtu_lst = ListInterfaceMTU(list()) if "TABLE_interface" in cmd_output.keys(): if "ROW_interface" in cmd_output.get("TABLE_interface").keys(): for interface in cmd_output.get("TABLE_interface").get( "ROW_interface"): if "Ethernet" in interface.get("interface", NOT_SET) or \ "mgmt" in interface.get("interface", NOT_SET): interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU(interface_name=_mapping_interface_name( interface.get("interface", NOT_SET)), mtu_size=interface.get( "eth_mtu", NOT_SET))) return MTU(hostname=hostname, interface_mtu_lst=interface_mtu_lst)
def _juniper_mtu_converter(hostname: str(), cmd_output: json) -> MTU: if cmd_output is None: return None interface_mtu_lst = ListInterfaceMTU(list()) if "interface-information" in cmd_output.keys(): for interface in cmd_output.get("interface-information")[0].get( "physical-interface"): if ("em" in interface.get("name")[0].get("data", NOT_SET) and \ "demux"not in interface.get("name")[0].get("data", NOT_SET)) or \ "fxp" in interface.get("name")[0].get("data", NOT_SET): interface_mtu_lst.interface_mtu_lst.append( InterfaceMTU(interface_name=_mapping_interface_name( interface.get("name")[0].get("data", NOT_SET)), mtu_size=interface.get("mtu")[0].get( "data", NOT_SET))) return MTU(hostname=hostname, interface_mtu_lst=interface_mtu_lst)