1 | import os |
---|
2 | import subprocess |
---|
3 | |
---|
4 | OG_PATH = '/opt/opengnsys/' |
---|
5 | |
---|
6 | def poweroff(): |
---|
7 | if os.path.exists('/scripts/oginit'): |
---|
8 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True) |
---|
9 | else: |
---|
10 | subprocess.call(['/sbin/poweroff']) |
---|
11 | |
---|
12 | def reboot(): |
---|
13 | if os.path.exists('/scripts/oginit'): |
---|
14 | subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/reboot', shell=True) |
---|
15 | else: |
---|
16 | subprocess.call(['/sbin/reboot']) |
---|
17 | |
---|
18 | def execCMD(httpparser): |
---|
19 | cmd = httpparser.getCMD() |
---|
20 | cmds = cmd.split(" ") |
---|
21 | try: |
---|
22 | result = subprocess.check_output(cmds) |
---|
23 | except: |
---|
24 | raise ValueError('Error: Incorrect command value') |
---|
25 | |
---|
26 | return result.decode('utf-8') |
---|
27 | |
---|
28 | def procsession(httpparser): |
---|
29 | disk = httpparser.getDisk() |
---|
30 | partition = httpparser.getPartition() |
---|
31 | |
---|
32 | try: |
---|
33 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], shell=True) |
---|
34 | except: |
---|
35 | raise ValueError('Error: Incorrect command value') |
---|
36 | |
---|
37 | return result.decode('utf-8') |
---|
38 | |
---|
39 | def procsoftware(httpparser, path): |
---|
40 | disk = httpparser.getDisk() |
---|
41 | partition = httpparser.getPartition() |
---|
42 | |
---|
43 | try: |
---|
44 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], shell=True) |
---|
45 | except: |
---|
46 | raise ValueError('Error: Incorrect command value') |
---|
47 | |
---|
48 | return result.decode('utf-8') |
---|
49 | |
---|
50 | def prochardware(path): |
---|
51 | try: |
---|
52 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True) |
---|
53 | except: |
---|
54 | raise ValueError('Error: Incorrect command value') |
---|
55 | |
---|
56 | return result.decode('utf-8') |
---|
57 | |
---|
58 | def procsetup(httpparser): |
---|
59 | disk = httpparser.getDisk() |
---|
60 | cache = httpparser.getCache() |
---|
61 | cachesize = httpparser.getCacheSize() |
---|
62 | partlist = httpparser.getPartitionSetup() |
---|
63 | |
---|
64 | for part in partlist: |
---|
65 | cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%' |
---|
66 | subprocess.check_output([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], shell=True) |
---|
67 | |
---|
68 | def procirestore(httpparser): |
---|
69 | disk = httpparser.getDisk() |
---|
70 | partition = httpparser.getPartition() |
---|
71 | name = httpparser.getName() |
---|
72 | repo = httpparser.getRepo() |
---|
73 | ctype = httpparser.getType() |
---|
74 | profile = httpparser.getProfile() |
---|
75 | cid = httpparser.getId() |
---|
76 | |
---|
77 | try: |
---|
78 | result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True) |
---|
79 | except: |
---|
80 | raise ValueError('Error: Incorrect command value') |
---|
81 | |
---|
82 | return result.decode('utf-8') |
---|