Skip to content

Commit b175ef9

Browse files
committed
hyper-v change
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 463f8fe commit b175ef9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

extensions/HyperV/hyperv.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ def status(self):
210210
power_state = "poweroff"
211211
succeed({"status": "success", "power_state": power_state})
212212

213+
def statuses(self):
214+
command = 'Get-VM | Select-Object Name, State | ConvertTo-Json'
215+
vms = json.loads(self.run_ps(command))
216+
power_state = {}
217+
if isinstance(vms, dict):
218+
vms = [vms]
219+
for vm in vms:
220+
state = vm["State"].strip().lower()
221+
if state == "running":
222+
power_state[vm["Name"]] = "poweron"
223+
elif state == "off":
224+
power_state[vm["Name"]] = "poweroff"
225+
else:
226+
power_state[vm["Name"]] = "unknown"
227+
succeed({"status": "success", "power_state": power_state})
228+
213229
def delete(self):
214230
try:
215231
self.run_ps_int(f'Remove-VM -Name "{self.data["vmname"]}" -Force')
@@ -283,6 +299,7 @@ def main():
283299
"reboot": manager.reboot,
284300
"delete": manager.delete,
285301
"status": manager.status,
302+
"statuses": manager.statuses,
286303
"suspend": manager.suspend,
287304
"resume": manager.resume,
288305
"listsnapshots": manager.list_snapshots,

0 commit comments

Comments
 (0)