Method: Cisco::Client::GRPC#handle_response

Defined in:
lib/cisco_node_utils/client/grpc/client.rb

#handle_response(args, replies) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/cisco_node_utils/client/grpc/client.rb', line 236

def handle_response(args, replies)
  klass = replies[0].class
  unless replies.all? { |r| r.class == klass }
    fail Cisco::ClientError, 'reply class inconsistent: ' +
      replies.map(&:class).join(', ')
  end
  debug "Handling #{replies.length} '#{klass}' reply(s):"
  case klass.to_s
  when /ShowCmdTextReply/
    replies.each { |r| debug "  output:\n#{r.output}" }
    output = replies.map(&:output).join('')
    output = handle_text_output(args, output)
  when /ShowCmdJSONReply/
    # TODO: not yet supported by server to test against
    replies.each { |r| debug "  jsonoutput:\n#{r.jsonoutput}" }
    output = replies.map(&:jsonoutput).join("\n---\n")
  when /CliConfigReply/
    # nothing to process
    output = ''
  when /ConfigGetReply/
    replies.each { |r| debug "  yangjson:\n#{r.yangjson}" }
    output = replies.map(&:yangjson).join('')
  when /GetOperReply/
    replies.each { |r| debug "  yangjson:\n#{r.yangjson}" }
    output = replies.map(&:yangjson).join('')
  when /ConfigReply/
    # nothing to process
    output = ''
  else
    fail Cisco::ClientError, "unsupported reply class #{klass}"
  end
  debug "Success with output:\n#{output}"
  output
end