Terminal_Task
class Methods
from FlexibleNetwork.Flexible_Network import Terminal_Task
task = Terminal_Task()
authenticate
Authenticate with an inventory group
The
authenticate()
method, esablishes SSH conenections with all the hosts of the inventory group (In parallel)
INPUT
Input | Type | Description |
---|---|---|
groups | list | List of group names eg. [‘switches’, ‘test_switches’] |
user | string | Username for authentication |
password | string | Password for authentication |
privileged_mode_password | String | Password of the Privileged mode (eg. enable in Cisco & super in Huawei) [ If Provided, the device login to privileged_mode after authentication. ] |
port | integer | Port for authentication |
OUTPUT
Returns an object with the following attributes
Input | Type | Description |
---|---|---|
hosts_total | list | List of the total hosts (of the inventory group/groups) provided for authentication |
hosts_connected | list | List the hosts were connected successfully |
hosts_failed | list | List the hosts failed to connect |
hosts_total_number | integer | Number of total hosts |
hosts_connected_number | integer | Number of connected hosts |
hosts_failed_number | integer | Number of failed hosts |
connection_report_table | string | Structured table displays connection report of the hosts |
execute_raw()
Execute a command on a remote device.
Note: This method does not print to the terminal.
INPUT
Input | Type | Description |
---|---|---|
host | string | Host to execute commands on (The host needs to be authenticated first) |
cmd | string | The command to execute |
OUTPUT
Returns an objects with the following attributes
Input | Type | Description |
---|---|---|
host | string | The host IP |
cmd | List | command (list of lines) |
stdout | List | STDOUT output (list of lines) |
stderr | List | STDERR output (list of lines) |
exit_code | Integer | 0 Executed without Errors. 1 Executed with Errors. -1 Connection inturrupted before or during execution |
execute()
Execute a command on a remote device.
Note: This method prints the output to the terminal.
INPUT
Input | Type | Description |
---|---|---|
host | string | Host to execute commands on (The host needs to be authenticated first) |
cmd | string | The command to execute |
only_on_hosts | List | A condition (List of hosts to execute only on) |
skip_hosts | List | A condition (List of hosts to Skip execution on) |
ask_for_confirmation | Boolean | If True, I will ask for confirmation before executing the command, Default: False |
exit_on_fail | Boolean | If True, the script will exit if the command exit with an Error, Default: True |
reconnect_closed_socket | Boolean | If True, Try to reconnect to the host if connection was inturrupted (Instead of considering it an error), Default: True |
OUTPUT
Returns an object with the following attributes
Input | Type | Description |
---|---|---|
host | string | Host |
cmd | List | command (list of lines) |
stdout | List | STDOUT output (list of lines) |
stderr | List | STDERR output (list of lines) |
exit_code | Integer | 0 executed without Errors. 1 Executed with Errors. -1 Connection inturrupted before or during execution |
execute_from_file()
Load commands from file & execute each line one by one. using the execute() method
Note: This method prints the output to the terminal.
INPUT
Input | Type | Description |
---|---|---|
host | string | Host to execute commands on (The host needs to be authenticated first) |
file | string | File with commands to execute |
ask_for_confirmation | Boolean | If True, I will ask for confirmation before executing the command, Default: False |
exit_on_fail | Boolean | If True, the script will exit if the command exit with an Error, Default: True |
reconnect_closed_socket | Boolean | If True, Try to reconnect to the host if connection was inturrupted (Instead of considering it an error), Default: True |
OUTPUT
does NOT return
take_config_backup()
Backup running configuration from the remote device & store them in the local directory by default, for other backup storage options
Note: This method prints the output to the terminal.
INPUT
Input | Type | Description | Options | Default |
---|---|---|---|---|
host | string | host to backup its config | ||
comment | string | A comment indicates the purpose of the backup | ||
target | string | Where to save the backup | local , s3 | local |
NOTE: targets other than
local
requires you to add the credentials in the config file
OUTPUT
Returns an object with the following attributes
Input | Type | Description |
---|---|---|
exit_code | Integer | 0 backup taken successfully. 1 Failed to take backup |
stderr | String | STDERR output |
stdout | String | STDOUT output |
location | String | location, where the backup exists |
id | String | The backup string |
get_config_backup()
Return a pre-taken config backup
Note: This method prints the output to the terminal.
INPUT
Input | Type | Description | Options | Default |
---|---|---|---|---|
backup id | string | The ID of the pre-taken backup |
NOTE: targets other than ‘local’ requires you to add the credentials in the config file
OUTPUT
Returns an object with the following attributes
Input | Type | Description |
---|---|---|
exit_code | Integer | 0 Got backup successfully. 1 Failed to return backup |
stderr | String | STDERR output |
stdout | String | STDOUT output |
target | String | indicates where the backup is located |
location | String | location, where the backup exists |
text | String | The backup text |