mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 18:24:08 +02:00
directly call zpool
This commit is contained in:
parent
2d0e93bfce
commit
e858c30645
5 changed files with 57 additions and 452 deletions
|
|
@ -4,7 +4,7 @@ use futures_util::future;
|
|||
use futures_util::stream::{Stream, StreamExt};
|
||||
use heim::sensors::TemperatureSensor;
|
||||
use heim::units::{information, ratio, thermodynamic_temperature};
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use once_cell::sync::Lazy;
|
||||
use parse_display::Display;
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
|
|
|
|||
45
src/zfs.rs
45
src/zfs.rs
|
|
@ -1,5 +1,5 @@
|
|||
use color_eyre::Result;
|
||||
use libzetta::zpool::{ZpoolEngine, ZpoolOpen3};
|
||||
use color_eyre::{Report, Result};
|
||||
use std::process::Command;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -9,33 +9,30 @@ pub struct ZfsPool {
|
|||
pub free: usize,
|
||||
}
|
||||
|
||||
pub struct ZFS {
|
||||
engine: ZpoolOpen3,
|
||||
}
|
||||
|
||||
impl Default for ZFS {
|
||||
fn default() -> Self {
|
||||
ZFS {
|
||||
engine: ZpoolOpen3::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct ZFS;
|
||||
|
||||
impl ZFS {
|
||||
pub async fn pools(self) -> Result<Vec<ZfsPool>> {
|
||||
spawn_blocking(move || {
|
||||
let pools = self.engine.all()?;
|
||||
pools
|
||||
.into_iter()
|
||||
.map(|pool| {
|
||||
let props = self.engine.read_properties(pool.name())?;
|
||||
Ok(ZfsPool {
|
||||
name: pool.name().to_string(),
|
||||
size: *props.size(),
|
||||
free: *props.size() * (*props.capacity() as usize) / 100,
|
||||
let mut z = Command::new("zpool");
|
||||
z.args(&["list", "-p", "-H", "-o", "name,size,free"]);
|
||||
let out = z.output()?;
|
||||
if out.status.success() {
|
||||
let output = String::from_utf8(out.stdout)?;
|
||||
Ok(output
|
||||
.lines()
|
||||
.flat_map(|line| {
|
||||
let mut parts = line.split_ascii_whitespace();
|
||||
let name = parts.next()?.to_string();
|
||||
let size = parts.next()?.parse().ok()?;
|
||||
let free = parts.next()?.parse().ok()?;
|
||||
Some(ZfsPool { name, size, free })
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
.collect())
|
||||
} else {
|
||||
Err(Report::msg(String::from_utf8(out.stderr)?))
|
||||
}
|
||||
})
|
||||
.await?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue