Skip to content

Commit

Permalink
Merge pull request #6 from wvandeun/develop
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
wvandeun authored Sep 4, 2020
2 parents 8d59186 + e68c2a7 commit bfdab61
Show file tree
Hide file tree
Showing 18 changed files with 998 additions and 284 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ The NetBox plugin exposes 2 inventory classes for usage.
The recommended way to install nornir_netbox is via pip or poetry.

```bash
pip install git+https://github.com/wvandeun/nornir_netbox.git
pip install nornir-netbox
```

```bash
poetry add git+https://github.com/wvandeun/nornir_netbox.git
poetry add nornir-netbox
```

## Example usage
Expand Down
21 changes: 17 additions & 4 deletions nornir_netbox/plugins/inventory/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,20 @@ def load(self) -> Inventory:
data["site"] = device.get("site", {}).get("slug")
data["role"] = device.get("device_role", {}).get("slug")
data["model"] = device.get("device_type", {}).get("slug")
if device.get("platform"):
platform = device.get("platform", {}).get("slug")
platform = (
device["platform"]["slug"]
if isinstance(device["platform"], dict)
else device["platform"]
)
else:
data["site"] = device.get("site", {}).get("name")
data["role"] = device.get("device_role")
data["model"] = device.get("device_type")
platform = device.get("platform")
platform = (
device["platform"]["name"]
if isinstance(device["platform"], dict)
else device["platform"]
)

hostname = None
if device.get("primary_ip"):
Expand Down Expand Up @@ -190,10 +197,16 @@ def load(self) -> Inventory:
if device.get("name") is not None:
hostname = device["name"]

platform = (
device["platform"]["name"]
if isinstance(device["platform"], dict)
else device["platform"]
)

host = Host(
name=device.get("name") or str(device.get("id")),
hostname=hostname,
platform=device.get("platform"),
platform=platform,
data=data,
)

Expand Down
Loading

0 comments on commit bfdab61

Please sign in to comment.