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

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

Add stop command

This patch includes a new support for stopping all the process running on
the ogClient.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import os
2import subprocess
3
4OG_PATH = '/opt/opengnsys/'
5
6def 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
12def 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
18def execCMD(httpparser, ogRest):
19        cmd = httpparser.getCMD()
20        cmds = cmd.split(" ")
21        try:
22                ogRest.proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, shell=True)
23                (output, error) = ogRest.proc.communicate()
24        except:
25                raise ValueError('Error: Incorrect command value')
26
27        return output.decode('utf-8')
28
29def procsession(httpparser, ogRest):
30        disk = httpparser.getDisk()
31        partition = httpparser.getPartition()
32
33        try:
34                ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/IniciarSesion', disk, partition], stdout=subprocess.PIPE, shell=True)
35                (output, error) = ogRest.proc.communicate()
36        except:
37                raise ValueError('Error: Incorrect command value')
38
39        return output.decode('utf-8')
40
41def procsoftware(httpparser, path, ogRest):
42        disk = httpparser.getDisk()
43        partition = httpparser.getPartition()
44
45        try:
46                ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioSoftware', disk, partition, path], stdout=subprocess.PIPE, shell=True)
47                (output, error) = ogRest.proc.communicate()
48        except:
49                raise ValueError('Error: Incorrect command value')
50
51        return output.decode('utf-8')
52
53def prochardware(path, ogRest):
54        try:
55                ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/InventarioHardware', path], stdout=subprocess.PIPE, shell=True)
56                (output, error) = ogRest.proc.communicate()
57        except:
58                raise ValueError('Error: Incorrect command value')
59
60        return output.decode('utf-8')
61
62def procsetup(httpparser, ogRest):
63        disk = httpparser.getDisk()
64        cache = httpparser.getCache()
65        cachesize = httpparser.getCacheSize()
66        partlist = httpparser.getPartitionSetup()
67        listConfigs = []
68
69        for part in partlist:
70                i = 0
71                json = {}
72                cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%'
73                if ogRest.terminated:
74                        break
75
76                try:
77                        ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/Configurar', disk, cfg], stdout=subprocess.PIPE, shell=True)
78                        (output, error) = ogRest.proc.communicate()
79                except:
80                        continue
81
82                result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True)
83                val = result.decode('utf-8').rstrip().split('\t')
84                while i < len(val):
85                        val[i] = val[i].split('=')[1]
86                        i += 1
87
88                json['partition'] = val[1]
89                json['code'] = val[4]
90                json['filesystem'] = val[2]
91                json['size'] = val[5]
92                json['format'] = val[6]
93                listConfigs.append(json)
94
95        return listConfigs
96
97def procirestore(httpparser, ogRest):
98        disk = httpparser.getDisk()
99        partition = httpparser.getPartition()
100        name = httpparser.getName()
101        repo = httpparser.getRepo()
102        ctype = httpparser.getType()
103        profile = httpparser.getProfile()
104        cid = httpparser.getId()
105
106        try:
107                ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/RestaurarImagen', disk, partition, name, repo, ctype], stdout=subprocess.PIPE, shell=True)
108                (output, error) = ogRest.proc.communicate()
109        except:
110                raise ValueError('Error: Incorrect command value')
111
112        return output.decode('utf-8')
Note: See TracBrowser for help on using the repository browser.