Link Search Menu Expand Document (external link)

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

InputTypeDescription
groupslistList of group names eg. [‘switches’, ‘test_switches’]
userstringUsername for authentication
passwordstringPassword for authentication
privileged_mode_passwordStringPassword of the Privileged mode (eg. enable in Cisco & super in Huawei) [ If Provided, the device login to privileged_mode after authentication. ]
portintegerPort for authentication


OUTPUT

Returns an object with the following attributes

InputTypeDescription
hosts_totallistList of the total hosts (of the inventory group/groups) provided for authentication
hosts_connectedlistList the hosts were connected successfully
hosts_failedlistList the hosts failed to connect
hosts_total_numberintegerNumber of total hosts
hosts_connected_numberintegerNumber of connected hosts
hosts_failed_numberintegerNumber of failed hosts
connection_report_tablestringStructured 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

InputTypeDescription
hoststringHost to execute commands on (The host needs to be authenticated first)
cmdstringThe command to execute


OUTPUT

Returns an objects with the following attributes

InputTypeDescription
hoststringThe host IP
cmdListcommand (list of lines)
stdoutListSTDOUT output (list of lines)
stderrListSTDERR output (list of lines)
exit_codeInteger0 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

InputTypeDescription
hoststringHost to execute commands on (The host needs to be authenticated first)
cmdstringThe command to execute
only_on_hostsListA condition (List of hosts to execute only on)
skip_hostsListA condition (List of hosts to Skip execution on)
ask_for_confirmationBooleanIf True, I will ask for confirmation before executing the command, Default: False
exit_on_failBooleanIf True, the script will exit if the command exit with an Error, Default: True
reconnect_closed_socketBooleanIf 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

InputTypeDescription
hoststringHost
cmdListcommand (list of lines)
stdoutListSTDOUT output (list of lines)
stderrListSTDERR output (list of lines)
exit_codeInteger0 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

InputTypeDescription
hoststringHost to execute commands on (The host needs to be authenticated first)
filestringFile with commands to execute
ask_for_confirmationBooleanIf True, I will ask for confirmation before executing the command, Default: False
exit_on_failBooleanIf True, the script will exit if the command exit with an Error, Default: True
reconnect_closed_socketBooleanIf 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

InputTypeDescriptionOptionsDefault
hoststringhost to backup its config  
commentstringA comment indicates the purpose of the backup  
targetstringWhere to save the backuplocal, s3local

NOTE: targets other than local requires you to add the credentials in the config file


OUTPUT

Returns an object with the following attributes

InputTypeDescription
exit_codeInteger0 backup taken successfully. 1 Failed to take backup
stderrStringSTDERR output
stdoutStringSTDOUT output
locationStringlocation, where the backup exists
idStringThe backup string

get_config_backup()

Return a pre-taken config backup


Note: This method prints the output to the terminal.


INPUT

InputTypeDescriptionOptionsDefault
backup idstringThe 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

InputTypeDescription
exit_codeInteger0 Got backup successfully. 1 Failed to return backup
stderrStringSTDERR output
stdoutStringSTDOUT output
targetStringindicates where the backup is located
locationStringlocation, where the backup exists
textStringThe backup text