Skip to content

Commit

Permalink
* Restconf top-level operations GET root resource modified to comply …
Browse files Browse the repository at this point in the history
…with

RFC 8040 Sec 3.1
  * non-pretty print remove all spaces, eg `{"operations":{"clixon-example:client-rpc":[null]`
  * Replaced JSON `null` with `[null]` as proper empty JSON leaf/leaf-list encoding.
* [Cannot write to config using restconf example #91](#91)
  * Updated restconf documentation (the example was wrong)
* [clixon-lib yang revision file name update #92](#92)
  * Clixon-lib yang file had conflicting filename and internal yang revision.
  * This was only detected in the use-case when a whole dir was loaded.
  * Inserted sanity check in all yang parse routines.
  * Committed updated clixon-lib yang file that triggered the error
  • Loading branch information
olofhagsand committed Aug 24, 2019
1 parent a8906fd commit 6df4340
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 192 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Clixon Changelog

## 4.2.0 (Expected: September)

### API changes on existing features (you may need to change your code)
* Restconf top-level operations GET root resource modified to comply with RFC 8040 Sec 3.1
* non-pretty print remove all spaces, eg `{"operations":{"clixon-example:client-rpc":[null]`
* Replaced JSON `null` with `[null]` as proper empty JSON leaf/leaf-list encoding.

### Corrected Bugs
* [Cannot write to config using restconf example #91](https://github.com/clicon/clixon/issues/91)
* Updated restconf documentation (the example was wrong)
* [clixon-lib yang revision file name update #92](https://github.com/clicon/clixon/issues/92)
* Clixon-lib yang file had conflicting filename and internal yang revision.
* This was only detected in the use-case when a whole dir was loaded.
* Inserted sanity check in all yang parse routines.
* Committed updated clixon-lib yang file that triggered the error

## 4.1.0 (18 August 2019)

### Summary
Expand Down
61 changes: 33 additions & 28 deletions apps/restconf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,62 @@ Download and start nginx. For example on ubuntu:

Define nginx config file: /etc/nginx/sites-available/default
```
server {
...
location /restconf {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params;
server {
...
location /restconf {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params;
}
}
}
```

Start nginx daemon
```
sudo /etc/init.d nginx start
sudo /etc/init.d nginx start
```
Alternatively, start it via systemd:
```
sudo /etc/init.d/nginx start
sudo systemctl start start.service
sudo systemctl start nginx.service
```

Start clixon backend daemon (if not already started)
```
sudo clixon_backend -s init -f /usr/local/etc/example.xml
```

Start clixon restconf daemon
```
> sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/example.xml " -s /bin/sh www-data
sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/example.xml " -s /bin/sh www-data
```

Make restconf calls with curl (or other http client). Example of writing a new interface specification:
```
curl -sX PUT http://localhost/restconf/data/ietf-interfaces:interfaces -H 'Content-Type: application/yang-data+json' -d '{"ietf-interfaces:interfaces":{"interface":{"name":"eth1","type":"clixon-example:eth","enabled":true}}}'
```

Make restconf calls with curl
Get the data
```
> curl -G http://127.0.0.1/restconf/data/ietf-interfaces:interfaces
[
curl -X GET http://127.0.0.1/restconf/data/ietf-interfaces:interfaces
{
"ietf-interfaces:interfaces": {
"interface":[
"interface": [
{
"name": "eth9",
"type": "ex:eth",
"enabled": true,
}
"name": "eth1",
"type": "clixon-example:eth",
"enabled": true
}
]
}
}
]
```
Get the type of a specific interface:
```
> curl -G http://127.0.0.1/restconf/data/interfaces/interface=eth9/type
{
"ietf-interfaces:type": "eth"
}
```
Example of writing a new interfaces specification:
```
curl -sX PUT http://localhost/restconf/data -d '{"ietf-interfaces:interfaces":{"interface":{"name":"eth1","type":"ex:eth","enabled":true}}}'
curl -X GET http://127.0.0.1/restconf/data/ietf-interfacesinterfaces/interface=eth1/type
{
"ietf-interfaces:type": "clixon-example:eth"
}
```

## Streams
Expand All @@ -83,7 +88,7 @@ RFC8040 Section 6 using SSE. One native and one using Nginx
nchan. The Nchan alternaitve is described in the
next section.

The (example)[../../example/README.md] creates an EXAMPLE stream.
The [example](../../example/main/README.md) creates an EXAMPLE stream.

Set the Clixon configuration options:
```
Expand Down
21 changes: 16 additions & 5 deletions apps/restconf/restconf_methods_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,10 @@ api_operations_get(clicon_handle h,
cprintf(cbx, "<operations>");
break;
case YANG_DATA_JSON:
cprintf(cbx, "{\"operations\": {");
if (pretty)
cprintf(cbx, "{\"operations\": {\n");
else
cprintf(cbx, "{\"operations\":{");
break;
default:
break;
Expand All @@ -467,22 +470,30 @@ api_operations_get(clicon_handle h,
cprintf(cbx, "<%s xmlns=\"%s\"/>", yang_argument_get(yc), namespace);
break;
case YANG_DATA_JSON:
if (i++)
if (i++){
cprintf(cbx, ",");
cprintf(cbx, "\"%s:%s\": null", yang_argument_get(ymod), yang_argument_get(yc));
if (pretty)
cprintf(cbx, "\n\t");
}
if (pretty)
cprintf(cbx, "\"%s:%s\": [null]", yang_argument_get(ymod), yang_argument_get(yc));
else
cprintf(cbx, "\"%s:%s\":[null]", yang_argument_get(ymod), yang_argument_get(yc));
break;
default:
break;
}

}
}
switch (media_out){
case YANG_DATA_XML:
cprintf(cbx, "</operations>");
break;
case YANG_DATA_JSON:
cprintf(cbx, "}}");
if (pretty)
cprintf(cbx, "}\n}");
else
cprintf(cbx, "}}");
break;
default:
break;
Expand Down
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2172,9 +2172,9 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
: ${INSTALLFLAGS="-s"}

CLIXON_VERSION_MAJOR="4"
CLIXON_VERSION_MINOR="1"
CLIXON_VERSION_MINOR="2"
CLIXON_VERSION_PATCH="0"
CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}\""
CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\""

# Check CLIgen
if test "$prefix" = "NONE"; then
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ AC_INIT(lib/clixon/clixon.h.in)
: ${INSTALLFLAGS="-s"}

CLIXON_VERSION_MAJOR="4"
CLIXON_VERSION_MINOR="1"
CLIXON_VERSION_MINOR="2"
CLIXON_VERSION_PATCH="0"
CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}\""
CLIXON_VERSION="\"${CLIXON_VERSION_MAJOR}.${CLIXON_VERSION_MINOR}.${CLIXON_VERSION_PATCH}.PRE\""

# Check CLIgen
if test "$prefix" = "NONE"; then
Expand Down
10 changes: 5 additions & 5 deletions doc/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ The main example:

## How do I run Clixon example commands?

- Start a backend server: `clixon_backend -F -s init -f /usr/local/etc/example.xml`
- Start a backend server: `sudo clixon_backend -s init -f /usr/local/etc/example.xml`
- Start a cli session: `clixon_cli -f /usr/local/etc/example.xml`
- Start a netconf session: `clixon_netconf -f /usr/local/etc/example.xml`
- Start a restconf daemon: `sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/example.xml " -s /bin/sh www-data`
- Send a restconf command: `curl -G http://127.0.0.1/restconf/data`
- Send a restconf command: `curl -X GET http://127.0.0.1/restconf/data`

More info in the [example](../example) directory.

Expand Down Expand Up @@ -195,12 +195,12 @@ Start the clixon restconf daemon
sudo su -c "/www-data/clixon_restconf -f /usr/local/etc/example.xml " -s /bin/sh www-data
```

Then acess:
Then access:
```
curl -G http://127.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=eth9/type
curl -X GET http://127.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=eth0/type
[
{
"ietf-interfaces:type": "ex:eth"
"ietf-interfaces:type": "clixon-example:eth"
}
]
```
Expand Down
6 changes: 4 additions & 2 deletions example/main/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ Start the clixon restconf daemon
```
then access using curl or wget:
```
curl -G http://127.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=eth9/type
curl -X GET http://127.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=eth1/type
```

More info: (restconf)[../../apps/restconf/README.md].

## Streams

The example has an EXAMPLE stream notification triggering every 5s. To start a notification
Expand All @@ -178,7 +180,7 @@ cli> no notify
cli>
```

Restconf support is also supported, see (restc)[../../apps/restconf/README.md].
Restconf support is also supported, see (restconf)[../../apps/restconf/README.md].


## RPC Operations
Expand Down
5 changes: 3 additions & 2 deletions lib/src/clixon_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ xml2json_vec(FILE *f,
int retval = 1;
cbuf *cb = NULL;

if ((cb = cbuf_new()) ==NULL){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
Expand Down Expand Up @@ -1084,7 +1084,8 @@ json_xmlns_translate(yang_stmt *yspec,
if (xml2ns(x, NULL, &namespace0) < 0)
goto done;
/* Set xmlns="" default namespace attribute (if diff from default) */
if (namespace0==NULL || strcmp(namespace0, namespace)){
if (namespace0 == NULL ||
strcmp(namespace0, namespace)){
if (xmlns_set(x, NULL, namespace) < 0)
goto done;
/* and remove prefix */
Expand Down
Loading

0 comments on commit 6df4340

Please sign in to comment.