Skip to content

[Feature]: Relocate VM PowerState from post-query #15

Description

@azolnowski

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions