diff options
Diffstat (limited to 'zone_nspawn/src/nspawn.rs')
-rw-r--r-- | zone_nspawn/src/nspawn.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/zone_nspawn/src/nspawn.rs b/zone_nspawn/src/nspawn.rs new file mode 100644 index 0000000..bf58303 --- /dev/null +++ b/zone_nspawn/src/nspawn.rs @@ -0,0 +1,29 @@ +use crate::{Config, Container, Error, Result}; +use figment::{Figment, Provider}; +use std::process::Command; +#[derive(Default, Debug)] +pub struct NSpawn { + pub config: Config, +} + +impl NSpawn { + pub fn new() -> Result<Self> { + Self::custom(Config::figment()) + } + + pub fn custom<T: Provider>(provider: T) -> Result<Self> { + Config::from(Figment::from(provider)) + .map_err(Error::from) + .map(|config| Self { config }) + } + + /// Uses Command to call to machinectl list -o json + pub fn get_containers() -> Result<Vec<Container>> { + Command::new("machinectl") + .arg("list") + .args(["-o", "json"]) + .output() + .map(|o| serde_json::from_slice(o.stdout.as_slice()))? + .map_err(Error::from) + } +} |