From 9545949b2ff144b3da291b146805b19cfddebb74 Mon Sep 17 00:00:00 2001 From: fliqqs Date: Thu, 9 Jan 2025 14:40:57 +1000 Subject: [PATCH] ospf: show ospf hostnames cmd --- src/internal_commands.rs | 24 ++++++++++++++++++++++++ src/internal_commands.xml | 4 ++++ src/token_xml.rs | 1 + 3 files changed, 29 insertions(+) diff --git a/src/internal_commands.rs b/src/internal_commands.rs index cc36296..7fba924 100644 --- a/src/internal_commands.rs +++ b/src/internal_commands.rs @@ -875,6 +875,8 @@ const XPATH_OSPF_INTERFACE: &str = "interfaces/interface"; const XPATH_OSPF_NEIGHBOR: &str = "neighbors/neighbor"; const XPATH_OSPF_RIB: &str = "ietf-ospf:ospf/local-rib/route"; const XPATH_OSPF_NEXTHOP: &str = "next-hops/next-hop"; +const XPATH_OSPF_HOSTNAMES: &str = + "ietf-ospf:ospf/holo-ospf:hostnames/hostname"; pub(crate) fn cmd_show_ospf_interface( _commands: &Commands, @@ -1146,6 +1148,28 @@ pub(crate) fn cmd_show_ospf_route( Ok(false) } +pub(crate) fn cmd_show_ospf_hostnames( + _commands: &Commands, + session: &mut Session, + mut args: ParsedArgs, +) -> Result { + let protocol = match get_arg(&mut args, "protocol").as_str() { + "ospfv2" => PROTOCOL_OSPFV2, + "ospfv3" => PROTOCOL_OSPFV3, + _ => unreachable!(), + }; + + YangTableBuilder::new(session, DataType::State) + .xpath(XPATH_PROTOCOL) + .filter_list_key("type", Some(protocol)) + .column_leaf("Instance", "name") + .xpath(XPATH_OSPF_HOSTNAMES) + .filter_list_key("prefix", get_opt_arg(&mut args, "router-id")) + .column_leaf("Router ID", "router-id") + .column_leaf("Hostname", "hostname") + .show()?; + Ok(false) +} // ===== RIP "show" commands ===== const PROTOCOL_RIPV2: &str = "ietf-rip:ripv2"; diff --git a/src/internal_commands.xml b/src/internal_commands.xml index c1a53a1..fc6b13c 100644 --- a/src/internal_commands.xml +++ b/src/internal_commands.xml @@ -52,6 +52,8 @@ + + @@ -72,6 +74,8 @@ + + diff --git a/src/token_xml.rs b/src/token_xml.rs index 038eb1c..2568b37 100644 --- a/src/token_xml.rs +++ b/src/token_xml.rs @@ -96,6 +96,7 @@ fn parse_tag_token( internal_commands::cmd_show_ospf_neighbor_detail } "cmd_show_ospf_route" => internal_commands::cmd_show_ospf_route, + "cmd_show_ospf_hostnames" => internal_commands::cmd_show_ospf_hostnames, "cmd_show_rip_interface" => internal_commands::cmd_show_rip_interface, "cmd_show_rip_interface_detail" => { internal_commands::cmd_show_rip_interface_detail