summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
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.')