s_document_device

s_document_device.document(session, command_list_name, folder_per_device, prompt_create_dirs=True)

This function captures the output of the provided commands and writes them to files. This is separated into a separate function so it can be called by both the single-device and multi-device version of this script.

Parameters:
  • session (sessions.Session) – A subclass of the sessions.Session object that represents this particular script session (either SecureCRTSession or DirectSession)
  • command_list (list) – A list of commands that will be sent to the connected device. Each output will be saved to a different file.
  • output_dir (str) – The full path to the directory where the output files are written.
  • folder_per_device (bool) – A boolean that if true will create a separate folder for each device
Returns:

s_document_device.script_main(session)
SINGLE device script
Author: Jamie Caesar

This script will grab the output for a list of commands from the connected device. The list of commands is taken from the ‘settings/settings.ini’ file. There is a separate list for each supported network operating system (IOS, NXOS and ASA) and by default the list that matches the network operating system of the connected device will be used.

Custom lists of commands are supported. These lists can be added manually to the [document_device] section of the ‘settings/settings.ini’ file. To be able to choose one of these lists when running the script, the ‘prompt_for_custom_lists’ setting needs to be changed to ‘True’ in the settings.ini file. Once this option is enabled, the script will prompt for the name of the list that you want to use. If the input is left blank then the default behavior (based on network OS) will choose the list.

Script Settings (found in settings/settings.ini):

  • show_instructions - When True, displays a pop-up upon launching the script
    explaining where to modify the list of commands sent to devices. This window also
    prompts the user if they want to continue seeing this message. If not, the script
    changes this setting to False.
  • folder_per_device - If True, Creates a folder for each device, based on the
    hostname, and saves all files inside that folder WITHOUT the hostname in the output
    file names. If False, it saves all the files directly into the output folder from
    the global settings and includes the hostname in each individual filename.
  • prompt_for_custom_lists - When set to True, the script will prompt the user to
    type the name of a list of commands to use with the connected device. This list
    name must be found as an option in the [document_device] section of the
    settings.ini file. The format is the same as the default network OS lists, ‘ios’,
    ‘nxos’, etc.
  • ios - The list of commands that will be run on IOS devices
  • nxos - The list of commands that will be run on NXOS devices
  • asa - The list of commands that will be run on ASA devices

Any additional options found in this section would be custom added by the user and are expected to be lists of commands for use with the ‘prompt_for_custom_lists’ setting.

By default, The outputs will be saved in a folder named after the hostname of the device, with each output file being saved inside that directory. This behavior can be changed in the settings above.

Parameters:session (sessions.Session) – A subclass of the sessions.Session object that represents this particular script session (either SecureCRTSession or DirectSession)