![]() ![]() class CRTSession(Session)) and a subclass for use with your local Python install (e.g. class Session) as well as a sub-class for use with SecureCRT (e.g. For those who understand Object-Oriented Programming and Classes work, both the Script and Session objects have an abstract base class (e.g. This is done by using the class system in Python. When trying to debug from within SecureCRT you are limited to either logging or printing debug info to the screen with a Message Box (which are both available if you prefer) ![]() When the script is run directly from your local Python 2.x install, then instead of trying to send (for example) show cdp neighbor to a device, it will prompt you to specify a file that contains the output for show cdp neighbor, so that you can step through the program logic with a debugging tool. The debug mode was added to speed development and troubleshooting of script logic that doesn’t involve SecureCRT’s API, such as testing/debugging parsing of the output from a device. ![]() An example of how to use these constants is in the comments of the file. This allows you define the format of the message box by adding together the constants you want into an appropriate value. There is a specific number assigned to each option and I have created a list of constants that are assigned the appropriate number. These SecureCRT constructs accept an optional number in the function call that dictates the layout of the box (what buttons are available, what icon is in the box, etc). Message_box_const.py - This file, while related to SecureCRT, holds information used in the formatting of message boxes and prompts. Functions in this file perform tasks such as reading settings from the INI file, creating the file if it exists, adding missing variables that are required for operation of these scripts, etc. Settings.py - This file contains the code used to handle the settings.ini file. This file contains functions that do things such as parsing TextFSM output into either a list or dictionary format, writing a 2-dimensional list to a CSV file, sorting text in “human” format (‘1,2,10,11’ instead of ‘1,10,11,2’), etc. ![]() Utilities.py - This file contains utility functions that are independent of SecureCRT and so are kept in a separate file. There are methods in this file for connecting to devices, finding the prompt of a device, sending data to a remote device, capturing command output to a variable, writing the output of a command to a file, disconnecting from a device, etc. Sessions.py - This file contains the code that interacts with a device via SecureCRT. Anything that requires interaction with the SecureCRT API but isn’t related to a specific connection to a remote device is kept here. It has the code for doing things like creating message boxes, file selector windows, importing a CSV with a list of devices that should each be connected to, etc. Scripts.py - This file contains the code that interacts with the SecureCRT application itself. The purpose of the files is explained below, while the documentation of all methods/functions defined in these files is in a later section. These files break up the code into groupings based on function so that the repository has a better organizational structure. The files that are a part of securecrt_tools are: This folder contains both the securecrt_tools and 3rd party modules in addition to a small number of other files. The code used to interact with SecureCRT is kept in the securecrt_tools module folder. * Some code to make the script run either when run from SecureCRT or in a debug (simulation) mode when run directly with your local Python installation/IDE. * Since SecureCRT uses its own Python interpreter that is bundled with the application, some special logic had to be added to support importing both securecrt_tools and the third porty modules used in some scripts. For example, some of the things handled by the starter template are: Unless you have a good reason not to, it is recommended to start with these templates because they already handle a few extra steps required to use the full functionality of the securecrt_tools module. The sections where code is meant to be added has been marked with comments saying “ADD YOUR CODE HERE”. When creating a new script it is highly recommended to look at the templates/ directory in this repository, which contains boilerplate starting points for new scripts. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |