summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-05-08 17:34:41 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-05-11 11:12:11 +0200
commit6ca16dd2008fe3bcea533904eb39202bdabdaebd (patch)
tree55e535c810910b12bb78cea657f12aca630fcdf7 /src/ogRest.py
parent7bde2a04e998316e52079e06cbc5fe48d92b6d5d (diff)
Poweroff when no VM and no jobs are running
This patch calls poweroff in virtual mode when no VM is running and no jobs are being executed. This is useful when the guest OS shutdowns so that the host OS does not continue to run.
Diffstat (limited to 'src/ogRest.py')
-rw-r--r--src/ogRest.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index fed998e..abe05c1 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -19,7 +19,7 @@ import signal
from src.restRequest import *
from src.linux.ogOperations import OgLinuxOperations
-from src.virtual.ogOperations import OgVirtualOperations
+from src.virtual.ogOperations import OgVirtualOperations, OgVM
class ThreadState(Enum):
IDLE = 0
@@ -97,6 +97,17 @@ class ogThread():
ogRest.state = ThreadState.IDLE
+ def check_vm_state_loop(ogRest):
+ POLLING_WAIT_TIME = 3
+ while True:
+ state = ogRest.operations.check_vm_state()
+ installed_os = ogRest.operations.get_installed_os()
+ if state == OgVM.State.STOPPED and \
+ ogRest.state == ThreadState.IDLE and \
+ len(installed_os) > 0:
+ ogRest.operations.poweroff_host()
+ time.sleep(POLLING_WAIT_TIME)
+
def poweroff(ogRest):
time.sleep(2)
ogRest.operations.poweroff()
@@ -242,6 +253,8 @@ class ogRest():
self.operations = OgLinuxOperations()
elif self.mode == 'virtual':
self.operations = OgVirtualOperations()
+ threading.Thread(target=ogThread.check_vm_state_loop,
+ args=(self,)).start()
else:
raise ValueError('Mode not supported.')