From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v2 2/2] config: helper: document public API
Date: Fri, 8 Aug 2025 12:23:30 +0200 [thread overview]
Message-ID: <20250808102333.121994-3-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250808102333.121994-1-s.hanreich@proxmox.com>
Add docstrings to the public API members for network interface
parsing, where they were missing before.
Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
proxmox-network-api/src/config/helper.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/proxmox-network-api/src/config/helper.rs b/proxmox-network-api/src/config/helper.rs
index 6d372b26..cc2f3dd0 100644
--- a/proxmox-network-api/src/config/helper.rs
+++ b/proxmox-network-api/src/config/helper.rs
@@ -119,11 +119,13 @@ pub(crate) fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option<u8>, b
}
}
+/// Struct representing the info_slave_data field inside link_info, as returned by `ip -details -json link show`.
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Deserialize)]
pub struct SlaveData {
perm_hw_addr: Option<MacAddress>,
}
+/// Struct representing the link_info field, as returned by `ip -details -json link show`.
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Deserialize)]
pub struct LinkInfo {
info_slave_data: Option<SlaveData>,
@@ -178,6 +180,7 @@ pub struct IpLink {
}
impl IpLink {
+ /// The index of the interface.
pub fn index(&self) -> i64 {
self.ifindex
}
@@ -204,6 +207,7 @@ impl IpLink {
PHYSICAL_NIC_REGEX.is_match(&self.ifname)
}
+ /// The name of the interface (ifname / IFLA_IFNAME).
pub fn name(&self) -> &str {
&self.ifname
}
@@ -227,15 +231,18 @@ impl IpLink {
None
}
+ /// Returns an iterator over the altnames of an interface.
pub fn altnames(&self) -> impl Iterator<Item = &String> {
self.altnames.iter()
}
+ /// Returns whether the interface is currently in an UP state.
pub fn active(&self) -> bool {
self.operstate == "UP"
}
}
+/// A mapping of altnames to the interfaces' ifname.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct AltnameMapping {
mapping: HashMap<String, String>,
@@ -263,6 +270,10 @@ impl FromIterator<IpLink> for AltnameMapping {
}
}
+/// Returns a list of all network interfaces currently available on the host.
+///
+/// This parses the output of `ip -details -json link show` and returns a map of the ifname to the
+/// [`IpLink`] for that interface.
pub fn get_network_interfaces() -> Result<HashMap<String, IpLink>, Error> {
let output = std::process::Command::new("ip")
.arg("-details")
--
2.47.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-08-08 10:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 10:23 [pbs-devel] [PATCH proxmox{, -network-interface-pinning} v2 0/3] make ip link deserializing more robust Stefan Hanreich
2025-08-08 10:23 ` [pbs-devel] [PATCH proxmox v2 1/2] network-api: properly parse ip link output based on link_type Stefan Hanreich
2025-08-08 10:23 ` Stefan Hanreich [this message]
2025-08-08 10:23 ` [pbs-devel] [PATCH proxmox-network-interface-pinning v2 1/1] network-interface-pinning: adapt to optional mac address Stefan Hanreich
2025-08-08 12:48 ` [pbs-devel] [PATCH proxmox{, -network-interface-pinning} v2 0/3] make ip link deserializing more robust Christian Ebner
2025-08-11 12:43 ` [pbs-devel] applied-series: " Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250808102333.121994-3-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox