src/api2/types.rs: define BLOCKDEVICE_NAME_SCHEMA
This commit is contained in:
parent
fa2bdc1309
commit
9069debcd8
|
@ -11,7 +11,7 @@ use crate::tools::disks::{
|
|||
get_disks, get_smart_data,
|
||||
};
|
||||
|
||||
use crate::api2::types::NODE_SCHEMA;
|
||||
use crate::api2::types::{NODE_SCHEMA, BLOCKDEVICE_NAME_SCHEMA};
|
||||
|
||||
#[api(
|
||||
protected: true,
|
||||
|
@ -72,8 +72,7 @@ pub fn list_disks(
|
|||
schema: NODE_SCHEMA,
|
||||
},
|
||||
disk: {
|
||||
description: "Block device name.",
|
||||
type: String,
|
||||
schema: BLOCKDEVICE_NAME_SCHEMA,
|
||||
},
|
||||
healthonly: {
|
||||
description: "If true returns only the health status.",
|
||||
|
|
|
@ -74,6 +74,8 @@ const_regex!{
|
|||
pub CERT_FINGERPRINT_SHA256_REGEX = r"^(?:[0-9a-fA-F][0-9a-fA-F])(?::[0-9a-fA-F][0-9a-fA-F]){31}$";
|
||||
|
||||
pub ACL_PATH_REGEX = concat!(r"^(?:/|", r"(?:/", PROXMOX_SAFE_ID_REGEX_STR!(), ")+", r")$");
|
||||
|
||||
pub BLOCKDEVICE_NAME_REGEX = r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$";
|
||||
}
|
||||
|
||||
pub const SYSTEMD_DATETIME_FORMAT: ApiStringFormat =
|
||||
|
@ -133,6 +135,8 @@ pub const CIDR_V6_FORMAT: ApiStringFormat =
|
|||
pub const CIDR_FORMAT: ApiStringFormat =
|
||||
ApiStringFormat::Pattern(&CIDR_REGEX);
|
||||
|
||||
pub const BLOCKDEVICE_NAME_FORMAT: ApiStringFormat =
|
||||
ApiStringFormat::Pattern(&BLOCKDEVICE_NAME_REGEX);
|
||||
|
||||
pub const PASSWORD_SCHEMA: Schema = StringSchema::new("Password.")
|
||||
.format(&PASSWORD_FORMAT)
|
||||
|
@ -353,6 +357,11 @@ pub const PROXMOX_GROUP_ID_SCHEMA: Schema = StringSchema::new("Group ID")
|
|||
.max_length(64)
|
||||
.schema();
|
||||
|
||||
pub const BLOCKDEVICE_NAME_SCHEMA: Schema = StringSchema::new("Block device name (/sys/block/<name>).")
|
||||
.format(&BLOCKDEVICE_NAME_FORMAT)
|
||||
.min_length(3)
|
||||
.max_length(64)
|
||||
.schema();
|
||||
|
||||
// Complex type definitions
|
||||
|
||||
|
|
|
@ -48,8 +48,7 @@ fn list_disks(mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value
|
|||
input: {
|
||||
properties: {
|
||||
disk: {
|
||||
description: "Block device name.",
|
||||
type: String,
|
||||
schema: BLOCKDEVICE_NAME_SCHEMA,
|
||||
},
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
|
|
|
@ -19,6 +19,8 @@ use proxmox::sys::linux::procfs::{MountInfo, mountinfo::Device};
|
|||
use proxmox::{io_bail, io_format_err};
|
||||
use proxmox::api::api;
|
||||
|
||||
use crate::api2::types::BLOCKDEVICE_NAME_REGEX;
|
||||
|
||||
mod zfs;
|
||||
pub use zfs::*;
|
||||
mod lvm;
|
||||
|
@ -29,8 +31,6 @@ pub use smart::*;
|
|||
lazy_static::lazy_static!{
|
||||
static ref ISCSI_PATH_REGEX: regex::Regex =
|
||||
regex::Regex::new(r"host[^/]*/session[^/]*").unwrap();
|
||||
static ref BLOCKDEV_REGEX: regex::Regex =
|
||||
regex::Regex::new(r"^(:?(:?h|s|x?v)d[a-z]+)|(:?nvme\d+n\d+)$").unwrap();
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
@ -727,7 +727,7 @@ pub fn get_disks(
|
|||
|
||||
let mut result = HashMap::new();
|
||||
|
||||
for item in crate::tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEV_REGEX)? {
|
||||
for item in crate::tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)? {
|
||||
let item = item?;
|
||||
|
||||
let name = item.file_name().to_str().unwrap().to_string();
|
||||
|
@ -823,7 +823,7 @@ pub fn get_disks(
|
|||
pub fn complete_disk_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||
let mut list = Vec::new();
|
||||
|
||||
let dir = match crate::tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEV_REGEX) {
|
||||
let dir = match crate::tools::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX) {
|
||||
Ok(dir) => dir,
|
||||
Err(_) => return list,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue