Skip to content

Host Action Functions

Micah J. Martin edited this page Apr 16, 2019 · 5 revisions

Action functions are the commands that you can call on a host object. Combinations of these commands allow you to create action functions that achieve complex tasks. This page documents the action functions that are available and how to use them

host.run(*args, **kwargs)

Run commands on the remote host.

Notes stdin can be passed into the program for scripts execution. Interactive mode does not shutdown stdin until the status has closed, do not use interactive with commands that read from stdin constantly (e.x. 'bash').

def run(self, command: str, stdin=None, sudo=False, interactive=False,
        connection=None, shell=False) -> dict:

Arguments

  • command (str): The command to run on the remote host
  • stdin (str, optional): The stdin to be passed into the running process
  • sudo (bool, optional): Whether or not the command should be run as sudo. Defaults to False.
  • interactive (bool, optional): Whether or not the program requires further interaction. Defaults to False.
  • connection (paramiko.SSHClient, optional): The connection to use for the interaction
  • shell (bool, optional): Whether to invoke a shell or not. May be required for certain commands to run. Defaults to False.

Returns

This function return the standard return format.

host.put(*args, **kwargs)

Push a local file (via SCP) onto the remote host.

def put(self, local, remote, sudo=False, tmp=None) -> dict:

Arguments

  • local (str): the local file path to send
  • remote (str): the remote location to store the file
  • sudo (bool, optional): Needed to copy the file into a privileged location
  • tmp (str, optional): If using sudo, the temporary location to write to, needs to be accessible to the unprivileged user. Defaults to "/tmp/det_tmp_file"

Returns

This function return the standard return format.

host.get(*args, **kwargs)

Download a file (via SCP) from the remote host.

def get(self, remote, local, sudo=False, tmp=None) -> dict:

Arguments

  • remote (str): the remote location to get the file from
  • local (str): the local file path to save the file to
  • sudo (bool, optional): Needed to get the file from a privileged location
  • tmp (str, optional): If using sudo, the temporary location to write to, needs to be accessible to the unprivileged user. Defaults to "/tmp/det_tmp_file"

Returns

This function return the standard return format.

Standard Return Format

All of the exposed action functions return a dictionary object containing information about the command that was run. This information is output in the following format.

{
    'host': host,        # The host that the command was run on
    'stdout': stdout,    # The stdout of the command
    'stderr': stderr,    # The stderr of the command
    'status': status,    # The status code of the command (exit code)
    'command': command   # The command that was run
}