Skip to content

Commit

Permalink
NBInventory - adds device name if no primary IP (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanderaa committed Jul 7, 2020
1 parent a8230f3 commit 08f7419
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nornir/plugins/inventory/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def __init__(
Netbox plugin
Arguments:
nb_url: Netbox url, defaults to http://localhost:8080.
nb_url: NetBox url, defaults to http://localhost:8080.
You can also use env variable NB_URL
nb_token: Netbokx token. You can also use env variable NB_TOKEN
nb_token: NetbBox token. You can also use env variable NB_TOKEN
use_slugs: Whether to use slugs or not
ssl_verify: Enable/disable certificate validation or provide path to CA bundle file
flatten_custom_fields: Whether to assign custom fields directly to the host or not
Expand Down Expand Up @@ -64,6 +64,10 @@ def __init__(
# Add value for IP address
if d.get("primary_ip", {}):
host["hostname"] = d["primary_ip"]["address"].split("/")[0]
else:
# Set to the hostname in NetBox if not a primary IP, expect DNS will be in place
if d.get("name") is not None:
host["hostname"] = d["name"]

# Add values that don't have an option for 'slug'
host["data"]["serial"] = d["serial"]
Expand Down

0 comments on commit 08f7419

Please sign in to comment.