#750: OGAgent for ogLive looks for {{{oglive}}} environ variable; route {{{GET /getconfig}}} returns data in JSON format.
parent
81a9b65d79
commit
8e4fedd75e
|
@ -43,6 +43,7 @@ from opengnsys import operations
|
||||||
from opengnsys.log import logger
|
from opengnsys.log import logger
|
||||||
from opengnsys.scriptThread import ScriptExecutorThread
|
from opengnsys.scriptThread import ScriptExecutorThread
|
||||||
from opengnsys.workers import ServerWorker
|
from opengnsys.workers import ServerWorker
|
||||||
|
from six.moves.urllib import parse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,6 +122,10 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
self.cmd = None
|
self.cmd = None
|
||||||
# Ensure cfg has required configuration variables or an exception will be thrown
|
# Ensure cfg has required configuration variables or an exception will be thrown
|
||||||
url = self.service.config.get('opengnsys', 'remote')
|
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)
|
self.REST = REST(url)
|
||||||
# Get network interfaces until they are active or timeout (5 minutes)
|
# Get network interfaces until they are active or timeout (5 minutes)
|
||||||
for t in range(0, 300):
|
for t in range(0, 300):
|
||||||
|
@ -342,7 +347,38 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
:param server:
|
:param server:
|
||||||
:return: object
|
:return: object
|
||||||
"""
|
"""
|
||||||
|
serialno = '' # Serial number
|
||||||
|
storage = [] # Storage configuration
|
||||||
|
warnings = 0 # Number of warnings
|
||||||
logger.debug('Recieved getconfig operation')
|
logger.debug('Recieved getconfig operation')
|
||||||
self.checkSecret(server)
|
self.checkSecret(server)
|
||||||
# Returns raw data
|
# Processing data
|
||||||
return {'config': operations.get_disk_config()}
|
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:
|
try:
|
||||||
_exec_ogcommand('/opt/opengnsys/interfaceAdm/getConfiguration')
|
_exec_ogcommand('/opt/opengnsys/interfaceAdm/getConfiguration')
|
||||||
# Returns content of configuration file.
|
# Returns content of configuration file
|
||||||
cfgdata = open('/tmp/getconfig', 'r').read()
|
cfgdata = open('/tmp/getconfig', 'r').read().strip()
|
||||||
except IOError:
|
except IOError:
|
||||||
cfgdata = ''
|
cfgdata = ''
|
||||||
return cfgdata
|
return cfgdata
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue