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

Commit

Permalink
Merge pull request #98 from nautobot/release-v0.9.6
Browse files Browse the repository at this point in the history
Release v0.9.6
  • Loading branch information
chadell authored Jun 1, 2022
2 parents d4eaa3b + 7793665 commit 33a081b
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 43 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
## v0.9.6 - 2022-05-31

### Fixed

- #94 - Fix `primary_ip` usage in `interface` model, `delete` operations and `device_content` embedded `iframe`.

### Changed

- #94 - Make `ssot-safe-delete` log messages less noisy, using `debug` log level.

## v0.9.5 - 2022-05-11

Expand Down
3 changes: 2 additions & 1 deletion nautobot_ssot_ipfabric/diffsync/adapter_ipfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def load_device_interfaces(self, device_model, interfaces, device_primary_ip):
type=DEFAULT_INTERFACE_TYPE,
mgmt_only=iface.get("mgmt_only", False),
ip_address=ip_address,
# TODO: why is only IPv4? and why /32?
subnet_mask="255.255.255.255",
ip_is_primary=ip_address == device_primary_ip,
ip_is_primary=ip_address is not None and ip_address == device_primary_ip,
status="Active",
)
self.add(interface)
Expand Down
14 changes: 9 additions & 5 deletions nautobot_ssot_ipfabric/diffsync/adapter_nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ def sync_complete(self, source: DiffSync, *args, **kwargs):

def load_interfaces(self, device_record: Device, diffsync_device):
"""Import a single Nautobot Interface object as a DiffSync Interface model."""
# Get MGMT IP
mgmt_int_qset = device_record.interfaces.filter(mgmt_only=True)
device_primary_ip = None
if device_record.primary_ip4:
device_primary_ip = device_record.primary_ip4
elif device_record.primary_ip6:
device_primary_ip = device_record.primary_ip6

for interface_record in device_record.interfaces.all():
interface = self.interface(
diffsync=self,
Expand All @@ -100,9 +104,9 @@ def load_interfaces(self, device_record: Device, diffsync_device):
type=DEFAULT_INTERFACE_TYPE,
mgmt_only=interface_record.mgmt_only if interface_record.mgmt_only else False,
pk=interface_record.pk,
ip_is_primary=bool(
any(interface for interface in mgmt_int_qset if interface.name == interface_record.name)
),
ip_is_primary=interface_record.ip_addresses.first() == device_primary_ip
if device_primary_ip
else False,
ip_address=str(interface_record.ip_addresses.first().host)
if interface_record.ip_addresses.first()
else None,
Expand Down
26 changes: 19 additions & 7 deletions nautobot_ssot_ipfabric/diffsync/diffsync_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def safe_delete(self, nautobot_object: Any, safe_delete_status: Optional[str] =
if update:
tonb_nbutils.tag_object(nautobot_object=nautobot_object, custom_field="ssot-synced-from-ipfabric")
else:
self.diffsync.job.log_warning(
self.diffsync.job.log_debug(
message=f"{nautobot_object} has previously been tagged with `ssot-safe-delete`. Skipping..."
)

Expand Down Expand Up @@ -118,7 +118,7 @@ def delete(self) -> Optional["DiffSyncModel"]:
site_object,
SAFE_DELETE_SITE_STATUS,
)
return self
return super().delete()

def update(self, attrs):
"""Update Site Object in Nautobot."""
Expand Down Expand Up @@ -215,7 +215,7 @@ def delete(self) -> Optional["DiffSyncModel"]:
device_object,
SAFE_DELETE_DEVICE_STATUS,
)
return self
return super().delete()
except NautobotDevice.DoesNotExist:
self.diffsync.job.log_warning(f"Unable to match device by name, {self.name}")

Expand Down Expand Up @@ -271,7 +271,7 @@ class Interface(DiffSyncExtras):
"mgmt_only",
"ip_address",
"subnet_mask",
# "ip_is_primary",
"ip_is_primary",
"status",
)

Expand Down Expand Up @@ -314,8 +314,10 @@ def create(cls, diffsync, ids, attrs):
if attrs.get("ip_is_primary"):
if ip_address_obj.family == 4:
device_obj.primary_ip4 = ip_address_obj
device_obj.save()
if ip_address_obj.family == 6:
device_obj.primary_ip6 = ip_address_obj
device_obj.save()
interface_obj.save()
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)

Expand All @@ -335,11 +337,11 @@ def delete(self) -> Optional["DiffSyncModel"]:
self.safe_delete(
interface,
)
return self
return super().delete()
except NautobotDevice.DoesNotExist:
self.diffsync.job.log_warning(f"Unable to match device by name, {self.name}")

def update(self, attrs):
def update(self, attrs): # pylint: disable=too-many-branches
"""Update Interface object in Nautobot."""
try:
ssot_tag, _ = Tag.objects.get_or_create(name="SSoT Synced from IPFabric")
Expand Down Expand Up @@ -372,6 +374,16 @@ def update(self, attrs):
object_pk=interface,
)
interface.ip_addresses.add(ip_address_obj)
if attrs.get("ip_is_primary"):
interface_obj = interface.ip_addresses.first()
if interface_obj:
if interface_obj.family == 4:
device.primary_ip4 = interface_obj
device.save()
if interface_obj.family == 6:
device.primary_ip6 = interface_obj
device.save()
interface.save()
tonb_nbutils.tag_object(nautobot_object=interface, custom_field="ssot-synced-from-ipfabric")
return super().update(attrs)

Expand Down Expand Up @@ -418,7 +430,7 @@ def delete(self) -> Optional["DiffSyncModel"]:
vlan,
SAFE_DELETE_VLAN_STATUS,
)
return self
return super().delete()

def update(self, attrs):
"""Update VLAN object in Nautobot."""
Expand Down
5 changes: 1 addition & 4 deletions nautobot_ssot_ipfabric/template_content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Testing."""
"""Template Content for other models."""
from nautobot.extras.plugins import PluginTemplateExtension


Expand All @@ -12,9 +12,6 @@ def full_width_page(self):
"""Implement cool topology from IPFabric based on site."""
return self.render(
"nautobot_ssot_ipfabric/inc/diagram.html",
extra_context={
"ipfabric_site": "{{ settings.PLUGINS_CONFIG.nautobot_ssot_ipfabric.ipfabric_host }}/graph?urls=domains%3Fad%3DvSite%252F55467784%2Btransit%3Fad%3DvSite%252F55467784"
},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<strong>IPFabric Site Diagram</strong>
</div>
<div class="panel-body">
<iframe src="{{ settings.PLUGINS_CONFIG.nautobot_ssot_ipfabric.ipfabric_host }}/graph?urls=domains%3Fad%3DvSite%252F{{ object.custom_field_data.ipfabric_site_id }}%2Btransit%3Fad%3DvSite%252F{{ object.custom_field_data.ipfabric_site_id }}" width="1500" height="1000"></iframe>
<iframe src="{{ settings.PLUGINS_CONFIG.nautobot_ssot_ipfabric.ipfabric_host }}/graph?urls=domains%3Fad%3DvSite%252F{{ object.cf | get_item:'ipfabric-site-id'}}%2Btransit%3Fad%3DvSite%252F{{ object.cf | get_item:'ipfabric-site-id' }}" width="1500" height="1000"></iframe>
</div>
</div>
{% endblock %}
53 changes: 29 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nautobot-ssot-ipfabric"
version = "0.9.5"
version = "0.9.6"
description = "Nautobot SSoT IPFabric"
authors = ["Network to Code, LLC <info@networktocode.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 33a081b

Please sign in to comment.