]> git.proxmox.com Git - proxmox-backup.git/blame - src/api2/admin/datastore.rs
use crate log and syslog
[proxmox-backup.git] / src / api2 / admin / datastore.rs
CommitLineData
15e9b4ed
DM
1use failure::*;
2
15e9b4ed
DM
3use crate::api::schema::*;
4use crate::api::router::*;
2085142e 5//use crate::server::rest::*;
15e9b4ed
DM
6use serde_json::{json, Value};
7
2085142e
DM
8//use hyper::StatusCode;
9//use hyper::rt::{Future, Stream};
7e21da6e 10
15e9b4ed
DM
11use crate::config::datastore;
12
13use crate::backup::datastore::*;
14
50cfb695 15mod catar;
1629d2ad 16
15e9b4ed
DM
17// this is just a test for mutability/mutex handling - will remove later
18fn start_garbage_collection(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
19
5a778d92 20 let store = param["store"].as_str().unwrap();
15e9b4ed 21
5a778d92 22 let datastore = DataStore::lookup_datastore(store)?;
15e9b4ed 23
5a778d92 24 println!("Starting garbage collection on store {}", store);
15e9b4ed
DM
25
26 datastore.garbage_collection()?;
27
28 Ok(json!(null))
29}
30
691c89a0
DM
31pub fn api_method_start_garbage_collection() -> ApiMethod {
32 ApiMethod::new(
33 start_garbage_collection,
34 ObjectSchema::new("Start garbage collection.")
5a778d92 35 .required("store", StringSchema::new("Datastore name."))
691c89a0
DM
36 )
37}
38
39fn garbage_collection_status(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
40
5a778d92 41 let store = param["store"].as_str().unwrap();
691c89a0 42
5a778d92 43 println!("Garbage collection status on store {}", store);
691c89a0
DM
44
45 Ok(json!(null))
46
47}
48
49pub fn api_method_garbage_collection_status() -> ApiMethod {
50 ApiMethod::new(
51 garbage_collection_status,
52 ObjectSchema::new("Garbage collection status.")
5a778d92 53 .required("store", StringSchema::new("Datastore name."))
691c89a0
DM
54 )
55}
56
83dbd80b
DM
57fn get_backup_list(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
58
59 let config = datastore::config()?;
60
61 let store = param["store"].as_str().unwrap();
62
63 let datastore = DataStore::lookup_datastore(store)?;
64
65 let mut list = vec![];
66
67 for info in datastore.list_backups()? {
68 list.push(json!({
69 "backup_type": info.backup_type,
70 "backup_id": info.backup_id,
71 "backup_time": info.backup_time.timestamp(),
72 }));
73 }
74
75 let result = json!(list);
76
77 Ok(result)
78}
7e21da6e 79
15e9b4ed
DM
80fn get_datastore_list(_param: Value, _info: &ApiMethod) -> Result<Value, Error> {
81
82 let config = datastore::config()?;
83
5a778d92 84 Ok(config.convert_to_array("store"))
15e9b4ed
DM
85}
86
691c89a0 87
15e9b4ed
DM
88pub fn router() -> Router {
89
90 let datastore_info = Router::new()
91 .get(ApiMethod::new(
92 |_,_| Ok(json!([
83dbd80b 93 {"subdir": "backups" },
29f34b8e 94 {"subdir": "catar" },
15e9b4ed
DM
95 {"subdir": "status"},
96 {"subdir": "gc" }
97 ])),
98 ObjectSchema::new("Directory index.")
5a778d92 99 .required("store", StringSchema::new("Datastore name.")))
15e9b4ed 100 )
83dbd80b
DM
101 .subdir(
102 "backups",
103 Router::new()
104 .get(ApiMethod::new(
105 get_backup_list,
106 ObjectSchema::new("List backups.")
107 .required("store", StringSchema::new("Datastore name.")))))
264f52cf 108 .subdir(
50cfb695 109 "catar",
264f52cf 110 Router::new()
50cfb695
DM
111 .download(catar::api_method_download_catar())
112 .upload(catar::api_method_upload_catar()))
15e9b4ed
DM
113 .subdir(
114 "gc",
115 Router::new()
691c89a0
DM
116 .get(api_method_garbage_collection_status())
117 .post(api_method_start_garbage_collection()));
7e21da6e 118
15e9b4ed
DM
119
120
121 let route = Router::new()
122 .get(ApiMethod::new(
123 get_datastore_list,
124 ObjectSchema::new("Directory index.")))
5a778d92 125 .match_all("store", datastore_info);
15e9b4ed
DM
126
127
128
129 route
130}