fix list_guest_directory for varying guest OS attributes

FileInfo attributes (owner, modificationTime, size, type) vary across
guest OS types. Use getattr with defaults to prevent AttributeError
when these optional fields are missing.
This commit is contained in:
Ryan Malloy 2025-12-26 18:26:55 -07:00
parent 7918a78bfa
commit d771db2e1d

View File

@ -308,16 +308,17 @@ class GuestOpsMixin(MCPMixin):
except vim.fault.FileNotFound:
raise ValueError(f"Directory not found: {guest_path}") from None
return [
{
results = []
for f in listing.files:
mod_time = getattr(f, "modificationTime", None)
results.append({
"name": f.path,
"size": f.size,
"type": f.type,
"owner": f.owner,
"modified": f.modificationTime.isoformat() if f.modificationTime else None,
}
for f in listing.files
]
"size": getattr(f, "size", None),
"type": getattr(f, "type", None),
"owner": getattr(f, "owner", None),
"modified": mod_time.isoformat() if mod_time else None,
})
return results
@mcp_tool(
name="create_guest_directory",