summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-04-28 11:27:16 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-04-28 11:27:16 +0200
commit298e1563173a13098179864b08af0672c5f988a0 (patch)
treeeaf9624bb344d5246b7e5face19b748b1cdd048d
parentdeb2e075cd3d94c7a884c7d00456bdb4373eae0d (diff)
Send last stored setup if VM is running
When virtual mode is activated, send the last stored partitions setup because it is not possible to access a running virtual drive to get its information.
-rw-r--r--src/virtual/ogOperations.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py
index c152d62..1856ac0 100644
--- a/src/virtual/ogOperations.py
+++ b/src/virtual/ogOperations.py
@@ -142,8 +142,28 @@ class OgVirtualOperations:
f'-display gtk -cpu host -m {vm_ram_mib}M -boot c -full-screen')
subprocess.Popen([cmd], shell=True)
+ def partitions_cfg_to_json(self, data):
+ for part in data['partition_setup']:
+ part.pop('virt-drive')
+ for k, v in part.items():
+ part[k] = str(v)
+ data['disk_setup'] = {k: str(v) for k, v in data['disk_setup'].items()}
+ return data
+
def refresh(self, ogRest):
path = f'{self.OG_PATH}/partitions.json'
+
+ try:
+ # Return last partitions setup in case VM is running.
+ qmp = OgQMP(self.IP, self.VIRTUAL_PORT)
+ qmp.disconnect()
+ with open(path, 'r') as f:
+ data = json.loads(f.read())
+ data = self.partitions_cfg_to_json(data)
+ return data
+ except:
+ pass
+
try:
with open(path, 'r+') as f:
data = json.loads(f.read())
@@ -207,12 +227,7 @@ class OgVirtualOperations:
with open(path, 'w+') as f:
f.write(json.dumps(data, indent=4))
- # TODO no debería ser necesario eliminar virt-drive ni transformar a strings
- for part in data['partition_setup']:
- part.pop('virt-drive')
- for k, v in part.items():
- part[k] = str(v)
- data['disk_setup'] = {k: str(v) for k, v in data['disk_setup'].items()}
+ data = self.partitions_cfg_to_json(data)
return data