Add system information
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user