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

Added flag for raw api output #136

Merged
merged 3 commits into from
Mar 16, 2020

Conversation

richard-olson
Copy link
Contributor

@richard-olson richard-olson commented Mar 15, 2020

This PR adds the ability to return the raw data of the Netbox API.

Currently when given the command device: "{{ lookup('netbox.netbox.nb_lookup', 'devices', api_endpoint=api_url, token=api_token }}" data is returned in the following format:

    "device": {
            "key": 7,
            "value": {
                "asset_tag": null,
                "cluster": null,
                "comments": "",
                <snipped for brevity>
      }

This adds an extra layer of complexity for usage as it increases the depth of the data structure behind a somewhat meaningless key/value construct where the Netbox object id becomes the key and the payload is hidden under value

This PR adds the option for the lookup plugin to return the raw Netbox API response in the following format

device: "{{ lookup('netbox.netbox.nb_lookup', 'devices', api_endpoint=api_url, token=api_token, raw_data=True }}"

    "device": {
        "asset_tag": null,
        "cluster": null,
        "comments": "",
        <snipped for brevity>
      }

Items with multiple returns will be available in a list format

    "interfaces": [
        {
            "cable": {
                "id": 1,
                "label": "",
                <snipped for brevity>
        },
        {
            "cable": {
                "id": 2,
                "label": "",
                <snipped for brevity>
         }
   ]

@FragmentedPacket
Copy link
Contributor

Thanks for taking care of this! You can get the tests to pass by pip install black and then running black . or black plugins/lookup/nb_lookup.py for it to format the file.

Can you also add integration tests for this new option? You can just add one that has this new option as True and then assert the data should be the way it is. If you have any questions on how to structure the tests then hit me up on Slack or here.

@FragmentedPacket FragmentedPacket merged commit 8640ac2 into netbox-community:devel Mar 16, 2020
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.

2 participants