mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
up and down commands
This commit is contained in:
parent
32fc90debe
commit
cd00701028
10 changed files with 77 additions and 16 deletions
27
src/up.rs
Normal file
27
src/up.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use crate::config::{Config, NamespaceName};
|
||||
use crate::namespace::NetNs;
|
||||
use main_error::MainResult;
|
||||
|
||||
pub fn up(config: Config) -> MainResult {
|
||||
let mut namespaces = NetNs::existing()?
|
||||
.map(NetNs::new)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for removed in namespaces.extract_if(.., |namespace| {
|
||||
config.get_namespace(namespace.name()).is_none()
|
||||
}) {
|
||||
removed.delete()?;
|
||||
}
|
||||
|
||||
for new in config.namespaces {
|
||||
if !has_namespace(&namespaces, &new.name) {
|
||||
namespaces.push(NetNs::new(new.name)?);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_namespace(namespaces: &[NetNs], name: &NamespaceName) -> bool {
|
||||
namespaces.iter().any(|existing| existing.name() == name)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue