PANTHEONtech / lighty

Lightweight OpenDaylight runtime library
https://lighty.io
Eclipse Public License 1.0
134 stars 74 forks source link

Lighty.io doesn't support patch request for container config #715

Closed MuhendisBey closed 3 years ago

MuhendisBey commented 3 years ago

pathc operation doesn't work for container config

Branch lighty.io branch [v 14.x]

To Reproduce Steps to reproduce the behavior:

  1. git checkout https://...
  2. cd lighty
  3. mvn clean install
  4. run restconf-netconf example
  5. add valid netconf device
  6. call this request: URL: http://localhost:8888/restconf/data/network-topology:network-topology/topology=topology-netconf/node=xxx-dhcp/yang-ext:mount/dhcpd-kea:dhcp-kea

BODY: { "subnets": [ { "id":8, "net": "192.168.8.0", "mask": "255.255.255.0", "routers": "192.168.1.3, 192.168.1.8", "tftpAddrs": "192.168.1.3" } ] }

  1. see error: image

Expected behavior user shouldn't get an error.

Environment (please complete the following information):

Here is the yang file

module dhcpd-kea {

  namespace "http://xxx-dhcp.xxx.com/ns/example/dhcpd";
  prefix dhcpd;

  import ietf-inet-types {
    prefix inet;
  }

  import tailf-xsd-types {
    prefix xs;
  }

  organization "xxx AG";

  contact "onur.gursoy@xxx.com";

  description
    "YANG datamodel for kea server subnet config
     (C) 2021-2024 xxx AG";

  revision 2021-06-15 {
    description "Adding key leaf as key into the subnet list";
  }

  revision 2019-02-14 {
    description "Normalized YANG identifier names.";
  }

  revision 2018-11-20 {
    description "YANG header information updated";
  }

  revision 2009-05-19 {
    description "Initial revision.";
  }

  typedef loglevel {
    type enumeration {
        enum kern;
        enum mail;
        enum local7;
    }
  }

  grouping subnet4-list {
    list subnets {
      key id;
      unique "net mask";
      leaf id {
        type uint32;
        }
      leaf net {
        type inet:ipv4-address;
      }
      leaf mask {
        type inet:ipv4-address;
      }
      container range {
        presence "";
        leaf dynamic-bootp {
          type boolean;
          default false;
          description "Enable BOOTP for this instance.";
        }
        leaf low-addr {
          type inet:ipv4-address;
          mandatory true;
          description "Enable BOOTP for this instance.";
        }
        leaf high-addr {
          type inet:ipv4-address;
          mandatory true;
          description "Enable BOOTP for this instance.";
        }
      }
      leaf routers {
        type string;
      }
      leaf tftpAddrs {
        type string;
      }
      leaf ntpAddrs {
        type string;
      }
      leaf dnsAddrs {
        type string;
      }
      leaf max-lease-time {
        type xs:duration;
        default PT7200S;
      }
      leaf default-lease-time {
        type xs:duration;
        default PT600S;
      }
    }
  }

  container dhcp-kea {
    leaf default-lease-time {
      type xs:duration;
      default PT600S;
    }
    leaf max-lease-time {
      type xs:duration;
      default PT7200S;
    }
    leaf log-facility {
      type loglevel;
      default local7;
    }
    uses subnet4-list;
    list shared-network {
      key name;
      max-elements 1024;
      leaf name {
        type string;
      }
      uses subnet4-list;
    }
  }
}
caladi commented 3 years ago

Hello @MuhendisBey,

Please try PATCH request in the format:

curl -X PATCH \
  http://localhost:8888/restconf/data/network-topology:network-topology/topology=topology-netconf/node=xxx-dhcp/yang-ext:mount/dhcpd-kea:dhcp-kea \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 30d2af9f-27b4-977e-92f7-6a2a00fadf9d' \
  -d '{
    "dhcpd-kea:dhcp-kea": {
        "subnets": [
            {
                "id":8,
                "net": "192.168.8.1",
                "mask": "255.255.255.0",
                "routers": "192.168.1.3, 192.168.1.8",
                "tftpAddrs": "192.168.1.3"
            }
        ]
    }
}'

Please, define container in request payload or define list with id in path, for example:

curl -X PATCH \
  http://localhost:8888/restconf/data/network-topology:network-topology/topology=topology-netconf/node=xxx-dhcp/yang-ext:mount/dhcpd-kea:dhcp-kea/subnets=8 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 2dff98c2-78a7-9e45-d144-4bc457df629b' \
  -d '{
    "subnets": [
        {
            "id":8,
            "net": "192.168.8.25",
            "mask": "255.255.255.0",
            "routers": "192.168.1.3, 192.168.1.8",
            "tftpAddrs": "192.168.1.3"
        }
    ]
}'

Please let us know if this works.

MuhendisBey commented 3 years ago

Hello @caladi Thx for your reply, it's working.

In that case, i have two question: 1-> why i can't see them in the swagger? Does swagger render patch endpoints. 2-> As you can see in that yang, Id is the key element. is it possible to change value of id without creating new entry ?

Many thanks, With My Best Regards,