virtualization interfaces can only be filtered by vm name, not id
Closed this issue · 4 comments
Summary
This is partly related to #209 that was fixed in #210. I am not sure, but looking at the code I think the fix might incorrectly assume that the filter names will only be filter_name
but never long_filter_name
, i.e. have more than one underscore.
I am encountering this issue when attempting to filter netbox_json_virtualization_interfaces_list
on name = "virtual_machine_id"
. It works fine with the virtual_machine
filter, but for the id I get this error:
Error: response status code does not match any response statuses defined for this endpoint in the swagger spec (status 400): {}
As before, I have verified that this call works against the API, i.e. /api/virtualization/interfaces/?virtual_machine_id=1452
gives back the expected response.
Version
Netbox version
3.5.4
Terraform version
v1.5.4
Provider version
7.0.0
Issue details
Affected Data(s) / Resource(s)
- data.netbox_json_virtualization_interfaces_list
Behaviors
Actual Behavior
Error message as above
Expected Behavior
Return interfaces with the provided vm id
Steps to Reproduce
Attempt to grab interfaces by vm id:
data "netbox_json_virtualization_interfaces_list" "ifs" {
filter {
name = "virtual_machine_id"
value = 123
}
limit = 0
}
output "found_interfaces" {
value = data.netbox_json_virtualization_interfaces_list.ifs
}
Here's some example code inspired by b72f202 that I think shows the issue:
package main
import (
"fmt"
"strings"
"unicode"
)
func fixUnderscores(input string) string {
split := strings.Split(input, "_")
k := split[0]
if len(split) > 1 {
r2 := []rune(split[1])
r2[0] = unicode.ToUpper(r2[0])
k = k + string(r2)
}
return k
}
func main() {
fmt.Println("short_filter becomes: " + fixUnderscores("short_filter"))
fmt.Println("a_longer_filter becomes: " + fixUnderscores("a_longer_filter"))
}
Output:
short_filter becomes: shortFilter
a_longer_filter becomes: aLonger
Doing something like this with a for-loop instead of an if might fix it:
func fixUnderscores(input string) string {
split := strings.Split(input, "_")
k := split[0]
for i := 1; i < len(split); i++ {
r2 := []rune(split[i])
r2[0] = unicode.ToUpper(r2[0])
k = k + string(r2)
}
return k
}
short_filter becomes: shortFilter
a_longer_filter becomes: aLongerFilter
Hello,
Thanks for the report.
You seems to have the fix so could you please open a PR ?
Thanks.