Method: Cisco::Client::GRPC#yang_req
- Defined in:
- lib/cisco_node_utils/client/grpc/client.rb
#yang_req(stub, type, args) ⇒ Object
Send a YANG request via gRPC
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/cisco_node_utils/client/grpc/client.rb', line 192 def yang_req(stub, type, args) debug "Sending '#{type}' request:" if args.is_a?(ConfigGetArgs) debug " with yangpathjson: #{args.yangpathjson}" elsif args.is_a?(ConfigArgs) debug " with yangjson: #{args.yangjson}" end output = Cisco::Client.silence_warnings do response = stub.send(type, args, timeout: @timeout, username: @username, password: @password) # gRPC server may split the response into multiples response = response.is_a?(Enumerator) ? response.to_a : [response] debug "Got responses: #{response.map(&:class).join(', ')}" debug "response: #{response}" # Check for errors first handle_errors(args, response.select { |r| !r.errors.empty? }) # If we got here, no errors occurred handle_response(args, response) end return output rescue ::GRPC::BadStatus => e warn "gRPC error '#{e.code}' during '#{type}' request: " if args.is_a?(ConfigGetArgs) debug " with yangpathjson: #{args.yangpathjson}" elsif args.is_a?(ConfigArgs) debug " with yangjson: #{args.yangjson}" end warn " '#{e.details}'" case e.code when ::GRPC::Core::StatusCodes::UNAVAILABLE raise Cisco::ConnectionRefused, "Connection refused: #{e.details}" when ::GRPC::Core::StatusCodes::UNAUTHENTICATED raise Cisco::AuthenticationFailed, e.details else raise Cisco::ClientError, e.details end end |