class ZoeWorkFlow: def __init__(self, workspace_base_path, identity, name): self.identity = identity self.name = name self.workspace = ZoeWorkspace(workspace_base_path, identity, name) self.exec_api = ZoeExecutionsAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) self.cont_api = ZoeServiceAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) info_api = ZoeInfoAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) zoe_info = info_api.info() self.hostname_prefix = zoe_info['name_prefix'] self.exec_counter = 0 def generate_hostname(self, process_name: str) -> str: return self.hostname_prefix + '-' + process_name + '-' + self.identity[ 'username'] def start_workflow(self): self.workspace.create() def end_workflow(self): self.workspace.destroy() def execution_start(self, app): self.exec_counter += 1 return self.exec_api.execution_start( self.name + '{}'.format(self.exec_counter), app) def wait_termination(self, exec_id): execution = self.exec_api.execution_get(exec_id) while execution['status'] == 'submitted' or execution[ 'status'] == 'running': time.sleep(1) execution = self.exec_api.execution_get(exec_id) def __enter__(self): self.start_workflow() return self def __exit__(self, exc_type, exc_val, exc_tb): self.end_workflow()
def get_execution_details(exec_id): print("zoe api: get_execution_details") try: print("zoe api: get_execution_details: found in vault with id = {}".format(exec_id)) return vault[exec_id] except KeyError: print("zoe api: get_execution_details: no execution found with id = {}".format(exec_id)) vault[exec_id] = {} exec_api = ZoeExecutionsAPI(ZOE_URL, ZOE_USER, ZOE_PWD) cont_api = ZoeServiceAPI(ZOE_URL, ZOE_USER, ZOE_PWD) exec_details = exec_api.execution_get(exec_id) owner, gateway = get_user_info(exec_details) service_details = [] for c_id in exec_details['services']: c = cont_api.get(c_id) ip = list(c['ip_address'].values())[0] # FIXME how to decide which network is the right one? cont_id = c['id'] cont_name = c['name'] tmp = {'name': cont_name, 'details': {}} for p in c['ports']: url = "{}://{}:{}{}".format(p['protocol'], ip, p['port_number'], p['path']) tmp['details'] = {'name': p['name'], 'url': url} service_details.append(tmp) exec_details.update({'service_details': service_details, 'owner': owner, 'gateway': _translate_gw(gateway)}) vault[exec_id].update(exec_details) return vault[exec_id]
def exec_get_cmd(args): exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) execution = exec_api.execution_get(args.id) if execution is None: print('Execution not found') else: print('Execution {} (ID: {})'.format(execution['name'], execution['id'])) print('Status: {}'.format(execution['status'])) if execution['status'] == 'error': print('Last error: {}'.format(execution['error'])) print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit']))) if execution['time_start'] is None: print('Time start: {}'.format('not yet')) else: print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start']))) if execution['time_end'] is None: print('Time end: {}'.format('not yet')) else: print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end']))) app = execution['description'] print('Application name: {}'.format(app['name'])) for c_id in execution['services']: c = cont_api.get(c_id) ip = list(c['ip_address'].values())[0] # FIXME how to decide which network is the right one? print('Service {} (ID: {})'.format(c['name'], c['id'])) for p in c['ports']: print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'], ip, p['port_number'], p['path']))
class ZoeWorkFlow: def __init__(self, workspace_base_path, identity, name): self.identity = identity self.name = name self.workspace = ZoeWorkspace(workspace_base_path, identity, name) self.exec_api = ZoeExecutionsAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) self.cont_api = ZoeServiceAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) info_api = ZoeInfoAPI(self.identity['zoe_url'], self.identity['username'], self.identity['password']) zoe_info = info_api.info() self.hostname_prefix = zoe_info['name_prefix'] self.exec_counter = 0 def generate_hostname(self, process_name: str) -> str: return self.hostname_prefix + '-' + process_name + '-' + self.identity['username'] def start_workflow(self): self.workspace.create() def end_workflow(self): self.workspace.destroy() def execution_start(self, app): self.exec_counter += 1 return self.exec_api.execution_start(self.name + '{}'.format(self.exec_counter), app) def wait_termination(self, exec_id): execution = self.exec_api.execution_get(exec_id) while execution['status'] == 'submitted' or execution['status'] == 'running': time.sleep(1) execution = self.exec_api.execution_get(exec_id) def __enter__(self): self.start_workflow() return self def __exit__(self, exc_type, exc_val, exc_tb): self.end_workflow()
def exec_get_cmd(args): app_api = ZoeApplicationAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) cont_api = ZoeContainerAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) execution = exec_api.execution_get(args.id) if execution is None: print('Execution not found') else: print('Execution {} (ID: {})'.format(execution['name'], execution['id'])) print('Status: {}'.format(execution['status'])) print('Time started: {}'.format(execution['time_started'])) print('Time scheduled: {}'.format(execution['time_scheduled'])) print('Time finished: {}'.format(execution['time_finished'])) app = app_api.get(execution['application_id']) print('Application name: {}'.format(app['name'])) for c_id in execution['containers']: c = cont_api.get(c_id) ip = list(c['ip_address'].values())[0] # FIXME how to decide which network is the right one? print('Container {} (ID: {})'.format(c['name'], c['id'])) for p in c['ports']: print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'], ip, p['port_number'], p['path']))
def exec_get_cmd(args): exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass()) execution = exec_api.execution_get(args.id) if execution is None: print('Execution not found') else: print('Execution {} (ID: {})'.format(execution['name'], execution['id'])) print('Status: {}'.format(execution['status'])) if execution['status'] == 'error': print('Last error: {}'.format(execution['error'])) print('Time submit: {}'.format( datetime.datetime.fromtimestamp(execution['time_submit']))) if execution['time_start'] is None: print('Time start: {}'.format('not yet')) else: print('Time start: {}'.format( datetime.datetime.fromtimestamp(execution['time_start']))) if execution['time_end'] is None: print('Time end: {}'.format('not yet')) else: print('Time end: {}'.format( datetime.datetime.fromtimestamp(execution['time_end']))) app = execution['description'] print('Application name: {}'.format(app['name'])) for c_id in execution['services']: c = cont_api.get(c_id) ip = list(c['ip_address'].values())[ 0] # FIXME how to decide which network is the right one? print('Service {} (ID: {})'.format(c['name'], c['id'])) for p in c['ports']: print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'], ip, p['port_number'], p['path']))