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

Add device_id and virtual_machine_id to ipam.forms.filtersets.ServiceFilterForm #13951

Closed
atownson opened this issue Oct 3, 2023 · 2 comments · Fixed by #14215
Closed

Add device_id and virtual_machine_id to ipam.forms.filtersets.ServiceFilterForm #13951

atownson opened this issue Oct 3, 2023 · 2 comments · Fixed by #14215
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@atownson
Copy link
Contributor

atownson commented Oct 3, 2023

NetBox version

v3.5.7

Feature type

Change to existing functionality

Proposed functionality

I propose to add fields device_id and virtual_machine_id to the ServiceFilterForm class. Currently there's no way to filter a service by the associated device or virtual machine in the web form. The search method also does not include these fields.

image

image

The API does support filtering by device and virtual machine.

This feature request can be accomplished by updating the filtersets.py from:

class ServiceFilterForm(ServiceTemplateFilterForm):
    model = Service
    tag = TagFilterField(model)

to:

class ServiceFilterForm(ServiceTemplateFilterForm):
    model = Service
    fieldsets = (
        (None, ('q', 'filter_id', 'tag')),
        (_('Attributes'), ('protocol', 'port')),
        (_('Device/VM'), ('device_id', 'virtual_machine_id')),
    )
    device_id = DynamicModelMultipleChoiceField(
        queryset=Device.objects.all(),
        required=False,
        label=_('Assigned Device'),
    )
    virtual_machine_id = DynamicModelMultipleChoiceField(
        queryset=VirtualMachine.objects.all(),
        required=False,
        label=_('Assigned VM'),
    )

Result:
image

image

I could handle this PR if desired and if this request is approved.

Use case

Adding these fields would improve the user experience, align the services model filterset with the IP address model filterset, and provide functionality available in the API to the web filter forms.

Database changes

None

External dependencies

None

@atownson atownson added the type: feature Introduction of new functionality to the application label Oct 3, 2023
@abhi1693 abhi1693 added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Oct 3, 2023
@atownson
Copy link
Contributor Author

atownson commented Oct 5, 2023

Another option for this would be to modify the string definition of the Service model to include the device/vm:

def __str__(self):
    return f'{self.device or self.virtual_machine} -> {self.name} ({self.get_protocol_display()}/{self.port_list})'

This could obviously get rather lengthy and verbose, depending on the Service properties, but one example might be:

vm01splunk -> Splunk Web (TCP/8000)

This would need to be searchable too.

@jeremystretch
Copy link
Member

The API does support filtering by device and virtual machine.

This is incorrect. ServiceFilterSet supports filtering by both device and VM by ID or name. The scope of this FR would be limited to adding these fields to the filter form.

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Nov 6, 2023
@abhi1693 abhi1693 self-assigned this Nov 8, 2023
@abhi1693 abhi1693 added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Nov 8, 2023
jeremystretch added a commit that referenced this issue Nov 9, 2023
* adds device and vm to service filter form #13951

* Tweak labels

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants