GithubHelp home page GithubHelp logo

Comments (4)

dgarros avatar dgarros commented on May 29, 2024

Please can you provide your DiffSyncModel for port

from diffsync.

jdrew82 avatar jdrew82 commented on May 29, 2024

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.

dgarros avatar dgarros commented on May 29, 2024

@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 avatar jdrew82 commented on May 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.