mirror of https://git.48k.eu/ogclient
Move check_vm_state_loop() into OgVirtualOperations
Improves code encapsulation by moving check_vm_state_loop method into OgVirtualOperations class. This also fixes import error when running ogclient in 'linux' mode.more_events
parent
80b7023ecb
commit
b29b2eb452
|
@ -96,17 +96,6 @@ class ogThread():
|
|||
|
||||
ogRest.state = ThreadState.IDLE
|
||||
|
||||
def check_vm_state_loop(ogRest):
|
||||
POLLING_WAIT_TIME = 12
|
||||
while True:
|
||||
time.sleep(POLLING_WAIT_TIME)
|
||||
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()
|
||||
|
||||
def poweroff(ogRest):
|
||||
time.sleep(2)
|
||||
ogRest.operations.poweroff()
|
||||
|
@ -252,10 +241,10 @@ class ogRest():
|
|||
if self.mode == 'linux':
|
||||
self.operations = OgLinuxOperations(self.CONFIG)
|
||||
elif self.mode == 'virtual':
|
||||
from src.virtual.ogOperations import (OgVM,
|
||||
OgVirtualOperations)
|
||||
from src.virtual.ogOperations import \
|
||||
OgVirtualOperations
|
||||
self.operations = OgVirtualOperations()
|
||||
threading.Thread(target=ogThread.check_vm_state_loop,
|
||||
threading.Thread(target=self.operations.check_vm_state_loop,
|
||||
args=(self,)).start()
|
||||
else:
|
||||
raise ValueError('Mode not supported.')
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# Free Software Foundation, version 3.
|
||||
#
|
||||
|
||||
from src.ogRest import ThreadState
|
||||
import socket
|
||||
import errno
|
||||
import select
|
||||
|
@ -221,6 +222,17 @@ class OgVirtualOperations:
|
|||
pass
|
||||
return installed_os
|
||||
|
||||
def check_vm_state_loop(self, ogRest):
|
||||
POLLING_WAIT_TIME = 12
|
||||
while True:
|
||||
time.sleep(POLLING_WAIT_TIME)
|
||||
state = self.check_vm_state()
|
||||
installed_os = self.get_installed_os()
|
||||
if state == OgVM.State.STOPPED and \
|
||||
ogRest.state == ThreadState.IDLE and \
|
||||
len(installed_os) > 0:
|
||||
self.poweroff_host()
|
||||
|
||||
def shellrun(self, request, ogRest):
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue