Skip to content

Week 9 recap

Pydantic

  • Provides
    • Type enforcement
    • Type casting
    • Rich objects (e.g. attribute based)
    • JSON objects
  • Types come from
    • Python (str, bool, etc)
    • Typing (List, Optional, etc)
    • Pydantic itself
  • Enums
    • Can create your own ENUM (or choices)
  • Nesting can happen with Pydantic

DiffSync

  • Models
    • Define what the data will look like
    • Based on Pydantic
  • Model Key attributes
    • _modelname*: Defines the type of the model; used to identify common models between different systems.
    • _identifiers*: List of instance field names used as primary keys for this object.
    • _shortname: List of instance field names to use for a shorter name. Unnecessary if matches _identifiers.
    • _attributes: List of non-identifier instance field names for this object; used to identify the fields in common between data models for different systems.
    • _children: Dict of {: } indicating which fields store references to child data model instances.
  • Adapters
    • Define how to load the data
    • Performs the CRUD operations

Nornir

  • Comes with a SimpleInventory that allows yaml diagrams
  • Three Components
    • hosts: device info, connection details, user defined data, groups
    • groups: logical grouping of devices, data inheritance, scale
    • defaults: define data that applies to all hosts as a baseline
  • Simple Filtering
    • nr.filter(role="leaf")
    • nr.filter(role="border", region="EU")
  • Advanced Filtering
    • nr.filter(F(region="EU") | F(region="US"))
    • nr.filter(F(role="border") & ~F(region="US"))