Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pycloudlib/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def _run_command(self, command, stdin):
"""Run command in the instance."""
return self._ssh(list(command), stdin=stdin)

def execute(self, command, stdin=None, description=None, **kwargs):
def execute(self, command, stdin=None, description=None, *, use_sudo=False,
**kwargs):
"""Execute command in instance, recording output, error and exit code.

Assumes functional networking and execution with the target filesystem
Expand All @@ -150,13 +151,16 @@ def execute(self, command, stdin=None, description=None, **kwargs):
`['sh', '-c', command]`
stdin: bytes content for standard in
description: purpose of command
use_sudo: boolean to run the command as sudo

Returns:
Result object

"""
if isinstance(command, str):
command = ['sh', '-c', command]
if use_sudo:
command = ['sudo', '--'] + command

self._log.info('executing: %s', shell_quote(command))
if description:
Expand Down