This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository x2gobroker. from f46d30b debian/python-x2gobroker.install: Install defaults.conf into bin:package python-x2gobroker. new 01be4fa Do an ICMP ping before querying a remote agent via SSH. new 55e5255 avoid calling x2gobroker.agent.has_sessions() twice The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: debian/changelog | 1 + x2gobroker/agent.py | 93 +++++++++++++++++++------------------ x2gobroker/brokers/base_broker.py | 1 - 3 files changed, 48 insertions(+), 47 deletions(-) -- Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 01be4facc37f05abe9dd87e99b7c4c0ed15a9f20 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Dec 7 00:05:25 2014 +0100 Do an ICMP ping before querying a remote agent via SSH. --- debian/changelog | 1 + x2gobroker/agent.py | 93 ++++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/debian/changelog b/debian/changelog index a0cc46b..9b765eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -202,6 +202,7 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low - Enable basic/random load-balancing for UCCS broker frontend. Make UCCS frontend aware of host session profile options of the form "host=<fqdn> (<ipaddr>:<port>). + - Do an ICMP ping before querying a remote agent via SSH. * debian/control: + Provide separate bin:package for SSH brokerage: x2gobroker-ssh. + Replace LDAP support with session brokerage support in LONG_DESCRIPTION. diff --git a/x2gobroker/agent.py b/x2gobroker/agent.py index e4bef4d..531c407 100644 --- a/x2gobroker/agent.py +++ b/x2gobroker/agent.py @@ -167,55 +167,56 @@ def _call_remote_broker_agent(username, task, cmdline_args=[], remote_agent=None elif not remote_agent.has_key('host_key_policy'): remote_agent['host_key_policy'] = paramiko.WarningPolicy() - cmd_line = [ - '{x2gobroker_agent_binary}'.format(x2gobroker_agent_binary=x2gobroker.defaults.X2GOBROKER_AGENT_CMD), - '{username}'.format(username=username), - '{task}'.format(task=task), - ] - - for cmdline_arg in cmdline_args: - cmd_line.append('"{arg}"'.format(arg=cmdline_arg)) - - remote_username = x2gobroker.defaults.X2GOBROKER_AGENT_USER remote_hostname = remote_agent[u'hostname'] - if remote_agent.has_key(u'port'): - remote_port = int(remote_agent[u'port']) - else: - remote_port = 22 - - # now, connect and use paramiko Client to negotiate SSH2 across the connection - try: - client = paramiko.SSHClient() - client.load_system_host_keys() - if os.path.exists(os.path.expanduser("~/.ssh/known_hosts")): - client.load_host_keys(os.path.expanduser("~/.ssh/known_hosts")) - client.set_missing_host_key_policy(remote_agent['host_key_policy']) - client.connect(remote_hostname, remote_port, remote_username, look_for_keys=True, allow_agent=True) - - result = [] - ssh_transport = client.get_transport() - if ssh_transport and ssh_transport.is_authenticated(): - cmd = ' '.join(cmd_line) - cmd = 'sh -c \'{cmd}\''.format(cmd=cmd) - logger_broker.info('Executing agent command on remote host ({remote_agent}): {cmd}'.format(remote_agent=remote_agent['hostname'], cmd=cmd)) - (stdin, stdout, stderr) = client.exec_command(cmd) - result = stdout.read().split('\n') - err = stderr.read().replace('\n', ' ') - if err: - logger_broker.warning('Remote agent command (host: {remote_agent}) reported an error: {err}'.format(remote_agent=remote_agent['hostname'], err=err)) - client.close() - if result: - logger_broker.info('Broker agent answered: {answer}'.format(answer="; ".join(result))) - if result and result[0].startswith('OK'): - return (True, [ r for r in result[1:] if r ]) + if icmp_ping(remote_hostname): + cmd_line = [ + '{x2gobroker_agent_binary}'.format(x2gobroker_agent_binary=x2gobroker.defaults.X2GOBROKER_AGENT_CMD), + '{username}'.format(username=username), + '{task}'.format(task=task), + ] + + for cmdline_arg in cmdline_args: + cmd_line.append('"{arg}"'.format(arg=cmdline_arg)) + + remote_username = x2gobroker.defaults.X2GOBROKER_AGENT_USER + if remote_agent.has_key(u'port'): + remote_port = int(remote_agent[u'port']) else: - return (False, []) - except paramiko.AuthenticationException: - raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Authentication to remote X2Go Broker Agent Host failed (user: {user}, hostname: {hostname}, port: {port}) failed'.format(user=remote_username, hostname=remote_hostname, port=remote_port)) - except (paramiko.SSHException, paramiko.BadHostKeyException, socket.error): - raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Query to remote X2Go Broker Agent (user: {user}, hostname: {hostname}, port: {port}) failed'.format(user=remote_username, hostname=remote_hostname, port=remote_port)) + remote_port = 22 - raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Query to remote X2Go Broker Agent failed with no response') + # now, connect and use paramiko Client to negotiate SSH2 across the connection + try: + client = paramiko.SSHClient() + client.load_system_host_keys() + if os.path.exists(os.path.expanduser("~/.ssh/known_hosts")): + client.load_host_keys(os.path.expanduser("~/.ssh/known_hosts")) + client.set_missing_host_key_policy(remote_agent['host_key_policy']) + client.connect(remote_hostname, remote_port, remote_username, look_for_keys=True, allow_agent=True) + + result = [] + ssh_transport = client.get_transport() + if ssh_transport and ssh_transport.is_authenticated(): + cmd = ' '.join(cmd_line) + cmd = 'sh -c \'{cmd}\''.format(cmd=cmd) + logger_broker.info('Executing agent command on remote host ({remote_agent}): {cmd}'.format(remote_agent=remote_agent['hostname'], cmd=cmd)) + (stdin, stdout, stderr) = client.exec_command(cmd) + result = stdout.read().split('\n') + err = stderr.read().replace('\n', ' ') + if err: + logger_broker.warning('Remote agent command (host: {remote_agent}) reported an error: {err}'.format(remote_agent=remote_agent['hostname'], err=err)) + client.close() + if result: + logger_broker.info('Broker agent answered: {answer}'.format(answer="; ".join(result))) + if result and result[0].startswith('OK'): + return (True, [ r for r in result[1:] if r ]) + else: + return (False, []) + except paramiko.AuthenticationException: + raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Authentication to remote X2Go Broker Agent Host failed (user: {user}, hostname: {hostname}, port: {port}) failed'.format(user=remote_username, hostname=remote_hostname, port=remote_port)) + except (paramiko.SSHException, paramiko.BadHostKeyException, socket.error): + raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Query to remote X2Go Broker Agent (user: {user}, hostname: {hostname}, port: {port}) failed'.format(user=remote_username, hostname=remote_hostname, port=remote_port)) + else: + raise x2gobroker.x2gobroker_exceptions.X2GoBrokerAgentException('Could not ping remote X2Go Broker Agent host ({remote_hostname})'.format(remote_hostname=remote_hostname)) def icmp_ping(hostname): -- Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2gobroker. commit 55e5255d3509ade6460b2341f4feb439b1e69e6d Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sun Dec 7 00:06:51 2014 +0100 avoid calling x2gobroker.agent.has_sessions() twice --- x2gobroker/brokers/base_broker.py | 1 - 1 file changed, 1 deletion(-) diff --git a/x2gobroker/brokers/base_broker.py b/x2gobroker/brokers/base_broker.py index 880e1d7..81addff 100644 --- a/x2gobroker/brokers/base_broker.py +++ b/x2gobroker/brokers/base_broker.py @@ -1055,7 +1055,6 @@ class X2GoBroker(object): remote_agent = self.get_remote_agent(profile_id) agent_query_mode = ( remote_agent == u'LOCAL') and u'LOCAL' or u'SSH' if remote_agent: - success, running_sessions, suspended_sessions = x2gobroker.agent.has_sessions(username, remote_agent=remote_agent) try: success, running_sessions, suspended_sessions = x2gobroker.agent.has_sessions(username, remote_agent=remote_agent) if running_sessions: -- Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git