Skip to main content

asterust_junos/system/services/
dhcp_local_server.rs

1//! `dhcp-local-server`
2//! `system { services { dhcp-local-server { ... } } }`.
3//!
4//! # See also
5//!
6//! - [dhcp-local-server](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dhcp-local-server-edit-system-services.html)
7
8use crate::{args_of, child_block, named_children};
9use asterust::config::ConfigLine;
10
11/// A `group <name>` of `dhcp-local-server`.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct DhcpLocalServerGroup {
15    pub name: String,
16    /// Each `interface` as written.
17    pub interfaces: Vec<String>,
18}
19
20/// The `system services dhcp-local-server` groups. The many per-group options are not extracted.
21#[derive(Clone, Debug, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct DhcpLocalServer {
24    pub groups: Vec<DhcpLocalServerGroup>,
25    /// Groups under `dhcpv6`.
26    pub dhcpv6_groups: Vec<DhcpLocalServerGroup>,
27}
28
29pub(super) fn parse_dhcp_local_server(server: &ConfigLine) -> DhcpLocalServer {
30    let groups = |parent: &ConfigLine| -> Vec<DhcpLocalServerGroup> {
31        named_children(parent, "group")
32            .map(|(name, group)| DhcpLocalServerGroup {
33                name: name.to_string(),
34                interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
35            })
36            .collect()
37    };
38    DhcpLocalServer {
39        groups: groups(server),
40        dhcpv6_groups: child_block(server, "dhcpv6").map(groups).unwrap_or_default(),
41    }
42}