nmstate/nm/nm_dbus/gen_conf/
conn.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use std::collections::HashMap;
4
5use super::{
6    super::{NmConnection, NmError, NmSettingConnection, ToKeyfile},
7    keyfile::keyfile_sections_to_string,
8};
9
10impl ToKeyfile for NmSettingConnection {}
11
12impl NmConnection {
13    pub fn to_keyfile(&self) -> Result<String, NmError> {
14        let mut sections: Vec<(&str, HashMap<String, zvariant::Value>)> =
15            Vec::new();
16        if let Some(con_set) = &self.connection {
17            sections.push(("connection", con_set.to_keyfile()?));
18        }
19        if let Some(bond_set) = &self.bond {
20            sections.push(("bond", bond_set.to_keyfile()?));
21        }
22        if let Some(bond_port_set) = &self.bond_port {
23            sections.push(("bond-port", bond_port_set.to_keyfile()?));
24        }
25        if let Some(br_set) = &self.bridge {
26            sections.push(("bridge", br_set.to_keyfile()?));
27        }
28        if let Some(br_port_set) = &self.bridge_port {
29            sections.push(("bridge-port", br_port_set.to_keyfile()?));
30        }
31        if let Some(ipv4_set) = &self.ipv4 {
32            sections.push(("ipv4", ipv4_set.to_keyfile()?));
33        }
34        if let Some(ipv6_set) = &self.ipv6 {
35            sections.push(("ipv6", ipv6_set.to_keyfile()?));
36        }
37        if let Some(ovs_bridge_set) = &self.ovs_bridge {
38            sections.push(("ovs-bridge", ovs_bridge_set.to_keyfile()?));
39        }
40        if let Some(ovs_port_set) = &self.ovs_port {
41            sections.push(("ovs-port", ovs_port_set.to_keyfile()?));
42        }
43        if let Some(ovs_iface_set) = &self.ovs_iface {
44            sections.push(("ovs-interface", ovs_iface_set.to_keyfile()?));
45        }
46        if let Some(ovs_patch_set) = &self.ovs_patch {
47            sections.push(("ovs-patch", ovs_patch_set.to_keyfile()?));
48        }
49        if let Some(ovs_dpdk_set) = &self.ovs_dpdk {
50            sections.push(("ovs-dpdk", ovs_dpdk_set.to_keyfile()?));
51        }
52        if let Some(wired_set) = &self.wired {
53            sections.push(("ethernet", wired_set.to_keyfile()?));
54        }
55        if let Some(vlan) = &self.vlan {
56            sections.push(("vlan", vlan.to_keyfile()?));
57        }
58        if let Some(vxlan) = &self.vxlan {
59            sections.push(("vxlan", vxlan.to_keyfile()?));
60        }
61        if let Some(sriov) = &self.sriov {
62            sections.push(("sriov", sriov.to_keyfile()?));
63        }
64        if let Some(mac_vlan) = &self.mac_vlan {
65            sections.push(("macvlan", mac_vlan.to_keyfile()?));
66        }
67        if let Some(macsec) = &self.macsec {
68            sections.push(("macsec", macsec.to_keyfile()?));
69        }
70        if let Some(vrf) = &self.vrf {
71            sections.push(("vrf", vrf.to_keyfile()?));
72        }
73        if let Some(veth) = &self.veth {
74            sections.push(("veth", veth.to_keyfile()?));
75        }
76        if let Some(user) = &self.user {
77            sections.push(("user", user.to_keyfile()?));
78        }
79        if let Some(ieee8021x) = &self.ieee8021x {
80            sections.push(("802-1x", ieee8021x.to_keyfile()?));
81        }
82        if let Some(ethtool) = &self.ethtool {
83            sections.push(("ethtool", ethtool.to_keyfile()?));
84        }
85        if let Some(ib) = &self.infiniband {
86            sections.push(("infiniband", ib.to_keyfile()?));
87        }
88        if let Some(ovs_eids) = &self.ovs_ext_ids {
89            sections.push(("ovs-external-ids", ovs_eids.to_keyfile()?));
90        }
91        if let Some(ovs_other_cfgs) = &self.ovs_other_config {
92            sections.push(("ovs-other-config", ovs_other_cfgs.to_keyfile()?));
93        }
94        if let Some(vpn_cfg) = &self.vpn {
95            sections.push(("vpn", vpn_cfg.to_keyfile()?));
96            if let Some(s) = vpn_cfg.secrets_to_keyfile() {
97                sections.push(("vpn-secrets", s));
98            }
99        }
100        if let Some(iface_match) = &self.iface_match {
101            sections.push(("match", iface_match.to_keyfile()?));
102        }
103
104        keyfile_sections_to_string(&sections)
105    }
106}