/
main.go
103 lines (90 loc) · 1.92 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
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/calavera/dkvolume"
"github.com/codegangsta/cli"
"github.com/phoenix-io/docker-iscsi-volume/iscsi"
)
const (
iscsiConf = "/etc/iscsi/iscsid.conf"
iscsiVolumeID = "_iscsiVolume"
socketAddress = "/usr/share/docker/plugins/iscsi-vol.sock"
)
var (
defaultPath = filepath.Join(dkvolume.DefaultDockerRootDirectory, iscsiVolumeID)
)
func main() {
plugin := cli.NewApp()
plugin.Name = "iscsi-docker-plugin"
plugin.Usage = "Manage iSCSI Volumes"
plugin.Version = "0.1.0"
plugin.Commands = []cli.Command{
{
Name: "list",
Usage: "List the iSCSI volumes (added/discovered)",
Action: listVolumes,
},
{
Name: "discover",
Usage: "Perform volume discovery",
Flags: []cli.Flag{
cli.StringFlag{
Name: "target",
Usage: "target IP / hostname for LUN discovery",
},
},
Action: discoverVolumes,
},
{
Name: "login",
Usage: "login the target",
Action: loginTarget,
},
{
Name: "logout",
Usage: "logout the target",
Action: logoutTarget,
},
}
plugin.Run(os.Args)
d := newISCSIVolumeDriver("iscsi")
h := dkvolume.NewHandler(d)
fmt.Println("Listening on ", socketAddress)
fmt.Println(h.ServeUnix("root", socketAddress))
}
func listVolumes(c *cli.Context) {
plugin := iscsi.NewISCSIPlugin()
err := plugin.ListVolumes()
if err != nil {
log.Panic(err)
}
}
func discoverVolumes(c *cli.Context) {
target := c.String("target")
if len(target) == 0 {
cli.ShowCommandHelp(c, "discover")
return
}
plugin := iscsi.NewISCSIPlugin()
err := plugin.DiscoverLUNs(target)
if err != nil {
log.Panic(err)
}
}
func loginTarget(c *cli.Context) {
plugin := iscsi.NewISCSIPlugin()
err := plugin.LoginTarget("", "")
if err != nil {
log.Panic(err)
}
}
func logoutTarget(c *cli.Context) {
plugin := iscsi.NewISCSIPlugin()
err := plugin.LogoutTarget("", "")
if err != nil {
log.Panic(err)
}
}