Interacting with a Network Device¶
After connecting to a device by running the CiscoAutomationFramework.connect_ssh you receive a child of this class that is specific to IOS/Nexus based on what is detected you are connected to. You will have all of the attributes documented here to interact with your Cisco device regardless of its firmware type.
-
class
CiscoAutomationFramework.FirmwareBase.
CiscoFirmware
(transport)¶ -
add_local_user
(username, password, password_code=0, *args, **kwargs)¶ Method here should be generating a string that the network device accepts in the following format ‘username USERNAME <args> <kwarg key> <kwarg value> password PASSWORD_CODE PASSWORD’
Parameters: - username – Username to use
- password – Password to set (cleartext or encrypted depending on password_code)
- password_code – Code for password you are providing
- args – Single word arguments in command string
- kwargs – Key word arguments in command string
Returns: Nothing
-
arp_table
¶ Returns the arp table in its raw form
Returns: Arp Table Return type: str
-
cli_to_config_mode
() → bool¶ Navigates the CLI into config mode regardless of where it is
Returns: True/False Return type: bool
-
cli_to_privileged_exec_mode
() → bool¶ Navigates the CLI into prvileged exec mode regardless of where it is. Will raise an EnablePasswordError if the transport engine does not have an enable password set and the network device asks for one.
Returns: True/False Return type: bool Raises: CiscoAutomationFramework.Exceptions.EnablePasswordError
-
close_connection
() → None¶ Closes connection to device
Returns: Nothing
-
commands_sent
¶ A list of all commands sent to the device in the order they are entered from first to last in the current session
Returns: List of commands sent Return type: list
-
delete_local_user
(username)¶ Deletes a locally defined user on device
Parameters: username (str) – username to delete Returns: Nothing
-
get_output
(buffer_size=100, timeout=1) → list¶ Gets output from the device until the prompt is returned or the timeout is reached. You should not need to run this directly often.
Parameters: - buffer_size – Size of buffer when getting output from device. You shouldnt have to modify this much
- timeout – Time to stop waiting for output if no output is received.
Returns:
-
hostname
¶ Hostname of the Cisco device.
Returns: Hostname Return type: str
-
interfaces
¶ List of interfaces on device
Returns: Interfaces Return type: list
-
is_nexus
¶ Returns True/False if the Cisco device is a Nexus
Returns: True/False Return type: bool
-
mac_address_table
¶ Returns the MAC address table in its raw form
Returns: MAC Address Table Return type: str
-
prompt
¶ Returns the latest prompt that was returned from the device
Returns: Latest prompt returned from device Return type: str
-
running_config
¶ Returns running config in its raw form
Returns: Running Configuration Return type: str
-
save_config
()¶ Saves running config to startup config
Returns: Nothing
-
send_command
(command, end='\n') → None¶ Sends command to device, does not get any output. You should not need to run this directly often
param command: Command to send param end: End character (default - )
return: Nothing
-
send_command_get_output
(command, end='\n', buffer_size=100, timeout=1, delay=0.5) → list¶ Sends a command to the device and returns the output from the device. If there were multiple commands sent this will gather the output from all the commands at once. This command is a combination of send_command and get_output.
param command: Command to send param end: End character (default - )
param buffer_size: Size of buffer when getting output from device. You shouldnt have to modify this much param timeout: Time to stop waiting for output if no output is received. param delay: Time to wait before gathering output from device return: Output from device starting with command, ending with prompt in a list split by line rtype: list
-
send_question_get_output
(command) → list¶ Special method to get the output from sending a command with a question mark. This will send the command with a trailing ‘?’ get the output from that and then erase the command that is returned on the ending prompt. You should NOT put a question mark in the command this function will handle that for you but if you do, it will be removed so the CLI doesnt do something that is not expected
Parameters: command – Command to inspect Returns: list of possible command completions, or next possible words in command Return type: list
-
startup_config
¶ Returns startup config in its raw form
Returns: Startup Config Return type: str
-
terminal_length
(n='0')¶ Sets terminal length of shell
Parameters: n (str) – length Returns: Nothing
-
terminal_width
(n='0')¶ Sets terminal width of shell
Parameters: n (str) – width Returns:
-
uptime
¶ Returns uptime of device
Returns: Uptime Return type: str
-