Skip to content

Instantly share code, notes, and snippets.

@rwestphal
Created May 22, 2020 15:34
Show Gist options
  • Save rwestphal/cf6b2a23138fc0d2011a8ee8f2e7fc0f to your computer and use it in GitHub Desktop.
Save rwestphal/cf6b2a23138fc0d2011a8ee8f2e7fc0f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
this_dir = File.expand_path(File.dirname(__FILE__))
lib_dir = File.join(this_dir, "ruby")
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
require "grpc"
require "frr-northbound_services_pb"
begin
host = "localhost:50000"
channel_args = { "grpc.max_send_message_length" => -1,
"grpc.max_receive_message_length" => -1 }
stub = Frr::Northbound::Stub.new(host, :this_channel_is_insecure, channel_args: channel_args)
# Prepare Get() parameters.
request = Frr::GetRequest.new
request.type = :STATE
request.encoding = :JSON
request.path = "/frr-vrf:lib/vrf[name='default']"
request.chunk_size = 1000
loop do
# Do the RPC.
response = stub.get(request).next
# Print response.
puts "timestamp: #{response.timestamp}\n"\
"encoding: #{response.data.encoding}\n"\
"#{response.data.data}"
# If the response includes an offset, it means not all data was
# received yet. In that case, Get() needs to be called again but
# this time providing a starting offset (taken from the response
# of the previous call).
break if response.offset.empty?
request.offset = response.offset
end
rescue GRPC::BadStatus => e
puts "Error #{e.code}: #{e.details}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment