Rpc call and return format

We have upgraded to confd 6.4 and we are facing the following mismatch for the returned output.

Before the default was xml format. Now we need to add an “Accept” header with xml indication to the curl command in order to get it back in xml.

Why this is changed ? and how can we set a previously to return xml as default.

Even in the documents it is a bit misleading…
at 21.2.3 of the rest api chapter it has an example that notes :
“The value of the Accept HTTP header, in this example: application/yang.data+json, must be a valid media type. Since XML is the default format we need to explicitly request JSON in the example below.”

We will need to change all of our script for our cloud manager in order to adapt to this change

Can you give us an example of when you need to add an “Accept” header?

From the ConfD 6.5 examples.confd/rest/basic/README:

We can get the running config datastore by following the link above:

$ curl -s -u admin:admin http://localhost:8008/api/running

(add -H “Accept: application/vnd.yang.datastore+json” for JSON format)

From the ConfD 6.5 examples.confd/restconf/basic/README:

The ‘data’ resource represents the combined configuration and
state data resources that can be accessed by a client.
We can get everything under this resource by following the link below:

$ curl -s -u admin:admin http://localhost:8008/restconf/data

(add -H “Accept: application/yang-data+json” for JSON format)

As it was up to now while using 6,2 version we were calling

curl -X POST -d @instantiate.json -u admin:admin -H “Content-Type: application/vnd.yang.data+json” http://127.0.0.1:8082/api/operations/vnf-instantiate

where we have defined in the YANG model

rpc vnf-instantiate { … data elements inside… }

The returned format to this was in XML format with 6.2

Now upgrading to 6.5 we get it back in JSON format. In order to get it XML we will need to add the “accept header” at the curl command.

Hence it means that confd defaults now to JSON instead of XML that was to 6.2 Is this right ?

Is there a way to configure it in a way to behave as in 6.2 ?

Hi,
How can I change the below POST requests to get XML back when the request content type is JSON?

$ source ~/tailf/confd-6.2/confdrc
$ pwd
CONFD_DIR/examples.confd/rest/basic
$ make all start
$ confd --version
6.2
$ cat action-params.xml
  <input>
    <clockSettings>1992-12-12T11:11:11</clockSettings>
    <utc>true</utc>
    <syncHardwareClock>true</syncHardwareClock>
  </input>
$ curl -X POST -T action-params.xml -u admin:admin http://localhost:8008/api/running/dhcp/_operations/set-clock
...
<output xmlns='http://yang-central.org/ns/example/dhcp'>
  <systemClock>0000-00-00T03:00:00+00:00</systemClock>
  <hardwareClock>0000-00-00T04:00:00+00:00</hardwareClock>
</output>
...
$ cat action-params.json
{
  "dhcp:input": {
    "clockSettings": "1992-12-12T11:11:11",
    "syncHardwareClock": "true"
  }
}
$ curl -X POST -H "Content-Type: application/vnd.yang.data+json" -T action-params.json -u admin:admin http://localhost:8008/api/running/dhcp/_operations/set-clock
...
{
  "output": {
    "systemClock": "0000-00-00T03:00:00+00:00",
    "hardwareClock": "0000-00-00T04:00:00+00:00"
  }
}
...
$ make stop clean
...
$ source ~/tailf/confd-6.5/confdrc
$ make all start
...
$ confd --version
6.5
$ curl -X POST -T action-params.xml -u admin:admin http://localhost:8008/api/running/dhcp/_operations/set-clock
...
<output xmlns='http://yang-central.org/ns/example/dhcp'>
  <systemClock>0000-00-00T03:00:00+00:00</systemClock>
  <hardwareClock>0000-00-00T04:00:00+00:00</hardwareClock>
</output>
...
$ curl -X POST -H "Content-Type: application/vnd.yang.data+json" -T action-params.json -u admin:admin http://localhost:8008/api/running/dhcp/_operations/set-clock
...
{
  "dhcp:output": {
    "systemClock": "0000-00-00T03:00:00+00:00",
    "hardwareClock": "0000-00-00T04:00:00+00:00"
  }
}
...

Hi,

Yes but what is happening is the following:

With confD 6.2 if you pass the input parameters in “json” format and you don’t add any “accept header” then the response still defautls to XML.

In confd 6,5 you get back JSON since the input parameters are in json !

This is leading to issues with backward compatibility. Neither this is described at the documentation

That’s not what’s happening in my 6.2 based test in my previous post:[quote=“cohult, post:4, topic:1668”]
$ confd --version
6.2

$ curl -X POST -H “Content-Type: application/vnd.yang.data+json” -T action-params.json -u admin:admin http://localhost:8008/api/running/dhcp/_operations/set-clock

{
“output”: {
“systemClock”: “0000-00-00T03:00:00+00:00”,
“hardwareClock”: “0000-00-00T04:00:00+00:00”
}
}

[/quote]

hm…Strange !!!

We didn’t have this behavior. Apart from this we are using
/api/operations/vnf-instantiate

and not

/api/running/…

Do you consider that this might be any configuration issue for part in confd.conf ?

Same result when going through the operations resource to an rpc action:

$ confd --version
6.2
$ curl -X POST -d @action-params.json -u admin:admin -H "Content-Type: application/vnd.yang.data+json" http://localhost:8008/api/operations/set-clock
{
  "output": {
    "systemClock": "0000-00-00T03:00:00+00:00",
    "hardwareClock": "0000-00-00T04:00:00+00:00"
  }
}
$ cat dhcp.yang |grep -A27 "rpc set-clock"
    rpc set-clock {
      tailf:actionpoint actions;
      input {
        leaf clockSettings {
          type yang:date-and-time;
          mandatory true;
        }
        leaf utc {
          type boolean;
          default true;
        }
        leaf syncHardwareClock {
          type boolean;
          default false;
          description "Make sure that the hardware clock is synchronized.";
        }
      }
      output {
        leaf systemClock {
          type yang:date-and-time;
          mandatory true;
        }
        leaf hardwareClock {
          type yang:date-and-time;
          mandatory true;
        }
      }
    }

No.

I can’t reproduce your issue. File a ticket with our support

Ok !
Thank you very much.
The example I see you use are in C. We will file a ticket. Most likely there is a strange or different behavior with Java.

Will try Java too, but the bug seems to be that you get an XML response to a JSON request without an XML accept header. (but I can’t reproduce that behaviour so it could be something in your curl request)

Or add the accept header:

$ confd --version
6.2
$ curl -X POST -d @action-params.json -u admin:admin -H "Content-Type: application/vnd.yang.operation+json" -H "Accept: application/vnd.yang.operation+xml" http://localhost:8008/api/operations/set-clock
<output xmlns='http://yang-central.org/ns/example/dhcp'>
  <systemClock>0000-00-00T03:00:00+00:00</systemClock>
  <hardwareClock>0000-00-00T04:00:00+00:00</hardwareClock>
</output>

It (of course) has nothing to do with Java either:

$ confd --status | grep vsn
vsn: 6.2
$ pwd
CONFD_DIR/examples.confd/intro/java/7-actions
$ curl -X POST -d @action-params-java.json -u admin:admin -H "Content-Type: application/vnd.yang.operation+json" http://localhost:8008/api/operations/config/system/restart
{
  "output": {
    "time": "test-result"
  }
}
$ curl -X POST -d @action-params-java.json -u admin:admin -H "Content-Type: application/vnd.yang.operation+json" -H "Accept: application/vnd.yang.operation+xml" http://localhost:8008/api/operations/config/system/restart
<output xmlns='http://tail-f.com/ns/example/config'>
  <time>test-result</time>
</output>
$ cat action-params-java.json
{
  "input": {
    "mode": "test"
  }
}