Skip to content

Week 2 recap

Monday

Netmiko Exploration

  • Ensure lab is up & healthy by validating with ping and ssh to the device via the lab host
  • Create the connection to the remote device using netmiko.ConnectHandler and pass in the minimum kwargs of device_type, ip, username, & password
  • Perform dir() on the instance of the ConnectHandler object and explore some of the key methods referenced on slide 15 of the lecture
  • Send a show commend to the remote device and inspect the output
  • Behind the scenes the send_command method uses the write channel in paramiko to send the command then switches to reading the return value in the read channel with a delay to get the return. Netmiko is able to detect when the command is finished by detecting the prompt has returned back to the original state.
    • On initial connection Netmiko attempts to set the terminal width and length based on the device_type's driver. IF this fails it will fail silently and can cause issues with handling pagination. This MAY be common when using a service account and commands are not allowed by TACACS.

Saving & Backing Up Configuration Challenge

  • Create SSH session using ConnectHandler
  • Send the appropriate command to save the configuration (remember some vendors do things differently)
  • Send the appropriate command to pull the configuration and assign the output to a variable
  • Save the output to a file using the hostname as the filename
  • Close your SSH session using disconnect()

Git

  • Create a PR, git add, git commit, git push, click link (or go to UI), and create PR
  • Direction of arrow is where the PR is going into, it may not be intuitive

Git Rebase

  • Ensure primary (generally develop/main) is in sync with origin (e.g. git pull origin develop)
  • Go into feature branch, git rebase develop (or main, depending on situation)
  • This will re-write the order, put your commits that are different on top
  • When you re-write the order, this will require you to perform a force push, e.g. git push -f origin

EAPI Exploration

  • The commands to turn on are under management api http-commands
  • Request creator is where you update, request viewer to see the created payload
  • Can add multiple commands, will always return as list of dictionaries
  • Provides type ahead capabilities from the UI

NX-API Sandbox Exploration

  • The commands to turn on are under feature nxapi
  • Creates payload and examples for multiple programming languages
  • Can chose multiple methods, we reviewed nxapi-cli
  • Message format reviewed json & xml
  • Command type reviewed is cli_config and cli_show

Tuesday

Regex

  • Helpful link: https://blog.networktocode.com/tags/regex
  • Meta Characters - building blocks of regular expressions
  • Special Sequences - regular expressions provide shortcuts for matching common patterns in text
  • Basic Matching - a basic match involves finding a specific sequence of characters within a given text
  • Escape Characters - Certain characters have special meanings in regular expressions. To match them literally, you need to escape them using a backslash
  • Character sets allow you to specify a group of characters that you want to match.
  • Repetitions specify how many times a preceding element can occur in the text, *, +, {}, ?.
  • Capturing groups - () regular expressions are used to group sub-patterns together
  • Non-capturing groups, denoted by (?:...), are similar to capturing groups but don't create a separate capture in the result
  • Alternation, denoted by the vertical bar |, allows you to match one of several alternative patterns
  • Anchors - ^ start and $ end that matches the beginning or end of a line or string
  • Lazy Matching - provides non-greedy or minimal matching
  • Special Sequences - digit, whitespace, word and the reverse of each.
  • Flags - in regular expressions modify the behavior of the pattern matching process

Wednesday

Netutils

  • Helpful link: https://blog.networktocode.com/post/journey-in-golden-config/
  • Review of Config parser
    • It returns a list of ConfigLine NamedTuple's
    • The parents are added for each level of nesting
  • Reviewed common issues with config parser
    • Duplicate configurations
    • Bad banners
  • Reviewed configuration compliance
    • Takes in OS, feature, actual, and intended configurations
    • Returns compliance and config based keys
    • How the parser dispatcher method works
  • Reviewed mock testing strategy in which raw data is processed and compared to previous run
  • Provided a tour of common functions that are used
  • Reviewed how doc strings generate the documentation
    • First line is description
    • Arguments become parameters and type hinting defines the type in docs
    • Returns provides the description of the return value
    • Examples are returned, and the actually run through doctest each time tests are ran

Thursday

Click

  • Python click is a library to help build command line apps
  • Provides both prompts and command line actions
  • Options are variables that can sent in with flags
  • Arguments are positional and do not need a flag
  • Groups create subcommands
  • Can use [tool.poetry.scripts] to make a cli command accessible anywhere

Rich

  • Displays advanced content such as tables, markdown, and syntax highlighted code.
  • Uses the bbcode syntax to markup console
  • Creating a Table
    • Table Class
    • add_column method
    • add_row method

Friday