Bug 2447 - les pages "cluster status" et "cluster user guide" affichent des quantités de mémoire erronées

- fixed a bug : now, the displayed memory is correct even if the mem_available sge attribute returns the memory in other units than gigabyte

- also, this commit includes an old improvement that makes executeCommandOn handle an optional user, which was previously slinetly ignored in the case of a local command
This commit is contained in:
Guillaume Raffy 2018-09-25 13:48:47 +00:00
parent a2be664bbe
commit 991744baf1
1 changed files with 10 additions and 6 deletions

16
Util.py
View File

@ -63,21 +63,25 @@ def executeCommand(command):
return result
def executeCommandOn(target_machine_fqdn, strCommand, remote_user=None):
def executeCommandOn(target_machine_fqdn, command, user=None):
"""
execute command on a local or remote machine (using ssh then)
:param str remote_user:
:param str user: if not None, the user that should be used to execute the command (instead of the current user)
"""
print("comparing %s and %s" % (getHostName(), target_machine_fqdn.split('.')[0]))
if getHostName() == target_machine_fqdn.split('.')[0]:
return executeCommand(strCommand)
if user is not None:
# su -c "ls -l /tmp" graffy
return executeCommand("su -c '%s' %s" % (command, user))
else:
if not remote_user is None:
target = '%s@%s' % (remote_user, target_machine_fqdn)
return executeCommand(command)
else:
if user is not None:
target = '%s@%s' % (user, target_machine_fqdn)
else:
target = target_machine_fqdn
return executeProgram(['ssh', target, "%s" % strCommand])
return executeProgram(['ssh', target, "%s" % command])
def getUpsStatus():