Skip to content

Commit

Permalink
Merge pull request #16 from fliqqs/ospf-dynamic-hostname
Browse files Browse the repository at this point in the history
ospf: show ospf hostnames cmd
  • Loading branch information
rwestphal authored Jan 9, 2025
2 parents f7b3d3b + 9545949 commit 38d3629
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/internal_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<bool, String> {
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";
Expand Down
4 changes: 4 additions & 0 deletions src/internal_commands.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<token name="detail" help="Detailed information" argument="detail" cmd="cmd_show_ospf_neighbor_detail"/>
</token>
</token>
<token name="hostnames" help="Router Hostnames" cmd="cmd_show_ospf_hostnames">
</token>
<token name="route" help="Route information" cmd="cmd_show_ospf_route">
<token name="prefix" help="IPv4 prefix" argument="prefix" kind="string" cmd="cmd_show_ospf_route"/>
</token>
Expand All @@ -72,6 +74,8 @@
<token name="route" help="Route information" cmd="cmd_show_ospf_route">
<token name="prefix" help="IPv4 prefix" argument="prefix" kind="string" cmd="cmd_show_ospf_route"/>
</token>
<token name="hostnames" help="Router Hostnames" cmd="cmd_show_ospf_hostnames">
</token>
</token>
<!-- RIP show commands -->
<token name="ripv2" argument="protocol" help="RIPv2 information">
Expand Down
1 change: 1 addition & 0 deletions src/token_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38d3629

Please sign in to comment.