Skip to content

Commit

Permalink
F OpenNebula/one-aiops#70: wait for OneKE implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRobres committed Jun 6, 2024
1 parent 422c81f commit 013b38b
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions lithops/serverless/backends/one/one.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os
import json
import time
import logging
import urllib3

Expand Down Expand Up @@ -94,20 +95,27 @@ def _instantiate_oneke(self, template_id, oneke_config):
return service_id


def _wait_for_oneke(self, service_id):
_service_json = self.client.servicepool[service_id].info()
logger.debug(_service_json)
logs = _service_json[service_id]['TEMPLATE']['BODY'].get('log', [])
if logs:
last_log = logs[-1]
logger.debug(last_log)
state = last_log['message'].split(':')[-1].strip()
if state == 'FAILED_DEPLOYING':
raise OneError(f"OneKE deployment has failed")
if state == 'RUNNING':
logger.info("OneKE is Running")
logger.debug("Deployment state: {}".format(state))


# TODO: look onegate connectivity
pass
def _wait_for_oneke(self, service_id, timeout=600):
start_time = time.time()
minutes_timeout = int(timeout/60)
logger.debug("Initializing OneKE service. Be patient, this process can take up to {} minutes".format(minutes_timeout))
while True:
_service_json = self.client.servicepool[service_id].info()
logs = _service_json[service_id]['TEMPLATE']['BODY'].get('log', [])
if logs:
last_log = logs[-1]
logger.debug(last_log)
state = last_log['message'].split(':')[-1].strip()
# Check OneKE deployment status
if state == 'FAILED_DEPLOYING':
raise OneError("OneKE deployment has failed")
if state == 'RUNNING':
logger.debug("OneKE is running")
break

# Check timeout
elapsed_time = time.time() - start_time
if elapsed_time > timeout:
raise OneError("Deployment timed out after {} seconds. You can try again once OneKE is in RUNNING state with the service_id option.".format(timeout))

time.sleep(10)

0 comments on commit 013b38b

Please sign in to comment.