Skip to content

Commit

Permalink
Use diffsync store methods (#267)
Browse files Browse the repository at this point in the history
* Use diffsync store methods
  • Loading branch information
chadell authored Jun 9, 2022
1 parent 1181e25 commit e87781e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions network_importer/adapters/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""BaseAdapter for the network importer."""
from diffsync import DiffSync
from diffsync.exceptions import ObjectNotFound
from network_importer.models import Site, Device, Interface, IPAddress, Cable, Vlan, Prefix


Expand Down Expand Up @@ -50,8 +51,10 @@ def get_or_create_vlan(self, vlan, site=None):
modelname = vlan.get_type()
uid = vlan.get_unique_id()

if uid in self._data[modelname]:
return self._data[modelname][uid], False
try:
return self.get(modelname, uid), False
except ObjectNotFound:
pass

self.add(vlan)
if site:
Expand All @@ -72,8 +75,10 @@ def get_or_add(self, obj):
modelname = obj.get_type()
uid = obj.get_unique_id()

if uid in self._data[modelname]:
return self._data[modelname][uid], False
try:
return self.get(modelname, uid), False
except ObjectNotFound:
pass

self.add(obj)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_load_batfish_interface_intf_ether_sub(network_importer_base, site_sfo,
assert not intf.is_lag_member
assert intf.allowed_vlans == ["sfo__201"]

assert "sfo__201" in adapter._data["vlan"] # pylint: disable=W0212
assert any("sfo__201" == str(obj) for obj in adapter.get_all("vlan"))


def test_load_batfish_interface_intf_lag_member(network_importer_base, site_sfo, dev_spine1):
Expand Down

0 comments on commit e87781e

Please sign in to comment.