src/api2/disks.rs - list-disks: add usage-type filter

This commit is contained in:
Dietmar Maurer 2020-06-06 11:48:58 +02:00
parent 553cd12ba6
commit ff30caeaf8
1 changed files with 15 additions and 4 deletions

View File

@ -7,8 +7,8 @@ use proxmox::api::router::{Router, SubdirMap};
use proxmox::{sortable, identity}; use proxmox::{sortable, identity};
use proxmox::{http_err, list_subdirs_api_method}; use proxmox::{http_err, list_subdirs_api_method};
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; use crate::config::acl::{PRIV_SYS_AUDIT};
use crate::tools::disks::{DiskUsageInfo, get_disks}; use crate::tools::disks::{DiskUsageInfo, DiskUsageType, get_disks};
#[api( #[api(
input: { input: {
@ -18,7 +18,11 @@ use crate::tools::disks::{DiskUsageInfo, get_disks};
type: bool, type: bool,
optional: true, optional: true,
default: false, default: false,
} },
"usage-type": {
type: DiskUsageType,
optional: true,
},
}, },
}, },
returns: { returns: {
@ -35,13 +39,20 @@ use crate::tools::disks::{DiskUsageInfo, get_disks};
/// List local disks /// List local disks
pub fn list_disks( pub fn list_disks(
skipsmart: bool, skipsmart: bool,
usage_type: Option<DiskUsageType>,
) -> Result<Vec<DiskUsageInfo>, Error> { ) -> Result<Vec<DiskUsageInfo>, Error> {
let mut list = Vec::new(); let mut list = Vec::new();
for (_, info) in get_disks(None, skipsmart)? { for (_, info) in get_disks(None, skipsmart)? {
if let Some(ref usage_type) = usage_type {
if info.used == *usage_type {
list.push(info); list.push(info);
} }
} else {
list.push(info);
}
}
Ok(list) Ok(list)
} }