#750: OGAgent for ogLive looks for {{{oglive}}} environ variable; route {{{GET /getconfig}}} returns data in JSON format.
parent
70ce2377da
commit
149d1bdc4f
|
@ -43,6 +43,7 @@ from opengnsys import operations
|
|||
from opengnsys.log import logger
|
||||
from opengnsys.scriptThread import ScriptExecutorThread
|
||||
from opengnsys.workers import ServerWorker
|
||||
from six.moves.urllib import parse
|
||||
|
||||
|
||||
|
||||
|
@ -94,6 +95,10 @@ class OpenGnSysWorker(ServerWorker):
|
|||
self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length))
|
||||
# Ensure cfg has required configuration variables or an exception will be thrown
|
||||
url = self.service.config.get('opengnsys', 'remote')
|
||||
if operations.os_type == 'ogLive' and 'oglive' in os.environ:
|
||||
# Replacing server IP if its running on ogLive clinet
|
||||
logger.debug('Activating on ogLive client, new server is {}'.format(os.environ['oglive']))
|
||||
url = parse.urlsplit(url)._replace(netloc=os.environ['oglive']).geturl()
|
||||
self.REST = REST(url)
|
||||
# Get network interfaces until they are active or timeout (5 minutes)
|
||||
for t in range(0, 300):
|
||||
|
@ -323,7 +328,38 @@ class OpenGnSysWorker(ServerWorker):
|
|||
:param server:
|
||||
:return: object
|
||||
"""
|
||||
serialno = '' # Serial number
|
||||
storage = [] # Storage configuration
|
||||
warnings = 0 # Number of warnings
|
||||
logger.debug('Recieved getconfig operation')
|
||||
self.checkSecret(server)
|
||||
# Returns raw data
|
||||
return {'config': operations.get_disk_config()}
|
||||
# Processing data
|
||||
for row in operations.get_disk_config().strip().split(';'):
|
||||
cols = row.split(':')
|
||||
if len(cols) == 1:
|
||||
if cols[0] != '':
|
||||
# Serial number
|
||||
serialno = cols[0]
|
||||
else:
|
||||
# Skip blank rows
|
||||
pass
|
||||
elif len(cols) == 7:
|
||||
disk, npart, tpart, fs, os, size, usage = cols
|
||||
try:
|
||||
if int(npart) == 0:
|
||||
# Disk information
|
||||
storage.append({'disk': int(disk), 'parttable': int(tpart), 'size': int(size)})
|
||||
else:
|
||||
# Partition information
|
||||
storage.append({'disk': int(disk), 'partition': int(npart), 'parttype': tpart,
|
||||
'filesystem': fs, 'operatingsystem': os, 'size': int(size),
|
||||
'usage': int(usage)})
|
||||
except ValueError:
|
||||
logger.warn('Configuration parameter error: {}'.format(cols))
|
||||
warnings += 1
|
||||
else:
|
||||
# Logging warnings
|
||||
logger.warn('Configuration data error: {}'.format(cols))
|
||||
warnings += 1
|
||||
# Returning configuration data and count of warnings
|
||||
return {'serialno': serialno, 'storage': storage, 'warnings': warnings}
|
||||
|
|
|
@ -181,9 +181,8 @@ def get_disk_config():
|
|||
"""
|
||||
try:
|
||||
_exec_ogcommand('/opt/opengnsys/interfaceAdm/getConfiguration')
|
||||
# Returns content of configuration file.
|
||||
cfgdata = open('/tmp/getconfig', 'r').read()
|
||||
# Returns content of configuration file
|
||||
cfgdata = open('/tmp/getconfig', 'r').read().strip()
|
||||
except IOError:
|
||||
cfgdata = ''
|
||||
return cfgdata
|
||||
|
||||
|
|
Loading…
Reference in New Issue