def _on_sso_command(self, args, user, user_api): # type: (Namespace, SSOUser, UserAPI) # Zato from zato.common.util.api import current_host response = user_api.login(self._get_cid(), args.username, None, None, '127.0.0.1', user_agent='Zato CLI {}'.format( current_host()), skip_sec=True) self.logger.info('User logged in %s', response.to_dict())
def _get_user(self): # Zato from zato.common.util.api import current_host, current_user return '{}@{}'.format(current_user(), current_host())
def _get_current_host(self): # Zato from zato.common.util.api import current_host return current_host()
def get_info(component_path, format, _now=datetime.utcnow): component_details = open(os.path.join(component_path, ZATO_INFO_FILE)).read() out = { 'component_details': component_details, 'component_full_path': component_path, 'component_host': current_host(), 'component_running': False, 'current_time': datetime.now().isoformat(), 'current_time_utc': datetime.utcnow().isoformat(), 'master_proc_connections': None, 'master_proc_pid': None, 'master_proc_name': None, 'master_proc_create_time': None, 'master_proc_create_time_utc': None, 'master_proc_username': None, 'master_proc_workers_no': None, 'master_proc_workers_pids': None, } master_proc_pid = None try: master_proc_pid = int( open(os.path.join(component_path, MISC.PIDFILE)).read()) except (IOError, ValueError): # Ok, no such file or it's empty pass if master_proc_pid: out['component_running'] = True master_proc = Process(master_proc_pid) workers_pids = sorted(elem.pid for elem in master_proc.children()) now = datetime.fromtimestamp(time(), UTC) mater_proc_create_time = master_proc.create_time() mater_proc_create_time_utc = datetime.fromtimestamp( mater_proc_create_time, UTC) out['mater_proc_uptime'] = now - mater_proc_create_time_utc out['mater_proc_uptime_seconds'] = int( out['mater_proc_uptime'].total_seconds()) out['master_proc_connections'] = format_connections( master_proc.connections(), format) out['master_proc_pid'] = master_proc.pid out['master_proc_create_time'] = datetime.fromtimestamp( mater_proc_create_time).isoformat() out['master_proc_create_time_utc'] = mater_proc_create_time_utc.isoformat( ) out['master_proc_username'] = master_proc.username() out['master_proc_name'] = master_proc.name() out['master_proc_workers_no'] = len(workers_pids) out['master_proc_workers_pids'] = workers_pids for pid in workers_pids: worker = Process(pid) worker_create_time = worker.create_time() worker_create_time_utc = datetime.fromtimestamp( worker_create_time, UTC) out['worker_{}_uptime'.format(pid)] = now - worker_create_time_utc out['worker_{}_uptime_seconds'.format(pid)] = int( out['worker_{}_uptime'.format(pid)].total_seconds()) out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp( worker_create_time).isoformat() out['worker_{}_create_time_utc'.format( pid)] = worker_create_time_utc.isoformat() out['worker_{}_connections'.format(pid)] = format_connections( worker.connections(), format) return out
def export(req, cluster_id): def _get_last_id(service): response = req.zato.client.invoke(service, {}) if response.has_data: return response.data.value def _get_last_dict_id(): return _get_last_id('zato.kvdb.data-dict.dictionary.get-last-id') def _get_last_translation_id(): return _get_last_id('zato.kvdb.data-dict.translation.get-last-id') def _get_dict_list(): for item in req.zato.client.invoke( 'zato.kvdb.data-dict.dictionary.get-list', {}): yield item.id, item.system, item.key, item.value def _get_translation_list(): for item in req.zato.client.invoke( 'zato.kvdb.data-dict.translation.get-list', {}): yield item.id, item.system1, item.key1, item.value1, item.system2, \ item.key2, item.value2, item.id1, item.id2 return_data = { 'meta': { 'current_host': current_host(), 'timestamp_utc': datetime.utcnow().isoformat(), 'user': req.user.username } } return_data['data'] = {'dict_list': [], 'translation_list': []} return_data['data']['last_dict_id'] = _get_last_dict_id() return_data['data']['last_translation_id'] = _get_last_translation_id() for id, system, key, value in _get_dict_list(): return_data['data']['dict_list'].append({ 'id': id, 'system': system, 'key': key, 'value': value }) for id, system1, key1, value1, system2, key2, value2, id1, id2 in _get_translation_list( ): return_data['data']['translation_list'].append({ translation_name(system1, key1, value1, system2, key2): { 'id': id, 'value2': value2, 'id1': id1, 'id2': id2 } }) data = dumps(return_data, indent=4) if isinstance(data, unicode): data = data.encode('utf8') data = bz2.compress(data) response = HttpResponse(data, content_type='application/x-bzip2') response['Content-Disposition'] = 'attachment; filename={}'.format( 'zato-data-dict-export.json.bz2') return response