Skip to content

Commit

Permalink
codedup: start using aip-go
Browse files Browse the repository at this point in the history
Related to opiproject#326

This will help us maintain less code

Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Jun 5, 2023
1 parent 021e9f6 commit 1028110
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
require (
github.com/digitalocean/go-libvirt v0.0.0-20220804181439-8648fbde413e // indirect
github.com/golang/protobuf v1.5.3 // indirect
go.einride.tech/aip v0.60.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.einride.tech/aip v0.60.0 h1:h6bgabZ5BCfAptbGex8jbh3VvPBRLa6xq+pQ1CAjHYw=
go.einride.tech/aip v0.60.0/go.mod h1:SdLbSbgSU60Xkb4TMkmsZEQPHeEWx0ikBoq5QnqZvdg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand Down
3 changes: 2 additions & 1 deletion pkg/backend/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -32,7 +33,7 @@ func sortAioControllers(controllers []*pb.AioController) {
func (s *Server) CreateAioController(_ context.Context, in *pb.CreateAioControllerRequest) (*pb.AioController, error) {
log.Printf("CreateAioController: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.AioControllerId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.AioControllerId, in.AioController.Name)
resourceID = in.AioControllerId
Expand Down
3 changes: 2 additions & 1 deletion pkg/backend/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -33,7 +34,7 @@ func sortNullDebugs(nullDebugs []*pb.NullDebug) {
func (s *Server) CreateNullDebug(_ context.Context, in *pb.CreateNullDebugRequest) (*pb.NullDebug, error) {
log.Printf("CreateNullDebug: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.NullDebugId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NullDebugId, in.NullDebug.Name)
resourceID = in.NullDebugId
Expand Down
3 changes: 2 additions & 1 deletion pkg/backend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -33,7 +34,7 @@ func sortNVMfRemoteControllers(controllers []*pb.NVMfRemoteController) {
func (s *Server) CreateNVMfRemoteController(_ context.Context, in *pb.CreateNVMfRemoteControllerRequest) (*pb.NVMfRemoteController, error) {
log.Printf("CreateNVMfRemoteController: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.NvMfRemoteControllerId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvMfRemoteControllerId, in.NvMfRemoteController.Name)
resourceID = in.NvMfRemoteControllerId
Expand Down
5 changes: 3 additions & 2 deletions pkg/frontend/blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"path"
"sort"

"github.com/google/uuid"
"github.com/opiproject/gospdk/spdk"
pc "github.com/opiproject/opi-api/common/v1/gen/go"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -33,7 +34,7 @@ func sortVirtioBlks(virtioBlks []*pb.VirtioBlk) {
func (s *Server) CreateVirtioBlk(_ context.Context, in *pb.CreateVirtioBlkRequest) (*pb.VirtioBlk, error) {
log.Printf("CreateVirtioBlk: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.VirtioBlkId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.VirtioBlkId, in.VirtioBlk.Name)
resourceID = in.VirtioBlkId
Expand Down
7 changes: 4 additions & 3 deletions pkg/frontend/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand Down Expand Up @@ -97,7 +98,7 @@ func (c *tcpSubsystemListener) Params(_ *pb.NvmeController, nqn string) spdk.Nvm
func (s *Server) CreateNvmeSubsystem(_ context.Context, in *pb.CreateNvmeSubsystemRequest) (*pb.NvmeSubsystem, error) {
log.Printf("CreateNvmeSubsystem: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.NvmeSubsystemId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeSubsystemId, in.NvmeSubsystem.Name)
resourceID = in.NvmeSubsystemId
Expand Down Expand Up @@ -279,7 +280,7 @@ func (s *Server) CreateNvmeController(_ context.Context, in *pb.CreateNvmeContro
return nil, status.Error(codes.InvalidArgument, "invalid input subsystem parameters")
}
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.NvmeControllerId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeControllerId, in.NvmeController.Name)
resourceID = in.NvmeControllerId
Expand Down Expand Up @@ -423,7 +424,7 @@ func (s *Server) CreateNvmeNamespace(_ context.Context, in *pb.CreateNvmeNamespa
return nil, status.Error(codes.InvalidArgument, "invalid input subsystem parameters")
}
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.NvmeNamespaceId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.NvmeNamespaceId, in.NvmeNamespace.Name)
resourceID = in.NvmeNamespaceId
Expand Down
5 changes: 3 additions & 2 deletions pkg/frontend/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opiproject/opi-spdk-bridge/pkg/server"

"github.com/google/uuid"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -33,7 +34,7 @@ func sortScsiControllers(controllers []*pb.VirtioScsiController) {
func (s *Server) CreateVirtioScsiController(_ context.Context, in *pb.CreateVirtioScsiControllerRequest) (*pb.VirtioScsiController, error) {
log.Printf("CreateVirtioScsiController: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.VirtioScsiControllerId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.VirtioScsiControllerId, in.VirtioScsiController.Name)
resourceID = in.VirtioScsiControllerId
Expand Down Expand Up @@ -188,7 +189,7 @@ func (s *Server) VirtioScsiControllerStats(_ context.Context, in *pb.VirtioScsiC
func (s *Server) CreateVirtioScsiLun(_ context.Context, in *pb.CreateVirtioScsiLunRequest) (*pb.VirtioScsiLun, error) {
log.Printf("CreateVirtioScsiLun: Received from client: %v", in)
// see https://google.aip.dev/133#user-specified-ids
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.VirtioScsiLunId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.VirtioScsiLunId, in.VirtioScsiLun.Name)
resourceID = in.VirtioScsiLunId
Expand Down
3 changes: 2 additions & 1 deletion pkg/middleend/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -32,7 +33,7 @@ func sortEncryptedVolumes(volumes []*pb.EncryptedVolume) {
func (s *Server) CreateEncryptedVolume(_ context.Context, in *pb.CreateEncryptedVolumeRequest) (*pb.EncryptedVolume, error) {
log.Printf("CreateEncryptedVolume: Received from client: %v", in)

resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.EncryptedVolumeId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.EncryptedVolumeId, in.EncryptedVolume.Name)
resourceID = in.EncryptedVolumeId
Expand Down
3 changes: 2 additions & 1 deletion pkg/middleend/qos.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/opiproject/gospdk/spdk"
pb "github.com/opiproject/opi-api/storage/v1alpha1/gen/go"
"github.com/opiproject/opi-spdk-bridge/pkg/server"
"go.einride.tech/aip/resourceid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand All @@ -29,7 +30,7 @@ func sortQosVolumes(volumes []*pb.QosVolume) {
// CreateQosVolume creates a QoS volume
func (s *Server) CreateQosVolume(_ context.Context, in *pb.CreateQosVolumeRequest) (*pb.QosVolume, error) {
log.Printf("CreateQosVolume: Received from client: %v", in)
resourceID := uuid.New().String()
resourceID := resourceid.NewSystemGenerated()
if in.QosVolumeId != "" {
log.Printf("client provided the ID of a resource %v, ignoring the name field %v", in.QosVolumeId, in.QosVolume.Name)
resourceID = in.QosVolumeId
Expand Down

0 comments on commit 1028110

Please sign in to comment.