mirror of https://git.48k.eu/ogclient
Add Refresh command
This patch allows us to execute refresh command using ogClient. This command gets all the configuration in our machine and send this information to the server. The format of the message that ogClient will send to the server will be: {"disk": "1", "partition_setup": [{"partition": "1", "code": "LINUX", "filesystem": "NTFS", "size": "498688", "format": "0"}, {"partition": "2", "code": "LINUX", "filesystem": "NTFS", "size": "498688", "format": "0"}, {"partition": "3", "code": "LINUX", "filesystem": "NTFS", "size": "498688", "format": "0"}]}more_events
parent
b2fd0b5fff
commit
b5e182f7dd
|
@ -11,6 +11,30 @@ import subprocess
|
|||
|
||||
OG_PATH = '/opt/opengnsys/'
|
||||
|
||||
def parseGetConf(out):
|
||||
listConfigs = []
|
||||
disk = -1;
|
||||
|
||||
configs = out.split('\n')
|
||||
configs = filter(None, configs)
|
||||
for item in configs:
|
||||
i = 0
|
||||
json = {}
|
||||
val = item.rstrip().split('\t')
|
||||
while i < len(val):
|
||||
val[i] = val[i].split('=')[1]
|
||||
i += 1
|
||||
|
||||
json['partition'] = val[1]
|
||||
json['code'] = val[4]
|
||||
json['filesystem'] = val[2]
|
||||
json['size'] = val[5]
|
||||
json['format'] = val[6]
|
||||
disk = val[0]
|
||||
listConfigs.append(json)
|
||||
|
||||
return [disk, listConfigs]
|
||||
|
||||
def poweroff():
|
||||
if os.path.exists('/scripts/oginit'):
|
||||
subprocess.call('source ' + OG_SCRIPT_PATH + 'etc/preinit/loadenviron.sh; ' + OG_SCRIPT_PATH + 'scripts/poweroff', shell=True)
|
||||
|
@ -75,8 +99,6 @@ def procsetup(httpparser, ogRest):
|
|||
listConfigs = []
|
||||
|
||||
for part in partlist:
|
||||
i = 0
|
||||
json = {}
|
||||
cfg = 'dis=' + disk + '*che=' + cache + '*tch=' + cachesize + '!par=' + part["partition"] + '*cpt='+part["code"] + '*sfi=' + part['filesystem'] + '*tam=' + part['size'] + '*ope=' + part['format'] + '%'
|
||||
if ogRest.terminated:
|
||||
break
|
||||
|
@ -87,20 +109,8 @@ def procsetup(httpparser, ogRest):
|
|||
except:
|
||||
continue
|
||||
|
||||
result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True)
|
||||
val = result.decode('utf-8').rstrip().split('\t')
|
||||
while i < len(val):
|
||||
val[i] = val[i].split('=')[1]
|
||||
i += 1
|
||||
|
||||
json['partition'] = val[1]
|
||||
json['code'] = val[4]
|
||||
json['filesystem'] = val[2]
|
||||
json['size'] = val[5]
|
||||
json['format'] = val[6]
|
||||
listConfigs.append(json)
|
||||
|
||||
return listConfigs
|
||||
result = subprocess.check_output([OG_PATH + 'interfaceAdm/getConfiguration'], shell=True)
|
||||
return parseGetConf(result.decode('utf-8'))[1]
|
||||
|
||||
def procirestore(httpparser, ogRest):
|
||||
disk = httpparser.getDisk()
|
||||
|
@ -141,3 +151,15 @@ def procicreate(path, httpparser, ogRest):
|
|||
raise ValueError('Error: Incorrect command value')
|
||||
|
||||
return output.decode('utf-8')
|
||||
|
||||
def procrefresh(ogRest):
|
||||
listConfigs = []
|
||||
disk = -1;
|
||||
|
||||
try:
|
||||
ogRest.proc = subprocess.Popen([OG_PATH + 'interfaceAdm/getConfiguration'], stdout=subprocess.PIPE, shell=True)
|
||||
(output, error) = ogRest.proc.communicate()
|
||||
except:
|
||||
raise ValueError('Error: Incorrect command value')
|
||||
|
||||
return parseGetConf(output.decode('utf-8'))
|
||||
|
|
|
@ -165,6 +165,20 @@ class ogThread():
|
|||
jsonResp.addElement('software', lines[0])
|
||||
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
|
||||
|
||||
# Process refresh
|
||||
def procrefresh(client, ogRest):
|
||||
try:
|
||||
out = ogOperations.procrefresh(ogRest)
|
||||
except ValueError as err:
|
||||
client.send(restResponse.getResponse(ogResponses.INTERNAL_ERR))
|
||||
return
|
||||
|
||||
jsonResp = jsonResponse()
|
||||
jsonResp.addElement('disk', out[0])
|
||||
jsonResp.addElement('partition_setup', out[1])
|
||||
|
||||
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
|
||||
|
||||
class ogResponses(Enum):
|
||||
BAD_REQUEST=0
|
||||
IN_PROGRESS=1
|
||||
|
@ -213,6 +227,8 @@ class ogRest():
|
|||
self.process_stop(client)
|
||||
elif ("image/create" in URI):
|
||||
self.process_icreate(client, httpparser)
|
||||
elif ("refresh" in URI):
|
||||
self.process_refresh(client)
|
||||
else:
|
||||
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
|
||||
else:
|
||||
|
@ -271,3 +287,6 @@ class ogRest():
|
|||
def process_icreate(self, client, httpparser):
|
||||
path = '/tmp/CSft-' + client.ip + '-' + httpparser.getPartition()
|
||||
threading.Thread(target=ogThread.procicreate, args=(client, path, httpparser, self,)).start()
|
||||
|
||||
def process_refresh(self, client):
|
||||
threading.Thread(target=ogThread.procrefresh, args=(client, self,)).start()
|
||||
|
|
Loading…
Reference in New Issue