source: ogClient-Git/src/utils/legacy.py @ 5d79977

Last change on this file since 5d79977 was 87e738b, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

image_restore: fix ogCopyEfiBootLoader

ogCopyEfiBootloader is an invalid legacy bash function name.

Rename to the correct function name 'ogCopyEfiBootLoader' and
rename utility python wrapper too.

Fixes: 0bd037c1a409c65fbcb01355ee0dd6dca770330e

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import ipaddress
2import logging
3import os
4import subprocess
5import shlex
6
7from subprocess import PIPE
8
9def ogGetImageInfo(path):
10    """
11    Bash function 'ogGetImageInfo' wrapper (client/engine/Image.lib)
12    """
13    proc = subprocess.run(f'ogGetImageInfo {path}',
14                          stdout=PIPE, shell=True,
15                          encoding='utf-8')
16
17    if proc.stdout.count(':') != 3:
18        return ''
19
20    image_info = {}
21    (image_info['clonator'],
22     image_info['compressor'],
23     image_info['filesystem'],
24     image_info['datasize']) = proc.stdout.rstrip().split(':', 4)
25    image_info['clientname'] = os.getenv('HOSTNAME')
26    return image_info
27
28
29def cambiar_acceso(mode='rw', user='opengnsys', pwd='og'):
30    """
31    'CambiarAcceso' wrapper (admin/Interface/CambiarAcceso)
32    """
33    if mode not in ['rw', 'ro']:
34        raise ValueError('Invalid remount mode option')
35
36    cmd = shlex.split(f'mount -o remount,{mode},username={user},password={pwd} /opt/opengnsys/images')
37    ret = True
38    try:
39        subprocess.run(cmd, check=True)
40    except CalledProcessError:
41        ret = False
42    finally:
43        return ret
44
45
46def ogChangeRepo(ip):
47    """
48    Bash function 'ogGetImageInfo' wrapper (client/engine/Net.lib)
49    """
50    try:
51        ipaddr = ipaddress.ip_address(ip)
52    except ValueError as e:
53        raise
54
55    return subprocess.run(f'ogChangeRepo {ipaddr}',
56                          shell=True)
57
58
59def ogCopyEfiBootLoader(disk, partition):
60    cmd = f'ogCopyEfiBootLoader {disk} {partition}'
61    try:
62        proc = subprocess.run(cmd,
63                              shell=True)
64    except:
65        logging.error('Exception when running ogCopyEfiBootLoader subprocess')
66        raise ValueError('Subprocess error: ogCopyEfiBootloader')
Note: See TracBrowser for help on using the repository browser.