1 | import ipaddress |
---|
2 | import logging |
---|
3 | import os |
---|
4 | import subprocess |
---|
5 | import shlex |
---|
6 | |
---|
7 | from subprocess import PIPE |
---|
8 | |
---|
9 | def 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 | |
---|
29 | def 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 | |
---|
46 | def 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 | |
---|
59 | def 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') |
---|