-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (76 loc) · 2.37 KB
/
main.go
File metadata and controls
95 lines (76 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"log/syslog"
"os"
"github.com/Sirupsen/logrus"
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
"github.com/digitalocean/go-metadata"
"github.com/docker/go-plugins-helpers/volume"
flag "github.com/ogier/pflag"
)
const (
DefaultBaseMetadataPath = "/etc/docker/plugins/dostorage/volumes"
DefaultBaseMountPath = "/mnt/dostorage"
DefaultUnixSocketGroup = "docker"
)
var (
// will be set if built using govvv
GitSummary string
DriverVersion = GitSummary
)
type CommandLineArgs struct {
accessToken *string
metadataPath *string
mountPath *string
unixSocketGroup *string
version *bool
}
func main() {
configureLogging()
args := parseCommandLineArgs()
doMetadataClient := metadata.NewClient()
doAPIClient := NewDoAPIClient(*args.accessToken)
doFacade := NewDoFacade(doMetadataClient, doAPIClient)
mountUtil := NewMountUtil()
driver, derr := NewDriver(doFacade, mountUtil, *args.metadataPath, *args.mountPath)
if derr != nil {
logrus.Fatalf("failed to create the driver: %v", derr)
os.Exit(1)
}
handler := volume.NewHandler(driver)
serr := handler.ServeUnix(*args.unixSocketGroup, DriverName)
if serr != nil {
logrus.Fatalf("failed to bind to the Unix socket: %v", serr)
os.Exit(1)
}
for {
// block while requests are served in a separate routine
}
}
func configureLogging() {
syslogHook, herr := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, DriverName)
if herr == nil {
logrus.AddHook(syslogHook)
} else {
logrus.Warn("it was not possible to activate logging to the local syslog")
}
}
func parseCommandLineArgs() *CommandLineArgs {
args := &CommandLineArgs{}
args.accessToken = flag.StringP("access-token", "t", "", "the DigitalOcean API access token")
args.metadataPath = flag.String("metadata-path", DefaultBaseMetadataPath, "the path under which to store volume metadata")
args.mountPath = flag.StringP("mount-path", "m", DefaultBaseMountPath, "the path under which to create the volume mount folders")
args.unixSocketGroup = flag.StringP("unix-socket-group", "g", DefaultUnixSocketGroup, "the group to assign to the Unix socket file")
args.version = flag.Bool("version", false, "outputs the driver version and exits")
flag.Parse()
if *args.version {
fmt.Printf("%v\n", DriverVersion)
os.Exit(0)
}
if *args.accessToken == "" {
flag.Usage()
os.Exit(1)
}
return args
}