Note

You are viewing the documentation for an older version of boto (boto2).

Boto3, the next version of Boto, is now stable and recommended for general use. It can be used side-by-side with Boto in the same project, so it is easy to start using Boto3 in your existing projects as well as new projects. Going forward, API updates and all new feature work will be focused on Boto3.

For more information, see the documentation for boto3.

manage

boto.manage

boto.manage.cmdshell

The cmdshell module uses the paramiko package to create SSH connections to the servers that are represented by instance objects. The module has functions for running commands, managing files, and opening interactive shell sessions over those connections.

class boto.manage.cmdshell.FakeServer(instance, ssh_key_file)

This object has a subset of the variables that are normally in a boto.manage.server.Server object. You can use this FakeServer object to create a boto.manage.SSHClient object if you don’t have a real Server object.

Variables:
  • instance – A boto Instance object.
  • ssh_key_file – The path to the SSH key file.
class boto.manage.cmdshell.LocalClient(server, host_key_file=None, uname='root')
Variables:
  • server – A Server object or FakeServer object.
  • host_key_file – The path to the user’s .ssh key files.
  • uname – The username for the SSH connection. Default = ‘root’.
close()
exists(path)

Check for the specified path, or check a file at the specified path.

Return type:boolean
Returns:If the path or the file exist, the function returns True.
get_file(src, dst)

Copy a file from one directory to another.

isdir(path)

Check the specified path to determine if it is a directory.

Return type:boolean
Returns:Returns True if the path is an existing directory.
listdir(path)

List all of the files and subdirectories at the specified path.

Return type:list
Returns:Return a list containing the names of the entries in the directory given by path.
put_file(src, dst)

Copy a file from one directory to another.

run()

Open a subprocess and run a command on the local host.

Return type:tuple
Returns:This function returns a tuple that contains an integer status and a string with the combined stdout and stderr output.
shell()
class boto.manage.cmdshell.SSHClient(server, host_key_file='~/.ssh/known_hosts', uname='root', timeout=None, ssh_pwd=None)

This class creates a paramiko.SSHClient() object that represents a session with an SSH server. You can use the SSHClient object to send commands to the remote host and manipulate files on the remote host.

Variables:
  • server – A Server object or FakeServer object.
  • host_key_file – The path to the user’s .ssh key files.
  • uname – The username for the SSH connection. Default = ‘root’.
  • timeout – The optional timeout variable for the TCP connection.
  • ssh_pwd – An optional password to use for authentication or for unlocking the private key.
close()

Close an SSH session and any open channels that are tied to it.

connect(num_retries=5)

Connect to an SSH server and authenticate with it.

Parameters:num_retries (int) – The maximum number of connection attempts.
exists(path)

Check the remote host for the specified path, or a file at the specified path. This function returns 1 if the path or the file exist on the remote host, and returns 0 if the path or the file does not exist on the remote host.

Parameters:path (string) – The path to the directory or file that you want to check.
Return type:integer
Returns:If the path or the file exist, the function returns 1. If the path or the file do not exist on the remote host, the function returns 0.
get_file(src, dst)

Open an SFTP session on the remote host, and copy a file from the remote host to the specified path on the local host.

Parameters:
  • src (string) – The path to the target file on the remote host.
  • dst (string) – The path on your local host where you want to store the file.
isdir(path)

Check the specified path on the remote host to determine if it is a directory.

Parameters:path (string) – The path to the directory that you want to check.
Return type:integer
Returns:If the path is a directory, the function returns 1. If the path is a file or an invalid path, the function returns 0.
listdir(path)

List all of the files and subdirectories at the specified path on the remote host.

Parameters:path (string) – The base path from which to obtain the list.
Return type:list
Returns:A list of files and subdirectories at the specified path.
open(filename, mode='r', bufsize=-1)

Open an SFTP session to the remote host, and open a file on that host.

Parameters:
  • filename (string) – The path to the file on the remote host.
  • mode (string) – The file interaction mode.
  • bufsize (integer) – The file buffer size.
Return type:

paramiko.sftp_file.SFTPFile

Returns:

A paramiko proxy object for a file on the remote server.

open_sftp()

Open an SFTP session on the SSH server.

Return type:paramiko.sftp_client.SFTPClient
Returns:An SFTP client object.
put_file(src, dst)

Open an SFTP session on the remote host, and copy a file from the local host to the specified path on the remote host.

Parameters:
  • src (string) – The path to the target file on your local host.
  • dst (string) – The path on the remote host where you want to store the file.
run(command)

Run a command on the remote host.

Parameters:command (string) – The command that you want to send to the remote host.
Return type:tuple
Returns:This function returns a tuple that contains an integer status, the stdout from the command, and the stderr from the command.
run_pty(command)

Request a pseudo-terminal from a server, and execute a command on that server.

Parameters:command (string) – The command that you want to run on the remote host.
Return type:paramiko.channel.Channel
Returns:An open channel object.
shell()

Start an interactive shell session with the remote host.

boto.manage.cmdshell.sshclient_from_instance(instance, ssh_key_file, host_key_file='~/.ssh/known_hosts', user_name='root', ssh_pwd=None)

Create and return an SSHClient object given an instance object.

Parameters:
  • instance (:class`boto.ec2.instance.Instance` object) – The instance object.
  • ssh_key_file (string) – A path to the private key file that is used to log into the instance.
  • host_key_file (string) – A path to the known_hosts file used by the SSH client. Defaults to ~/.ssh/known_hosts
  • user_name (string) – The username to use when logging into the instance. Defaults to root.
  • ssh_pwd (string) – The passphrase, if any, associated with private key.
boto.manage.cmdshell.start(server)

Connect to the specified server.

Returns:If the server is local, the function returns a boto.manage.cmdshell.LocalClient object. If the server is remote, the function returns a boto.manage.cmdshell.SSHClient object.

boto.manage.propget

boto.manage.propget.get(prop, choices=None)

boto.manage.server

boto.manage.task

boto.manage.volume