Skip to content

Commit

Permalink
Add ListQosVolume method.
Browse files Browse the repository at this point in the history
Signed-off-by: Artsiom Koltun <[email protected]>
  • Loading branch information
artek-koltun authored and glimchb committed May 4, 2023
1 parent de935a8 commit 1e678a3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/middleend/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"fmt"
"log"

"github.com/google/uuid"
"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -87,6 +89,32 @@ func (s *Server) UpdateQosVolume(_ context.Context, in *pb.UpdateQosVolumeReques
return in.QosVolume, nil
}

// ListQosVolumes lists QoS volumes
func (s *Server) ListQosVolumes(_ context.Context, in *pb.ListQosVolumesRequest) (*pb.ListQosVolumesResponse, error) {
log.Printf("ListQosVolume: Received from client: %v", in)

size, offset, err := server.ExtractPagination(in.PageSize, in.PageToken, s.Pagination)
if err != nil {
log.Printf("error: %v", err)
return nil, err
}

volumes := []*pb.QosVolume{}
for _, qosVolume := range s.volumes.qosVolumes {
volumes = append(volumes, proto.Clone(qosVolume).(*pb.QosVolume))
}

token := ""
log.Printf("Limiting result len(%d) to [%d:%d]", len(volumes), offset, size)
volumes, hasMoreElements := server.LimitPagination(volumes, offset, size)
if hasMoreElements {
token = uuid.New().String()
s.Pagination[token] = offset + size
}

return &pb.ListQosVolumesResponse{QosVolumes: volumes, NextPageToken: token}, nil
}

// GetQosVolume gets a QoS volume
func (s *Server) GetQosVolume(_ context.Context, in *pb.GetQosVolumeRequest) (*pb.QosVolume, error) {
log.Printf("GetQosVolume: Received from client: %v", in)
Expand Down

0 comments on commit 1e678a3

Please sign in to comment.