Skip to content

Add support for _choices #25

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

Ichabond
Copy link

This adds initial support for the dcim/_choices endpoint. This fixes #24

I added a seperate Choice class, to deal with the unique return values. Added an exception for the _choices endpoint to map to this class.

This adds initial support for the `dcim/_choices` endpoint. This fixes netbox-community#24
@zachmoody
Copy link
Contributor

👋 Thanks for the PR. I'd been playing around with the idea of using the data from _choices to make places we have to use the values more human-friendly (e.g. mostly kwargs for the various Record and Endpoint methods), but not necessarily exposing the endpoint itself. Just curious if that would address what you were trying to do or there's some uses I'm missing.

I didn't have a lot of time to play around with your branch, but it looks like all I could get are the keys from the NetBox response. Was that all you were looking to do? Some tests (need these anyways) and more docs would definitely help me better understand the goal.

@Ichabond
Copy link
Author

Hey,

The values of _choices are needed when creating or modifying an interface to set the interface form-factor. I think it would still be a good idea to expose what the options are, instead of just internally mapping a human-readable label to the value, although that is a good idea as well.

If you do the following:
api.dcim._choices.get('interface:form_factor'), you get the label and values, which is currently all that's really needed. Maybe use the label as a dictionary key, and merge the list of dictionaries into 1 dictionary instead?

@zachmoody
Copy link
Contributor

Got some more time to play with it. I was using all() and getting some odd behavior. It returned a list of Choice objects, but .items() just returned the key as a string, but .get() works though. I'm kinda thinking an Endpoint object might not be the right container for this stuff. Calling any of the other method ends badly.

Had a half-baked idea. Maybe a .choices() Endpoint method that'd by default return the choices for the endpoint it's called from (maybe pass a kwarg to other endpoint's choices, if needed)? Could maybe use that to provide interpolation for values passed to create(), and pass it down to the Record objects for the same thing. Will give it a little more thought though.

At the very least, I'm thinking we should subclass Endpoint and raise NotImplemented where it makes sense.

@vzaletny
Copy link

Hi guys.

How about support for _choices in pynetbox?

@zachmoody
Copy link
Contributor

Some basic support for choices is getting adding to the upcoming 4.0 release that should be out around the same time as NetBox 2.5.

@zachmoody zachmoody closed this Nov 23, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for the dcim/_choices endpoint
3 participants