Comments (4)
Please can you provide your DiffSyncModel for port
from diffsync.
Here ya go:
class Port(DiffSyncModel):
"""Port model."""
_modelname = "port"
_identifiers = ("device", "name")
_shortname = ("name",)
_attributes = ("enabled", "mtu", "description", "mac_addr", "type", "tags")
_children = {}
name: str
device: str
enabled: Optional[bool]
mtu: Optional[int]
description: Optional[str]
mac_addr: Optional[str]
type: Optional[str]
ipaddrs: Optional[List["IPAddress"]]
tags: Optional[List[str]]
@classmethod
def create(cls, diffsync, ids, attrs): # pylint: disable=inconsistent-return-statements
"""Create Interface object in Nautobot."""
diffsync.job.log_debug(f"Creating Interface {ids['name']} for {ids['device']}.")
try:
if ids.get("device"):
new_intf = NautobotInterface(
name=ids["name"],
device=NautobotDevice.objects.get(name=ids["device"]),
enabled=is_truthy(attrs["enabled"]),
mtu=attrs["mtu"] if attrs.get("mtu") in range(1, 65537) else None,
description=attrs["description"],
type=attrs["type"],
mac_address=attrs["mac_addr"][:12] if attrs.get("mac_addr") else None,
)
if attrs.get("tags"):
for _tag in nbutils.get_tags(attrs["tags"]):
new_intf.tags.add(_tag)
new_intf.validated_save()
return super().create(ids=ids, diffsync=diffsync, attrs=attrs)
except NautobotDevice.DoesNotExist as err:
print(f"{ids['name']} doesn't exist. {err}")
def update(self, attrs):
"""Update Interface object in Nautobot."""
return super().update(attrs)
def delete(self):
"""Delete Interface object from Nautobot.
Because Interface has a direct relationship with Cables and IP Addresses it can't be deleted before they are.
The self.diffsync._objects_to_delete dictionary stores all objects for deletion and removes them from Nautobot
in the correct order. This is used in the Nautobot adapter sync_complete function.
"""
print(f"Interface {self.name} for {self.device} will be deleted.")
super().delete()
_dev = NautobotInterface.objects.get(
name=self.get_identifiers()["name"], device__name=self.get_identifiers()["device"]
)
self.diffsync._objects_to_delete["port"].append(_dev) # pylint: disable=protected-access
return self
The Port class is a child of Device so should be unique to that Device.
from diffsync.
@jdrew82 as a workaround, if you remove the line _shortname = ("name",)
from your model it will report the full name of the object that is generating the exception.
Not 100% sure if this something that should be fixed or if this is the expected behavior ...
from diffsync.
@jdrew82 as a workaround, if you remove the line
_shortname = ("name",)
from your model it will report the full name of the object that is generating the exception.Not 100% sure if this something that should be fixed or if this is the expected behavior ...
I was able to address this by not having the model be a top-level. I only created this issue as @glennmatthews requested that I do so to improve the logging information returned. If possible it'd be great if you could provide the parent context the object is in relation to. The error message as I provided isn't helpful as I have no idea which interface it's talking about.
from diffsync.
Related Issues (20)
- API reference docs problems HOT 1
- Automated adapter unit tests HOT 1
- Pydantic 2.0 Migration HOT 4
- Feature request: self-referencing models HOT 2
- Remove need to call `add_child` AND `add`
- How can one reduce duplication of effort between create & update HOT 3
- DiffSync Fails to Identify Discrepancies in Item Sets Between Source and Target HOT 2
- Provide a `filter` method on the `DiffSync` class
- Bug with DiffSyncModelFlags.NATURAL_DELETION_ORDER
- Feature to pass logger into Backend or sync_from/sync_to methods
- Return sync result from create/update/delete methods instead of returning the HOT 4
- Refactor parent/child relationship HOT 2
- Remove `diffsync` field from DiffSyncModel HOT 4
- Add `.load()` class-method to DiffSyncModel
- non id non attribute fields are not available during creation HOT 1
- Upgrade networktocode/gh-action-setup-poetry-environment to v6
- field "model_flags" conflicts with Pydantic 2 protected namespaces
- Add Depends On Attribute
- Add `Adapter.filter` method
- General versus Per-Model flags
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from diffsync.