Added Ampere_Openedge hardware type
[rec.git] / workflows / REC_create.py
index 8c06cec..3467b53 100755 (executable)
@@ -27,7 +27,7 @@ this script (via the INPUT.yaml file) are:
 
 import datetime
 import docker
-import requests
+import requests, urllib3
 import os, sys, time, yaml
 import POD
 
@@ -43,9 +43,12 @@ HTTPS_PORT   = 8443
 API_PORT     = 15101
 ADMIN_PASSWD = 'recAdm1n'
 REMOVE_ISO   = False
+HOST_IP      = '127.0.0.1'
 
 def start(ds, **kwargs):
     # Read the user input from the POST
+    global HOST_IP
+    urllib3.disable_warnings()
     yaml = read_yaml(WORKDIR + '/INPUT.yaml')
     REC_ISO_IMAGE_NAME        = yaml['iso_primary']
     REC_PROVISIONING_ISO_NAME = yaml['iso_secondary']
@@ -139,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.
@@ -147,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'