Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #88 from nautobot/develop
Browse files Browse the repository at this point in the history
feat: Add Extensibility Attributes (#85)
  • Loading branch information
jdrew82 authored Jul 26, 2022
2 parents 7108e29 + d5c8624 commit 2f9a574
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 35 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ Below are the data mappings between objects within Infoblox and the correspondin
| VLAN | VLAN |
| VLAN view | VLAN Group |
| Network container | Aggregate |
| Extensibility Attrs | Custom Fields |

> **_NOTE_**: VLAN and VLAN Group will be turned on within the next available releases.
NOTE - More information about Extensibility Attributes can be found in the [project documentation](#project-documentation).

### DiffSyncModel - Network

Expand Down
31 changes: 31 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ TODO: Write plugin documentation, the outline here is provided as a guide and sh
## Views

## Models

## Extensibility Attributes

Extensibility Attributes in Infoblox are a method of adding additional contextual information to objects in Infoblox. The closest analog in Nautobot is a Custom Field so this information has been imported as such. There is also an effort to attempt to match the information in these fields where possible to available objects in Nautobot. These available links are noted below:

### Network (Prefixes)

- Site/Facility
- VRF
- Role
- Tenant/Department

### IP Address

- VRF
- Role
- Tenant/Department

### VLAN Group

- Site/Facility

### VLAN

- Site/Facility
- Role
- Tenant/Department

### Aggregate

- Tenant/Department
6 changes: 6 additions & 0 deletions nautobot_ssot_infoblox/diffsync/adapters/infoblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from diffsync.enum import DiffSyncFlags
from nautobot.extras.plugins.exceptions import PluginImproperlyConfigured
from nautobot_ssot_infoblox.utils.client import InfobloxApi
from nautobot_ssot_infoblox.utils.diffsync import get_ext_attr_dict
from nautobot_ssot_infoblox.diffsync.models.infoblox import (
InfobloxAggregate,
InfobloxIPAddress,
Expand Down Expand Up @@ -57,6 +58,7 @@ def load_prefixes(self):
network=_pf["network"],
description=_pf.get("comment", ""),
status=_pf.get("status", "active"),
ext_attrs=get_ext_attr_dict(extattrs=_pf.get("extattrs", {})),
)
self.add(new_pf)

Expand All @@ -72,6 +74,7 @@ def load_ipaddresses(self):
dns_name=_ip["names"][0],
status=self.conn.get_ipaddr_status(_ip),
description=_ip["comment"],
ext_attrs=get_ext_attr_dict(extattrs=_ip.get("extattrs", {})),
)
self.add(new_ip)

Expand All @@ -81,6 +84,7 @@ def load_vlanviews(self):
new_vv = self.vlangroup(
name=_vv["name"],
description=_vv["comment"] if _vv.get("comment") else "",
ext_attrs=get_ext_attr_dict(extattrs=_vv.get("extattrs", {})),
)
self.add(new_vv)

Expand All @@ -94,6 +98,7 @@ def load_vlans(self):
status=_vlan["status"],
vlangroup=vlan_group.group(1) if vlan_group else "",
description=_vlan["comment"] if _vlan.get("comment") else "",
ext_attrs=get_ext_attr_dict(extattrs=_vlan.get("extattrs", {})),
)
self.add(new_vlan)

Expand Down Expand Up @@ -136,5 +141,6 @@ def load(self):
new_aggregate = self.aggregate(
network=container["network"],
description=container["comment"] if container.get("comment") else "",
ext_attrs=container.get("extattrs", {}),
)
self.add(new_aggregate)
42 changes: 40 additions & 2 deletions nautobot_ssot_infoblox/diffsync/adapters/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,20 @@ def load_prefixes(self):
"""Load Prefixes from Nautobot."""
all_prefixes = list(chain(Prefix.objects.all(), Aggregate.objects.all()))
for prefix in all_prefixes:
# Reset CustomFields for Nautobot objects to blank if they failed to get linked originally.
if prefix.site is None:
prefix.custom_field_data["site"] = ""
if prefix.vrf is None:
prefix.custom_field_data["vrf"] = ""
if prefix.role is None:
prefix.custom_field_data["role"] = ""
if prefix.tenant is None:
prefix.custom_field_data["tenant"] = ""
_prefix = self.prefix(
network=str(prefix.prefix),
description=prefix.description,
status=prefix.status.slug if hasattr(prefix, "status") else "container",
ext_attrs=prefix.custom_field_data,
pk=prefix.id,
)
try:
Expand All @@ -115,6 +125,14 @@ def load_prefixes(self):
def load_ipaddresses(self):
"""Load IP Addresses from Nautobot."""
for ipaddr in IPAddress.objects.all():
# Reset CustomFields for Nautobot objects to blank if they failed to get linked originally.
if ipaddr.vrf is None:
ipaddr.custom_field_data["vrf"] = ""
if ipaddr.role is None:
ipaddr.custom_field_data["role"] = ""
if ipaddr.tenant is None:
ipaddr.custom_field_data["tenant"] = ""

addr = ipaddr.host
# the last Prefix is the most specific and is assumed the one the IP address resides in
prefix = Prefix.objects.net_contains(addr).last()
Expand Down Expand Up @@ -142,6 +160,7 @@ def load_ipaddresses(self):
prefix_length=prefix.prefix_length if prefix else ipaddr.prefix_length,
dns_name=ipaddr.dns_name,
description=ipaddr.description,
ext_attrs=ipaddr.custom_field_data,
pk=ipaddr.id,
)
try:
Expand All @@ -152,18 +171,30 @@ def load_ipaddresses(self):
def load_vlangroups(self):
"""Load VLAN Groups from Nautobot."""
for grp in VLANGroup.objects.all():
_vg = self.vlangroup(name=grp.name, description=grp.description, pk=grp.id)
# Reset CustomFields for Nautobot objects to blank if they failed to get linked originally.
if grp.site is None:
grp.custom_field_data["site"] = ""
_vg = self.vlangroup(name=grp.name, description=grp.description, ext_attrs=grp.custom_field_data, pk=grp.id)
self.add(_vg)

def load_vlans(self):
"""Load VLANs from Nautobot."""
for vlan in VLAN.objects.all():
# Reset CustomFields for Nautobot objects to blank if they failed to get linked originally.
if vlan.site is None:
vlan.custom_field_data["site"] = ""
if vlan.role is None:
vlan.custom_field_data["role"] = ""
if vlan.tenant is None:
vlan.custom_field_data["tenant"] = ""

_vlan = self.vlan(
vid=vlan.vid,
name=vlan.name,
description=vlan.description,
vlangroup=vlan.group.name if vlan.group else "",
status=nautobot_vlan_status(vlan.status.name),
ext_attrs=vlan.custom_field_data,
pk=vlan.id,
)
self.add(_vlan)
Expand Down Expand Up @@ -197,7 +228,14 @@ def __init__(self, *args, job=None, sync=None, **kwargs):
def load(self):
"""Load aggregate models from Nautobot."""
for aggregate in Aggregate.objects.all():
# Reset CustomFields for Nautobot objects to blank if they failed to get linked originally.
if aggregate.tenant is None:
aggregate.custom_field_data["tenant"] = ""

_aggregate = self.aggregate(
network=str(aggregate.prefix), description=aggregate.description, pk=aggregate.id
network=str(aggregate.prefix),
description=aggregate.description,
ext_attrs=aggregate.custom_field_data,
pk=aggregate.id,
)
self.add(_aggregate)
15 changes: 10 additions & 5 deletions nautobot_ssot_infoblox/diffsync/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class Network(DiffSyncModel):

_modelname = "prefix"
_identifiers = ("network",)
_attributes = ("description",)
_attributes = ("description", "status", "ext_attrs")

network: str
description: Optional[str]
status: Optional[str]
ext_attrs: Optional[dict]
pk: Optional[uuid.UUID] = None


Expand All @@ -22,10 +23,11 @@ class VlanView(DiffSyncModel):

_modelname = "vlangroup"
_identifiers = ("name",)
_attributes = ("description",)
_attributes = ("description", "ext_attrs")

name: str
description: Optional[str]
ext_attrs: Optional[dict]
pk: Optional[uuid.UUID] = None


Expand All @@ -34,13 +36,14 @@ class Vlan(DiffSyncModel):

_modelname = "vlan"
_identifiers = ("vid", "name", "vlangroup")
_attributes = ("description", "status")
_attributes = ("description", "status", "ext_attrs")

vid: int
name: str
status: str
description: Optional[str]
vlangroup: Optional[str]
ext_attrs: Optional[dict]
pk: Optional[uuid.UUID] = None


Expand All @@ -50,14 +53,15 @@ class IPAddress(DiffSyncModel):
_modelname = "ipaddress"
_identifiers = ("address", "prefix", "prefix_length")
_shortname = ("address",)
_attributes = ("description", "dns_name", "status")
_attributes = ("description", "dns_name", "status", "ext_attrs")

address: str
dns_name: str
prefix: str
prefix_length: int
status: Optional[str]
description: Optional[str]
ext_attrs: Optional[dict]
pk: Optional[uuid.UUID] = None


Expand All @@ -66,8 +70,9 @@ class Aggregate(DiffSyncModel):

_modelname = "aggregate"
_identifiers = ("network",)
_attributes = ("description",)
_attributes = ("description", "ext_attrs")

network: str
description: Optional[str]
ext_attrs: Optional[dict]
pk: Optional[uuid.UUID] = None
Loading

0 comments on commit 2f9a574

Please sign in to comment.