X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=rec.git;a=blobdiff_plain;f=workflows%2FREC_create.py;fp=workflows%2FREC_create.py;h=3467b5390876e98c6375b8ecf771a2f0eec314a8;hp=8e8fb921bfd79e2d87d2b525f0df4e310d5e485c;hb=e9585ab225af5e910238902ef8fa86129e6b2638;hpb=60a3d0bb8aae8f9afb610b0cfa8b79631cdf98ff diff --git a/workflows/REC_create.py b/workflows/REC_create.py index 8e8fb92..3467b53 100755 --- a/workflows/REC_create.py +++ b/workflows/REC_create.py @@ -142,6 +142,16 @@ def send_request(ri_ip, CLOUDNAME, ISO, BOOTISO): print(response) return response.json().get('uuid') +def create_podevent(msg='Default msg', level='INFO'): + API_HOST = 'http://arc-api:8080' + if os.environ.get('LOGGING_USER') and os.environ.get('LOGGING_PASSWORD'): + payload = {'name': os.environ['LOGGING_USER'], 'password': os.environ['LOGGING_PASSWORD']} + response = requests.post(API_HOST+'/api/v1/login', json=payload) + token = response.headers['X-ARC-Token'] + headers = {'X-ARC-Token': token} + payload = {'uuid': POD.POD, 'level': level, 'message': msg} + response = requests.post(API_HOST+'/api/v1/podevent', headers=headers, json=payload) + def wait_for_completion(ri_ip, id, ntimes): """ Wait (up to ntimes minutes) for the remote_installer to finish. @@ -150,17 +160,21 @@ def wait_for_completion(ri_ip, id, ntimes): status = 'ongoing' URL = 'https://%s:%d/v1/installations/%s/state' % (ri_ip, API_PORT, id) certs = (CERT_DIR+'/clientcert.pem', CERT_DIR+'/clientkey.pem') + lastevent = '' while status == 'ongoing' and ntimes > 0: time.sleep(60) response = requests.get(URL, cert=certs, verify=False) j = response.json() t = ( - datetime.datetime.now().strftime('%x %X'), str(j.get('status')), str(j.get('percentage')), str(j.get('description')) ) - print('%s: Status is %s (%s) %s' % t) + event = 'Status is %s (%s) %s' % t + print('%s: %s' % (datetime.datetime.now().strftime('%x %X'), event)) + if event != lastevent: + create_podevent(event) + lastevent = event status = j.get('status') ntimes = ntimes - 1 return status != 'completed'