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

Inventory module site and prefix data extended #646

Conversation

Eric-Sim
Copy link
Contributor

@Eric-Sim Eric-Sim commented Nov 9, 2021

This PR satisfies (Issue #640) without causing any changes to default functionality.

Both the extension of Site Data and Prefix Data are enabled by additional parameters passed to the module.
site_data: (boolean)
prefixes: (boolean)
These changes follow the same methodology as the interfaces option.

No changes in the default behavior of the module in order to guarantee legacy applications will continue working as intended.

The site_data parameter will cause the entire data structure returned by the /api/dcim/sites API call to be captured and inserted into hostvars appropriately for each device in inventory, instead of just the slug that is collected currently.

The prefixes option extends this section of the hostvars further by nesting the datastructure of the prefix assigned to the site as well. This is done by a calling an additional endpoint /api/ipam/prefixes.
Current optimizations are maintained with the "fetch_all" option.
Only ACTIVE prefixes, that are assigned to a site are pulled; and only for the sites that have at least one queried device assigned to them.

@Eric-Sim
Copy link
Contributor Author

Eric-Sim commented Nov 9, 2021

Please link to issue #640

Copy link
Contributor

@sc68cal sc68cal left a comment

Choose a reason for hiding this comment

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

Some thoughts

plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
plugins/inventory/nb_inventory.py Outdated Show resolved Hide resolved
@sc68cal
Copy link
Contributor

sc68cal commented Nov 16, 2021

approved a run through CI

@Eric-Sim
Copy link
Contributor Author

Looks like 2 of the tasks are issues with the CI pipeline itself, but the other 2 are black complaining.
I allowed this formatting in 9ff30f9, but ended up undoing it when reviewing with sc68cal.

Please let me know if I need to allow black to reformat.
(the changes it wants to make do not help readability)

@sc68cal
Copy link
Contributor

sc68cal commented Nov 18, 2021

I think we need to tweak our black settings, because I too do not care for that formatting that black is insisting on

@sc68cal
Copy link
Contributor

sc68cal commented Nov 18, 2021

@rodvand Can you take a look at this? The problem is that black was complaining about a line that was not originally part of his patchset, and in the process of doing this PR he changed this line but frankly I don't think it was a related change.

Does he need to rebase?

@rodvand
Copy link
Contributor

rodvand commented Nov 28, 2021

Not quite sure why this happens. @Eric-Sim Do you run black locally to format the code? But yeah, try to rebase based on devel. @sc68cal The latest black requires python 3.6.2 so we need to up our requirements before we upgrade our black version. When that's done it shouldn't be a big deal upgrading. Did a test run with a newer black and it only changed a few of the files, so not a massive re-format.

@Eric-Sim
Copy link
Contributor Author

Eric-Sim commented Dec 1, 2021

I had run black locally to format the code. And it did apply the same formatting that the project CI/CD pipeline is trying to apply. The problem was what @sc68cal had pointed out, it ends up changing things that are outside the scope of what I revised; so I reverted those.

I will rebase from devel tonight.

@Eric-Sim
Copy link
Contributor Author

My branch is up to date. No new commits in Devel that I can rebase into my branch.

I have re-run black locally and committed its formatting changes.

@rodvand rodvand linked an issue Dec 11, 2021 that may be closed by this pull request
@sc68cal
Copy link
Contributor

sc68cal commented Dec 13, 2021

OK, something must be going on with your local black because it is failing on those lines in CI.

@Eric-Sim
Copy link
Contributor Author

Sorry for the slow update.
I went ahead and manually matched the changes the the project's black wanted, and pushed.

Copy link
Contributor

@sc68cal sc68cal left a comment

Choose a reason for hiding this comment

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

This looks good to me, probably this needs to be a squash & merge operation

@rodvand rodvand merged commit 7b2bdb4 into netbox-community:devel Dec 27, 2021
@bluikko
Copy link
Contributor

bluikko commented Jan 13, 2022

What about the functionality for virtualization app? This only does it for dcim?

For users who have both physical and virtual infrastructure a feature parity between the 2 apps would really be needed - or everything must be done for the lowest common denominator (i.e. if some feature is only for dcim but not virtualization then it could not be used).

@Eric-Sim
Copy link
Contributor Author

What about the functionality for virtualization app? This only does it for dcim?

For users who have both physical and virtual infrastructure a feature parity between the 2 apps would really be needed - or everything must be done for the lowest common denominator (i.e. if some feature is only for dcim but not virtualization then it could not be used).

Hey @bluikko, I can look back through when I get a chance.
Off the top of my head, I don't remember seeing anything that would cause a virtual device to operate differently than a physical one.

@k-y
Copy link

k-y commented Feb 4, 2022

I've got the site object getting populated correctly into hostvars and see a single prefix in site, however, only the 1st prefix for each site seems to be getting populated. All of our sites have prefix_count > 1 but I don't see the rest of the prefixes.

e.g.

        "site": {                                                                 
...
            "prefix": {    
                "created": "2021-09-16",
...
            },
            "prefix_count": 23,

@rodvand
Copy link
Contributor

rodvand commented Feb 6, 2022

@k-y Could you open an issue with enough data to reproduce?

@Eric-Sim
Copy link
Contributor Author

Eric-Sim commented Feb 6, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pull complete site data and prefixes (optionally) in Inventory module
5 participants