summaryrefslogtreecommitdiffstats
path: root/src/virtual/ogOperations.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/virtual/ogOperations.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/virtual/ogOperations.py')
-rw-r--r--src/virtual/ogOperations.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py
index b13aeb4..1b4a871 100644
--- a/src/virtual/ogOperations.py
+++ b/src/virtual/ogOperations.py
@@ -19,12 +19,17 @@ import pathlib
import re
import math
import sys
+import enum
class OgVM:
DEFAULT_CPU = 'host'
DEFAULT_VGA = 'std'
DEFAULT_QMP_PORT = 4444
+ class State(enum.Enum):
+ STOPPED = 0
+ RUNNING = 1
+
def __init__(self,
partition_path,
memory=None,
@@ -134,6 +139,7 @@ class OgVirtualOperations:
self.OG_PATH = os.path.dirname(os.path.realpath(sys.argv[0]))
self.OG_IMAGES_PATH = f'{self.OG_PATH}/images'
self.OG_PARTITIONS_PATH = f'{self.OG_PATH}/partitions'
+ self.OG_PARTITIONS_CFG_PATH = f'{self.OG_PATH}/partitions.json'
if not os.path.exists(self.OG_IMAGES_PATH):
os.mkdir(self.OG_IMAGES_PATH, mode=0o755)
@@ -168,6 +174,26 @@ class OgVirtualOperations:
except:
pass
+ def check_vm_state(self):
+ try:
+ qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
+ qmp.disconnect()
+ return OgVM.State.RUNNING
+ except:
+ return OgVM.State.STOPPED
+
+ def get_installed_os(self):
+ installed_os = {}
+ try:
+ with open(self.OG_PARTITIONS_CFG_PATH, 'r') as f:
+ cfg = json.loads(f.read())
+ for part in cfg['partition_setup']:
+ if len(part['os']) > 0:
+ installed_os[part['os']] = (part['disk'], part['partition'])
+ except:
+ pass
+ return installed_os
+
def execCMD(self, request, ogRest):
# TODO Implement.
raise NotImplementedError