#750: New route {{{GET /hardware}}}.

oglive^2^2^2
Ramón M. Gómez 2018-06-20 20:25:30 +02:00
parent 4272d559e7
commit e5ba6cfc10
2 changed files with 30 additions and 3 deletions

View File

@ -296,7 +296,7 @@ class OpenGnSysWorker(ServerWorker):
logger.debug('Recieved getconfig operation') logger.debug('Recieved getconfig operation')
self.checkSecret(server) self.checkSecret(server)
# Processing data # Processing data
for row in operations.get_disk_config().strip().split(';'): for row in operations.get_configuration().split(';'):
cols = row.split(':') cols = row.split(':')
if len(cols) == 1: if len(cols) == 1:
if cols[0] != '': if cols[0] != '':
@ -325,3 +325,16 @@ class OpenGnSysWorker(ServerWorker):
warnings += 1 warnings += 1
# Returning configuration data and count of warnings # Returning configuration data and count of warnings
return {'serialno': serialno, 'storage': storage, 'warnings': warnings} return {'serialno': serialno, 'storage': storage, 'warnings': warnings}
def process_hardware(self, path, get_params, post_params, server):
"""
Returns client's hardware profile
:param path:
:param get_params:
:param post_params:
:param server:
"""
logger.debug('Recieved {} operation'.format(path))
self.checkSecret(server)
# Returning raw data
return operations.get_hardware()

View File

@ -174,9 +174,9 @@ def poweroff():
_exec_ogcommand('/opt/opengnsys/scripts/poweroff') _exec_ogcommand('/opt/opengnsys/scripts/poweroff')
def get_disk_config(): def get_configuration():
""" """
Returns disk configuration Returns client's configuration
Warning: this operation may take some time Warning: this operation may take some time
""" """
try: try:
@ -186,3 +186,17 @@ def get_disk_config():
except IOError: except IOError:
cfgdata = '' cfgdata = ''
return cfgdata return cfgdata
def get_hardware():
"""
Returns client's hardware list
"""
try:
filepath = _exec_ogcommand('/opt/opengnsys/scripts/listHardwareInfo').strip()
# Returns content of configuration file, skipping the header line and newline characters
with open(filepath, 'r') as f:
harddata = map(str.strip, f.readlines()[1:])
except IOError:
harddata = ''
return harddata