diff options
author | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-04-17 15:40:02 +0200 |
---|---|---|
committer | Roberto Hueso Gómez <rhueso@soleta.eu> | 2020-04-17 15:50:35 +0200 |
commit | 7ccc4980147954b68829d5555fcc9e5b7dd2c4ec (patch) | |
tree | 1cf06afe9ba92ab85386002f44f6fb1f971ab584 /src | |
parent | dfb69e9dd5f983bc2f97302866fcf37f2ef5d064 (diff) |
Use samba for create and restore virtual partitions
This requires to configure user and password for samba repositories.
Diffstat (limited to 'src')
-rw-r--r-- | src/ogClient.py | 9 | ||||
-rw-r--r-- | src/ogRest.py | 3 | ||||
-rw-r--r-- | src/virtual/ogOperations.py | 17 |
3 files changed, 24 insertions, 5 deletions
diff --git a/src/ogClient.py b/src/ogClient.py index b9f6a95..ff2c704 100644 --- a/src/ogClient.py +++ b/src/ogClient.py @@ -23,14 +23,19 @@ class State(Enum): FORCE_DISCONNECTED = 2 class ogClient: - def __init__(self, ip, port, mode): + def __init__(self, ip, port, mode, samba_config=None): if mode not in {'virtual', 'linux'}: raise ValueError('Mode not supported.') + if samba_config: + assert('user' in samba_config) + assert('pass' in samba_config) + self.ip = ip self.port = port self.mode = mode - self.ogrest = ogRest(self.mode) + self.samba_config = samba_config + self.ogrest = ogRest(self.mode, self.samba_config) def get_socket(self): return self.sock diff --git a/src/ogRest.py b/src/ogRest.py index cf15c6e..24c8a70 100644 --- a/src/ogRest.py +++ b/src/ogRest.py @@ -232,11 +232,12 @@ class ogResponses(Enum): SERVICE_UNAVAILABLE=5 class ogRest(): - def __init__(self, mode): + def __init__(self, mode, samba_config): self.proc = None self.terminated = False self.state = ThreadState.IDLE self.mode = mode + self.samba_config = samba_config if self.mode == 'linux' and platform.system() == 'Linux': self.operations = OgLinuxOperations() diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py index 064fbc9..a9cf06b 100644 --- a/src/virtual/ogOperations.py +++ b/src/virtual/ogOperations.py @@ -227,6 +227,7 @@ class OgVirtualOperations: partition = request.getPartition() name = request.getName() repo = request.getRepo() + samba_config = ogRest.samba_config # Check if VM is running. qmp = OgQMP(self.IP, self.VIRTUAL_PORT) @@ -238,8 +239,11 @@ class OgVirtualOperations: drive_path = f'{self.OG_PARTITIONS_PATH}/disk{disk}_part{partition}.qcow2' - drive_path = f'disk{disk}_part{partition}.qcow2' - repo_path = f'images' + cmd = f'mount -t cifs //{repo}/ogimages {self.OG_IMAGES_PATH} -o ' \ + f'rw,nolock,serverino,acl,' \ + f'username={samba_config["user"]},' \ + f'password={samba_config["pass"]}' + subprocess.run([cmd], shell=True) try: shutil.copy(drive_path, f'{self.OG_IMAGES_PATH}/{name}') @@ -259,6 +263,7 @@ class OgVirtualOperations: ctype = request.getType() profile = request.getProfile() cid = request.getId() + samba_config = ogRest.samba_config # Check if VM is running. qmp = OgQMP(self.IP, self.VIRTUAL_PORT) @@ -273,11 +278,19 @@ class OgVirtualOperations: if os.path.exists(drive_path): os.remove(drive_path) + cmd = f'mount -t cifs //{repo}/ogimages {self.OG_IMAGES_PATH} -o ' \ + f'ro,nolock,serverino,acl,' \ + f'username={samba_config["user"]},' \ + f'password={samba_config["pass"]}' + subprocess.run([cmd], shell=True) + try: shutil.copy(f'{self.OG_IMAGES_PATH}/{name}', drive_path) except: return None + subprocess.run([f'umount {self.OG_IMAGES_PATH}'], shell=True) + return True def software(self, request, path, ogRest): |