Closed ugoleleux closed 1 month ago
Hi. Thanks for the report, I've had a lot of trouble making that field work, but now I see that NetBox's Service forms behave better. I will see what I can do for the next release.
NetBox's services have exactly the same issue, but they are usually used with far fewer ports. I've overridden upstream's NumericArrayField to display the ranges in edit forms.
What tool are you using for your export? This is neither the native export to CSV nor what the API returns (an array of int, not a string), so I can't help you there.
NetBox's services have exactly the same issue, but they are usually used with far fewer ports. I've overridden upstream's NumericArrayField to display the ranges in edit forms.
What tool are you using for your export? This is neither the native export to CSV nor what the API returns (an array of int, not a string), so I can't help you there.
Hi, thank you for your replies. For the export, I use a custom export template in jinja2
[{% for object in queryset %}
{
"id":"{{object.id}}",
"name":"{{object.name}}",
"status":"{{object.status}}",
"protocol":"{{object.protocol}}",
"application":"{{object.application}}",
"source_ports":"{{object.source_ports}}",
"destination_ports":"{{object.destination_ports}}",
"sources":"{% for source in object.sources.all() %}{{ source.name }}{{ "," if not loop.last }}{% endfor %}",
"destinations":"{% for destination in object.destinations.all() %}{{ destination.name }}{{ "," if not loop.last }}{% endfor %}",
"description":"{{object.description}}",
"comments":"{{object.comments}}",
"tags":"{% for tag in object.tags.all() %}{{ tag.slug }}{{ "," if not loop.last }}{% endfor %}"
},
{% endfor %}]
Hi, Ah, I see. Then, two easy options for the moment:
"source_ports": {{object.source_ports}},
"destination_ports": {{object.destination_ports}},
"Any"
, which must be replaced by ""
before being reimported; and it's not supposed to be public API so it can be removed/renamed/changed in future updates.
"source_ports": "{{object.source_port_list}}",
"destination_ports": "{{object.destination_port_list}}",
If you want a better support for that use case, please make a separate issue. I'll close that issue as the form prefilling is fixed.
Thank you very much for the hint.
I followed you advice and I removed the ""
in the jinja template :
"source_ports": {{object.source_ports}},
"destination_ports": {{object.destination_ports}},
And i can reimport data without any problem now.
Thanks again for your help.
Regards Ugo
Hello,
I am facing a strange behaviour, When I choose to register a source or a destination range of port using hyphen caracter it is well saved with the same format but when I go to edit it once again, the hyphen as been replaced by each ports in the range coma separated I can save and the UI is still showing a range of ports, but I think it will be difficult to handle when I will enter a range of thousand of ports.
I am also confused with the export format which is natively a square bracket list This format is not the same as any other netbox fields therefore I can't import it without removing the brackets in the first time
Thank you for reading my issue which is more a improvement suggestion.
Regards Ugo