use proxmox::api::{ApiHandler, ApiMethod, RpcEnvironment};
use proxmox::api::schema::*;
use proxmox::api::cli::*;
+use proxmox::api::api;
use proxmox_backup::tools;
use proxmox_backup::api2::types::*;
.insert("shell", catalog_shell_cmd_def)
}
+#[api(
+ input: {
+ properties: {
+ repository: {
+ schema: REPO_URL_SCHEMA,
+ optional: true,
+ },
+ limit: {
+ description: "The maximal number of tasks to list.",
+ type: Integer,
+ optional: true,
+ minimum: 1,
+ maximum: 1000,
+ default: 50,
+ },
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ }
+ }
+)]
+/// List running server tasks for this repo user
+fn task_list(param: Value) -> Result<Value, Error> {
+
+ async_main(async {
+ let output_format = param["output-format"].as_str().unwrap_or("text").to_owned();
+ let repo = extract_repository_from_value(¶m)?;
+ let client = HttpClient::new(repo.host(), repo.user(), None)?;
+
+ let limit = param["limit"].as_u64().unwrap_or(50) as usize;
+
+ let args = json!({ "start": 0, "limit": limit, "userfilter": repo.user()});
+ let result = client.get("api2/json/nodes/localhost/tasks", Some(args)).await?;
+
+ let data = &result["data"];
+
+ if output_format == "text" {
+ for item in data.as_array().unwrap() {
+ println!(
+ "{} {}",
+ item["upid"].as_str().unwrap(),
+ item["status"].as_str().unwrap_or("running"),
+ );
+ }
+ } else {
+ format_and_print_result(data, &output_format);
+ }
+
+ Ok::<_, Error>(())
+ })?;
+
+ Ok(Value::Null)
+}
+
+#[api(
+ input: {
+ properties: {
+ repository: {
+ schema: REPO_URL_SCHEMA,
+ optional: true,
+ },
+ upid: {
+ schema: UPID_SCHEMA,
+ },
+ }
+ }
+)]
+/// Display the task log.
+fn task_log(param: Value) -> Result<Value, Error> {
+
+ async_main(async {
+ let repo = extract_repository_from_value(¶m)?;
+ let upid = tools::required_string_param(¶m, "upid")?;
+
+ let client = HttpClient::new(repo.host(), repo.user(), None)?;
+
+ display_task_log(client, upid, true).await?;
+
+ Ok::<_, Error>(())
+ })?;
+
+ Ok(Value::Null)
+}
+
+fn task_mgmt_cli() -> CliCommandMap {
+
+ let task_list_cmd_def = CliCommand::new(&API_METHOD_TASK_LIST)
+ .completion_cb("repository", complete_repository);
+
+ let task_log_cmd_def = CliCommand::new(&API_METHOD_TASK_LOG)
+ .arg_param(&["upid"]);
+
+ CliCommandMap::new()
+ .insert("log", task_log_cmd_def)
+ .insert("list", task_list_cmd_def)
+
+}
fn main() {
.insert("status", status_cmd_def)
.insert("key", key_mgmt_cli())
.insert("mount", mount_cmd_def)
- .insert("catalog", catalog_mgmt_cli());
+ .insert("catalog", catalog_mgmt_cli())
+ .insert("task", task_mgmt_cli());
run_cli_command(cmd_def);
}