-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
104 lines (81 loc) · 3.26 KB
/
main.go
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
96
97
98
99
100
101
102
103
104
//-----------------------------------------------------------------------------
// This volume driver is meant to be used by docker >= 1.8.x
//
// 1- run the driver:
// sudo docker-volume-rbd
//
// 2- run the container:
// docker run -it --volume-driver rbd -v foo:/foo alpine sh
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Package membership:
//-----------------------------------------------------------------------------
package main
//-----------------------------------------------------------------------------
// Package factored import statement:
//-----------------------------------------------------------------------------
import (
// Standard library:
"flag"
"fmt"
"log"
"os"
"path/filepath"
// Community:
dkvolume "github.com/docker/go-plugins-helpers/volume"
)
//-----------------------------------------------------------------------------
// Package constant declarations factored into a block:
//-----------------------------------------------------------------------------
const (
id = "rbd"
socket = "/var/run/docker/plugins/" + id + ".sock"
)
//-----------------------------------------------------------------------------
// Package variable declarations factored into a block:
//-----------------------------------------------------------------------------
var (
// Predefined defaults:
defVolRoot = filepath.Join(dkvolume.DefaultDockerRootDirectory, id)
// Flags:
volRoot = flag.String("volroot", defVolRoot, "Docker volumes root directory")
defPool = flag.String("pool", "rbd", "Default Ceph pool for RBD operations")
defSize = flag.Int("size", 2048, "Default block device image size")
defFsType = flag.String("fsType", "xfs", "Default file system type for new images")
)
//-----------------------------------------------------------------------------
// func init() is called after all the variable declarations in the package
// have evaluated their initializers, and those are evaluated only after all
// the imported packages have been initialized:
//-----------------------------------------------------------------------------
func init() {
// Check for mandatory argc:
if len(os.Args) < 1 {
usage()
}
// Change the flags on the default logger:
log.SetFlags(log.LstdFlags | log.Lshortfile)
// Parse commandline flags:
flag.Usage = usage
flag.Parse()
}
//-----------------------------------------------------------------------------
// func usage() reports the correct commandline usage for this driver:
//-----------------------------------------------------------------------------
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
//-----------------------------------------------------------------------------
// Function main of package main:
//-----------------------------------------------------------------------------
func main() {
// Request handler with a driver implementation
log.Printf("[Init] INFO volume root is %s\n", *volRoot)
d := initDriver(*volRoot, *defPool, *defFsType, *defSize)
h := dkvolume.NewHandler(&d)
// Listen for requests in a unix socket:
log.Printf("[Init] INFO listening on %s\n", socket)
fmt.Println(h.ServeUnix("", socket))
}