| 1 | package guestos |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | _ "embed" |
| 6 | ) |
| 7 | |
| 8 | |
| 9 | func WindowsVMResourceCeiling(hostMemoryGiB, hostCPUs int) (memoryGiB, cpus int) { |
| 10 | return min(256, hostMemoryGiB*3/4), min(64, hostCPUs) |
| 11 | } |
| 12 | |
| 13 | type WindowsVMResourceState struct { |
| 14 | State string `json:"state"` |
| 15 | CPUs int `json:"cpus"` |
| 16 | MemoryStartup uint64 `json:"memory_startup_bytes"` |
| 17 | MemoryMinimum uint64 `json:"memory_minimum_bytes"` |
| 18 | MemoryMaximum uint64 `json:"memory_maximum_bytes"` |
| 19 | MemoryAssigned uint64 `json:"memory_assigned_bytes"` |
| 20 | DynamicMemory bool `json:"dynamic_memory"` |
| 21 | } |
| 22 | |
| 23 | |
| 24 | func (s WindowsVMResourceState) MatchesAllocation(memoryGiB, cpus int) bool { |
| 25 | return s.DynamicMemory && s.MemoryMinimum == 4<<30 && s.MemoryStartup == 4<<30 && |
| 26 | s.MemoryMaximum == uint64(memoryGiB)<<30 && s.CPUs == cpus |
| 27 | } |
| 28 | |
| 29 | |
| 30 | var windowsVMResourcesScript string |
| 31 | |
| 32 | func WindowsVMResources(ctx context.Context, root string, memoryGiB, cpus int) (WindowsVMResourceState, error) { |
| 33 | return windowsVMResources(ctx, root, memoryGiB, cpus) |
| 34 | } |