wvandeun/nornir_netbox

Setting Scrapli Connection Options via Netbox

MrPaulAR opened this issue · 2 comments

Is there a mechanism to set the ConnectionOptions for scrapli in netbox?

Right now I'm doing this in code but I think it would be better set within netbox. Specifically the classic variant. The other fields are being pulled from the inventory/defaults.yml file but I'm lazilly setting it again.

from nornir.core.inventory import ConnectionOptions
nokia_rtrs.inventory.defaults.connection_options["scrapli"] = ConnectionOptions(extras={'auth_strict_key': False,
    'ssh_config_file': True, 'variant': "classic"})

NetBox does not have a specific model that allows you to store this information.
That doesn't mean it is impossible to do it. You can, for example, use configuration context data for this.

The problem is that configuration context data is free form, everyone can use their own schema for the data that is defined in it. Therefor the NetBox inventory plugin can't implement this, as we don't control the schema that the user wants for the config context datat they want to define.

You can however access the config context of a Host under the data attribute. You can write a transform function to define this config context as ConnectiopnOptions for a device.

I was hoping that something already existed (and defined) to utilize the config context where I could provide this in json and the nornir_netbox plugin would do the right thing and populate the host data if the right key/value pairs existed.

Sample logic for config data.

{
  "nornir_netbox": {
    "connection_options": {
      "scrapli": {
        "variant": "classic"
      }
    }
  }
}

I'll continue to mangle it manually as these are legacy devices on legacy code and haven't had a use case for this otherwise. Thanks for your time.