tape: add media pool cli
This commit is contained in:
parent
05e90d6463
commit
9700d5374a
@ -51,7 +51,7 @@ use crate::{
|
||||
},
|
||||
)]
|
||||
/// Create a new media pool
|
||||
fn create_pool(
|
||||
pub fn create_pool(
|
||||
name: String,
|
||||
drive: String,
|
||||
allocation: Option<String>,
|
||||
@ -95,7 +95,7 @@ fn create_pool(
|
||||
},
|
||||
)]
|
||||
/// List media pools
|
||||
fn list_pools(
|
||||
pub fn list_pools(
|
||||
mut rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<Vec<MediaPoolConfig>, Error> {
|
||||
|
||||
@ -121,7 +121,7 @@ fn list_pools(
|
||||
},
|
||||
)]
|
||||
/// Get media pool configuration
|
||||
fn get_config(name: String) -> Result<MediaPoolConfig, Error> {
|
||||
pub fn get_config(name: String) -> Result<MediaPoolConfig, Error> {
|
||||
|
||||
let (config, _digest) = config::media_pool::config()?;
|
||||
|
||||
@ -134,7 +134,7 @@ fn get_config(name: String) -> Result<MediaPoolConfig, Error> {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Deletable property name
|
||||
enum DeletableProperty {
|
||||
pub enum DeletableProperty {
|
||||
/// Delete media set allocation policy.
|
||||
allocation,
|
||||
/// Delete pool retention policy
|
||||
@ -177,7 +177,7 @@ enum DeletableProperty {
|
||||
},
|
||||
)]
|
||||
/// Update media pool settings
|
||||
fn update_pool(
|
||||
pub fn update_pool(
|
||||
name: String,
|
||||
drive: Option<String>,
|
||||
allocation: Option<String>,
|
||||
@ -224,7 +224,7 @@ fn update_pool(
|
||||
},
|
||||
)]
|
||||
/// Delete a media pool configuration
|
||||
fn delete_pool(name: String) -> Result<(), Error> {
|
||||
pub fn delete_pool(name: String) -> Result<(), Error> {
|
||||
|
||||
let _lock = config::media_pool::lock()?;
|
||||
|
||||
|
@ -29,7 +29,7 @@ use crate::{
|
||||
|
||||
pub const MEDIA_POOL_NAME_SCHEMA: Schema = StringSchema::new("Media pool name.")
|
||||
.format(&PROXMOX_SAFE_ID_FORMAT)
|
||||
.min_length(3)
|
||||
.min_length(2)
|
||||
.max_length(32)
|
||||
.schema();
|
||||
|
||||
|
@ -210,6 +210,7 @@ fn main() {
|
||||
)
|
||||
.insert("changer", changer_commands())
|
||||
.insert("drive", drive_commands())
|
||||
.insert("pool", pool_commands())
|
||||
.insert(
|
||||
"load-media",
|
||||
CliCommand::new(&API_METHOD_LOAD_MEDIA)
|
||||
|
@ -3,3 +3,6 @@ pub use changer::*;
|
||||
|
||||
mod drive;
|
||||
pub use drive::*;
|
||||
|
||||
mod pool;
|
||||
pub use pool::*;
|
||||
|
137
src/bin/proxmox_tape/pool.rs
Normal file
137
src/bin/proxmox_tape/pool.rs
Normal file
@ -0,0 +1,137 @@
|
||||
use anyhow::{Error};
|
||||
use serde_json::Value;
|
||||
|
||||
use proxmox::{
|
||||
api::{
|
||||
api,
|
||||
cli::*,
|
||||
RpcEnvironment,
|
||||
ApiHandler,
|
||||
},
|
||||
};
|
||||
|
||||
use proxmox_backup::{
|
||||
api2::{
|
||||
self,
|
||||
types::{
|
||||
MEDIA_POOL_NAME_SCHEMA,
|
||||
},
|
||||
},
|
||||
config::{
|
||||
drive::{
|
||||
complete_drive_name,
|
||||
},
|
||||
media_pool::{
|
||||
complete_pool_name,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn pool_commands() -> CommandLineInterface {
|
||||
|
||||
let cmd_def = CliCommandMap::new()
|
||||
.insert("list", CliCommand::new(&API_METHOD_LIST_POOLS))
|
||||
.insert("config",
|
||||
CliCommand::new(&API_METHOD_GET_CONFIG)
|
||||
.arg_param(&["name"])
|
||||
.completion_cb("name", complete_pool_name)
|
||||
)
|
||||
.insert(
|
||||
"remove",
|
||||
CliCommand::new(&api2::config::media_pool::API_METHOD_DELETE_POOL)
|
||||
.arg_param(&["name"])
|
||||
.completion_cb("name", complete_pool_name)
|
||||
)
|
||||
.insert(
|
||||
"create",
|
||||
CliCommand::new(&api2::config::media_pool::API_METHOD_CREATE_POOL)
|
||||
.arg_param(&["name"])
|
||||
.completion_cb("name", complete_pool_name)
|
||||
.completion_cb("drive", complete_drive_name)
|
||||
)
|
||||
.insert(
|
||||
"update",
|
||||
CliCommand::new(&api2::config::media_pool::API_METHOD_UPDATE_POOL)
|
||||
.arg_param(&["name"])
|
||||
.completion_cb("name", complete_pool_name)
|
||||
.completion_cb("drive", complete_drive_name)
|
||||
)
|
||||
;
|
||||
|
||||
cmd_def.into()
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// List media pool
|
||||
fn list_pools(
|
||||
param: Value,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
let info = &api2::config::media_pool::API_METHOD_LIST_POOLS;
|
||||
let mut data = match info.handler {
|
||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let options = default_table_format_options()
|
||||
.column(ColumnConfig::new("name"))
|
||||
.column(ColumnConfig::new("drive"))
|
||||
.column(ColumnConfig::new("allocation"))
|
||||
.column(ColumnConfig::new("retention"))
|
||||
.column(ColumnConfig::new("template"))
|
||||
;
|
||||
|
||||
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[api(
|
||||
input: {
|
||||
properties: {
|
||||
"output-format": {
|
||||
schema: OUTPUT_FORMAT,
|
||||
optional: true,
|
||||
},
|
||||
name: {
|
||||
schema: MEDIA_POOL_NAME_SCHEMA,
|
||||
},
|
||||
},
|
||||
},
|
||||
)]
|
||||
/// Get media pool configuration
|
||||
fn get_config(
|
||||
param: Value,
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let output_format = get_output_format(¶m);
|
||||
let info = &api2::config::media_pool::API_METHOD_GET_CONFIG;
|
||||
let mut data = match info.handler {
|
||||
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let options = default_table_format_options()
|
||||
.column(ColumnConfig::new("name"))
|
||||
.column(ColumnConfig::new("drive"))
|
||||
.column(ColumnConfig::new("allocation"))
|
||||
.column(ColumnConfig::new("retention"))
|
||||
.column(ColumnConfig::new("template"))
|
||||
;
|
||||
|
||||
format_and_print_result_full(&mut data, info.returns, &output_format, &options);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user