]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/admin/datastore.rs: start prune api
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Feb 2019 15:53:17 +0000 (16:53 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 27 Feb 2019 15:53:17 +0000 (16:53 +0100)
just a dummy for now.

src/api2/admin/datastore.rs
src/bin/proxmox-backup-client.rs

index 1c0b0a8aca402084f0705f79b75aedc1a69d9e06..79e79bdb977c8d97a2a23ece878db87e7f90949d 100644 (file)
@@ -14,6 +14,47 @@ use crate::backup::*;
 
 mod catar;
 
+fn prune(
+    param: Value,
+    _info: &ApiMethod,
+    _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
+
+    let store = param["store"].as_str().unwrap();
+
+    let datastore = DataStore::lookup_datastore(store)?;
+
+    println!("Starting prune on store {}", store);
+
+    println!("PARAMS {:?}", param);
+
+
+    Ok(json!(null))
+}
+
+pub fn add_common_prune_prameters(schema: ObjectSchema) -> ObjectSchema  {
+
+    schema
+        .optional(
+            "keep-daily",
+            IntegerSchema::new("Number of daily backups to keep")
+                .minimum(0)
+        )
+}
+
+fn api_method_prune() -> ApiMethod {
+    ApiMethod::new(
+        prune,
+        add_common_prune_prameters(
+            ObjectSchema::new("Prune the datastore.")
+                .required(
+                    "store",
+                    StringSchema::new("Datastore name.")
+                )
+        )
+    )
+}
+
 // this is just a test for mutability/mutex handling  - will remove later
 fn start_garbage_collection(
     param: Value,
@@ -109,9 +150,10 @@ pub fn router() -> Router {
             |_,_,_| Ok(json!([
                 {"subdir": "backups" },
                 {"subdir": "catar" },
-                {"subdir": "status"},
-                {"subdir": "gc" }
-            ])),
+                {"subdir": "gc" },
+                {"subdir": "status" },
+                {"subdir": "prune" },
+           ])),
             ObjectSchema::new("Directory index.")
                 .required("store", StringSchema::new("Datastore name.")))
         )
@@ -131,7 +173,11 @@ pub fn router() -> Router {
             "gc",
             Router::new()
                 .get(api_method_garbage_collection_status())
-                .post(api_method_start_garbage_collection()));
+                .post(api_method_start_garbage_collection()))
+        .subdir(
+            "prune",
+            Router::new()
+                .post(api_method_prune()));
 
 
 
index 544f671c0bfcdbb2d4ae2e17b35f9ba98f2739dc..491cf54f442c14151ac64e787ff07e1549a53fc9 100644 (file)
@@ -232,6 +232,26 @@ pub fn complete_backup_source(arg: &str) -> Vec<String> {
     result
 }
 
+fn prune(
+    mut param: Value,
+    _info: &ApiMethod,
+    _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
+
+    let repo_url = tools::required_string_param(&param, "repository")?;
+    let repo = BackupRepository::parse(repo_url)?;
+
+    let mut client = HttpClient::new(&repo.host, &repo.user);
+
+    let path = format!("api2/json/admin/datastore/{}/prune", repo.store);
+
+    param.as_object_mut().unwrap().remove("repository");
+
+    let result = client.post_json(&path, param)?;
+
+    Ok(result)
+}
+
 fn main() {
 
     let repo_url_schema: Arc<Schema> = Arc::new(
@@ -286,10 +306,20 @@ fn main() {
         ))
         .arg_param(vec!["repository"]);
 
+    let prune_cmd_def = CliCommand::new(
+        ApiMethod::new(
+            prune,
+            proxmox_backup::api2::admin::datastore::add_common_prune_prameters(
+                ObjectSchema::new("Prune backup repository.")
+                    .required("repository", repo_url_schema.clone())
+            )
+        ))
+        .arg_param(vec!["repository"]);
     let cmd_def = CliCommandMap::new()
         .insert("create".to_owned(), create_cmd_def.into())
         .insert("garbage-collect".to_owned(), garbage_collect_cmd_def.into())
-        .insert("list".to_owned(), list_cmd_def.into());
+        .insert("list".to_owned(), list_cmd_def.into())
+        .insert("prune".to_owned(), prune_cmd_def.into());
 
     run_cli_command(cmd_def.into());
 }