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 } }) response = HttpResponse(dumps(return_data, indent=4).encode('bz2'), content_type='application/x-bzip2') response['Content-Disposition'] = 'attachment; filename={}'.format( 'zato-data-dict-export.json.bz2') return response
def get_info(component_path, format): 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()) out['master_proc_connections'] = format_connections( master_proc.connections(), format) out['master_proc_pid'] = master_proc.pid out['master_proc_create_time'] = datetime.fromtimestamp( master_proc.create_time()).isoformat() out['master_proc_create_time_utc'] = datetime.fromtimestamp( master_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) out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp( worker.create_time()).isoformat() out['worker_{}_create_time_utc'.format( pid)] = datetime.fromtimestamp(worker.create_time(), UTC).isoformat() out['worker_{}_connections'.format(pid)] = format_connections( worker.connections(), format) return out
def get_info(component_path, format): 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()) out['master_proc_connections'] = format_connections(master_proc.connections(), format) out['master_proc_pid'] = master_proc.pid out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time()).isoformat() out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_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) out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time()).isoformat() out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time(), UTC).isoformat() out['worker_{}_connections'.format(pid)] = format_connections(worker.connections(), format) return out
def server_up_down(self, token, status, update_host=False): """ Updates the information regarding the server is RUNNING or CLEAN_DOWN etc. and what host it's running on. """ with closing(self.session()) as session: server = session.query(Server).\ filter(Server.token==token).\ one() server.up_status = status server.up_mod_date = datetime.utcnow() if update_host: server.host = current_host() session.add(server) session.commit()
def server_up_down(self, token, status, update_host=False, bind_host=None, bind_port=None): """ Updates the information regarding the server is RUNNING or CLEAN_DOWN etc. and what host it's running on. """ with closing(self.session()) as session: server = session.query(Server).\ filter(Server.token==token).\ one() server.up_status = status server.up_mod_date = datetime.utcnow() if update_host: server.host = current_host() server.bind_host = bind_host server.bind_port = bind_port session.add(server) session.commit()
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}}) response = HttpResponse(dumps(return_data, indent=4).encode('bz2'), mimetype='application/x-bzip2') response['Content-Disposition'] = 'attachment; filename={}'.format('zato-data-dict-export.json.bz2') return response
def _on_server(self, args): os.chdir(self.original_dir) abs_args_path = os.path.abspath(args.path) component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read() out = { 'component_details': component_details, 'component_full_path': abs_args_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 = self._zdaemon_command('status') master_proc_pid = master_proc_pid.values() if master_proc_pid and master_proc_pid[0]: out['component_running'] = True master_proc_pid = int(master_proc_pid[0]) master_proc = Process(master_proc_pid) workers_pids = sorted(elem.pid for elem in master_proc.get_children()) out['master_proc_connections'] = master_proc.get_connections() out['master_proc_pid'] = master_proc.pid out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time).isoformat() out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_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) out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time).isoformat() out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time, UTC).isoformat() out['worker_{}_connections'.format(pid)] = worker.get_connections() if getattr(args, 'json', False): out['component_details'] = loads(out['component_details']) self.logger.info(dumps(out)) else: cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH cols_width = (elem.strip() for elem in cols_width.split(',')) cols_width = [int(elem) for elem in cols_width] table = Texttable() table.set_cols_width(cols_width) # Use text ('t') instead of auto so that boolean values don't get converted into ints table.set_cols_dtype(['t', 't']) rows = [['Key', 'Value']] rows.extend(sorted(out.items())) table.add_rows(rows) self.logger.info(table.draw())
def _on_server(self, args): os.chdir(self.original_dir) abs_args_path = os.path.abspath(args.path) component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read() out = { "component_details": component_details, "component_full_path": abs_args_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 = self._zdaemon_command("status") master_proc_pid = master_proc_pid.values() if master_proc_pid and master_proc_pid[0]: out["component_running"] = True master_proc_pid = int(master_proc_pid[0]) master_proc = Process(master_proc_pid) workers_pids = sorted(elem.pid for elem in master_proc.get_children()) out["master_proc_connections"] = master_proc.get_connections() out["master_proc_pid"] = master_proc.pid out["master_proc_create_time"] = datetime.fromtimestamp(master_proc.create_time).isoformat() out["master_proc_create_time_utc"] = datetime.fromtimestamp(master_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_memory_percent = worker.get_memory_percent() out["worker_{}_create_time".format(pid)] = datetime.fromtimestamp(worker.create_time).isoformat() out["worker_{}_create_time_utc".format(pid)] = datetime.fromtimestamp( worker.create_time, UTC ).isoformat() out["worker_{}_connections".format(pid)] = worker.get_connections() if getattr(args, "json", False): out["component_details"] = loads(out["component_details"]) self.logger.info(dumps(out)) else: cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH cols_width = (elem.strip() for elem in cols_width.split(",")) cols_width = [int(elem) for elem in cols_width] table = Texttable() table.set_cols_width(cols_width) # Use text ('t') instead of auto so that boolean values don't get converted into ints table.set_cols_dtype(["t", "t"]) rows = [["Key", "Value"]] rows.extend(sorted(out.items())) table.add_rows(rows) self.logger.info(table.draw())
# Python 2/3 compatibility from past.builtins import unicode # Zato from zato.common.odb.model import SSOUser # For pyflakes Namespace = Namespace SSOUser = SSOUser unicode = unicode # ################################################################################################################################ _current_app = 'zato-cli' _current_host = current_host() _cid = 'cli' # ################################################################################################################################ _sso_tables = [_SSOAttr.__table__, _SSOSession.__table__, _SSOUser.__table__] # ################################################################################################################################ class SSOCommand(ZatoCommand): """ Base class for SSO-related commands. """ user_required = True def _get_sso_config(self, args, repo_location, secrets_conf):
def execute(self, args): try: # Make sure the ODB tables exists. # Note: Also make sure that's always at the very top of the method # as otherwise the 'quickstart' command will fail on a pristine # database, one that hasn't been used with Zato yet. create_odb.CreateODB().execute(args) args.cluster_name = "ZatoQuickstart" args.server_name = "ZatoServer" engine = self._get_engine(args) print("\nPinging database..") engine.execute(ping_queries[args.odb_type]) print("Ping OK\n") session = self._get_session(engine) next_id = self.get_next_id( session, Cluster, Cluster.name, "ZatoQuickstartCluster-%", Cluster.id.desc(), "#" ) cluster_name = "ZatoQuickstartCluster-#{next_id}".format(next_id=next_id) ca_dir = os.path.abspath(os.path.join(self.target_dir, "./ca")) lb_dir = os.path.abspath(os.path.join(self.target_dir, "./load-balancer")) server_dir = os.path.abspath(os.path.join(self.target_dir, "./server")) zato_admin_dir = os.path.abspath(os.path.join(self.target_dir, "./zato-admin")) broker_dir = os.path.abspath(os.path.join(self.target_dir, "./broker")) # Create the CA. os.mkdir(ca_dir) ca_create_ca.CreateCA(ca_dir).execute(args) # Create the broker cb = create_broker.CreateBroker(broker_dir) cb.execute(args) # Create crypto stuff for each component (but not for the broker) lb_format_args = ca_create_lb_agent.CreateLBAgent(ca_dir).execute(args) server_format_args = ca_create_server.CreateServer(ca_dir).execute(args) zato_admin_format_args = ca_create_zato_admin.CreateZatoAdmin(ca_dir).execute(args) # Create the LB agent os.mkdir(lb_dir) create_lb.CreateLoadBalancer(lb_dir).execute(args) # .. copy the LB agent's crypto material over to its directory shutil.copy2(lb_format_args["priv_key_name"], os.path.join(lb_dir, "config", "lba-priv-key.pem")) shutil.copy2(lb_format_args["cert_name"], os.path.join(lb_dir, "config", "lba-cert.pem")) shutil.copy2( os.path.join(ca_dir, "ca-material/ca-cert.pem"), os.path.join(lb_dir, "config", "ca-chain.pem") ) # Create the server os.mkdir(server_dir) cs = create_server.CreateServer(server_dir, cluster_name) # Copy crypto stuff to the newly created directories. We're doing # it here because CreateServer's execute expects the pub_key to be # already at its place. cs.prepare_directories() shutil.copy2(server_format_args["priv_key_name"], os.path.join(server_dir, "config/repo/zs-priv-key.pem")) shutil.copy2(server_format_args["pub_key_name"], os.path.join(server_dir, "config/repo/zs-pub-key.pem")) shutil.copy2(server_format_args["cert_name"], os.path.join(server_dir, "config/repo/zs-cert.pem")) shutil.copy2( os.path.join(ca_dir, "ca-material/ca-cert.pem"), os.path.join(server_dir, "config/repo/ca-chain.pem") ) cs.execute(args) # Create the web admin now. tech_account_name = "zato-{random}".format(random=uuid4().hex[:10]) tech_account_password_clear = uuid4().hex os.mkdir(zato_admin_dir) create_zato_admin.CreateZatoAdmin(zato_admin_dir, tech_account_name, tech_account_password_clear).execute( args ) # .. copy the web admin's material over to its directory # Will be used later on. priv_key_path = os.path.join(zato_admin_dir, "zato-admin-priv-key.pem") shutil.copy2(zato_admin_format_args["priv_key_name"], priv_key_path) shutil.copy2(zato_admin_format_args["cert_name"], os.path.join(zato_admin_dir, "zato-admin-cert.pem")) shutil.copy2(os.path.join(ca_dir, "ca-material/ca-cert.pem"), os.path.join(zato_admin_dir, "ca-chain.pem")) print("Setting up ODB objects..") # # Cluster # cluster = Cluster( None, cluster_name, "An automatically generated quickstart cluster", args.odb_type, args.odb_host, args.odb_port, args.odb_user, args.odb_dbname, args.odb_schema, args.broker_host, args.broker_start_port, cb.token, "localhost", 20151, 11223, ) # # Server # server = Server( None, "ZatoQuickstartServer-(cluster-#{next_id})".format(next_id=next_id), cluster, cs.odb_token, "ACCEPTED", datetime.now(), "zato-quickstart/" + current_host(), ) session.add(server) # # SOAP Services # soap_services = { # SQL connection pools "zato:pool.sql.get-list": "zato.server.service.internal.sql.GetSQLConnectionPoolList", "zato:pool.sql.create": "zato.server.service.internal.sql.CreateSQLConnectionPool", "zato:pool.sql.edit": "zato.server.service.internal.sql.EditSQLConnectionPool", "zato:pool.sql.delete": "zato.server.service.internal.sql.DeleteSQLConnectionPool", "zato:pool.sql.change-password": "******", "zato:pool.sql.ping": "zato.server.service.internal.sql.PingSQLConnectionPool", # Scheduler "zato:scheduler.job.get-list": "zato.server.service.internal.scheduler.GetList", "zato:scheduler.job.create": "zato.server.service.internal.scheduler.Create", "zato:scheduler.job.edit": "zato.server.service.internal.scheduler.Edit", "zato:scheduler.job.execute": "zato.server.service.internal.scheduler.Execute", "zato:scheduler.job.delete": "zato.server.service.internal.scheduler.Delete", # Services "zato:service.get-list": "zato.server.service.internal.service.GetList", "zato:service.get-by-id": "zato.server.service.internal.service.GetByID", "zato:service.create": "zato.server.service.internal.service.Create", "zato:service.edit": "zato.server.service.internal.service.Edit", "zato:service.delete": "zato.server.service.internal.service.Delete", # SOAP channels "zato:channel.soap.get-list": "zato.server.service.internal.channel.soap.GetList", # Security "zato:security.get-list": "zato.server.service.internal.security.GetList", # Technical accounts "zato:security.tech-account.get-list": "zato.server.service.internal.security.tech_account.GetList", "zato:security.tech-account.get-by-id": "zato.server.service.internal.security.tech_account.GetByID", "zato:security.tech-account.create": "zato.server.service.internal.security.tech_account.Create", "zato:security.tech-account.edit": "zato.server.service.internal.security.tech_account.Edit", "zato:security.tech-account.change-password": "******", "zato:security.tech-account.delete": "zato.server.service.internal.security.tech_account.Delete", # WS-Security "zato:security.wss.get-list": "zato.server.service.internal.security.wss.GetList", "zato:security.wss.create": "zato.server.service.internal.security.wss.Create", "zato:security.wss.edit": "zato.server.service.internal.security.wss.Edit", "zato:security.wss.change-password": "******", "zato:security.wss.delete": "zato.server.service.internal.security.wss.Delete", # HTTP Basic Auth "zato:security.basic-auth.get-list": "zato.server.service.internal.security.basic_auth.GetList", "zato:security.basic-auth.create": "zato.server.service.internal.security.basic_auth.Create", "zato:security.basic-auth.edit": "zato.server.service.internal.security.basic_auth.Edit", "zato:security.basic-auth.change-password": "******", "zato:security.basic-auth.delete": "zato.server.service.internal.security.basic_auth.Delete", # Definitions - AMQP "zato:definition.amqp.get-list": "zato.server.service.internal.definition.amqp.GetList", "zato:definition.amqp.get-by-id": "zato.server.service.internal.definition.amqp.GetByID", "zato:definition.amqp.create": "zato.server.service.internal.definition.amqp.Create", "zato:definition.amqp.change-password": "******", "zato:definition.amqp.edit": "zato.server.service.internal.definition.amqp.Edit", "zato:definition.amqp.delete": "zato.server.service.internal.definition.amqp.Delete", # Definitions - JMS WebSphere MQ "zato:definition.jms_wmq.get-list": "zato.server.service.internal.definition.jms_wmq.GetList", "zato:definition.jms_wmq.get-by-id": "zato.server.service.internal.definition.jms_wmq.GetByID", "zato:definition.jms_wmq.create": "zato.server.service.internal.definition.jms_wmq.Create", "zato:definition.jms_wmq.edit": "zato.server.service.internal.definition.jms_wmq.Edit", "zato:definition.jms_wmq.delete": "zato.server.service.internal.definition.jms_wmq.Delete", # Channels - AMQP "zato:channel.amqp.get-list": "zato.server.service.internal.channel.amqp.GetList", "zato:channel.amqp.create": "zato.server.service.internal.channel.amqp.Create", "zato:channel.amqp.edit": "zato.server.service.internal.channel.amqp.Edit", "zato:channel.amqp.delete": "zato.server.service.internal.channel.amqp.Delete", # Channels - JMS WebSphere MQ "zato:channel.jms_wmq.get-list": "zato.server.service.internal.channel.jms_wmq.GetList", "zato:channel.jms_wmq.create": "zato.server.service.internal.channel.jms_wmq.Create", "zato:channel.jms_wmq.edit": "zato.server.service.internal.channel.jms_wmq.Edit", "zato:channel.jms_wmq.delete": "zato.server.service.internal.channel.jms_wmq.Delete", # Channels - ZeroMQ "zato:channel.zmq.get-list": "zato.server.service.internal.channel.zmq.GetList", "zato:channel.zmq.create": "zato.server.service.internal.channel.zmq.Create", "zato:channel.zmq.edit": "zato.server.service.internal.channel.zmq.Edit", "zato:channel.zmq.delete": "zato.server.service.internal.channel.zmq.Delete", # Outgoing connections - AMQP "zato:outgoing.amqp.get-list": "zato.server.service.internal.outgoing.amqp.GetList", "zato:outgoing.amqp.create": "zato.server.service.internal.outgoing.amqp.Create", "zato:outgoing.amqp.edit": "zato.server.service.internal.outgoing.amqp.Edit", "zato:outgoing.amqp.delete": "zato.server.service.internal.outgoing.amqp.Delete", # Outgoing connections - JMS WebSphere MQ "zato:outgoing.jms_wmq.get-list": "zato.server.service.internal.outgoing.jms_wmq.GetList", "zato:outgoing.jms_wmq.create": "zato.server.service.internal.outgoing.jms_wmq.Create", "zato:outgoing.jms_wmq.edit": "zato.server.service.internal.outgoing.jms_wmq.Edit", "zato:outgoing.jms_wmq.delete": "zato.server.service.internal.outgoing.jms_wmq.Delete", # Outgoing connections - S3 "zato:outgoing.s3.get-list": "zato.server.service.internal.outgoing.s3.GetList", "zato:outgoing.s3.create": "zato.server.service.internal.outgoing.s3.Create", "zato:outgoing.s3.edit": "zato.server.service.internal.outgoing.s3.Edit", "zato:outgoing.s3.delete": "zato.server.service.internal.outgoing.s3.Delete", # Outgoing connections - FTP "zato:outgoing.ftp.get-list": "zato.server.service.internal.outgoing.ftp.GetList", "zato:outgoing.ftp.create": "zato.server.service.internal.outgoing.ftp.Create", "zato:outgoing.ftp.edit": "zato.server.service.internal.outgoing.ftp.Edit", "zato:outgoing.ftp.delete": "zato.server.service.internal.outgoing.ftp.Delete", "zato:outgoing.ftp.change-password": "******", # Outgoing connections - ZeroMQ "zato:outgoing.zmq.get-list": "zato.server.service.internal.outgoing.zmq.GetList", "zato:outgoing.zmq.create": "zato.server.service.internal.outgoing.zmq.Create", "zato:outgoing.zmq.edit": "zato.server.service.internal.outgoing.zmq.Edit", "zato:outgoing.zmq.delete": "zato.server.service.internal.outgoing.zmq.Delete", # HTTP SOAP "zato:http_soap.get-list": "zato.server.service.internal.http_soap.GetList", "zato:http_soap.create": "zato.server.service.internal.http_soap.Create", "zato:http_soap.edit": "zato.server.service.internal.http_soap.Edit", "zato:http_soap.delete": "zato.server.service.internal.http_soap.Delete", } # # TechnicalAccount # salt = uuid4().hex password = tech_account_password(tech_account_password_clear, salt) tech_account = TechnicalAccount( None, tech_account_name, True, password, salt, security_def_type.tech_account, cluster ) session.add(tech_account) # # HTTPSOAP + services # zato_soap_channels = [] for soap_action, service_name in soap_services.iteritems(): service = Service(None, service_name, True, service_name, True, cluster) session.add(service) zato_soap = HTTPSOAP( None, soap_action, True, True, "channel", "soap", "/zato/soap", None, soap_action, "1.1", service=service, cluster=cluster, security_id=tech_account.id, ) session.add(zato_soap) zato_soap_channels.append(zato_soap) # # Security definition for all the other admin services uses a technical account. # # sec_def = SecurityDefinition(None, security_def_type.tech_account) # session.add(sec_def) # # HTTPSOAPSecurity # # for soap_channel in zato_soap_channels: # chan_url_sec = HTTPSOAPSecurity(soap_channel, sec_def) # session.add(chan_url_sec) # Ping services # self.add_ping(session, cluster) # Commit all the stuff. session.commit() print("ODB objects created") print("") print("Quickstart OK. You can now start the newly created Zato components.\n") print( """To start the server, type 'zato start {server_dir}'. To start the load-balancer's agent, type 'zato start {lb_dir}'. To start the ZatoAdmin web console, type 'zato start {zato_admin_dir}'. """.format( server_dir=server_dir, lb_dir=lb_dir, zato_admin_dir=zato_admin_dir ) ) except Exception, e: print("\nAn exception has been caught, quitting now!\n") traceback.print_exc() print("")
def _on_server(self, args): os.chdir(self.original_dir) abs_args_path = os.path.abspath(args.path) component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read() out = { 'component_details': component_details, 'component_full_path': abs_args_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 = self._zdaemon_command('status') master_proc_pid = master_proc_pid.values() if master_proc_pid and master_proc_pid[0]: out['component_running'] = True master_proc_pid = int(master_proc_pid[0]) master_proc = Process(master_proc_pid) workers_pids = sorted(elem.pid for elem in master_proc.get_children()) out['master_proc_connections'] = master_proc.get_connections() out['master_proc_pid'] = master_proc.pid out['master_proc_create_time'] = datetime.fromtimestamp( master_proc.create_time).isoformat() out['master_proc_create_time_utc'] = datetime.fromtimestamp( master_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_memory_percent = worker.get_memory_percent() out['worker_{}_create_time'.format( pid)] = datetime.fromtimestamp( worker.create_time).isoformat() out['worker_{}_create_time_utc'.format( pid)] = datetime.fromtimestamp(worker.create_time, UTC).isoformat() out['worker_{}_connections'.format( pid)] = worker.get_connections() if getattr(args, 'json', False): out['component_details'] = loads(out['component_details']) self.logger.info(dumps(out)) else: cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH cols_width = (elem.strip() for elem in cols_width.split(',')) cols_width = [int(elem) for elem in cols_width] table = Texttable() table.set_cols_width(cols_width) # Use text ('t') instead of auto so that boolean values don't get converted into ints table.set_cols_dtype(['t', 't']) rows = [['Key', 'Value']] rows.extend(sorted(out.items())) table.add_rows(rows) self.logger.info(table.draw())
def _on_sso_command(self, args, user, user_api): # type: (Namespace, SSOUser, UserAPI) response = user_api.login( _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())