Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add features: start, stop, save VMs #1

Open
sheepla opened this issue Feb 4, 2023 · 1 comment
Open

Add features: start, stop, save VMs #1

sheepla opened this issue Feb 4, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sheepla
Copy link
Owner

sheepla commented Feb 4, 2023

Allows to perform operations such as start, stop or save VMs

@sheepla sheepla added the enhancement New feature or request label Feb 4, 2023
@sheepla
Copy link
Owner Author

sheepla commented Feb 5, 2023

I've found that it can be done using PowerShell, but I just don't know how to do that in Go. 🤔

It should be able to change the VM state by invoking the RequestStateChange method of the Msvm_ComputerSystem class that represents the VM.

Msvm_ComputerSystem.RequestStateChange

# PowerShell (Administrator)
> Get-VM -Name debian

Name   State CPUUsage(%) MemoryAssigned(M) Uptime   Status     Version
----   ----- ----------- ----------------- ------   ------     -------
Debian Off   0           0                 00:00:00 正常稼働中 10.0

> $enable = 2
> $disable = 3
> Get-CimInstance -Namespace root/virtualization/v2 -ClassName Msvm_ComputerSystem | 
    ? ElementName -eq "Debian" | 
    Invoke-CimMethod -MethodName "RequestStateChange" -Arguments @{RequestedState = 2}

Job                                                                    ReturnValue PSComputerName
---                                                                    ----------- --------------
Msvm_ConcreteJob (InstanceID = "6E69C4C8-0A89-4857-8E85-C9CC77A78BD1")        4096

> Get-VM -Name Debian

Name   State   CPUUsage(%) MemoryAssigned(M) Uptime           Status     Version
----   -----   ----------- ----------------- ------           ------     -------
Debian Running 0           1024              00:00:50.8140000 正常稼働中 10.0

@sheepla sheepla added the help wanted Extra attention is needed label Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant