diff --git a/client/api/system/v1alpha1/api.pb.go b/client/api/system/v1alpha1/api.pb.go new file mode 100644 index 00000000..6eb3ce7f --- /dev/null +++ b/client/api/system/v1alpha1/api.pb.go @@ -0,0 +1,205 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto + +package v1alpha1 + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type GetBIOSSerialNumberRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBIOSSerialNumberRequest) Reset() { *m = GetBIOSSerialNumberRequest{} } +func (m *GetBIOSSerialNumberRequest) String() string { return proto.CompactTextString(m) } +func (*GetBIOSSerialNumberRequest) ProtoMessage() {} +func (*GetBIOSSerialNumberRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_714d71facb074551, []int{0} +} + +func (m *GetBIOSSerialNumberRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Unmarshal(m, b) +} +func (m *GetBIOSSerialNumberRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Marshal(b, m, deterministic) +} +func (m *GetBIOSSerialNumberRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBIOSSerialNumberRequest.Merge(m, src) +} +func (m *GetBIOSSerialNumberRequest) XXX_Size() int { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Size(m) +} +func (m *GetBIOSSerialNumberRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetBIOSSerialNumberRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBIOSSerialNumberRequest proto.InternalMessageInfo + +type GetBIOSSerialNumberResponse struct { + // Serial number + SerialNumber string `protobuf:"bytes,1,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBIOSSerialNumberResponse) Reset() { *m = GetBIOSSerialNumberResponse{} } +func (m *GetBIOSSerialNumberResponse) String() string { return proto.CompactTextString(m) } +func (*GetBIOSSerialNumberResponse) ProtoMessage() {} +func (*GetBIOSSerialNumberResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_714d71facb074551, []int{1} +} + +func (m *GetBIOSSerialNumberResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Unmarshal(m, b) +} +func (m *GetBIOSSerialNumberResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Marshal(b, m, deterministic) +} +func (m *GetBIOSSerialNumberResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBIOSSerialNumberResponse.Merge(m, src) +} +func (m *GetBIOSSerialNumberResponse) XXX_Size() int { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Size(m) +} +func (m *GetBIOSSerialNumberResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetBIOSSerialNumberResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBIOSSerialNumberResponse proto.InternalMessageInfo + +func (m *GetBIOSSerialNumberResponse) GetSerialNumber() string { + if m != nil { + return m.SerialNumber + } + return "" +} + +func init() { + proto.RegisterType((*GetBIOSSerialNumberRequest)(nil), "v1alpha1.GetBIOSSerialNumberRequest") + proto.RegisterType((*GetBIOSSerialNumberResponse)(nil), "v1alpha1.GetBIOSSerialNumberResponse") +} + +func init() { + proto.RegisterFile("src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto", fileDescriptor_714d71facb074551) +} + +var fileDescriptor_714d71facb074551 = []byte{ + // 211 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xf2, 0x29, 0x2e, 0x4a, 0xd6, + 0x4f, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0x2e, 0x4d, 0x4a, 0x2d, + 0xca, 0x4b, 0x2d, 0x49, 0x2d, 0xd6, 0x4d, 0x2e, 0xce, 0xd4, 0x4f, 0x2e, 0xce, 0xd4, 0x2d, 0x28, + 0xca, 0xaf, 0xa8, 0xd4, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x2c, 0xc8, 0xd4, 0x2f, + 0xae, 0x2c, 0x2e, 0x49, 0xcd, 0xd5, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, 0x48, 0x34, 0x04, 0x89, + 0xe9, 0x15, 0x14, 0xe5, 0x97, 0xe4, 0x0b, 0x71, 0xc0, 0xc4, 0x94, 0x64, 0xb8, 0xa4, 0xdc, 0x53, + 0x4b, 0x9c, 0x3c, 0xfd, 0x83, 0x83, 0x53, 0x8b, 0x32, 0x13, 0x73, 0xfc, 0x4a, 0x73, 0x93, 0x52, + 0x8b, 0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x94, 0x9c, 0xb8, 0xa4, 0xb1, 0xca, 0x16, 0x17, + 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0x29, 0x73, 0xf1, 0x16, 0x83, 0xc5, 0xe3, 0xf3, 0xc0, 0x12, 0x12, + 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x3c, 0xc5, 0x48, 0x8a, 0x8d, 0xf2, 0xb8, 0xd8, 0x82, 0xc1, + 0x0e, 0x11, 0x4a, 0xe1, 0x12, 0xc6, 0x62, 0x9a, 0x90, 0x8a, 0x1e, 0xcc, 0x35, 0x7a, 0xb8, 0x9d, + 0x22, 0xa5, 0x4a, 0x40, 0x15, 0xc4, 0x49, 0x4a, 0x0c, 0x4e, 0x0e, 0x51, 0x76, 0x94, 0x85, 0x53, + 0x12, 0x1b, 0x38, 0x90, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x01, 0xa9, 0x3f, 0x74, + 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// SystemClient is the client API for System service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type SystemClient interface { + // GetBIOSSerialNumber returns the device's serial number + GetBIOSSerialNumber(ctx context.Context, in *GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*GetBIOSSerialNumberResponse, error) +} + +type systemClient struct { + cc *grpc.ClientConn +} + +func NewSystemClient(cc *grpc.ClientConn) SystemClient { + return &systemClient{cc} +} + +func (c *systemClient) GetBIOSSerialNumber(ctx context.Context, in *GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*GetBIOSSerialNumberResponse, error) { + out := new(GetBIOSSerialNumberResponse) + err := c.cc.Invoke(ctx, "/v1alpha1.System/GetBIOSSerialNumber", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SystemServer is the server API for System service. +type SystemServer interface { + // GetBIOSSerialNumber returns the device's serial number + GetBIOSSerialNumber(context.Context, *GetBIOSSerialNumberRequest) (*GetBIOSSerialNumberResponse, error) +} + +// UnimplementedSystemServer can be embedded to have forward compatible implementations. +type UnimplementedSystemServer struct { +} + +func (*UnimplementedSystemServer) GetBIOSSerialNumber(ctx context.Context, req *GetBIOSSerialNumberRequest) (*GetBIOSSerialNumberResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBIOSSerialNumber not implemented") +} + +func RegisterSystemServer(s *grpc.Server, srv SystemServer) { + s.RegisterService(&_System_serviceDesc, srv) +} + +func _System_GetBIOSSerialNumber_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBIOSSerialNumberRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SystemServer).GetBIOSSerialNumber(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/v1alpha1.System/GetBIOSSerialNumber", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SystemServer).GetBIOSSerialNumber(ctx, req.(*GetBIOSSerialNumberRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _System_serviceDesc = grpc.ServiceDesc{ + ServiceName: "v1alpha1.System", + HandlerType: (*SystemServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBIOSSerialNumber", + Handler: _System_GetBIOSSerialNumber_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto", +} diff --git a/client/api/system/v1alpha1/api.proto b/client/api/system/v1alpha1/api.proto new file mode 100644 index 00000000..8640c151 --- /dev/null +++ b/client/api/system/v1alpha1/api.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package v1alpha1; + +option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1"; + +service System { + // GetBIOSSerialNumber returns the device's serial number + rpc GetBIOSSerialNumber(GetBIOSSerialNumberRequest) returns (GetBIOSSerialNumberResponse) {} +} + +message GetBIOSSerialNumberRequest { + // Intentionally empty +} + +message GetBIOSSerialNumberResponse { + // Serial number + string serial_number = 1; +} diff --git a/client/groups/system/v1alpha1/client_generated.go b/client/groups/system/v1alpha1/client_generated.go new file mode 100644 index 00000000..7c8a6d6f --- /dev/null +++ b/client/groups/system/v1alpha1/client_generated.go @@ -0,0 +1,56 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "net" + + "github.com/Microsoft/go-winio" + "github.com/kubernetes-csi/csi-proxy/client" + "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "google.golang.org/grpc" +) + +const groupName = "system" + +var version = apiversion.NewVersionOrPanic("v1alpha1") + +type Client struct { + client v1alpha1.SystemClient + connection *grpc.ClientConn +} + +// NewClient returns a client to make calls to the system API group version v1alpha1. +// It's the caller's responsibility to Close the client when done. +func NewClient() (*Client, error) { + pipePath := client.PipePath(groupName, version) + + connection, err := grpc.Dial(pipePath, + grpc.WithContextDialer(func(context context.Context, s string) (net.Conn, error) { + return winio.DialPipeContext(context, s) + }), + grpc.WithInsecure()) + if err != nil { + return nil, err + } + + client := v1alpha1.NewSystemClient(connection) + return &Client{ + client: client, + connection: connection, + }, nil +} + +// Close closes the client. It must be called before the client gets GC-ed. +func (w *Client) Close() error { + return w.connection.Close() +} + +// ensures we implement all the required methods +var _ v1alpha1.SystemClient = &Client{} + +func (w *Client) GetBIOSSerialNumber(context context.Context, request *v1alpha1.GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*v1alpha1.GetBIOSSerialNumberResponse, error) { + return w.client.GetBIOSSerialNumber(context, request, opts...) +} diff --git a/cmd/csi-proxy/main.go b/cmd/csi-proxy/main.go index bea07ee0..ff004a9f 100644 --- a/cmd/csi-proxy/main.go +++ b/cmd/csi-proxy/main.go @@ -6,11 +6,13 @@ import ( diskapi "github.com/kubernetes-csi/csi-proxy/internal/os/disk" filesystemapi "github.com/kubernetes-csi/csi-proxy/internal/os/filesystem" smbapi "github.com/kubernetes-csi/csi-proxy/internal/os/smb" + sysapi "github.com/kubernetes-csi/csi-proxy/internal/os/system" volumeapi "github.com/kubernetes-csi/csi-proxy/internal/os/volume" "github.com/kubernetes-csi/csi-proxy/internal/server" disksrv "github.com/kubernetes-csi/csi-proxy/internal/server/disk" filesystemsrv "github.com/kubernetes-csi/csi-proxy/internal/server/filesystem" smbsrv "github.com/kubernetes-csi/csi-proxy/internal/server/smb" + syssrv "github.com/kubernetes-csi/csi-proxy/internal/server/system" srvtypes "github.com/kubernetes-csi/csi-proxy/internal/server/types" volumesrv "github.com/kubernetes-csi/csi-proxy/internal/server/volume" "golang.org/x/sys/windows" @@ -77,11 +79,17 @@ func apiGroups() ([]srvtypes.APIGroup, error) { return []srvtypes.APIGroup{}, err } + syssrv, err := syssrv.NewServer(sysapi.New()) + if err != nil { + return []srvtypes.APIGroup{}, err + } + return []srvtypes.APIGroup{ fssrv, disksrv, volumesrv, smbsrv, + syssrv, }, nil } diff --git a/integrationtests/system_test.go b/integrationtests/system_test.go new file mode 100644 index 00000000..7ec29016 --- /dev/null +++ b/integrationtests/system_test.go @@ -0,0 +1,33 @@ +package integrationtests + +import ( + "context" + "os/exec" + "strings" + "testing" + + "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" + v1alpha1client "github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1" + "github.com/stretchr/testify/require" +) + +func TestGetBIOSSerialNumber(t *testing.T) { + t.Run("GetBIOSSerialNumber", func(t *testing.T) { + client, err := v1alpha1client.NewClient() + require.Nil(t, err) + defer client.Close() + + request := &v1alpha1.GetBIOSSerialNumberRequest{} + response, err := client.GetBIOSSerialNumber(context.TODO(), request) + require.Nil(t, err) + require.NotNil(t, response) + + result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output() + require.Nil(t, err) + + t.Logf("The serial number is %s", response.SerialNumber) + + resultString := string(result) + require.True(t, strings.Contains(resultString, response.SerialNumber)) + }) +} diff --git a/internal/os/system/api.go b/internal/os/system/api.go new file mode 100644 index 00000000..284e1f67 --- /dev/null +++ b/internal/os/system/api.go @@ -0,0 +1,39 @@ +package system + +import ( + "fmt" + "os/exec" + "strings" +) + +// Implements the System OS API calls. All code here should be very simple +// pass-through to the OS APIs. Any logic around the APIs should go in +// internal/server/system/server.go so that logic can be easily unit-tested +// without requiring specific OS environments. + +type APIImplementor struct{} + +func New() APIImplementor { + return APIImplementor{} +} + +func (APIImplementor) GetBIOSSerialNumber() (string, error) { + // Taken from Kubernetes vSphere cloud provider + // https://github.com/kubernetes/kubernetes/blob/103e926604de6f79161b78af3e792d0ed282bc06/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere_util_windows.go#L28 + result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output() + if err != nil { + return "", err + } + lines := strings.FieldsFunc(string(result), func(r rune) bool { + switch r { + case '\n', '\r': + return true + default: + return false + } + }) + if len(lines) != 2 { + return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result)) + } + return lines[1], nil +} diff --git a/internal/server/system/api_group_generated.go b/internal/server/system/api_group_generated.go new file mode 100644 index 00000000..7ba1afe2 --- /dev/null +++ b/internal/server/system/api_group_generated.go @@ -0,0 +1,27 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package system + +import ( + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "github.com/kubernetes-csi/csi-proxy/internal/server/system/internal" + "github.com/kubernetes-csi/csi-proxy/internal/server/system/internal/v1alpha1" + srvtypes "github.com/kubernetes-csi/csi-proxy/internal/server/types" +) + +const name = "system" + +// ensure the server defines all the required methods +var _ internal.ServerInterface = &Server{} + +func (s *Server) VersionedAPIs() []*srvtypes.VersionedAPI { + v1alpha1Server := v1alpha1.NewVersionedServer(s) + + return []*srvtypes.VersionedAPI{ + { + Group: name, + Version: apiversion.NewVersionOrPanic("v1alpha1"), + Registrant: v1alpha1Server.Register, + }, + } +} diff --git a/internal/server/system/internal/types.go b/internal/server/system/internal/types.go new file mode 100644 index 00000000..a08b3fb9 --- /dev/null +++ b/internal/server/system/internal/types.go @@ -0,0 +1,8 @@ +package internal + +type GetBIOSSerialNumberRequest struct { +} + +type GetBIOSSerialNumberResponse struct { + SerialNumber string +} diff --git a/internal/server/system/internal/types_generated.go b/internal/server/system/internal/types_generated.go new file mode 100644 index 00000000..b029dbc9 --- /dev/null +++ b/internal/server/system/internal/types_generated.go @@ -0,0 +1,19 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package internal + +import ( + "context" + + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "google.golang.org/grpc" +) + +type VersionedAPI interface { + Register(grpcServer *grpc.Server) +} + +// All the functions this group's server needs to define. +type ServerInterface interface { + GetBIOSSerialNumber(context.Context, *GetBIOSSerialNumberRequest, apiversion.Version) (*GetBIOSSerialNumberResponse, error) +} diff --git a/internal/server/system/internal/v1alpha1/conversion.go b/internal/server/system/internal/v1alpha1/conversion.go new file mode 100644 index 00000000..23e83731 --- /dev/null +++ b/internal/server/system/internal/v1alpha1/conversion.go @@ -0,0 +1,3 @@ +package v1alpha1 + +// Add manual conversion functions here to override automatic conversion functions diff --git a/internal/server/system/internal/v1alpha1/conversion_generated.go b/internal/server/system/internal/v1alpha1/conversion_generated.go new file mode 100644 index 00000000..c92883bb --- /dev/null +++ b/internal/server/system/internal/v1alpha1/conversion_generated.go @@ -0,0 +1,46 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" + internal "github.com/kubernetes-csi/csi-proxy/internal/server/system/internal" +) + +func autoConvert_v1alpha1_GetBIOSSerialNumberRequest_To_internal_GetBIOSSerialNumberRequest(in *v1alpha1.GetBIOSSerialNumberRequest, out *internal.GetBIOSSerialNumberRequest) error { + return nil +} + +// Convert_v1alpha1_GetBIOSSerialNumberRequest_To_internal_GetBIOSSerialNumberRequest is an autogenerated conversion function. +func Convert_v1alpha1_GetBIOSSerialNumberRequest_To_internal_GetBIOSSerialNumberRequest(in *v1alpha1.GetBIOSSerialNumberRequest, out *internal.GetBIOSSerialNumberRequest) error { + return autoConvert_v1alpha1_GetBIOSSerialNumberRequest_To_internal_GetBIOSSerialNumberRequest(in, out) +} + +func autoConvert_internal_GetBIOSSerialNumberRequest_To_v1alpha1_GetBIOSSerialNumberRequest(in *internal.GetBIOSSerialNumberRequest, out *v1alpha1.GetBIOSSerialNumberRequest) error { + return nil +} + +// Convert_internal_GetBIOSSerialNumberRequest_To_v1alpha1_GetBIOSSerialNumberRequest is an autogenerated conversion function. +func Convert_internal_GetBIOSSerialNumberRequest_To_v1alpha1_GetBIOSSerialNumberRequest(in *internal.GetBIOSSerialNumberRequest, out *v1alpha1.GetBIOSSerialNumberRequest) error { + return autoConvert_internal_GetBIOSSerialNumberRequest_To_v1alpha1_GetBIOSSerialNumberRequest(in, out) +} + +func autoConvert_v1alpha1_GetBIOSSerialNumberResponse_To_internal_GetBIOSSerialNumberResponse(in *v1alpha1.GetBIOSSerialNumberResponse, out *internal.GetBIOSSerialNumberResponse) error { + out.SerialNumber = in.SerialNumber + return nil +} + +// Convert_v1alpha1_GetBIOSSerialNumberResponse_To_internal_GetBIOSSerialNumberResponse is an autogenerated conversion function. +func Convert_v1alpha1_GetBIOSSerialNumberResponse_To_internal_GetBIOSSerialNumberResponse(in *v1alpha1.GetBIOSSerialNumberResponse, out *internal.GetBIOSSerialNumberResponse) error { + return autoConvert_v1alpha1_GetBIOSSerialNumberResponse_To_internal_GetBIOSSerialNumberResponse(in, out) +} + +func autoConvert_internal_GetBIOSSerialNumberResponse_To_v1alpha1_GetBIOSSerialNumberResponse(in *internal.GetBIOSSerialNumberResponse, out *v1alpha1.GetBIOSSerialNumberResponse) error { + out.SerialNumber = in.SerialNumber + return nil +} + +// Convert_internal_GetBIOSSerialNumberResponse_To_v1alpha1_GetBIOSSerialNumberResponse is an autogenerated conversion function. +func Convert_internal_GetBIOSSerialNumberResponse_To_v1alpha1_GetBIOSSerialNumberResponse(in *internal.GetBIOSSerialNumberResponse, out *v1alpha1.GetBIOSSerialNumberResponse) error { + return autoConvert_internal_GetBIOSSerialNumberResponse_To_v1alpha1_GetBIOSSerialNumberResponse(in, out) +} diff --git a/internal/server/system/internal/v1alpha1/server_generated.go b/internal/server/system/internal/v1alpha1/server_generated.go new file mode 100644 index 00000000..d4b75a34 --- /dev/null +++ b/internal/server/system/internal/v1alpha1/server_generated.go @@ -0,0 +1,47 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + + "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "github.com/kubernetes-csi/csi-proxy/internal/server/system/internal" + "google.golang.org/grpc" +) + +var version = apiversion.NewVersionOrPanic("v1alpha1") + +type versionedAPI struct { + apiGroupServer internal.ServerInterface +} + +func NewVersionedServer(apiGroupServer internal.ServerInterface) internal.VersionedAPI { + return &versionedAPI{ + apiGroupServer: apiGroupServer, + } +} + +func (s *versionedAPI) Register(grpcServer *grpc.Server) { + v1alpha1.RegisterSystemServer(grpcServer, s) +} + +func (s *versionedAPI) GetBIOSSerialNumber(context context.Context, versionedRequest *v1alpha1.GetBIOSSerialNumberRequest) (*v1alpha1.GetBIOSSerialNumberResponse, error) { + request := &internal.GetBIOSSerialNumberRequest{} + if err := Convert_v1alpha1_GetBIOSSerialNumberRequest_To_internal_GetBIOSSerialNumberRequest(versionedRequest, request); err != nil { + return nil, err + } + + response, err := s.apiGroupServer.GetBIOSSerialNumber(context, request, version) + if err != nil { + return nil, err + } + + versionedResponse := &v1alpha1.GetBIOSSerialNumberResponse{} + if err := Convert_internal_GetBIOSSerialNumberResponse_To_v1alpha1_GetBIOSSerialNumberResponse(response, versionedResponse); err != nil { + return nil, err + } + + return versionedResponse, err +} diff --git a/internal/server/system/server.go b/internal/server/system/server.go new file mode 100644 index 00000000..964b3734 --- /dev/null +++ b/internal/server/system/server.go @@ -0,0 +1,36 @@ +package system + +import ( + "context" + + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "github.com/kubernetes-csi/csi-proxy/internal/server/system/internal" + "k8s.io/klog" +) + +type Server struct { + hostAPI API +} + +type API interface { + GetBIOSSerialNumber() (string, error) +} + +func NewServer(hostAPI API) (*Server, error) { + return &Server{ + hostAPI: hostAPI, + }, nil +} + +func (s *Server) GetBIOSSerialNumber(context context.Context, request *internal.GetBIOSSerialNumberRequest, version apiversion.Version) (*internal.GetBIOSSerialNumberResponse, error) { + klog.V(4).Infof("calling GetBIOSSerialNumber") + response := &internal.GetBIOSSerialNumberResponse{} + serialNumber, err := s.hostAPI.GetBIOSSerialNumber() + if err != nil { + klog.Errorf("failed GetBIOSSerialNumber: %v", err) + return response, err + } + + response.SerialNumber = serialNumber + return response, nil +} diff --git a/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.pb.go b/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.pb.go new file mode 100644 index 00000000..6eb3ce7f --- /dev/null +++ b/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.pb.go @@ -0,0 +1,205 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto + +package v1alpha1 + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +type GetBIOSSerialNumberRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBIOSSerialNumberRequest) Reset() { *m = GetBIOSSerialNumberRequest{} } +func (m *GetBIOSSerialNumberRequest) String() string { return proto.CompactTextString(m) } +func (*GetBIOSSerialNumberRequest) ProtoMessage() {} +func (*GetBIOSSerialNumberRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_714d71facb074551, []int{0} +} + +func (m *GetBIOSSerialNumberRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Unmarshal(m, b) +} +func (m *GetBIOSSerialNumberRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Marshal(b, m, deterministic) +} +func (m *GetBIOSSerialNumberRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBIOSSerialNumberRequest.Merge(m, src) +} +func (m *GetBIOSSerialNumberRequest) XXX_Size() int { + return xxx_messageInfo_GetBIOSSerialNumberRequest.Size(m) +} +func (m *GetBIOSSerialNumberRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetBIOSSerialNumberRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBIOSSerialNumberRequest proto.InternalMessageInfo + +type GetBIOSSerialNumberResponse struct { + // Serial number + SerialNumber string `protobuf:"bytes,1,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBIOSSerialNumberResponse) Reset() { *m = GetBIOSSerialNumberResponse{} } +func (m *GetBIOSSerialNumberResponse) String() string { return proto.CompactTextString(m) } +func (*GetBIOSSerialNumberResponse) ProtoMessage() {} +func (*GetBIOSSerialNumberResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_714d71facb074551, []int{1} +} + +func (m *GetBIOSSerialNumberResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Unmarshal(m, b) +} +func (m *GetBIOSSerialNumberResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Marshal(b, m, deterministic) +} +func (m *GetBIOSSerialNumberResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBIOSSerialNumberResponse.Merge(m, src) +} +func (m *GetBIOSSerialNumberResponse) XXX_Size() int { + return xxx_messageInfo_GetBIOSSerialNumberResponse.Size(m) +} +func (m *GetBIOSSerialNumberResponse) XXX_DiscardUnknown() { + xxx_messageInfo_GetBIOSSerialNumberResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBIOSSerialNumberResponse proto.InternalMessageInfo + +func (m *GetBIOSSerialNumberResponse) GetSerialNumber() string { + if m != nil { + return m.SerialNumber + } + return "" +} + +func init() { + proto.RegisterType((*GetBIOSSerialNumberRequest)(nil), "v1alpha1.GetBIOSSerialNumberRequest") + proto.RegisterType((*GetBIOSSerialNumberResponse)(nil), "v1alpha1.GetBIOSSerialNumberResponse") +} + +func init() { + proto.RegisterFile("src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto", fileDescriptor_714d71facb074551) +} + +var fileDescriptor_714d71facb074551 = []byte{ + // 211 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xf2, 0x29, 0x2e, 0x4a, 0xd6, + 0x4f, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0xcf, 0x2e, 0x4d, 0x4a, 0x2d, + 0xca, 0x4b, 0x2d, 0x49, 0x2d, 0xd6, 0x4d, 0x2e, 0xce, 0xd4, 0x4f, 0x2e, 0xce, 0xd4, 0x2d, 0x28, + 0xca, 0xaf, 0xa8, 0xd4, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0x4f, 0x2c, 0xc8, 0xd4, 0x2f, + 0xae, 0x2c, 0x2e, 0x49, 0xcd, 0xd5, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, 0x48, 0x34, 0x04, 0x89, + 0xe9, 0x15, 0x14, 0xe5, 0x97, 0xe4, 0x0b, 0x71, 0xc0, 0xc4, 0x94, 0x64, 0xb8, 0xa4, 0xdc, 0x53, + 0x4b, 0x9c, 0x3c, 0xfd, 0x83, 0x83, 0x53, 0x8b, 0x32, 0x13, 0x73, 0xfc, 0x4a, 0x73, 0x93, 0x52, + 0x8b, 0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x94, 0x9c, 0xb8, 0xa4, 0xb1, 0xca, 0x16, 0x17, + 0xe4, 0xe7, 0x15, 0xa7, 0x0a, 0x29, 0x73, 0xf1, 0x16, 0x83, 0xc5, 0xe3, 0xf3, 0xc0, 0x12, 0x12, + 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x3c, 0xc5, 0x48, 0x8a, 0x8d, 0xf2, 0xb8, 0xd8, 0x82, 0xc1, + 0x0e, 0x11, 0x4a, 0xe1, 0x12, 0xc6, 0x62, 0x9a, 0x90, 0x8a, 0x1e, 0xcc, 0x35, 0x7a, 0xb8, 0x9d, + 0x22, 0xa5, 0x4a, 0x40, 0x15, 0xc4, 0x49, 0x4a, 0x0c, 0x4e, 0x0e, 0x51, 0x76, 0x94, 0x85, 0x53, + 0x12, 0x1b, 0x38, 0x90, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x01, 0xa9, 0x3f, 0x74, + 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// SystemClient is the client API for System service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type SystemClient interface { + // GetBIOSSerialNumber returns the device's serial number + GetBIOSSerialNumber(ctx context.Context, in *GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*GetBIOSSerialNumberResponse, error) +} + +type systemClient struct { + cc *grpc.ClientConn +} + +func NewSystemClient(cc *grpc.ClientConn) SystemClient { + return &systemClient{cc} +} + +func (c *systemClient) GetBIOSSerialNumber(ctx context.Context, in *GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*GetBIOSSerialNumberResponse, error) { + out := new(GetBIOSSerialNumberResponse) + err := c.cc.Invoke(ctx, "/v1alpha1.System/GetBIOSSerialNumber", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// SystemServer is the server API for System service. +type SystemServer interface { + // GetBIOSSerialNumber returns the device's serial number + GetBIOSSerialNumber(context.Context, *GetBIOSSerialNumberRequest) (*GetBIOSSerialNumberResponse, error) +} + +// UnimplementedSystemServer can be embedded to have forward compatible implementations. +type UnimplementedSystemServer struct { +} + +func (*UnimplementedSystemServer) GetBIOSSerialNumber(ctx context.Context, req *GetBIOSSerialNumberRequest) (*GetBIOSSerialNumberResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBIOSSerialNumber not implemented") +} + +func RegisterSystemServer(s *grpc.Server, srv SystemServer) { + s.RegisterService(&_System_serviceDesc, srv) +} + +func _System_GetBIOSSerialNumber_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBIOSSerialNumberRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SystemServer).GetBIOSSerialNumber(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/v1alpha1.System/GetBIOSSerialNumber", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SystemServer).GetBIOSSerialNumber(ctx, req.(*GetBIOSSerialNumberRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _System_serviceDesc = grpc.ServiceDesc{ + ServiceName: "v1alpha1.System", + HandlerType: (*SystemServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBIOSSerialNumber", + Handler: _System_GetBIOSSerialNumber_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "src/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto", +} diff --git a/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto b/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto new file mode 100644 index 00000000..8640c151 --- /dev/null +++ b/vendor/github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1/api.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package v1alpha1; + +option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1"; + +service System { + // GetBIOSSerialNumber returns the device's serial number + rpc GetBIOSSerialNumber(GetBIOSSerialNumberRequest) returns (GetBIOSSerialNumberResponse) {} +} + +message GetBIOSSerialNumberRequest { + // Intentionally empty +} + +message GetBIOSSerialNumberResponse { + // Serial number + string serial_number = 1; +} diff --git a/vendor/github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1/client_generated.go b/vendor/github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1/client_generated.go new file mode 100644 index 00000000..7c8a6d6f --- /dev/null +++ b/vendor/github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1/client_generated.go @@ -0,0 +1,56 @@ +// Code generated by csi-proxy-api-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "net" + + "github.com/Microsoft/go-winio" + "github.com/kubernetes-csi/csi-proxy/client" + "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1" + "github.com/kubernetes-csi/csi-proxy/client/apiversion" + "google.golang.org/grpc" +) + +const groupName = "system" + +var version = apiversion.NewVersionOrPanic("v1alpha1") + +type Client struct { + client v1alpha1.SystemClient + connection *grpc.ClientConn +} + +// NewClient returns a client to make calls to the system API group version v1alpha1. +// It's the caller's responsibility to Close the client when done. +func NewClient() (*Client, error) { + pipePath := client.PipePath(groupName, version) + + connection, err := grpc.Dial(pipePath, + grpc.WithContextDialer(func(context context.Context, s string) (net.Conn, error) { + return winio.DialPipeContext(context, s) + }), + grpc.WithInsecure()) + if err != nil { + return nil, err + } + + client := v1alpha1.NewSystemClient(connection) + return &Client{ + client: client, + connection: connection, + }, nil +} + +// Close closes the client. It must be called before the client gets GC-ed. +func (w *Client) Close() error { + return w.connection.Close() +} + +// ensures we implement all the required methods +var _ v1alpha1.SystemClient = &Client{} + +func (w *Client) GetBIOSSerialNumber(context context.Context, request *v1alpha1.GetBIOSSerialNumberRequest, opts ...grpc.CallOption) (*v1alpha1.GetBIOSSerialNumberResponse, error) { + return w.client.GetBIOSSerialNumber(context, request, opts...) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index eb96e687..db280936 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,6 +19,7 @@ github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta1 github.com/kubernetes-csi/csi-proxy/client/api/smb/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/api/smb/v1beta1 +github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/api/volume/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1 github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta2 @@ -26,6 +27,7 @@ github.com/kubernetes-csi/csi-proxy/client/apiversion github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1beta1 github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta1 github.com/kubernetes-csi/csi-proxy/client/groups/smb/v1beta1 +github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1alpha1 github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1 # github.com/pkg/errors v0.8.1