refs #522 remove duplicated initialisation code
parent
f25252fcf9
commit
b6945279bc
|
@ -23,7 +23,7 @@ log=DEBUG
|
|||
[ogAdmClient]
|
||||
#path=test_modules/server
|
||||
## this URL will probably be left equal to the other one, but let's see
|
||||
remote=https://192.168.1.249/opengnsys/rest/__ogAdmClient
|
||||
remote=https://192.168.2.10/opengnsys/rest
|
||||
log=DEBUG
|
||||
|
||||
#servidorAdm=192.168.2.1
|
||||
|
|
|
@ -94,8 +94,6 @@ class ogAdmClientWorker(ServerWorker):
|
|||
Sends OGAgent stopping notification to OpenGnsys server
|
||||
"""
|
||||
logger.debug('onDeactivation')
|
||||
self.REST.sendMessage('stopped', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
||||
'ostype': operations.os_type, 'osversion': operations.os_version})
|
||||
|
||||
def processClientMessage(self, message, data):
|
||||
logger.debug('Got OpenGnsys message from client: {}, data {}'.format(message, data))
|
||||
|
@ -250,7 +248,7 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
|||
def tomaIPlocal(self):
|
||||
try:
|
||||
self.IPlocal = self.interfaceAdmin ('getIpAddress');
|
||||
logger.info (self.IPlocal)
|
||||
logger.info ('local IP is "{}"'.format (self.IPlocal))
|
||||
except Exception as e:
|
||||
logger.error (e)
|
||||
logger.error ('No se ha podido recuperar la dirección IP del cliente')
|
||||
|
@ -467,7 +465,6 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
|||
"""
|
||||
Sends OGAgent activation notification to OpenGnsys server
|
||||
"""
|
||||
t = 0 # Count of time
|
||||
# Generate random secret to send on activation
|
||||
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
|
||||
|
@ -485,43 +482,6 @@ with open (subprocs_log, 'ab') as fd: ## TODO improve this logging
|
|||
raise e
|
||||
self.REST = REST(url)
|
||||
|
||||
# Get network interfaces until they are active or timeout (5 minutes)
|
||||
for t in range(0, 300):
|
||||
try:
|
||||
# Get the first network interface
|
||||
self.interface = list(operations.getNetworkInfo())[0]
|
||||
except Exception as e:
|
||||
# Wait 1 sec. and retry
|
||||
logger.warn (e)
|
||||
time.sleep(1)
|
||||
finally:
|
||||
# Exit loop if interface is active
|
||||
if self.interface:
|
||||
if t > 0:
|
||||
logger.debug("Fetch connection data after {} tries".format(t))
|
||||
break
|
||||
# Raise error after timeout
|
||||
if not self.interface:
|
||||
raise Exception ('not self.interface')
|
||||
|
||||
# Loop to send initialization message
|
||||
init_retries = 100
|
||||
for t in range(0, init_retries):
|
||||
try:
|
||||
self.REST.sendMessage('started', {'mac': self.interface.mac, 'ip': self.interface.ip,
|
||||
'secret': self.random, 'ostype': operations.os_type,
|
||||
'osversion': operations.os_version,
|
||||
'agent_version': VERSION})
|
||||
break
|
||||
except Exception as e:
|
||||
logger.warn (str (e))
|
||||
time.sleep(3)
|
||||
# Raise error after timeout
|
||||
if t < init_retries-1:
|
||||
logger.debug('Successful connection after {} tries'.format(t))
|
||||
elif t == init_retries-1:
|
||||
raise Exception('Initialization error: Cannot connect to remote server')
|
||||
|
||||
if (not self.tomaIPlocal()):
|
||||
raise Exception ('Se han generado errores. No se puede continuar la ejecución de este módulo')
|
||||
|
||||
|
|
Loading…
Reference in New Issue