summaryrefslogtreecommitdiffstats
path: root/src/utils/legacy.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-08-30 17:04:41 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-09-14 17:12:14 +0200
commit00a95bdb61aae943c670eed6fd59185546adc777 (patch)
tree3427f62bda9fba0939db2b62741982fff24c45ee /src/utils/legacy.py
parent5d799773f6cbf887dd1b236bb8f9a2c3a06d2c21 (diff)
live: rewrite image_restore
Integrates image restore command into native ogClient code. Further reduces the need for external Bash scripts. After a succesful image restore, OS configuration is still using external Bash script "osConfigure/osConfigureCustom".
Diffstat (limited to 'src/utils/legacy.py')
-rw-r--r--src/utils/legacy.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/utils/legacy.py b/src/utils/legacy.py
index 8f39fe2..aca8abe 100644
--- a/src/utils/legacy.py
+++ b/src/utils/legacy.py
@@ -3,6 +3,7 @@ import logging
import os
import subprocess
import shlex
+import shutil
from subprocess import PIPE
@@ -56,6 +57,51 @@ def ogChangeRepo(ip):
shell=True)
+def restoreImageCustom(repo_ip, image_name, disk, partition, method):
+ """
+ """
+ if not shutil.which('restoreImageCustom'):
+ logging.error('Invalid restoreImageCustom invocation')
+ raise ValueError('Error: restoreImageCustom not found')
+
+ if ogChangeRepo(repo).returncode != 0:
+ logging.error('ogChangeRepo could not change repository to %s', repo)
+ raise ValueError(f'Error: Cannot change repository to {repo}')
+
+ cmd = f'restoreImageCustom {repo_ip} {image_name} {disk} {partition} {method}'
+ with open('/tmp/command.log', 'wb', 0) as logfile:
+ try:
+ proc = subprocess.run(cmd,
+ stdout=logfile,
+ encoding='utf-8',
+ shell=True)
+ except:
+ logging.error('Exception when running restoreImageCustom subprocess')
+ raise ValueError('Error: Incorrect command value')
+ return proc.returncode
+
+
+def configureOs(disk, partition):
+ """
+ """
+ if shutil.which('configureOsCustom'):
+ cmd_configure = f"configureOsCustom {disk} {partition}"
+ else:
+ cmd_configure = f"configureOs {disk} {partition}"
+
+ try:
+ proc = subprocess.run(cmd_configure,
+ stdout=PIPE,
+ encoding='utf-8',
+ shell=True)
+ out = proc.stdout
+ except:
+ logging.error('Exception when running configureOs subprocess')
+ raise ValueError('Error: Incorrect command value')
+
+ return out
+
+
def ogCopyEfiBootLoader(disk, partition):
cmd = f'ogCopyEfiBootLoader {disk} {partition}'
try: