]> git.proxmox.com Git - proxmox-backup.git/blob - examples/upload-speed.rs
use new proxmox-async crate
[proxmox-backup.git] / examples / upload-speed.rs
1 use anyhow::{Error};
2
3 use pbs_client::{HttpClient, HttpClientOptions, BackupWriter};
4 use pbs_api_types::Authid;
5
6 async fn upload_speed() -> Result<f64, Error> {
7
8 let host = "localhost";
9 let datastore = "store2";
10
11 let auth_id = Authid::root_auth_id();
12
13 let options = HttpClientOptions::default()
14 .interactive(true)
15 .ticket_cache(true);
16
17 let client = HttpClient::new(host, 8007, auth_id, options)?;
18
19 let backup_time = proxmox_time::epoch_i64();
20
21 let client = BackupWriter::start(client, None, datastore, "host", "speedtest", backup_time, false, true).await?;
22
23 println!("start upload speed test");
24 let res = client.upload_speedtest(true).await?;
25
26 Ok(res)
27 }
28
29 fn main() {
30 match proxmox_async::runtime::main(upload_speed()) {
31 Ok(mbs) => {
32 println!("average upload speed: {} MB/s", mbs);
33 }
34 Err(err) => {
35 eprintln!("ERROR: {}", err);
36 }
37 }
38 }