aboutsummaryrefslogtreecommitdiff
path: root/pkg/driver/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/driver/utils.go')
-rw-r--r--pkg/driver/utils.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go
new file mode 100644
index 0000000..2334e27
--- /dev/null
+++ b/pkg/driver/utils.go
@@ -0,0 +1,52 @@
+package driver
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/container-storage-interface/spec/lib/go/csi"
+ "github.com/golang/glog"
+ "golang.org/x/net/context"
+ "google.golang.org/grpc"
+)
+
+func NewIdentityServer(d *SeaweedFsDriver) *IdentityServer {
+ return &IdentityServer{
+ Driver: d,
+ }
+}
+
+func NewControllerServer(d *SeaweedFsDriver) *ControllerServer {
+ return &ControllerServer{
+ Driver: d,
+ }
+}
+
+func NewControllerServiceCapability(cap csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
+ return &csi.ControllerServiceCapability{
+ Type: &csi.ControllerServiceCapability_Rpc{
+ Rpc: &csi.ControllerServiceCapability_RPC{
+ Type: cap,
+ },
+ },
+ }
+}
+
+func ParseEndpoint(ep string) (string, string, error) {
+ if strings.HasPrefix(strings.ToLower(ep), "unix://") || strings.HasPrefix(strings.ToLower(ep), "tcp://") {
+ s := strings.SplitN(ep, "://", 2)
+ if s[1] != "" {
+ return s[0], s[1], nil
+ }
+ }
+ return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
+}
+
+func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
+ glog.V(3).Infof("GRPC call: %s", info.FullMethod)
+ resp, err := handler(ctx, req)
+ if err != nil {
+ glog.Errorf("GRPC error: %v", err)
+ }
+ return resp, err
+}