Unable to set/change Gateway from REST API
Description
Problem/Justification
None
Impact
None
Attachments
1
- 07 Jul 2023, 02:26 PM
duplicates
Activity
Show:

Dionisis Deligiannopoulos July 10, 2023 at 8:49 AM
You were right about the format.
I am however still getting this as response, while successfully setting the gateway:
{'message': "(22, 'Invalid argument')", 'traceback': 'Traceback (most recent call last):\n File "/usr/lib/python3/dist-packages/middlewared/restful.py", line 768, in do\n result = await self.middleware.call(methodname, *method_args, **method_kwargs)\n File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1395, in call\n return await self._call(\n File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1344, in _call\n return await methodobj(*prepared_call.args)\n File "/usr/lib/python3/dist-packages/middlewared/service.py", line 576, in update\n rv = await self.middleware._call(\n File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1344, in _call\n return await methodobj(*prepared_call.args)\n File "/usr/lib/python3/dist-packages/middlewared/schema.py", line 1246, in nf\n res = await f(*args, **kwargs)\n File "/usr/lib/python3/dist-packages/middlewared/schema.py", line 1378, in nf\n return await func(*args, **kwargs)\n File "/usr/lib/python3/dist-packages/middlewared/plugins/network_/global.py", line 353, in do_update\n await self.middleware.call(\'route.sync\')\n File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1395, in call\n return await self._call(\n File "/usr/lib/python3/dist-packages/middlewared/main.py", line 1344, in _call\n return await methodobj(*prepared_call.args)\n File "/usr/lib/python3/dist-packages/middlewared/plugins/network_/route.py", line 143, in sync\n routing_table.change(ipv6_gateway)\n File "/usr/lib/python3/dist-packages/middlewared/plugins/interface/netif_linux/routing.py", line 205, in change\n self._op("set", route)\n File "/usr/lib/python3/dist-packages/middlewared/plugins/interface/netif_linux/routing.py", line 235, in _op\n ip.route(op, **kwargs)\n File "/usr/lib/python3/dist-packages/pyroute2/iproute/linux.py", line 1909, in route\n ret = self.nlm_request(msg,\n File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 376, in nlm_request\n return tuple(self._genlm_request(*argv, **kwarg))\n File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 867, in nlm_request\n for msg in self.get(msg_seq=msg_seq,\n File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 379, in get\n return tuple(self._genlm_get(*argv, **kwarg))\n File "/usr/lib/python3/dist-packages/pyroute2/netlink/nlsocket.py", line 704, in get\n raise msg[\'header\'][\'error\']\npyroute2.netlink.exceptions.NetlinkError: (22, \'Invalid argument\')\n'}

Caleb July 7, 2023 at 6:09 PM
@Dionisis Deligiannopoulos you're using the API wrong and sending incorrect data to the endpoint. I would suggest you read the restful api documentation. You can find this on the truenas by browsing to `http://<truenas-ip>/api/docs`.

Dionisis Deligiannopoulos July 7, 2023 at 2:26 PM
While able to perform the action from the cli as suggested, the result returns netlink error. Although the gateway is set succesfully.
Yet. The REST API is still having troubles
payload={'ipv4gateway': '172.16.0.2'}
result='500 Internal Server Error\n\nServer got itself in trouble'
That is why I tried sending a payload that assembles the result of get network/configuration

Kris Moore July 7, 2023 at 2:02 PM
Same issue as: NAS-122835

Dionisis Deligiannopoulos July 7, 2023 at 9:04 AM
The goal is to change the ipv4ateway
from 172.16.0.1
to 172.16.0.2
payload = {
"id": 1,
"hostname": "truenas",
"domain": "local",
"ipv4gateway": "172.16.0.2",
"ipv6gateway": "fe80::daec:e5ff:fe78:7877",
"nameserver1": "1.1.1.1",
"nameserver2": "",
"nameserver3": "",
"httpproxy": "",
"netwait_enabled": false,
"netwait_ip": [],
"hosts": "",
"domains": [],
"service_announcement": {
"mdns": true,
"wsd": true,
"netbios": true
},
"activity": {
"type": "DENY",
"activities": []
},
"hostname_local": "truenas",
"state": {
"ipv4gateway": "172.16.0.2",
"ipv6gateway": "fe80::5862:27ff:fe5b:e9df",
"nameserver1": "1.1.1.1",
"nameserver2": "",
"nameserver3": ""
}
}
url='http://my_ip/api/v2.0/network/configuration'
headers = {'Content-Type': 'application/json'}
requests.put(
url, verify=False, headers=headers, data=payload,
timeout=self.config['timeout'],
auth=(user , password)
)
Returns
'500 Internal Server Error\n\nServer got itself in trouble'
User Configuration Error
Pinned fields
Click on the next to a field label to start pinning.
Details
Details
Assignee

Reporter

Labels
Impact
High
Fix versions
Affects versions
Priority
More fields
Time tracking
More fields
Time trackingKatalon Platform
Linked Test Cases, Katalon Defect Results, Katalon Studio Test Results
Katalon Platform
Linked Test Cases, Katalon Defect Results, Katalon Studio Test Results
Created July 6, 2023 at 2:42 PM
Updated July 10, 2023 at 8:49 AM
Resolved July 7, 2023 at 6:09 PM
When trying to either change or set a gateway from the REST API, an error is returned:
'500 Internal Server Error\n\nServer got itself in trouble'