2020-05-21 09:44:45 +00:00
|
|
|
use anyhow::Error;
|
|
|
|
use serde_json::Value;
|
|
|
|
|
2021-10-08 09:19:37 +00:00
|
|
|
use proxmox_router::{cli::*, ApiHandler, RpcEnvironment};
|
|
|
|
use proxmox_schema::api;
|
2020-05-21 09:44:45 +00:00
|
|
|
|
2021-09-10 06:40:58 +00:00
|
|
|
use pbs_api_types::JOB_ID_SCHEMA;
|
|
|
|
|
|
|
|
use proxmox_backup::api2;
|
2020-05-21 09:44:45 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// Sync job list.
|
|
|
|
fn list_sync_jobs(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
|
|
|
|
let info = &api2::config::sync::API_METHOD_LIST_SYNC_JOBS;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options()
|
|
|
|
.column(ColumnConfig::new("id"))
|
|
|
|
.column(ColumnConfig::new("store"))
|
|
|
|
.column(ColumnConfig::new("remote"))
|
|
|
|
.column(ColumnConfig::new("remote-store"))
|
|
|
|
.column(ColumnConfig::new("schedule"))
|
|
|
|
.column(ColumnConfig::new("comment"));
|
|
|
|
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-05-21 09:44:45 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
id: {
|
|
|
|
schema: JOB_ID_SCHEMA,
|
|
|
|
},
|
|
|
|
"output-format": {
|
|
|
|
schema: OUTPUT_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// Show sync job configuration
|
|
|
|
fn show_sync_job(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let output_format = get_output_format(¶m);
|
|
|
|
|
|
|
|
let info = &api2::config::sync::API_METHOD_READ_SYNC_JOB;
|
|
|
|
let mut data = match info.handler {
|
|
|
|
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let options = default_table_format_options();
|
2020-12-18 11:26:07 +00:00
|
|
|
format_and_print_result_full(&mut data, &info.returns, &output_format, &options);
|
2020-05-21 09:44:45 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn sync_job_commands() -> CommandLineInterface {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
|
|
|
.insert("list", CliCommand::new(&API_METHOD_LIST_SYNC_JOBS))
|
|
|
|
.insert("show",
|
|
|
|
CliCommand::new(&API_METHOD_SHOW_SYNC_JOB)
|
|
|
|
.arg_param(&["id"])
|
2021-09-08 04:57:23 +00:00
|
|
|
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
|
2020-05-21 09:44:45 +00:00
|
|
|
)
|
|
|
|
.insert("create",
|
|
|
|
CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB)
|
|
|
|
.arg_param(&["id"])
|
2021-09-08 04:57:23 +00:00
|
|
|
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
|
2021-09-10 06:40:58 +00:00
|
|
|
.completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
|
|
|
|
.completion_cb("store", pbs_config::datastore::complete_datastore_name)
|
2021-09-02 12:25:15 +00:00
|
|
|
.completion_cb("remote", pbs_config::remote::complete_remote_name)
|
2020-05-21 09:44:45 +00:00
|
|
|
.completion_cb("remote-store", crate::complete_remote_datastore_name)
|
2021-10-28 13:00:55 +00:00
|
|
|
.completion_cb("groups", crate::complete_remote_datastore_group_filter)
|
2020-05-21 09:44:45 +00:00
|
|
|
)
|
|
|
|
.insert("update",
|
|
|
|
CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB)
|
|
|
|
.arg_param(&["id"])
|
2021-09-08 04:57:23 +00:00
|
|
|
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
|
2021-09-10 06:40:58 +00:00
|
|
|
.completion_cb("schedule", pbs_config::datastore::complete_calendar_event)
|
|
|
|
.completion_cb("store", pbs_config::datastore::complete_datastore_name)
|
2020-05-21 09:44:45 +00:00
|
|
|
.completion_cb("remote-store", crate::complete_remote_datastore_name)
|
2021-10-28 13:00:55 +00:00
|
|
|
.completion_cb("groups", crate::complete_remote_datastore_group_filter)
|
2020-05-21 09:44:45 +00:00
|
|
|
)
|
|
|
|
.insert("remove",
|
|
|
|
CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
|
|
|
|
.arg_param(&["id"])
|
2021-09-08 04:57:23 +00:00
|
|
|
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
|
2020-05-21 09:44:45 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
cmd_def.into()
|
|
|
|
}
|