"""
Exception thrown on command failure
"""
- def __init__(self, command, exitstatus, node=None):
+ def __init__(self, command, exitstatus, node=None, label=None):
self.command = command
self.exitstatus = exitstatus
self.node = node
+ self.label = label
def __str__(self):
- return "Command failed on {node} with status {status}: {cmd!r}".format(
+ prefix = "Command failed"
+ if self.label:
+ prefix = "Command failed ({label})".format(label=self.label)
+ return "{prefix} on {node} with status {status}: {cmd!r}".format(
node=self.node,
status=self.exitstatus,
cmd=self.command,
+ prefix=prefix,
)
'greenlets',
# for orchestra.remote.Remote to place a backreference
'remote',
+ 'label',
]
- def __init__(self, client, args, check_status=True, hostname=None):
+ def __init__(self, client, args, check_status=True, hostname=None, label=None):
"""
Create the object. Does not initiate command execution.
:param check_status: Whether to raise CommandFailedError on non-zero
exit status, and . Defaults to True. All signals
and connection loss are made to look like SIGHUP.
- :param hostname: Name of remote host (optional)
+ :param hostname: Name of remote host (optional)
+ :param label: Can be used to label or describe what the
+ command is doing.
"""
self.client = client
self.args = args
self.command = quote(args)
self.check_status = check_status
+ self.label = label
if hostname:
self.hostname = hostname
"""
Execute remote command
"""
- log.getChild(self.hostname).info(u"Running: {cmd!r}".format(
- cmd=self.command))
+ prefix = "Running:"
+ if self.label:
+ prefix = "Running ({label}):".format(label=self.label)
+ log.getChild(self.hostname).info(u"{prefix} {cmd!r}".format(
+ cmd=self.command, prefix=prefix))
(self._stdin_buf, self._stdout_buf, self._stderr_buf) = \
self.client.exec_command(self.command)
raise CommandCrashedError(command=self.command)
if status != 0:
raise CommandFailedError(command=self.command,
- exitstatus=status, node=self.hostname)
+ exitstatus=status, node=self.hostname,
+ label=self.label)
return status
def _get_exitstatus(self):
logger=None,
check_status=True,
wait=True,
- name=None
+ name=None,
+ label=None
):
"""
Run a command remotely. If any of 'args' contains shell metacharacters
actual status is available via ``.get()``.
:param name: Human readable name (probably hostname) of the destination
host
+ :param label: Can be used to label or describe what the command is doing.
"""
try:
(host, port) = client.get_transport().getpeername()
if name is None:
name = host
- r = RemoteProcess(client, args, check_status=check_status, hostname=name)
+ r = RemoteProcess(client, args, check_status=check_status, hostname=name, label=label)
r.execute()
r.stdin = KludgeFile(wrapped=r.stdin)