Add system information

This commit is contained in:
2024-05-03 21:24:43 +02:00
parent 2fefdb97be
commit 9407d8f0a8
4 changed files with 58 additions and 2 deletions

View File

@ -84,6 +84,19 @@ pub struct VMState {
pub state: String,
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct SystemSystemInfo {
physical_core_count: usize,
uptime: usize,
used_memory: usize,
available_memory: usize,
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct SystemInfo {
system: SystemSystemInfo,
}
#[derive(serde::Deserialize, Debug)]
pub struct TokenRight {
verb: String,
@ -134,6 +147,11 @@ impl TokenInfo {
.map(|r| VMUuid::from_str(r.path.rsplit_once('/').unwrap().1).unwrap())
.collect::<Vec<_>>()
}
/// Check if system info can be retrived
pub fn can_retrieve_system_info(&self) -> bool {
self.is_route_allowed("GET", "/api/server/info")
}
}
/// Perform a request on the API
@ -224,7 +242,7 @@ pub async fn vm_resume(id: VMUuid) -> anyhow::Result<()> {
Ok(())
}
/// Resume a vm
/// Grab a screenshot of the VM
pub async fn vm_screenshot(id: VMUuid) -> anyhow::Result<Vec<u8>> {
Ok(request(id.route_screenshot())
.await?
@ -232,3 +250,8 @@ pub async fn vm_screenshot(id: VMUuid) -> anyhow::Result<Vec<u8>> {
.await?
.to_vec())
}
/// Get current server information
pub async fn get_server_info() -> anyhow::Result<SystemInfo> {
json_request("/api/server/info").await
}