How do we use regex in RESTCONF key locations?
I have multiple groups and i want to retrieve them all.
curl -kisu 'admin:admin' -X GET -H "Accept:application/yang-data+xml" https://10.54.28.15/restconf/data/context=default/Group=\*
How do we use regex in RESTCONF key locations?
I have multiple groups and i want to retrieve them all.
curl -kisu 'admin:admin' -X GET -H "Accept:application/yang-data+xml" https://10.54.28.15/restconf/data/context=default/Group=\*
See the “filter query parameter” that take an XPath 1.0 expression in the RESTCONF RFC8040:
https://tools.ietf.org/html/rfc8040#section-4.8.4
A few examples in the RFC:
https://tools.ietf.org/html/rfc8040#appendix-B.3.6
The XPath 1.0 standard that the RFC link to (for example “4.1 Node Set Functions” can be handy sometimes)
https://www.w3.org/TR/1999/REC-xpath-19991116/
Thanks.
Tried, but seem to work:
curl -kisu 'admin:admin' -X GET -H "Accept:application/yang-data+xml" https://<ip>/restconf/data/Context=default/?filter=Group=2
HTTP/1.1 400 Bad Request
Date: Thu, 21 Nov 2019 11:39:30 GMT
Server:
Content-Length: 243
Content-Type: application/yang-data+xml
Vary: Accept-Encoding
Content-Security-Policy: frame-ancestors ‘self’
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Permitted-Cross-Domain-Policies: master-only
Strict-Transport-Security: max-age=31536000, includeSubDomains, preload
Cache-Control: no-cache, no-store, must-revalidate, private
Pragma: no-cache
Connection: close
What does your YANG model look like?
Hi Cohult,
Sorry for late reply.
For any list or leaf-list, if they contain multiple nodes/elements then RESTCONF curl request couldn’t retrieve all nodes, unlike REST request.
For list
list currentStatus { key alarmId;
REST curl request: curl -u admin:admin -X GET -i -s http://localhost:8008/api/operational/alarms/currentStatus retrieves all nodes/elements as a collection.
curl -u admin:admin -X GET -i -s http://localhost:8008/api/operational/alarms/currentStatus HTTP/1.1 200 OK Server: Date: Tue, 10 Dec 2019 10:21:58 GMT Cache-Control: private, no-cache, must-revalidate, proxy-revalidate Content-Type: application/vnd.yang.collection+xml Transfer-Encoding: chunked Pragma: no-cache <collection xmlns:y="http://tail-f.com/ns/rest"> <currentStatus xmlns="http://xxx.com/ns/mibs/xxx-ALARM-MGR/1.0"> <alarmId>500</alarmId> <clearType>AUTOMATIC</clearType> <timestamp>2019-12-10T10:09:29-00:00</timestamp> <initialTimestamp>2019-12-10T10:09:29-00:00</initialTimestamp> <count>1</count> <desc>The number of log files of type 'MEM' has reached 100 percent of the configured maximum (32/32). Please process and remove files!</desc> <reporter>ENM</reporter> <severity>Major</severity> <acknowledgeState>unAcknowledge</acknowledgeState> <comment></comment> </currentStatus> <currentStatus xmlns="http://xxx.com/ns/mibs/xxx-ALARM-MGR/1.0"> <alarmId>511</alarmId> <clearType>AUTOMATIC</clearType> <timestamp>2019-12-10T10:19:29-00:00</timestamp> <initialTimestamp>2019-12-10T10:09:29-00:00</initialTimestamp> <count>3</count> <desc>Debug Event Log filter level is set to INFO. Set to MAJOR if finished troubleshooting</desc> <reporter>EVLOG</reporter> <severity>Major</severity> <acknowledgeState>unAcknowledge</acknowledgeState> <comment></comment> </currentStatus> </collection>
Whereas RESTCONF returns error…
curl -u admin:admin -X GET -i -s http://localhost:8008/restconf/data/alarms/currentStatus/ -H "Content-type: application/yang-data+xml" HTTP/1.1 400 Bad Request Server: Date: Tue, 10 Dec 2019 10:37:18 GMT Cache-Control: private, no-cache, must-revalidate, proxy-revalidate Content-Length: 229 Content-Type: application/yang-data+xml Vary: Accept-Encoding Pragma: no-cache <errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"> <error> <error-message>too many instances: 2</error-message> <error-tag>invalid-value</error-tag> <error-type>application</error-type> </error> </errors>
I was thinking of using regex to retrieve all, But wasn’t successful.
Thnaks,
This is intended behavior, See https://tools.ietf.org/html/rfc8040#section-4.3 fourth paragraph.
From the user guide RESTCONF API section (22.7.1), under extensions -> collections:
The RESTCONF specification states that a result containing multiple instances (e.g a number of list entries) is not allowed if XML encoding is used, The reason for this is that an XML document can only have one root node.
To remedy this, a HTTP GET request can make use of the “Accept:” media type:
application/vnd.yang.collection+xml as shown in the following example:
curl -H “Accept: application/vnd.yang.collection+xml” http://…
Thanks.
I used colletion method and i was able to get all the keys of list.