Exscript.stdlib.connection module

Exscript.stdlib.connection.authenticate(*args, **kwargs)[source]

Looks for any username/password prompts on the current connection and logs in using the login information that was passed to Exscript.

Exscript.stdlib.connection.authenticate_user(*args, **kwargs)[source]

Like authenticate(), but logs in using the given user and password. If a user and password are not given, the function uses the same user and password that were used at the last login attempt; it is an error if no such attempt was made before.

Parameters:
  • user (string) – A username.
  • password (string) – A password.
Exscript.stdlib.connection.authorize(*args, **kwargs)[source]

Looks for a password prompt on the current connection and enters the given password. If a password is not given, the function uses the same password that was used at the last login attempt; it is an error if no such attempt was made before.

Parameters:password (string) – A password.
Exscript.stdlib.connection.auto_authorize(*args, **kwargs)[source]

Executes a command on the remote host that causes an authorization procedure to be started, then authorizes using the given password in the same way in which authorize() works. Depending on the detected operating system of the remote host the following commands are started:

  • on IOS, the “enable” command is executed.
  • nothing on other operating systems yet.
Parameters:password (string) – A password.
Exscript.stdlib.connection.autoinit(*args, **kwargs)[source]

Make the remote host more script-friendly by automatically executing one or more commands on it. The commands executed depend on the currently used driver. For example, the driver for Cisco IOS would execute the following commands:

term len 0
term width 0
Exscript.stdlib.connection.close(*args, **kwargs)[source]

Closes the existing connection with the remote host. This function is rarely used, as normally Exscript closes the connection automatically when the script has completed.

Exscript.stdlib.connection.exec_(*args, **kwargs)[source]

Sends the given data to the remote host and waits until the host has responded with a prompt. If the given data is a list of strings, each item is sent, and after each item a prompt is expected.

This function also causes the response of the command to be stored in the built-in __response__ variable.

Parameters:data (string) – The data that is sent.
Exscript.stdlib.connection.execline(*args, **kwargs)[source]

Like exec(), but appends a newline to the command in data before sending it.

Parameters:data (string) – The data that is sent.
Exscript.stdlib.connection.guess_os(*args, **kwargs)[source]

Guesses the operating system of the connected host.

The recognition is based on the past conversation that has happened on the host; Exscript looks for known patterns and maps them to specific operating systems.

Return type:string
Returns:The operating system.
Exscript.stdlib.connection.send(*args, **kwargs)[source]

Like exec(), but does not wait for a response of the remote host after sending the command.

Parameters:data (string) – The data that is sent.
Exscript.stdlib.connection.sendline(*args, **kwargs)[source]

Like execline(), but does not wait for a response of the remote host after sending the command.

Parameters:data (string) – The data that is sent.
Exscript.stdlib.connection.set_error(*args, **kwargs)[source]

Defines a pattern that, whenever detected in the response of the remote host, causes an error to be raised.

In other words, whenever Exscript waits for a prompt, it searches the response of the host for the given pattern and raises an error if the pattern is found.

Parameters:error_re (regex) – The error pattern.
Exscript.stdlib.connection.set_prompt(*args, **kwargs)[source]

Defines the pattern that is recognized at any future time when Exscript needs to wait for a prompt. In other words, whenever Exscript waits for a prompt, it searches the response of the host for the given pattern and continues as soon as the pattern is found.

Exscript waits for a prompt whenever it sends a command (unless the send() method was used). set_prompt() redefines as to what is recognized as a prompt.

Parameters:prompt (regex) – The prompt pattern.
Exscript.stdlib.connection.set_timeout(*args, **kwargs)[source]

Defines the time after which Exscript fails if it does not receive a prompt from the remote host.

Parameters:timeout (int) – The timeout in seconds.
Exscript.stdlib.connection.wait_for(*args, **kwargs)[source]

Waits until the response of the remote host contains the given pattern.

Parameters:prompt (regex) – The prompt pattern.