proxmox-backup-manager: split out datastore.rs
This commit is contained in:
		@ -4,7 +4,7 @@ use std::collections::HashMap;
 | 
			
		||||
use anyhow::{bail, format_err, Error};
 | 
			
		||||
use serde_json::{json, Value};
 | 
			
		||||
 | 
			
		||||
use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
 | 
			
		||||
use proxmox::api::{api, cli::*, RpcEnvironment};
 | 
			
		||||
 | 
			
		||||
use proxmox_backup::configdir;
 | 
			
		||||
use proxmox_backup::tools;
 | 
			
		||||
@ -54,97 +54,6 @@ fn connect() -> Result<HttpClient, Error> {
 | 
			
		||||
    Ok(client)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[api(
 | 
			
		||||
    input: {
 | 
			
		||||
        properties: {
 | 
			
		||||
            "output-format": {
 | 
			
		||||
                schema: OUTPUT_FORMAT,
 | 
			
		||||
                optional: true,
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
)]
 | 
			
		||||
/// Datastore list.
 | 
			
		||||
fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
 | 
			
		||||
 | 
			
		||||
    let output_format = get_output_format(¶m);
 | 
			
		||||
 | 
			
		||||
    let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES;
 | 
			
		||||
    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("path"))
 | 
			
		||||
        .column(ColumnConfig::new("comment"));
 | 
			
		||||
 | 
			
		||||
    format_and_print_result_full(&mut data, info.returns, &output_format, &options);
 | 
			
		||||
 | 
			
		||||
    Ok(Value::Null)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[api(
 | 
			
		||||
    input: {
 | 
			
		||||
        properties: {
 | 
			
		||||
            name: {
 | 
			
		||||
                schema: DATASTORE_SCHEMA,
 | 
			
		||||
            },
 | 
			
		||||
            "output-format": {
 | 
			
		||||
                schema: OUTPUT_FORMAT,
 | 
			
		||||
                optional: true,
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
)]
 | 
			
		||||
/// Show datastore configuration
 | 
			
		||||
fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
 | 
			
		||||
 | 
			
		||||
    let output_format = get_output_format(¶m);
 | 
			
		||||
 | 
			
		||||
    let info = &api2::config::datastore::API_METHOD_READ_DATASTORE;
 | 
			
		||||
    let mut data = match info.handler {
 | 
			
		||||
        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
 | 
			
		||||
        _ => unreachable!(),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let options = default_table_format_options();
 | 
			
		||||
    format_and_print_result_full(&mut data, info.returns, &output_format, &options);
 | 
			
		||||
 | 
			
		||||
    Ok(Value::Null)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn datastore_commands() -> CommandLineInterface {
 | 
			
		||||
 | 
			
		||||
    let cmd_def = CliCommandMap::new()
 | 
			
		||||
        .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES))
 | 
			
		||||
        .insert("show",
 | 
			
		||||
                CliCommand::new(&API_METHOD_SHOW_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
        )
 | 
			
		||||
        .insert("create",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name", "path"])
 | 
			
		||||
        )
 | 
			
		||||
        .insert("update",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
                .completion_cb("gc-schedule", config::datastore::complete_calendar_event)
 | 
			
		||||
                .completion_cb("prune-schedule", config::datastore::complete_calendar_event)
 | 
			
		||||
    )
 | 
			
		||||
        .insert("remove",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    cmd_def.into()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[api(
 | 
			
		||||
   input: {
 | 
			
		||||
        properties: {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										97
									
								
								src/bin/proxmox_backup_manager/datastore.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/bin/proxmox_backup_manager/datastore.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
			
		||||
use anyhow::Error;
 | 
			
		||||
use serde_json::Value;
 | 
			
		||||
 | 
			
		||||
use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
 | 
			
		||||
 | 
			
		||||
use proxmox_backup::config;
 | 
			
		||||
use proxmox_backup::api2::{self, types::* };
 | 
			
		||||
 | 
			
		||||
#[api(
 | 
			
		||||
    input: {
 | 
			
		||||
        properties: {
 | 
			
		||||
            "output-format": {
 | 
			
		||||
                schema: OUTPUT_FORMAT,
 | 
			
		||||
                optional: true,
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
)]
 | 
			
		||||
/// Datastore list.
 | 
			
		||||
fn list_datastores(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
 | 
			
		||||
 | 
			
		||||
    let output_format = get_output_format(¶m);
 | 
			
		||||
 | 
			
		||||
    let info = &api2::config::datastore::API_METHOD_LIST_DATASTORES;
 | 
			
		||||
    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("path"))
 | 
			
		||||
        .column(ColumnConfig::new("comment"));
 | 
			
		||||
 | 
			
		||||
    format_and_print_result_full(&mut data, info.returns, &output_format, &options);
 | 
			
		||||
 | 
			
		||||
    Ok(Value::Null)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[api(
 | 
			
		||||
    input: {
 | 
			
		||||
        properties: {
 | 
			
		||||
            name: {
 | 
			
		||||
                schema: DATASTORE_SCHEMA,
 | 
			
		||||
            },
 | 
			
		||||
            "output-format": {
 | 
			
		||||
                schema: OUTPUT_FORMAT,
 | 
			
		||||
                optional: true,
 | 
			
		||||
            },
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
)]
 | 
			
		||||
/// Show datastore configuration
 | 
			
		||||
fn show_datastore(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
 | 
			
		||||
 | 
			
		||||
    let output_format = get_output_format(¶m);
 | 
			
		||||
 | 
			
		||||
    let info = &api2::config::datastore::API_METHOD_READ_DATASTORE;
 | 
			
		||||
    let mut data = match info.handler {
 | 
			
		||||
        ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
 | 
			
		||||
        _ => unreachable!(),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let options = default_table_format_options();
 | 
			
		||||
    format_and_print_result_full(&mut data, info.returns, &output_format, &options);
 | 
			
		||||
 | 
			
		||||
    Ok(Value::Null)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn datastore_commands() -> CommandLineInterface {
 | 
			
		||||
 | 
			
		||||
    let cmd_def = CliCommandMap::new()
 | 
			
		||||
        .insert("list", CliCommand::new(&API_METHOD_LIST_DATASTORES))
 | 
			
		||||
        .insert("show",
 | 
			
		||||
                CliCommand::new(&API_METHOD_SHOW_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
        )
 | 
			
		||||
        .insert("create",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_CREATE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name", "path"])
 | 
			
		||||
        )
 | 
			
		||||
        .insert("update",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_UPDATE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
                .completion_cb("gc-schedule", config::datastore::complete_calendar_event)
 | 
			
		||||
                .completion_cb("prune-schedule", config::datastore::complete_calendar_event)
 | 
			
		||||
    )
 | 
			
		||||
        .insert("remove",
 | 
			
		||||
                CliCommand::new(&api2::config::datastore::API_METHOD_DELETE_DATASTORE)
 | 
			
		||||
                .arg_param(&["name"])
 | 
			
		||||
                .completion_cb("name", config::datastore::complete_datastore_name)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    cmd_def.into()
 | 
			
		||||
}
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
mod acl;
 | 
			
		||||
pub use acl::*;
 | 
			
		||||
mod datastore;
 | 
			
		||||
pub use datastore::*;
 | 
			
		||||
mod dns;
 | 
			
		||||
pub use dns::*;
 | 
			
		||||
mod network;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user