tape: implement API to run tape backup jobs

This commit is contained in:
Dietmar Maurer 2021-02-15 11:09:30 +01:00
parent fe291ab794
commit 41a8db3576
2 changed files with 68 additions and 4 deletions

View File

@ -31,6 +31,7 @@ use crate::{
MEDIA_POOL_NAME_SCHEMA, MEDIA_POOL_NAME_SCHEMA,
DRIVE_NAME_SCHEMA, DRIVE_NAME_SCHEMA,
UPID_SCHEMA, UPID_SCHEMA,
JOB_ID_SCHEMA,
MediaPoolConfig, MediaPoolConfig,
}, },
server::WorkerTask, server::WorkerTask,
@ -49,6 +50,13 @@ use crate::{
}, },
}; };
const TAPE_BACKUP_JOB_ROUTER: Router = Router::new()
.post(&API_METHOD_RUN_TAPE_BACKUP_JOB);
pub const ROUTER: Router = Router::new()
.post(&API_METHOD_BACKUP)
.match_all("id", &TAPE_BACKUP_JOB_ROUTER);
pub fn do_tape_backup_job( pub fn do_tape_backup_job(
mut job: Job, mut job: Job,
tape_job: TapeBackupJobConfig, tape_job: TapeBackupJobConfig,
@ -118,6 +126,32 @@ pub fn do_tape_backup_job(
Ok(upid_str) Ok(upid_str)
} }
#[api(
input: {
properties: {
id: {
schema: JOB_ID_SCHEMA,
},
},
},
)]
/// Runs a tape backup job manually.
pub fn run_tape_backup_job(
id: String,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<String, Error> {
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let (config, _digest) = config::tape_job::config()?;
let backup_job: TapeBackupJobConfig = config.lookup("backup", &id)?;
let job = Job::new("tape-backup-job", &id)?;
let upid_str = do_tape_backup_job(job, backup_job, &auth_id, None)?;
Ok(upid_str)
}
#[api( #[api(
input: { input: {
properties: { properties: {
@ -190,10 +224,6 @@ pub fn backup(
Ok(upid_str.into()) Ok(upid_str.into())
} }
pub const ROUTER: Router = Router::new()
.post(&API_METHOD_BACKUP);
fn backup_worker( fn backup_worker(
worker: &WorkerTask, worker: &WorkerTask,
datastore: Arc<DataStore>, datastore: Arc<DataStore>,

View File

@ -5,6 +5,10 @@ use proxmox::api::{api, cli::*, RpcEnvironment, ApiHandler};
use proxmox_backup::{ use proxmox_backup::{
config, config,
client::{
connect_to_localhost,
view_task_result,
},
api2::{ api2::{
self, self,
types::*, types::*,
@ -75,6 +79,31 @@ fn show_tape_backup_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result
Ok(Value::Null) Ok(Value::Null)
} }
#[api(
input: {
properties: {
id: {
schema: JOB_ID_SCHEMA,
},
},
},
)]
/// Run THape Backup Job
async fn run_tape_backup_job(mut param: Value) -> Result<(), Error> {
let output_format = get_output_format(&param);
let id = param["id"].take().as_str().unwrap().to_string();
let mut client = connect_to_localhost()?;
let result = client.post(&format!("api2/json/tape/backup/{}", id), Some(param)).await?;
view_task_result(&mut client, result, &output_format).await?;
Ok(())
}
pub fn backup_job_commands() -> CommandLineInterface { pub fn backup_job_commands() -> CommandLineInterface {
let cmd_def = CliCommandMap::new() let cmd_def = CliCommandMap::new()
@ -84,6 +113,11 @@ pub fn backup_job_commands() -> CommandLineInterface {
.arg_param(&["id"]) .arg_param(&["id"])
.completion_cb("id", config::tape_job::complete_tape_job_id) .completion_cb("id", config::tape_job::complete_tape_job_id)
) )
.insert("run",
CliCommand::new(&API_METHOD_RUN_TAPE_BACKUP_JOB)
.arg_param(&["id"])
.completion_cb("id", config::tape_job::complete_tape_job_id)
)
.insert("create", .insert("create",
CliCommand::new(&api2::config::tape_backup_job::API_METHOD_CREATE_TAPE_BACKUP_JOB) CliCommand::new(&api2::config::tape_backup_job::API_METHOD_CREATE_TAPE_BACKUP_JOB)
.arg_param(&["id"]) .arg_param(&["id"])