Method: Rbeapi::Eapilib::EapiConnection#request

Defined in:
lib/rbeapi/eapilib.rb

#request(commands, opts = {}) ⇒ Hash

Generates the eAPI JSON request message.

Examples:

eAPI Request

{
  "jsonrpc": "2.0",
  "method": "runCmds",
  "params": {
    "version": 1,
    "cmds": [
      <commands>
    ],
    "format": [json, text],
  }
  "id": <reqid>
}

Parameters:

  • commands (Array)

    The ordered set of commands that should be included in the eAPI request.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • id (String)

    The value to use for the eAPI request id. If not provided,the object_id for the connection instance will be used.

  • format (String)

    The encoding formation to pass in the eAPI request. Valid values are json or text. The default value is json.

Returns:

  • (Hash)

    Returns a Ruby hash of the request message that is suitable to be JSON encoded and sent to the destination node.



207
208
209
210
211
212
213
214
# File 'lib/rbeapi/eapilib.rb', line 207

def request(commands, opts = {})
  id = opts.fetch(:reqid, object_id)
  format = opts.fetch(:format, 'json')
  cmds = [*commands]
  params = { 'version' => 1, 'cmds' => cmds, 'format' => format }
  { 'jsonrpc' => '2.0', 'method' => 'runCmds',
    'params' => params, 'id' => id }
end