src/api2/disks.rs: start disks api

This commit is contained in:
Dietmar Maurer 2020-06-06 11:38:47 +02:00
parent de1e1a9d95
commit 553cd12ba6
2 changed files with 62 additions and 0 deletions

View File

@ -8,6 +8,7 @@ mod subscription;
pub mod types; pub mod types;
pub mod version; pub mod version;
pub mod pull; pub mod pull;
pub mod disks;
use proxmox::api::router::SubdirMap; use proxmox::api::router::SubdirMap;
use proxmox::api::Router; use proxmox::api::Router;
@ -20,6 +21,7 @@ pub const SUBDIRS: SubdirMap = &[
("admin", &admin::ROUTER), ("admin", &admin::ROUTER),
("backup", &backup::ROUTER), ("backup", &backup::ROUTER),
("config", &config::ROUTER), ("config", &config::ROUTER),
("disks", &disks::ROUTER),
("nodes", &NODES_ROUTER), ("nodes", &NODES_ROUTER),
("pull", &pull::ROUTER), ("pull", &pull::ROUTER),
("reader", &reader::ROUTER), ("reader", &reader::ROUTER),

60
src/api2/disks.rs Normal file
View File

@ -0,0 +1,60 @@
use anyhow::{bail, format_err, Error};
use serde_json::{json, Value};
use proxmox::api::{api, RpcEnvironment, Permission, UserInformation};
use proxmox::api::router::{Router, SubdirMap};
use proxmox::{sortable, identity};
use proxmox::{http_err, list_subdirs_api_method};
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
use crate::tools::disks::{DiskUsageInfo, get_disks};
#[api(
input: {
properties: {
skipsmart: {
description: "Skip smart checks.",
type: bool,
optional: true,
default: false,
}
},
},
returns: {
description: "Local disk list.",
type: Array,
items: {
type: DiskUsageInfo,
},
},
access: {
permission: &Permission::Privilege(&["system", "disks"], PRIV_SYS_AUDIT, false),
},
)]
/// List local disks
pub fn list_disks(
skipsmart: bool,
) -> Result<Vec<DiskUsageInfo>, Error> {
let mut list = Vec::new();
for (_, info) in get_disks(None, skipsmart)? {
list.push(info);
}
Ok(list)
}
#[sortable]
const SUBDIRS: SubdirMap = &sorted!([
// ("lvm", &lvm::ROUTER),
(
"list", &Router::new()
.get(&API_METHOD_LIST_DISKS)
),
]);
pub const ROUTER: Router = Router::new()
.get(&list_subdirs_api_method!(SUBDIRS))
.subdirs(SUBDIRS);