diff --git a/gosdn-cli/gosdn-cli.go b/gosdn-cli/gosdn-cli.go index daf42cfe93bb1de1ab3bc95953a08f79a867cbaf..52e73a71def5bf1ce12ef8126b5161cc14bc8644 100644 --- a/gosdn-cli/gosdn-cli.go +++ b/gosdn-cli/gosdn-cli.go @@ -43,7 +43,9 @@ var commandList = map[string]commandOptions{ "hello": {"hello", "test connection to goSDN controller", goSDNSayHello}, "shutdown": {"shutdown", "request goSDN controller to shutdown", goSDNShutdown}, "testdb" : {"testdb", "test all database connections", goSDNTestDB}, - "tapigetnodes" : {"testdb", "test all database connections", goSDNTestDB}, + "tapigetedge" : {"tapigetedge", "get list of edges", TAPIGetEdge}, + "tapigetedgenode" : {"tapigetedgenode", "get list of edgenodes", TAPIGetEdgeNode}, + "tapigetlink" : {"tapigetlink", "get list of links", TAPIGetLink}, } /* @@ -119,8 +121,6 @@ func main() { } } -func goSDNSayHello(conn *grpc.ClientConn) { - func goSDNSayHello (conn *grpc.ClientConn) { c := pb.NewGrpcCliClient(conn) @@ -158,5 +158,59 @@ func goSDNShutdown(conn *grpc.ClientConn) { } func goSDNTestDB(conn *grpc.ClientConn) { - // TODO: fill with code + // TODO: fill with code and also see if grpc interface has this stub implemented. } + + +func TAPIGetEdge(conn *grpc.ClientConn) { + + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetEdge(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetEdge said: %s", r.GetMessage()) +} + +func TAPIGetEdgeNode(conn *grpc.ClientConn) { + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetEdgeNode(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetEdgeNode said: %s", r.GetMessage()) +} + +func TAPIGetLink(conn *grpc.ClientConn) { + + c := pb.NewGrpcCliClient(conn) + + // Contact the server and print out its response. + name := defaultName + if len(os.Args) > 1 { + name = os.Args[0] + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + r, err := c.TAPIGetLink(ctx, &pb.TAPIRequest{Name: name}) + if err != nil { + log.Fatalf("could not request shutdown: %v", err) + } + log.Printf("TAPIGetLink said: %s", r.GetMessage()) +} \ No newline at end of file diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index c0bce2a5d7f3d8ddfe0bf140174bf882e93b114d..581acceabed1423d9af20fa46322a0c9a442cd71 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -55,6 +55,7 @@ func (s *server) TAPIGetEdge(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR log.Info("Received: %v", in.GetName()) if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodes(); err != nil { log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil } return &pb.TAPIReply{Message: "Done"}, nil } @@ -63,6 +64,7 @@ func (s *server) TAPIGetEdgeNode(ctx context.Context, in *pb.TAPIRequest) (*pb.T log.Info("Received: %v", in.GetName()) if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetNodeEdgePoints(); err != nil { log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil } return &pb.TAPIReply{Message: "Done"}, nil } @@ -71,6 +73,7 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR log.Info("Received: %v", in.GetName()) if err := s.core.clients["ciena-mcp"].(*ciena.MCPClient).GetLinks(); err != nil { log.Error(err) + return &pb.TAPIReply{Message: "TAPI error"}, nil } return &pb.TAPIReply{Message: "Done"}, nil }