3.6.1. 编码操作资源输入参数

如果“rpc”或“action”语句具有“input”部分,那么这些输入参数的实例将在定义了“rpc”或“action”语句的模块名称空间中,在名为XML的元素或JSON对象中对“input”进行编码,它位于定义“rpc”或“action”语句的模块名称空间中。

如果“rpc”或“action”语句有一个“input”部分,并且“input”对象树包含任何被认为是强制节点的子数据节点,则消息体必须由客户端在请求中发送。

如果“rpc”或“action”语句具有“input”部分并且“input”对象树不包含任何被认为是强制节点的子节点,则客户端可以在请求中发送消息体。

如果“rpc”或“action”语句没有“input”部分,请求消息必须不包含消息体。

例子:

下面的YANG模块用于本节中的RPC操作示例。

module example-ops {
  namespace "https://example.com/ns/example-ops";
  prefix "ops";

  organization "Example, Inc.";
  contact "support at example.com";
  description "Example Operations Data Model Module.";
  revision "2016-07-07" {
    description "Initial version.";
    reference "example.com document 3-3373.";
  }

  rpc reboot {
    description "Reboot operation.";
    input {
      leaf delay {
        type uint32;
        units "seconds";
        default 0;
        description
          "Number of seconds to wait before initiating the
           reboot operation.";
      }
      leaf message {
        type string;
        description
          "Log message to display when reboot is started.";
      }
      leaf language {
        type string;
        description "Language identifier string.";
        reference "RFC 5646.";
      }
    }
  }

  rpc get-reboot-info {
    description
      "Retrieve parameters used in the last reboot operation.";
    output {
      leaf reboot-time {
        type uint32;
        description
          "The 'delay' parameter used in the last reboot
           operation.";
      }
      leaf message {
        type string;
        description
          "The 'message' parameter used in the last reboot
           operation.";
      }
      leaf language {
        type string;
        description
          "The 'language' parameter used in the last reboot
           operation.";
      }
    }
  }
}

以下的YANG模块用于本节的YANG动作示例。

module example-actions {
  yang-version 1.1;
  namespace "https://example.com/ns/example-actions";
  prefix "act";
  import ietf-yang-types { prefix yang; }

  organization "Example, Inc.";
  contact "support at example.com";
  description "Example Actions Data Model Module.";
  revision "2016-07-07" {
    description "Initial version.";
    reference "example.com document 2-9973.";
  }

  container interfaces {
    description "System interfaces.";
    list interface {
      key name;
      description "One interface entry.";
      leaf name {
        type string;
        description "Interface name.";
      }

      action reset {
        description "Reset an interface.";
        input {
          leaf delay {
            type uint32;
            units "seconds";
            default 0;
            description
              "Number of seconds to wait before starting the
               interface reset.";
          }
        }
      }

      action get-last-reset-time {
        description
          "Retrieve the last interface reset time.";
        output {
          leaf last-reset {
            type yang:date-and-time;
            mandatory true;
            description
              "Date and time of the last interface reset, or
               the last reboot time of the device.";
          }
        }
      }
    }
  }

}

RPC输入示例:

客户端可能会发送以下POST请求消息来调用“reboot”这个RPC操作:

POST /restconf/operations/example-ops:reboot HTTP/1.1
Host: example.com
Content-Type: application/yang-data+xml

<input xmlns="https://example.com/ns/example-ops">
 <delay>600</delay>
 <message>Going down for system maintenance</message>
 <language>en-US</language>
</input>

服务器可能会如下回应:

HTTP/1.1 204 No Content
Date: Thu, 26 Jan 2017 20:56:30 GMT
Server: example-server

这里使用JSON编码显示了相同的示例请求消息:

POST /restconf/operations/example-ops:reboot HTTP/1.1
Host: example.com
Content-Type: application/yang-data+json

{
  "example-ops:input" : {
    "delay" : 600,
    "message" : "Going down for system maintenance",
    "language" : "en-US"
  }
}

操作输入示例:

客户端可能会发送以下POST请求消息来调用“reset”操作:

POST /restconf/data/example-actions:interfaces/\
   interface=eth0/reset HTTP/1.1
Host: example.com
Content-Type: application/yang-data+xml

<input xmlns="https://example.com/ns/example-actions">
  <delay>600</delay>
</input>

服务器可能会如下回应:

HTTP/1.1 204 No Content
Date: Thu, 26 Jan 2017 20:56:30 GMT
Server: example-server

这里使用JSON编码显示了相同的示例请求消息:

POST /restconf/data/example-actions:interfaces/\
  interface=eth0/reset HTTP/1.1
Host: example.com
Content-Type: application/yang-data+json

{ "example-actions:input" : {
    "delay" : 600
  }
}

results matching ""

    No results matching ""