Feature Category
Virtual Machines
Problem or Use Case
For Get-VergeVM.ps1, $PowerState can be cast ToLower() in $filters to avoid the need to filter post-query.
Proposed Solution
After the following lines in Get-VergeVM.ps1 (138-141):
# Filter by cluster
if ($Cluster) {
$filters.Add("machine#cluster#name eq '$Cluster'")
}
Add:
# Filter by PowerState
if ($PowerState) {
$filters.Add("machine#cluster#status eq '$($PowerState.ToLower())'")
}
The following lines can be eliminated as a result (184-199):
# Filter by PowerState if specified (needs to be done post-query)
if ($PowerState) {
$statusMap = @{
'Running' = 'running'
'Stopped' = 'stopped'
'Hibernated' = 'hibernated'
'Stopping' = 'stopping'
'Starting' = 'starting'
'Migrating' = 'migrating'
'Unresponsive' = 'unresponsive'
'Error' = 'error'
'Maintenance' = 'maintenance'
}
$targetStatus = $statusMap[$PowerState]
$vms = $vms | Where-Object { $_.status -eq $targetStatus }
}
Note: At the very least, the $statusMap is not required, as PowerShell comparison operators are case insensitive by default. (e.g. $vms = $vms | Where-Object { $_.status -eq $PowerState } achieves the same goal)
Example Usage
Alternatives Considered
No response
VergeOS API Support
None
Additional Context
No response
Feature Category
Virtual Machines
Problem or Use Case
For Get-VergeVM.ps1, $PowerState can be cast ToLower() in $filters to avoid the need to filter post-query.
Proposed Solution
After the following lines in Get-VergeVM.ps1 (138-141):
Add:
The following lines can be eliminated as a result (184-199):
Note: At the very least, the $statusMap is not required, as PowerShell comparison operators are case insensitive by default. (e.g.
$vms = $vms | Where-Object { $_.status -eq $PowerState }achieves the same goal)Example Usage
Alternatives Considered
No response
VergeOS API Support
None
Additional Context
No response