source: ogClient-Git/src/linux/ogOperations.py @ 1ced3dd

Last change on this file since 1ced3dd was 1ced3dd, checked in by Alvaro Neira Ayuso <alvaroneay@…>, 5 years ago

Improve hardware command response behavior

This patch give us a better support in case of error or success execution.
In error cases, the new behavior is to send an Internal Error http message (500).
Otherwise, the server will receive a message with a json with this format:

{ "hardware" : "xyz" }

"xyz" is the output saved in a specific path during the execution of
InventarioHardware?.

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[62a8ca4]1import os
2import subprocess
3
[2997952]4OG_PATH = '/opt/opengnsys/'
5
[ebd640a]6def poweroff():
[62a8ca4]7        if os.path.exists('/scripts/oginit'):
[2997952]8                subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True)
[62a8ca4]9        else:
10                subprocess.call(['/sbin/poweroff'])
[ebd640a]11
[fdf7701]12def reboot():
[dbbc7fa]13        if os.path.exists('/scripts/oginit'):
[2997952]14                subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/reboot', shell=True)
[dbbc7fa]15        else:
16                subprocess.call(['/sbin/reboot'])
[e20daf6]17
[2e342b5]18def execCMD(httpparser):
19        cmd = httpparser.getCMD()
[e20daf6]20        cmds = cmd.split(" ")
[e6eba4b]21        try:
22                result = subprocess.check_output(cmds)
23        except:
24                raise ValueError('Error: Incorrect command value')
25
26        return result.decode('utf-8')
[2fa8aa4]27
[2e342b5]28def procsession(httpparser):
29        disk = httpparser.getDisk()
30        partition = httpparser.getPartition()
31
[0f32b9c]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
[2fa8aa4]37        return result.decode('utf-8')
[6d1e79b]38
[2e342b5]39def procsoftware(httpparser, path):
40        disk = httpparser.getDisk()
41        partition = httpparser.getPartition()
42
[683afa6]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
[6d1e79b]48        return result.decode('utf-8')
[261a5ed]49
50def prochardware(path):
[1ced3dd]51        try:
52                result = subprocess.check_output([OG_PATH + 'interfaceAdm/InventarioHardware', path], shell=True)
53        except:
54                raise ValueError('Error: Incorrect command value')
55
[261a5ed]56        return result.decode('utf-8')
[efbe8a7]57
[2e342b5]58def procsetup(httpparser):
59        disk = httpparser.getDisk()
60        cache = httpparser.getCache()
61        cachesize = httpparser.getCacheSize()
62        partlist = httpparser.getPartitionSetup()
63
[efbe8a7]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)
[cc11d8f]67
[2e342b5]68def 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
[cc11d8f]77        result = subprocess.check_output([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], shell=True)
78        return result.decode('utf-8')
Note: See TracBrowser for help on using the repository browser.