Some checks failed
Run Check Script / check (pull_request) Failing after 19s
67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
//! Example: install a package with full log output.
|
|
//!
|
|
//! ```text
|
|
//! cargo run --example install_verbose -- os-haproxy
|
|
//! ```
|
|
|
|
mod common;
|
|
|
|
use serde::Deserialize;
|
|
use std::env;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct InstallResponse {
|
|
status: String,
|
|
#[serde(default)]
|
|
msg_uuid: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct UpgradeStatus {
|
|
#[serde(default)]
|
|
status: String,
|
|
#[serde(default)]
|
|
log: String,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let client = common::client_from_env();
|
|
|
|
let pkg_name = env::args().nth(1).unwrap_or_else(|| {
|
|
eprintln!("Usage: cargo run --example install_verbose -- <package_name>");
|
|
std::process::exit(1);
|
|
});
|
|
|
|
println!("Installing {pkg_name}...");
|
|
|
|
let resp: InstallResponse = client
|
|
.post_typed(
|
|
"core",
|
|
"firmware",
|
|
&format!("install/{pkg_name}"),
|
|
None::<&()>,
|
|
)
|
|
.await
|
|
.expect("install API call failed");
|
|
|
|
println!("Install response: {resp:?}");
|
|
|
|
// Poll and print full log
|
|
for i in 0..60 {
|
|
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
|
|
|
let status: UpgradeStatus = client
|
|
.get_typed("core", "firmware", "upgradestatus")
|
|
.await
|
|
.expect("upgradestatus failed");
|
|
|
|
println!("--- Poll {i} (status={}) ---", status.status);
|
|
println!("{}", status.log);
|
|
|
|
if status.status == "done" {
|
|
break;
|
|
}
|
|
}
|
|
}
|