Display Windows fixed volumes individually in both fleet views
This commit is contained in:
@@ -261,7 +261,6 @@ pub async fn detail(
|
||||
.ok_or(Error(StatusCode::NOT_FOUND, "NOT_FOUND"))?;
|
||||
let hosts = assigned_hosts(&mut tx, tenant, now, std::slice::from_ref(&row)).await?;
|
||||
let mut item = project(&row, now, true, &hosts);
|
||||
item["volumes"] = volumes(&item["inventory"]);
|
||||
item["recent_jobs"] = if p.permits_scope("operations:read")
|
||||
&& crate::permissions::allowed(&mut tx, &p.name, "operations:read").await?
|
||||
{
|
||||
@@ -296,6 +295,14 @@ fn observed<'a>(data: &'a Value, scope: &str) -> &'a Value {
|
||||
}
|
||||
fn volumes(data: &Value) -> Value {
|
||||
let mut items = Vec::new();
|
||||
if let Some(drives) = observed(data, "windows.volumes")["drives"].as_array() {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for drive in drives.iter().take(26) {
|
||||
let Some(name) = drive["name"].as_str() else { continue };
|
||||
if !matches!(name.as_bytes(), [b'A'..=b'Z', b':']) || !seen.insert(name) { continue; }
|
||||
items.push(json!({"name":name,"free_bytes":drive["free_bytes"].as_u64(),"total_bytes":drive["total_bytes"].as_u64()}));
|
||||
}
|
||||
}
|
||||
if let Some(rows) = observed(data, "linux.volumes").as_array() {
|
||||
for entry in rows.iter().filter(|entry| entry["quality"] == "valid") {
|
||||
let v = &entry["data"];
|
||||
@@ -552,6 +559,9 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
||||
"source_id":row.get::<Option<String>,_>("source_id"),"quality":if data.is_null(){"unknown"}else{"valid"},
|
||||
"completeness":"partial","health":"unknown"
|
||||
});
|
||||
if full || observed(&data, "windows.volumes").is_object() {
|
||||
item["volumes"] = volumes(&data);
|
||||
}
|
||||
if device_type == Some(DeviceType::Virtual) && row.get::<String, _>("lifecycle") == "current" {
|
||||
let assigned_id: Option<Uuid> = row.get("hypervisor_asset_id");
|
||||
let assigned = assigned_id.and_then(|id| hosts.get(&id));
|
||||
@@ -578,6 +588,18 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn windows_drives_include_other_letters_and_preserve_legacy_system_volume() {
|
||||
let mut snapshot = json!({"root_available_bytes":4,"root_total_bytes":8,"observations":[
|
||||
{"scope":"windows.volumes","quality":"valid","data":{}}]});
|
||||
assert_eq!(volumes(&snapshot)[0]["name"], "Systemvolume");
|
||||
let drives = json!([{"name":"C:","free_bytes":4,"total_bytes":8},
|
||||
{"name":"D:","free_bytes":0,"total_bytes":64},
|
||||
{"name":"E:","free_bytes":null,"total_bytes":null}]);
|
||||
snapshot["observations"][0]["data"]["drives"] = drives.clone();
|
||||
assert_eq!(volumes(&snapshot), drives);
|
||||
}
|
||||
|
||||
fn windows_os(name: &str, build: &str) -> String {
|
||||
let old = json!({"os":name,"observations":[{"scope":"windows.os","quality":"valid",
|
||||
"data":{"product_name":name,"build":build,"display_version":"26H2"}}]});
|
||||
|
||||
Reference in New Issue
Block a user