Skip to content

Commit

Permalink
Merge d38cf96 into b1751e6
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlamprecht committed Aug 17, 2018
2 parents b1751e6 + d38cf96 commit 97fc295
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nornir/plugins/inventory/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def __init__(
if d.get("primary_ip", {}):
temp["hostname"] = d["primary_ip"]["address"].split("/")[0]

# Find interface name using additional API call
i = requests.get(
"{}/api/ipam/ip-addresses/?address={}".format(
nb_url, temp["nornir_host"]),headers=headers)
i.raise_for_status()
i = i.json()

# Strip extraneous information and add it to the dictionary
temp["primary_interface"] = i["results"][0]["interface"]["name"]

# Add values that don't have an option for 'slug'
temp["serial"] = d["serial"]
temp["vendor"] = d["device_type"]["manufacturer"]["name"]
Expand Down
37 changes: 37 additions & 0 deletions tests/plugins/inventory/netbox/2.3.5/mocked/address_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"family": 4,
"address": "10.0.1.1/32",
"vrf": null,
"tenant": null,
"status": {
"value": 1,
"label": "Active"
},
"role": null,
"interface": {
"id": 1,
"url": "http://netbox.local:8080/api/dcim/interfaces/1/",
"device": {
"id": 1,
"url": "http://netbox.local:8080/api/dcim/devices/1/",
"name": "1-Core",
"display_name": "1-Core"
},
"virtual_machine": null,
"name": "lo0.0"
},
"description": "",
"nat_inside": null,
"nat_outside": null,
"custom_fields": {},
"created": "2018-07-26",
"last_updated": "2018-07-26T06:58:35.918980Z"
}
]
}
37 changes: 37 additions & 0 deletions tests/plugins/inventory/netbox/2.3.5/mocked/address_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 2,
"family": 4,
"address": "172.16.2.1/32",
"vrf": null,
"tenant": null,
"status": {
"value": 1,
"label": "Active"
},
"role": null,
"interface": {
"id": 2,
"url": "http://netbox.local:8080/api/dcim/interfaces/2/",
"device": {
"id": 2,
"url": "http://netbox.local:8080/api/dcim/devices/2/",
"name": "2-Distribution",
"display_name": "2-Distribution"
},
"virtual_machine": null,
"name": "lo0.0"
},
"description": "",
"nat_inside": null,
"nat_outside": null,
"custom_fields": {},
"created": "2018-07-26",
"last_updated": "2018-07-26T07:23:11.518980Z"
}
]
}
37 changes: 37 additions & 0 deletions tests/plugins/inventory/netbox/2.3.5/mocked/address_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 3,
"family": 4,
"address": "192.168.3.1/32",
"vrf": null,
"tenant": null,
"status": {
"value": 1,
"label": "Active"
},
"role": null,
"interface": {
"id": 3,
"url": "http://netbox.local:8080/api/dcim/interfaces/3/",
"device": {
"id": 3,
"url": "http://netbox.local:8080/api/dcim/devices/3/",
"name": "3-Access",
"display_name": "3-Access"
},
"virtual_machine": null,
"name": "Loopback0"
},
"description": "",
"nat_inside": null,
"nat_outside": null,
"custom_fields": {},
"created": "2018-07-26",
"last_updated": "2018-07-26T07:59:42.981450Z"
}
]
}

0 comments on commit 97fc295

Please sign in to comment.