networktocode/network-importer

Unable to import data to nautobot

Tolisan opened this issue · 2 comments

Environment

  • Python version: 3.10.6
  • Network Importer version: 3.1.0
  • Nautobot version 1.5.17
  • pynautobot 1.4.0

Impoter works with 'check' argument but unable to import data with 'apply' keyword.

Steps to Reproduce

  1. network-importer apply --update-configs --limit=somedevice

Expected Behavior

Run without errors

Observed Behavior

Traceback (most recent call last):
  File "/opt/nautobot/bin/network-importer", line 8, in <module>
    sys.exit(main())
  File "/opt/nautobot/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/nautobot/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/nautobot/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/nautobot/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/network_importer/cli.py", line 108, in apply
    ni.sync()
  File "/opt/nautobot/lib/python3.10/site-packages/network_importer/main.py", line 142, in sync
    self.sot.sync_from(self.network, diff_class=NetworkImporterDiff)
  File "/opt/nautobot/lib/python3.10/site-packages/diffsync/__init__.py", line 561, in sync_from
    result = syncer.perform_sync()
  File "/opt/nautobot/lib/python3.10/site-packages/diffsync/helpers.py", line 327, in perform_sync
    changed |= self.sync_diff_element(element)
  File "/opt/nautobot/lib/python3.10/site-packages/diffsync/helpers.py", line 391, in sync_diff_element
    changed |= self.sync_diff_element(child, parent_model=dst_model)
  File "/opt/nautobot/lib/python3.10/site-packages/diffsync/helpers.py", line 367, in sync_diff_element
    changed, modified_model = self.sync_model(src_model=src_model, dst_model=dst_model, ids=ids, attrs=attrs)
  File "/opt/nautobot/lib/python3.10/site-packages/diffsync/helpers.py", line 416, in sync_model
    dst_model = self.model_class.create(diffsync=self.dst_diffsync, ids=ids, attrs=attrs)
  File "/opt/nautobot/lib/python3.10/site-packages/network_importer/adapters/nautobot_api/models.py", line 572, in create
    nb_params = item.translate_attrs_for_nautobot(attrs)
  File "/opt/nautobot/lib/python3.10/site-packages/network_importer/adapters/nautobot_api/models.py", line 525, in translate_attrs_for_nautobot
    tag_id = device.get_device_tag_id()
  File "/opt/nautobot/lib/python3.10/site-packages/network_importer/adapters/nautobot_api/models.py", line 58, in get_device_tag_id
    self.device_tag_id = tag.id
  File "/opt/nautobot/lib/python3.10/site-packages/pynautobot/core/response.py", line 189, in __getattr__
    raise AttributeError('object has no attribute "{}"'.format(k))
AttributeError: object has no attribute "id"

config_file

[main]
import_ips = true
import_prefixes = true
import_intf_status = true

# Vlans (name, vlan-id) can be imported from the configuration, from the CLI or both
# - "config" will import the vlans just from the configuration
# - "cli" will import the vlans from the cli using the action `get_vlans`
# - "true" will import vlans from both cli and config
# - no or false will not import any vlans
# The association between interface and vlans will always be derived from the configuration.
import_vlans = "config"         # Valid options are ["cli", "config", "no", true, false]

# Cabling can be imported from LLDP, CDP or the configuration (for some point to point links)
# - "lldp" or "cdp" will import the vlans from the cli using the action `get_neighbors`
# - "config" will import the neighbors from the configuration (for point to point links)
# - "true" will import neighbors from both cli and config
# - no or false will not import any neighbors
import_cabling = "cdp"         # Valid options are ["lldp", "cdp", "config", "no", true, false]
backend = "nautobot"            # Valid options are ["nautobot", "netbox"]

# Number of Nornir tasks to execute at the same time
nbr_workers = 25

[inventory]
# Define a list of supported platform,
# if defined all devices without platform or with a different platforms will be removed from the inventory
supported_platforms = [ "ios", "nxos_ssh" ]

[inventory.settings]
# The information to connect to Nautobot needs to be provided, either in the config file or as environment variables
# These settings are specific to the Nautobot inventory, please check the documentation of your inventory for the
# exist list of of available settings.
address = "nburlhere"                   # Alternative Env Variable : NAUTOBOT_ADDRESS
token = "sometoken"  # Alternative Env Variable : NAUTOBOT_TOKEN
verify_ssl = false                                   # Alternative Env Variable : NAUTOBOT_VERIFY_SSL

[network]
# To be able to pull live information from the devices, the credential information needs to be provided
# either in the configuration file or as environment variables ( & NETWORK_DEVICE_PWD)
login = "somelogin"      # Alternative Env Variable : NETWORK_DEVICE_LOGIN
password = "somepassword"   # Alternative Env Variable : NETWORK_DEVICE_PWD

[batfish]
address= "localhost"    # Alternative Env Variable : BATFISH_ADDRESS
# api_key = "XXXX"      # Alternative Env Variable : BATFISH_API_KEY
# use_ssl = false

[logs]
# Define log level, currently the logs are printed on the screen
 level = "debug" # "debug", "info", "warning"

After spending a few days debugging code, I discovered the reason why the object wasn't being created. It turns out that in my configuration, I mistakenly used "http" instead of "https". As a result, when the code made a request to the server, it received a 200 OK response, indicating success. However, since the server automatically redirects HTTP requests to HTTPS, the object creation process was not triggered.

Would adding a warning for non-https connections in this day and age be something that I think we could add in?