aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-04-12 12:49:06 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-04-12 12:49:06 +0200
commite935cb7e308e8e16fa250c52537d07795e532c84 (patch)
treecd50bdfa1a3f993f52db64b2d509221d0aff9853 /src
parent3032d9f89c31ae35775218605eb631fb436b60fb (diff)
link existence api and waiting helpers
Diffstat (limited to 'src')
-rw-r--r--src/link.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/link.rs b/src/link.rs
index 93c4ca8..f6b9f03 100644
--- a/src/link.rs
+++ b/src/link.rs
@@ -120,7 +120,7 @@ pub fn add_vlan(link: String, parent: String, vlan_id: u16) -> Result<()> {
Runtime::new()?.block_on(do_add_vlan(link, parent, vlan_id))
}
-pub fn wait(link: String) -> Result<()> {
+pub fn wait_up(link: String) -> Result<()> {
while !match is_up(link.clone()) {
Ok(v) => v,
Err(e) => {
@@ -143,3 +143,31 @@ pub fn wait(link: String) -> Result<()> {
Ok(())
}
+
+async fn do_exists(link: String) -> Result<bool> {
+ let (conn, handle, _) = rtnetlink::new_connection()?;
+ tokio::spawn(conn);
+
+ let exists = handle
+ .link()
+ .get()
+ .match_name(link)
+ .execute()
+ .try_next()
+ .await
+ .is_ok();
+
+ Ok(exists)
+}
+
+pub fn exists(link: String) -> Result<bool> {
+ Runtime::new()?.block_on(do_exists(link))
+}
+
+pub fn wait_exists(link: String) -> Result<()> {
+ while !exists(link.clone())? {
+ thread::sleep(Duration::from_secs(1));
+ }
+
+ Ok(())
+}