Package: nautobot-ssot-aristacv
Nautobot to Arista CloudVision SyncA plugin forNautobotthat allows synchronization of data directly between CloudVision and Nautobot. From Nautobot into CloudVision, it synchronizes user device tags. From CloudVision into Nautobot, it synchronizes devices, their interfaces, associated IP addresses, and their system tags. Here is a table showing the data mappings when syncing from CloudVision.CloudVision System TagsNautobot Device Custom Fieldtopology_network_typeTopology Network TypemlagmlagmplsmplsmodelDevice Type*systypesystypeserialnumberDevice Serial NumberpimbidirpimbidirsflowsFloweostrainEOS TraintapaggTAP AggregationpimpimbgpbgpterminattrTerminAttr VersionztpztpeosEOS Version**topology_typeTopology Type*The model system tag is mapped to the device type model in Nautobot.**If theDevice Lifecycle plug-inis found to be installed, a matching Version will be created with a RelationshipAssociation connecting the device and that Version.When syncing User tags from Nautobot to CloudVision the data mappings are as follows:NautobotCloudVisionInterfaceInterface-----------------------TagsDevice TagsThis plugin is an extension of theNautobot Single Source of Truth (SSoT)and you must have that plugin installed before installing this extension.ScreenshotsThis screenshot shows the CloudVision to Nautobot home page. This contains a list of all the system tags from CloudVision and how they map to custom fields in Nautobot. This also displays your plugin configuration and the sync history.This screenshot shows the Nautobot to CloudVision home page. It also contains data mappings, plugin configuration and sync history.InstallationThe plugin is available as a Python package in PyPI and can be installed with pippipinstallnautobot_ssot_aristacvThe plugin is compatible with Nautobot 1.0.0 and higherTo ensure Nautobot to Arista CloudVision Sync is automatically re-installed during future upgrades, create a file namedlocal_requirements.txt(if not already existing) in the Nautobot root directory (alongsiderequirements.txt) and list thenautobot_ssot_aristacvpackage:# echo nautobot_ssot_aristacv >> local_requirements.txtOnce installed, the plugin needs to be enabled in yournautobot_configuration.pyand plugin settings need to be defined.# In your configuration.pyPLUGINS=["nautobot_ssot","nautobot_ssot_aristacv"]PLUGINS_CONFIG={"nautobot_ssot":{"hide_example_jobs":True,},"nautobot_ssot_aristacv":{"cvp_token":os.getenv("NAUTOBOT_ARISTACV_TOKEN",""),"cvp_host":os.getenv("NAUTOBOT_ARISTACV_HOST",""),"cvp_port":os.getenv("NAUTOBOT_ARISTACV_PORT",443),"cvp_user":os.getenv("NAUTOBOT_ARISTACV_USERNAME",""),"cvp_password":os.getenv("NAUTOBOT_ARISTACV_PASSWORD",""),"verify":is_truthy(os.getenv("NAUTOBOT_ARISTACV_VERIFY",True)),"from_cloudvision_default_site":"","from_cloudvision_default_device_role":"","from_cloudvision_default_device_role_color":"","delete_devices_on_sync":is_truthy(os.getenv("NAUTOBOT_ARISTACV_DELETE_ON_SYNC",False)),"apply_import_tag":is_truthy(os.getenv("NAUTOBOT_ARISTACV_IMPORT_TAG",False)),"import_active":is_truthy(os.getenv("NAUTOBOT_ARISTACV_IMPORT_ACTIVE",False)),"create_controller":is_truthy(os.getenv("NAUTOBOT_ARISTACV_CREATE_CONTROLLER",False)),"controller_site":os.getenv("NAUTOBOT_ARISTACV_CONTROLLER_SITE",""),"hostname_patterns":[""],"site_mappings":{},"role_mappings":{},}}All plugin settings are defined in the picture above as an example. Only some will be needed as described below.Upon installation, this plugin creates the following custom fields in Nautobot:arista_bgparista_eosarista_eostrainarista_mlagarista_mplsarista_pimarista_pimbidirarista_sflowarista_systypearista_tapaggarista_terminattrarista_topology_network_typearista_topology_typearista_ztpWhile these contain the prefix "arista" in the custom field admin portal, when looking at them on a device the prefix is removed.Other custom fields may need to be created by the user. When a sync is run and a system tag for a device in CloudVision is found without a corresponding custom field, the sync log will display a message. To have that data synced, a custom field must be created in the Admin UI using the given name in the message.The plugin can connect to either on-premise or a cloud instance of CloudVision. To connect to an on-premise instance, you must set the following variables in the Nautobot configuration file.Configuration VariableTypeUsagecvp_hoststringHostname or ip address of the onprem instance of CloudVision.cvp_portstringgRPC port (defaults to 8443, but this port has changed to 443 as of CVP 2021.3.0)cvp_userstringThe username used to connect to the on-prem instance of CloudVision.cvp_passwordstringThe password used by the user specified above.cvp_tokenstringToken to be used when connecting to CloudVision.verifybooleanIf False, the plugin will download the certificate from CloudVision and trust it for gRPC calls.To connect to a cloud instance of CloudVision you must set the following variable:Configuration VariableTypeUsageDefaultcvaas_urlstringURL used to connect to your CvaaS instance.www.arista.io:443When syncing from CloudVision, this plugin will create new Arista devices that do not exist in Nautobot. When creating new devices in Nautobot, a site, device role, device role color, device status, and device are required. You may define which values to use by configuring the following values in yournautobot_config.pyfile. If you define adefault_device_roleanddefault_device_statusthat already exist, the default color value for both of those will be ignored as it will pull that information from Nautobot.Configuration VariableTypeUsageDefaultfrom_cloudvision_default_sitestringDefault site created when syncing new devices to Nautobot.cloudvision_importedfrom_cloudvision_default_device_rolestringDefault role created when syncing new devices to Nautobot.networkfrom_cloudvision_default_device_role_colorstringDefault role color used for default role.ff0000When these variables are not defined in the plugin settings, the plugin will use the default values mentioned.When an Arista device exists in Nautobot but not in CloudVision, this plugin can either delete or leave the device in Nautobot. That behavior can be set with the following variable in thenautobot_config.pyfile.Configuration VariableTypeUsageDefaultdelete_devices_on_syncbooleanIf true, devices in Nautobot with device type manufacturer name set to Arista that do not exist in CloudVision but do exist in Nautobot upon sync will be deleted.FalseWhen this variable is not defined in the plugin settings, the plugin will default to usingFalse.Optionally, an import tag with the namecloudvision_importedcan be applied to devices that are imported from CloudVision.Configuration VariableTypeUsageDefaultapply_import_tagbooleanApply import tag to devices imported from CloudVision.FalseIf apply_import_tag is set to True, the tag value that is applied to devices iscloudvision_imported.In addition, you can control whether only active devices are imported or whether all devices regardless of status are imported.Configuration VariableTypeUsageDefaultimport_activebooleanOnly import active devices from CloudVision.FalseThere is also the option of having your CloudVision instance created within Nautobot and linked to the Devices managed by the instance. If thecreate_controllersetting isTruethen a CloudVision Device will be created and Relationships created to the imported Devices from CVP. Thecontroller_sitesetting allows you to specify the name of the Site you wish the Device to be created in. If this setting is blank a new CloudVision Site will be created and the Device will be placed in it.Configuration VariableTypeUsageDefaultcreate_controllerbooleanCreate CloudVision Device in Nautobot.Falsecontroller_sitestringThe Site to associate with CloudVision Device.""Finally, there is the option to parse device hostname's for codes that indicate the assigned site or device role. This is done through a combination of a few settings. First, the hostname_patterns setting defines a list of regex patterns that define your hostname structure. These patterns must include a named capture group using thesiteandrolekey to identify the portion of the hostname that indicates those pieces of data, ie(?P<site>\w+)and(?P<role>\w+). Once those pieces are extracted they are then evaluated against the relevant map, ie the value for thesitecapture group is looked for in thesite_mappingsdictionary expecting the value to be a key with the map value being the name of the Site. If the Site doesn't exist it will be created in Staging status. For the Device Role, it will be created if it doesn't exist in Nautobot. Please note that the hostname is converted to all lowercase when the parsing is performed so the keys are expected to be all lowercase too.Configuration VariableTypeUsageDefaulthostname_patternsList[str]Define the portions of a hostname that indicate site/role.[]site_mappingsdictDefine the site name associated with code in hostname.{}role_mappingsdictDefine the role name associated with code in hostname.{}As the Device hostname is used as the identifier for Device objects any change in hostname implies a new Device and thus should trigger a deletion and creation of a new Device in Nautobot. For this reason, the hostname parsing feature is not done during updates and only at initial creation of the Device. If you need to correct the Site or Role for a Device after initial creation you will need to manually correct it or delete it and run the import Job again.UsageThis extension can sync data bothtoandfromNautobot. Once the plugin has been installed successfully two new options are available under theNautobot Single Source of Truth (SSoT)plugin.Please be aware that interfaces that are part of a breakout bundle, ie a 40G port broken out into 4x10G ports, will show the base interface SFP transceiver as the interface type. This is due to the way interfaces and transceivers are returned from CloudVision.Syncing From CloudVisionWhen loading Nautobot data, this tool only loads devices with a device type that has a manufacturer of "Arista"When syncing data from CloudVision to Nautobot, devices along with their interfaces and tags are synchronized.  When a device exists in CloudVision that doesn't exist in Nautobot, this tool creates the device in Nautobot with the default values specified in the configuration file. When a device exists in Nautobot that does not exist in CloudVision, this tool can be configured to either delete or skip that device.
You can watch the below video for an example.When syncing data from Nautobot to CloudVision, the tag data in Nautobot is copied into User Tags in CloudVision. You can watch the video below for an example.ContributingPull requests are welcomed and automatically built and tested against multiple versions of Python and multiple versions of Nautobot through GitHub Actions.The project is packaged with a light development environment based ondocker-composeto help with the local development of the project and to run the tests within a Docker container.The project is following Network to Code software development guidelines and is leveraging:Black, Pylint, Bandit and pydocstyle for Python linting and formatting.Django unit test to ensure the plugin is working properly.Development EnvironmentThe development environment can be used in 2 ways. First, with a local poetry environment if you wish to develop outside of Docker. Second, inside of a docker container.Invoke tasksThePyInvokelibrary is used to provide some helper commands based on the environment.  There are a few configuration parameters that can be passed to PyInvoke to override the default configuration:nautobot_ver: the version of Nautobot to use as a base for any built docker containers (default: develop-latest)project_name: the default docker compose project name (default: aristacv-sync)python_ver: the version of Python to use as a base for any built docker containers (default: 3.6)local: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)compose_dir: the full path to a directory containing the project compose filescompose_files: a list of compose files applied in order (seeMultiple Compose filesfor more information)Using PyInvoke these configuration options can be overridden usingseveral methods.  Perhaps the simplest is simply setting an environment variableINVOKE_ARISTACV-SYNC_VARIABLE_NAMEwhereVARIABLE_NAMEis the variable you are trying to override.  The only exception iscompose_files, because it is a list it must be overridden in a YAML file.  There is an exampleinvoke.ymlin this directory which can be used as a starting point.Local Poetry Development EnvironmentCopydevelopment/creds.example.envtodevelopment/creds.env(This file will be ignored by git and docker)Uncomment thePOSTGRES_HOST,REDIS_HOST, andNAUTOBOT_ROOTvariables indevelopment/creds.envCreate an invoke.yml with the following contents at the root of the repo:---
aristacv_sync:local:truecompose_files:-"docker-compose.requirements.yml"Run the following commands:poetryshell
poetryinstallexport$(catdevelopment/dev.env|xargs)export$(catdevelopment/creds.env|xargs)You can now run nautobot-server commands as you would from theNautobot documentationfor example to start the development server:nautobot-serverrunserver0.0.0.0:8080--insecureNautobot server can now be accessed athttp://localhost:8080.Docker Development EnvironmentThis project is managed byPython Poetryand has a few requirements to setup your development environment:Install Poetry, see thePoetry Documentationfor your operating system.Install Docker, see theDocker documentationfor your operating system.Once you have Poetry and Docker installed you can run the following commands to install all other development dependencies in an isolated python virtual environment:poetryshell
poetryinstall
invokestartNautobot server can now be accessed athttp://localhost:8080.CLI Helper CommandsThe project is coming with a CLI helper based oninvoketo help set up the development environment. The commands are listed below in 3 categoriesdev environment,utilityandtesting.Each command can be executed withinvoke <command>. Environment variablesINVOKE_ARISTACV-SYNC_PYTHON_VERandINVOKE_ARISTACV-SYNC_NAUTOBOT_VERmay be specified to override the default versions. Each command also has its own helpinvoke <command> --helpDocker dev environmentbuild            Build all docker images.
  debug            Start Nautobot and its dependencies in debug mode.
  destroy          Destroy all containers and volumes.
  restart          Restart Nautobot and its dependencies.
  start            Start Nautobot and its dependencies in detached mode.
  stop             Stop Nautobot and its dependencies.Utilitycli              Launch a bash shell inside the running Nautobot container.
  create-user      Create a new user in django (default: admin), will prompt for password.
  makemigrations   Run Make Migration in Django.
  nbshell          Launch a nbshell session.Testingbandit           Run bandit to validate basic static code security analysis.
  black            Run black to check that Python files adhere to its style standards.
  flake8           This will run flake8 for the specified name and Python version.
  pydocstyle       Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
  pylint           Run pylint code analysis.
  tests            Run all tests for this plugin.
  unittest         Run Django unit tests for the plugin.QuestionsFor any questions or comments, please check theFAQfirst and feel free to swing by theNetwork to Code slack channel(channel #networktocode).
Sign uphere