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