refs #886 implement InventarioHardware()

pull/10/head
Natalia Serrano 2024-10-08 09:31:03 +02:00
parent 239bfc21f7
commit 08dba6d99a
2 changed files with 59 additions and 3 deletions

View File

@ -170,6 +170,12 @@ def disponibilidad_comandos():
@app.route('/opengnsys/rest/ogAdmClient/recibeArchivo', methods=['POST'])
def oac_recibe_archivo():
logging.info(f'{request.get_json()}')
j = request.get_json(force=True)
nfl = j['nfl']
contents = j['contents']
logging.info(f'nfl ({nfl}) contents ({contents})')
dec = base64.b64decode (contents).decode ('utf-8')
logging.info(f'dec ({dec})')
return jsonify({'anything':'anything'}) ## if we return {}, then we trigger "if not {}" which happens to be true
@app.route('/opengnsys/rest/ogAdmClient/<cucu>', methods=['GET', 'POST'])
@ -188,6 +194,12 @@ def oac_cucu(cucu):
@app.route('/opengnsys/rest/CloningEngine/recibeArchivo', methods=['POST'])
def ce_recibe_archivo():
logging.info(f'{request.get_json()}')
j = request.get_json(force=True)
nfl = j['nfl']
contents = j['contents']
logging.info(f'nfl ({nfl}) contents ({contents})')
dec = base64.b64decode (contents).decode ('utf-8')
logging.info(f'dec ({dec})')
return jsonify({'anything':'anything'}) ## if we return {}, then we trigger "if not {}" which happens to be true
@app.route('/opengnsys/rest/CloningEngine/<cucu>', methods=['GET', 'POST'])

View File

@ -623,11 +623,55 @@ class ogAdmClientWorker (ogLiveWorker):
logger.debug ('in process_Configurar, path "{}" get_params "{}" post_params "{}" server "{}"'.format (path, get_params, post_params, server))
return self._long_running_job ('Configurar', self.do_Configurar, args=(post_params,))
def process_EjecutarScript (self, path, get_params, post_params, server):
logger.warning ('in process_EjecutarScript')
def do_InventarioHardware (self, post_params):
for k in ['nfn', 'ids']:
if k not in post_params:
logger.error (f'required parameter ({k}) not in POST params')
return {}
nfn = post_params['nfn']
ids = post_params['ids']
self.muestraMensaje (6)
hrdsrc = f'/tmp/Chrd-{self.IPlocal}' ## Nombre que tendra el archivo de inventario
hrddst = f'/tmp/Shrd-{self.IPlocal}' ## Nombre que tendra el archivo en el Servidor
try:
self.interfaceAdmin (nfn, [hrdsrc])
hrdsrc_contents = Path (hrdsrc).read_bytes()
logger.debug (f'hrdsrc_contents 1 ({hrdsrc_contents})')
herror = 0
except:
logger.warning ('Error al ejecutar el comando')
self.muestraMensaje (18)
herror = 1
if herror:
hrddst = ''
else:
logger.debug (f'hrdsrc_contents 2 ({hrdsrc_contents})')
## Envía fichero de inventario al servidor
res = self.enviaMensajeServidor ('recibeArchivo', { 'nfl': hrddst, 'contents': base64.b64encode (hrdsrc_contents).decode ('utf-8') })
logger.debug (res)
if not res:
logger.error ('Ha ocurrido algún problema al enviar un archivo por la red')
herror = 12 ## Error de envío de fichero por la red
self.muestraMensaje (17)
## Envia respuesta de ejecución de la función de interface
cmd = {
'nfn': 'RESPUESTA_InventarioHardware',
'hrd': hrddst,
}
self.muestraMenu()
return self.respuestaEjecucionComando (cmd, herror, ids)
def process_InventarioHardware (self, path, get_params, post_params, server):
logger.warning ('in process_InventarioHardware')
logger.debug ('in process_InventarioHardware, path "{}" get_params "{}" post_params "{}" server "{}"'.format (path, get_params, post_params, server))
return self._long_running_job ('InventarioHardware', self.do_InventarioHardware, args=(post_params,))
def process_EjecutarScript (self, path, get_params, post_params, server):
logger.warning ('in process_EjecutarScript')
def process_InventarioSoftware (self, path, get_params, post_params, server):
logger.warning ('in process_InventarioSoftware')