Skip to content
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

EOS: Add a JSON option when running a cli command #1637

Merged
merged 11 commits into from
Jun 3, 2022

Conversation

dasturiasArista
Copy link
Contributor

pyeapi supports JSON as an option for the cli commands. However right
now the JSON option isn't exposed to users of this API. This exposes the
JSON option as well.

I manually tested this with an Arista switch and verified the changes work.

pyeapi supports JSON as an option for the cli commands. However right
now the JSON option isn't exposed to users of this API. This exposes the
JSON option as well.
pyeapi supports JSON as an option for the cli commands. However right
now the JSON option isn't exposed to users of this API. This exposes the
JSON option as well.
@ktbyers
Copy link
Contributor

ktbyers commented May 12, 2022

Tests are failing on this change.

@dasturiasArista
Copy link
Contributor Author

Tests are failing on this change.

I was noticing that. I'm wondering the best way to handle adding functionality would be. It looks like tests are failing because I've added an extra argument to this function that it's not expecting. Would it ok to modify the test to allow the extra args in the EOS case?

@ktbyers
Copy link
Contributor

ktbyers commented May 12, 2022

So the test issue is that all of the NAPALM drivers (junos, eos, ios, etc) must have the same signature for the method:

    def cli(self, commands, encoding="text"):

So if we add the encoding argument, then we have to add it for all of the drivers.

You can always access pyeapi via napalm using:

napalm_object.device

I guess I wonder if we really need to be able to execute the cli method but with JSON output. Note, I basically never use the cli method...so probably would be better if @mirceaulinic or other users of CLI commented on this and whether it is worth doing this.

@dasturiasArista
Copy link
Contributor Author

So the test issue is that all of the NAPALM drivers (junos, eos, ios, etc) must have the same signature for the method:

    def cli(self, commands, encoding="text"):

So if we add the encoding argument, then we have to add it for all of the drivers.

You can always access pyeapi via napalm using:

napalm_object.device

I guess I wonder if we really need to be able to execute the cli method but with JSON output. Note, I basically never use the cli method...so probably would be better if @mirceaulinic or other users of CLI commented on this and whether it is worth doing this.

Ok. that seems reasonable. I was unaware that the "device" attribute was considered a stable part of the api. I have proposed this solution for the customer trying to use this to confirm if this works for them or not.

@ktbyers
Copy link
Contributor

ktbyers commented May 12, 2022

Yeah, I would think we would not change napalm_object.device (at least not without really good reason and without following semantic versioning i.e. a major release) as that would break lots of things.

It is possible this napalm_object.device convention is not followed in napalm-community drivers, but it should be followed in napalm core.

@ktbyers
Copy link
Contributor

ktbyers commented May 12, 2022

@dasturiasArista Yeah, let us know what you find and if that solution works.

@dasturiasArista
Copy link
Contributor Author

@dasturiasArista Yeah, let us know what you find and if that solution works.

Yes will do! Not to keep you hanging, still waiting from the response from the customer.

@mirceaulinic
Copy link
Member

Just to add to Kirk's comment further:

So if we add the encoding argument, then we have to add it for all of the drivers.

We have a similar request for Junos (#1500) so it'd be great if you could go ahead with this and I can take care of the Junos implementation.

@dasturiasArista
Copy link
Contributor Author

Just to add to Kirk's comment further:

So if we add the encoding argument, then we have to add it for all of the drivers.

We have a similar request for Junos (#1500) so it'd be great if you could go ahead with this and I can take care of the Junos implementation.

Ok. I can go ahead and add the argument to all of the drivers, but for those that don't support that encoding i'll just have it raise an error. How do you feel about raising a ValueError?

pyeapi supports JSON as an option for the cli commands. However right
now the JSON option isn't exposed to users of this API. This exposes the
JSON option as well.
@dasturiasArista
Copy link
Contributor Author

Just to add to Kirk's comment further:

So if we add the encoding argument, then we have to add it for all of the drivers.

We have a similar request for Junos (#1500) so it'd be great if you could go ahead with this and I can take care of the Junos implementation.

Ok. I can go ahead and add the argument to all of the drivers, but for those that don't support that encoding i'll just have it raise an error. How do you feel about raising a ValueError?

Btw I have proactively made the changes we talked about here. Also, each method will check that it's valid and throw a ValueError if it's not a valid encoding.

Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just requesting to raise NotImplementedError instead of ValueError.

napalm/eos/eos.py Outdated Show resolved Hide resolved
napalm/ios/ios.py Outdated Show resolved Hide resolved
napalm/iosxr/iosxr.py Outdated Show resolved Hide resolved
napalm/junos/junos.py Outdated Show resolved Hide resolved
napalm/nxos/nxos.py Outdated Show resolved Hide resolved
napalm/nxos_ssh/nxos_ssh.py Outdated Show resolved Hide resolved
Copy link
Member

@mirceaulinic mirceaulinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mirceaulinic mirceaulinic merged commit 25454ef into napalm-automation:develop Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants