Add VM Count to Clusters Export #1562

Closed
opened 2025-12-29 16:32:58 +01:00 by adam · 5 comments
Owner

Originally created by @iDemonix on GitHub (Feb 19, 2018).

Issue type

[x] Feature request

Description

When exporting clusters to CSV or similar, one of the most useful pieces of information is the VM Count (which is included in the default Clusters table). Would it be possible to add this (and maybe host count) either to the default export, or allow it to be pulled using an export template?

There are counts on virtualization/clusters/1/ but not api/virtualization/clusters/1/, maybe it'd be worth adding the counts to this too?

Originally created by @iDemonix on GitHub (Feb 19, 2018). ### Issue type [x] Feature request <!-- An enhancement of existing functionality --> <!-- FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description When exporting clusters to CSV or similar, one of the most useful pieces of information is the VM Count (which is included in the default Clusters table). Would it be possible to add this (and maybe host count) either to the default export, or allow it to be pulled using an export template? There are counts on `virtualization/clusters/1/` but not `api/virtualization/clusters/1/`, maybe it'd be worth adding the counts to this too?
adam closed this issue 2025-12-29 16:32:58 +01:00
Author
Owner

@mabazyar commented on GitHub (Feb 20, 2018):

Yeah, confirming, this feature makes our life a lot easier too.

@mabazyar commented on GitHub (Feb 20, 2018): Yeah, confirming, this feature makes our life a lot easier too.
Author
Owner

@jeremystretch commented on GitHub (Feb 21, 2018):

The built-in CSV export is limited to data directly associated with each object; it is essentially the complement to the CSV import approach. This does not entail statistical information such as VM/host count, however NetBox allows you to create your own custom export template to retrieve this information.

As for the API serializer, AFAICT the only place we currently include counts of child objects is on the site model (count_prefixes, count_devices, etc.). (And incidentally, a count of virtual machines is missing from the serializer.) I'm not against adding similar counts to Cluster and other models, but we probably want to give more thought to how that data is conveyed.

@jeremystretch commented on GitHub (Feb 21, 2018): The built-in CSV export is limited to data directly associated with each object; it is essentially the complement to the CSV import approach. This does not entail statistical information such as VM/host count, however NetBox allows you to create your own custom [export template](http://netbox.readthedocs.io/en/stable/data-model/extras/#export-templates) to retrieve this information. As for the API serializer, AFAICT the only place we currently include counts of child objects is on the site model (`count_prefixes`, `count_devices`, etc.). (And incidentally, a count of virtual machines is missing from the serializer.) I'm not against adding similar counts to Cluster and other models, but we probably want to give more thought to how that data is conveyed.
Author
Owner

@iDemonix commented on GitHub (Feb 21, 2018):

Hi @jeremystretch, are you saying it's possible to have the count of VMs (for example) in an export template? I wasn't sure if that was possible, but if it is then that's all I was aiming to request - would you mind showing an example or pointing to the docs for that?

@iDemonix commented on GitHub (Feb 21, 2018): Hi @jeremystretch, are you saying it's possible to have the count of VMs (for example) in an export template? I wasn't sure if that was possible, but if it is then that's all I was aiming to request - would you mind showing an example or pointing to the docs for that?
Author
Owner

@jeremystretch commented on GitHub (Feb 21, 2018):

In the admin UI, go to Extras -> Export Templates and create a new template for "virtualization > cluster". You can do something like this to get the VM count for each cluster:

{% for cluster in queryset %}{{ cluster.name }}: {{ cluster.virtual_machines.count }}
{% endfor %}
@jeremystretch commented on GitHub (Feb 21, 2018): In the admin UI, go to Extras -> Export Templates and create a new template for "virtualization > cluster". You can do something like this to get the VM count for each cluster: ``` {% for cluster in queryset %}{{ cluster.name }}: {{ cluster.virtual_machines.count }} {% endfor %} ```
Author
Owner

@iDemonix commented on GitHub (Feb 21, 2018):

Thanks Jeremy!

I'll close this issue as that's the exact functionality I was after. Maybe it'd be worth mentioning that counts are possible in the docs for Export Templates as it seems both me and @mabazyar missed it.

@iDemonix commented on GitHub (Feb 21, 2018): Thanks Jeremy! I'll close this issue as that's the exact functionality I was after. Maybe it'd be worth mentioning that counts are possible in the docs for Export Templates as it seems both me and @mabazyar missed it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1562