Skip to content

Commit

Permalink
feat: get guest id list for HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
anrs committed May 13, 2023
1 parent 80e2610 commit 386566a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 7 additions & 2 deletions internal/server/grpc/grpc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
// GRPCYavirtd .
type GRPCYavirtd struct {
service *server.Service
pb.UnimplementedYavirtdRPCServer
}

// Ping .
Expand Down Expand Up @@ -64,7 +63,8 @@ func (y *GRPCYavirtd) GetGuest(ctx context.Context, opts *pb.GetGuestOptions) (*
}, nil
}

func (y *GRPCYavirtd) GetGuestIDList(ctx context.Context, opts *pb.GetGuestIDListOptions) (*pb.GetGuestIDListMessage, error) {
// GetGuestIDList gets all local vms' domain names regardless of their metadata validility.
func (y *GRPCYavirtd) GetGuestIDList(ctx context.Context, _ *pb.GetGuestIDListOptions) (*pb.GetGuestIDListMessage, error) {
log.Infof("[grpcserver] get guest id list")
ids, err := y.service.GetGuestIDList(y.service.VirtContext(ctx))
if err != nil {
Expand All @@ -73,6 +73,11 @@ func (y *GRPCYavirtd) GetGuestIDList(ctx context.Context, opts *pb.GetGuestIDLis
return &pb.GetGuestIDListMessage{Ids: ids}, nil
}

// Events
func (y *GRPCYavirtd) Events(*pb.EventsOptions, pb.YavirtdRPC_EventsServer) error {
return errors.New("Events method has not been implemented")
}

// GetGuestUUID .
func (y *GRPCYavirtd) GetGuestUUID(ctx context.Context, opts *pb.GetGuestOptions) (*pb.GetGuestUUIDMessage, error) {
log.Infof("[grpcserver] get guest UUID: %s", opts.Id)
Expand Down
8 changes: 5 additions & 3 deletions internal/server/http/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ func (s *apiServer) dispatchMsg(c *gin.Context, req any, fn func(virt.Context) e
type operate func(virt.Context) (any, error)

func (s *apiServer) dispatch(c *gin.Context, req any, fn operate) {
if err := s.bind(c, req); err != nil {
s.renderErr(c, err)
return
if req != nil {
if err := s.bind(c, req); err != nil {
s.renderErr(c, err)
return
}
}

var resp, err = fn(s.virtContext())
Expand Down
6 changes: 6 additions & 0 deletions internal/server/http/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func (s *apiServer) GetGuest(c *gin.Context) {
})
}

func (s *apiServer) GetGuestIDList(c *gin.Context) {
s.dispatch(c, nil, func(ctx virt.Context) (any, error) {
return s.service.GetGuestIDList(ctx)
})
}

func (s *apiServer) GetGuestUUID(c *gin.Context) {
var req types.GuestReq
s.dispatch(c, &req, func(ctx virt.Context) (any, error) {
Expand Down

0 comments on commit 386566a

Please sign in to comment.