Exscript.host module

Representing a device to connect with.

class Exscript.host.Host(uri, default_protocol='telnet')[source]

Bases: future.types.newobject.newobject

Represents a device on which to open a connection.

__init__(uri, default_protocol='telnet')[source]

Constructor. The given uri is passed to Host.set_uri(). The default_protocol argument defines the protocol that is used in case the given uri does not specify it.

Parameters:
  • uri (string) – A hostname; see set_uri() for more info.
  • default_protocol (string) – The protocol name.
account
address
append(name, value)[source]

Appends the given value to the list variable with the given name.

Parameters:
  • name (string) – The name of the variable.
  • value (object) – The appended value.
get(name, default=None)[source]

Returns the value of the given variable, or the given default value if the variable is not defined.

Parameters:
  • name (string) – The name of the variable.
  • default (object) – The default value.
Return type:

object

Returns:

The value of the variable.

get_account()[source]

Returns the account that is used to log in.

Return type:Account
Returns:The account.
get_address()[source]

Returns the address that is used to open the connection.

Return type:string
Returns:The address that is used to open the connection.
get_all()[source]

Returns a dictionary containing all variables.

Return type:dict
Returns:The dictionary with the variables.
get_dict()[source]

Returns a dict containing the host’s attributes. The following keys are contained:

  • hostname
  • address
  • protocol
  • port
Return type:dict
Returns:The resulting dictionary.
get_name()[source]

Returns the name.

Return type:string
Returns:The hostname excluding the name.
get_option(name, default=None)[source]

Returns the value of the given option if it is defined, returns the given default value otherwise.

Parameters:
  • name (str) – The option name.
  • default (object) – A default value.
get_options()[source]

Return a dictionary containing all defined options.

Return type:dict
Returns:The options.
get_protocol()[source]

Returns the name of the protocol.

Return type:string
Returns:The protocol name.
get_tcp_port()[source]

Returns the TCP port number.

Return type:string
Returns:The TCP port number.
get_uri()[source]

Returns a URI formatted representation of the host, including all of it’s attributes except for the name. Uses the address, not the name of the host to build the URI.

Return type:str
Returns:A URI.
has_key(name)[source]

Returns True if the variable with the given name is defined, False otherwise.

Parameters:name (string) – The name of the variable.
Return type:bool
Returns:Whether the variable is defined.
name
options
protocol
set(name, value)[source]

Stores the given variable/value in the object for later retrieval.

Parameters:
  • name (string) – The name of the variable.
  • value (object) – The value of the variable.
set_account(account)[source]

Defines the account that is used to log in.

Parameters:account (Exscript.Account) – The account.
set_address(address)[source]

Set the address of the remote host the is contacted, without changing hostname, username, password, protocol, and TCP port number. This is the actual address that is used to open the connection.

Parameters:address (string) – A hostname or IP name.
set_all(variables)[source]

Like set(), but replaces all variables by using the given dictionary. In other words, passing an empty dictionary results in all variables being removed.

Parameters:variables (dict) – The dictionary with the variables.
set_default(name, value)[source]

Like set(), but only sets the value if the variable is not already defined.

Parameters:
  • name (string) – The name of the variable.
  • value (object) – The value of the variable.
set_name(name)[source]

Set the hostname of the remote host without changing username, password, protocol, and TCP port number.

Parameters:name (string) – A hostname or IP address.
set_option(name, value)[source]

Defines a (possibly protocol-specific) option for the host. Possible options include:

verify_fingerprint: bool
Parameters:
  • name (str) – The option name.
  • value (object) – The option value.
set_protocol(protocol)[source]

Defines the protocol. The following protocols are currently supported:

  • telnet: Telnet
  • ssh1: SSH version 1
  • ssh2: SSH version 2
  • ssh: Automatically selects the best supported SSH version
  • dummy: A virtual device that accepts any command, but that does not respond anything useful.
  • pseudo: A virtual device that loads a file with the given “hostname”. The given file is a Python file containing information on how the virtual device shall respond to commands. For more information please refer to the documentation of protocols.Dummy.load_command_handler_from_file().
Parameters:protocol (string) – The protocol name.
set_tcp_port(tcp_port)[source]

Defines the TCP port number.

Parameters:tcp_port (int) – The TCP port number.
set_uri(uri)[source]

Defines the protocol, hostname/address, TCP port number, username, and password from the given URL. The hostname may be URL formatted, so the following formats are all valid:

For a list of supported protocols please see set_protocol().

Parameters:uri (string) – An URL formatted hostname.
tcp_port
vars