Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Update calculation of free/used space in IML CLI (#1803)
Browse files Browse the repository at this point in the history
Make it show the same data as in GUI.

Signed-off-by: Igor Pashev <pashev.igor@gmail.com>

Co-authored-by: Joe Grund <jgrund@whamcloud.io>
  • Loading branch information
ip1981 and jgrund authored Oct 1, 2020
1 parent e3b4d45 commit de206f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
21 changes: 11 additions & 10 deletions iml-manager-cli/src/display_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ where
}

pub fn usage(
free: Option<u64>,
used: Option<u64>,
total: Option<u64>,
formatter: fn(f64, Option<usize>) -> String,
) -> String {
match (free, total) {
(Some(free), Some(total)) => format!(
"{} / {}",
formatter(total as f64 - free as f64, Some(0)),
formatter(total as f64, Some(0))
),
(None, Some(total)) => format!("Calculating ... / {}", formatter(total as f64, Some(0))),
_ => "Calculating ...".to_string(),
}
format!(
"{} / {}",
used.map(|u| formatter(u as f64, Some(0)))
.as_deref()
.unwrap_or("---"),
total
.map(|t| formatter(t as f64, Some(0)))
.as_deref()
.unwrap_or("---")
)
}

pub trait IsEmpty {
Expand Down
20 changes: 16 additions & 4 deletions iml-manager-cli/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub enum FilesystemCommand {
},
}

fn option_sub(a: Option<u64>, b: Option<u64>) -> Option<u64> {
Some(a?.saturating_sub(b?))
}

async fn detect_filesystem(hosts: Option<String>) -> Result<(), ImlManagerCliError> {
let hosts = if let Some(hl) = hosts {
let hostlist = hostlist_parser::parse(&hl)?;
Expand Down Expand Up @@ -158,12 +162,20 @@ pub async fn filesystem_cli(command: FilesystemCommand) -> Result<(), ImlManager
let mut table = Table::new();
table.add_row(Row::from(&["Name".to_string(), fs.label]));
table.add_row(Row::from(&[
"Space".to_string(),
usage(st.bytes_free, st.bytes_total, format_bytes),
"Space Used/Avail".to_string(),
usage(
option_sub(st.bytes_total, st.bytes_free),
st.bytes_avail,
format_bytes,
),
]));
table.add_row(Row::from(&[
"Inodes".to_string(),
usage(st.files_free, st.files_total, format_number),
"Inodes Used/Avail".to_string(),
usage(
option_sub(st.files_total, st.files_free),
st.files_total,
format_number,
),
]));
table.add_row(Row::from(&["State".to_string(), fs.state]));
table.add_row(Row::from(&[
Expand Down

0 comments on commit de206f7

Please sign in to comment.