diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-18 18:03:04 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-20 10:33:10 +0900 |
commit | 95e68a8d8824874d0919435d7829fdfd2afdc6bc (patch) | |
tree | cc6d231744307f02ac73c97db52d7e8310870238 /server/grpc_server.go | |
parent | f834e421284080a8d4b9150d19148be3b886779e (diff) |
api/cli: refactor api to retrieve policy
make it similar to other policy api
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/grpc_server.go')
-rw-r--r-- | server/grpc_server.go | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index d68ecd96..44c3562d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -63,6 +63,7 @@ const ( REQ_MOD_DEFINED_SET REQ_STATEMENT REQ_MOD_STATEMENT + REQ_POLICY ) const GRPC_PORT = 8080 @@ -326,42 +327,6 @@ func (s *Server) modPolicy(arg *api.PolicyArguments, stream interface{}) error { return nil } -func (s *Server) GetPolicyRoutePolicies(arg *api.PolicyArguments, stream api.GobgpApi_GetPolicyRoutePoliciesServer) error { - var rf bgp.RouteFamily - var reqType int - switch arg.Resource { - case api.Resource_POLICY_ROUTEPOLICY: - reqType = REQ_POLICY_ROUTEPOLICIES - default: - return fmt.Errorf("unsupported resource type: %v", arg.Resource) - } - req := NewGrpcRequest(reqType, "", rf, arg) - s.bgpServerCh <- req - return handleMultipleResponses(req, func(res *GrpcResponse) error { - return stream.Send(res.Data.(*api.PolicyDefinition)) - }) -} - -func (s *Server) GetPolicyRoutePolicy(ctx context.Context, arg *api.PolicyArguments) (*api.PolicyDefinition, error) { - var rf bgp.RouteFamily - var reqType int - switch arg.Resource { - case api.Resource_POLICY_ROUTEPOLICY: - reqType = REQ_POLICY_ROUTEPOLICY - default: - return nil, fmt.Errorf("unsupported resource type: %v", arg.Resource) - } - req := NewGrpcRequest(reqType, "", rf, arg) - s.bgpServerCh <- req - - res := <-req.ResponseCh - if err := res.Err(); err != nil { - log.Debug(err.Error()) - return nil, err - } - return res.Data.(*api.PolicyDefinition), nil -} - func (s *Server) ModPolicyRoutePolicy(stream api.GobgpApi_ModPolicyRoutePolicyServer) error { for { arg, err := stream.Recv() @@ -486,6 +451,22 @@ func (s *Server) ModStatement(ctx context.Context, arg *api.ModStatementArgument return s.mod(REQ_MOD_STATEMENT, arg) } +func (s *Server) GetPolicy(ctx context.Context, arg *api.Policy) (*api.Policy, error) { + d, err := s.get(REQ_POLICY, arg) + if err != nil { + return nil, err + } + return d.(*api.Policy), nil +} + +func (s *Server) GetPolicies(arg *api.Policy, stream api.GobgpApi_GetPoliciesServer) error { + req := NewGrpcRequest(REQ_POLICY, "", bgp.RouteFamily(0), arg) + s.bgpServerCh <- req + return handleMultipleResponses(req, func(res *GrpcResponse) error { + return stream.Send(res.Data.(*api.Policy)) + }) +} + type GrpcRequest struct { RequestType int Name string |