question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should open() arguments in the ConnectionPlugin Abstract Base Class be move to be bound to the object

See original GitHub issue

Should these arguments just be bound to the object?

    @abstractmethod
    def open(
        self,
        hostname: str,
        username: str,
        password: str,
        ssh_port: int,
        network_api_port: int,
        operating_system: str,
        nos: str,
        connection_options: Optional[Dict[str, Any]] = None,
        configuration: Optional[Config] = None,
    ) -> None:

It seems like we are doing a lot of passing around of shared state which might not be necessary.

This relates to #202 (i.e. how many arguments actually are there/will there be)

This might also enable the glue-code for processing the connection arguments (which is currently in the connection plugins) could be moved to a common method self.process_args which returns a dictionary of arguments.

So then the end napalm driver would just look something like this (the open method):

    # napalm
    def open(
        self,
    ) -> None:

    parameters = self.process_args()
    network_driver = get_network_driver(nos)
    connection = network_driver(**parameters)
    connection.open()
    self.connection = connection

The netmiko driver would be very similar.

This would also make testing of the argument processing easier (which I am running into on PR #216)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dbarrosopcommented, Aug 4, 2018

What I like about this is that it simplifies the connection plugins.

I think it is effectively the same exact code, the only difference is you are shortening the signature by sorting data in the class which has a benefit and two drawbacks in my opinion:

  1. Benefit, signature is shorter.
  2. Drawbacks:
    1. It requires to keep unnecessary data in the class which is ok if you are managing a few hundred of devices but it may be a problem when going up to the thousands or tens of thousands. It’s basically going to make the code slower and heavier.
    2. It hides the parameters the open connection can use, which simplifies the signature but makes the code look more like “magic”.

of having a common _process_args()

I don’t think so. I mean, the magic to resolve the arguments should be in the Nornir object, the connection plugin shouldn’t bother with business logic. So the only thing the plugin has to effectively do is map the attributes to the right argument. I think this will look clearer though once we work on #202

Let me summon @dmfigol and @ogenstad and see what they think. As I said, I am a bit ambivalent about this as I think the pros/cons have more or less the same weight so I’d like to hear more opinions.

0reactions
ktbyerscommented, Aug 8, 2018

Okay, let’s leave it as-is. I will just go ahead and close this PR.

Yes, I totally agree on _process_args(), I think it is probably useful to have this, but we can do that independent of binding the arguments to the object. I also agree that it doesn’t needs to be mandated by the abstract base class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

18. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
A class that is derived from an abstract class cannot be instantiated unless all of its abstract methods are overridden. You may think...
Read more >
Consolidate inventory attributes · Issue #202 · nornir ... - GitHub
Should open() arguments in the ConnectionPlugin Abstract Base Class be move to be bound to the object #221.
Read more >
Abstract Base Classes and Protocols: What Are They? When ...
In Python there are two similar, yet different, concepts for defining something akin to an interface, or a contract describing what methods ...
Read more >
c++ - Can functions accept abstract base classes as arguments?
If an class contains atleast one pure virtual function( speak() ) then the class becomes an Abstract class and you cannot create any...
Read more >
Abstract Classes in Python - GeeksforGeeks
An abstract class can be considered as a blueprint for other classes. It allows you to create a set of methods that must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found