Skip to main content

asterust_junos/system/services/
dhcp_local_server.rs

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