-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a default value for Interface.type #97
Conversation
Netbox and Nautobot have different choice options for the Interface.type field. This defaults to using the "other" type in Nautobot when the Netbox type is not supported by Nautobot.
I think it's a sane approach that supports any unexpected interface type not supported, and a pattern we can reuse in other cases where the enums are different. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some nitpicks but this absolutely looks like a solid approach.
ec75451
to
921f1ab
Compare
@chadell @glennmatthews I changed this up to centralize this code some, and some of these models won't have an |
The `_type_choices` variable should be a set of the valid choices for the type per | ||
Nautobot. | ||
""" | ||
if "type" not in cls.__fields__ or "_type_choices" not in cls.__dict__: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the cleanest way to do this, or would something like if not hasattr(cls, "type") or not hasattr(cls, "_type_choices")
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, the Pydantic definitions are not class attributes, and so hasattr(cls, "type")
will fail. However, I think we can simplify this just to check for _type_choices
and any implementation that opts in has to define a type field (which why define _type_choices without having a type?)
# model: dcim.cable | ||
|
||
#- fields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Y'know, I don't recall why the cable instances are commented out in this validation data. Is it because of the use of GenericForeignKeys making it hard to know in advance what the termination_*_id
value will be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, and I felt like I've spent too much time on this PR already and didn't want to go down another rabbit hole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Netbox and Nautobot have different choice options for the Interface.type field. This defaults to using the "other" type in Nautobot when the Netbox type is not supported by Nautobot.