-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphc.go
137 lines (124 loc) · 2.9 KB
/
graphc.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
"github.com/willmtemple/graphc/graphdriver"
_ "github.com/willmtemple/graphc/graphdriver/vfs"
)
func initDriver(c *cli.Context) graphdriver.Driver {
graphdriver.DefaultDriver = c.GlobalString("driver")
homedir := c.GlobalString("home")
drv, err := graphdriver.New(homedir, []string{})
if err != nil {
fmt.Printf("Failed to instantiate graphdriver: %s\n", err)
os.Exit(1)
}
fmt.Printf("[DEBUG] Using driver %s.\n%g\nHome directory: %s\n", drv.String(), drv.Status(), homedir)
return drv
}
func create(c *cli.Context) {
driver := initDriver(c)
id := c.Args().First()
if err := driver.Create(id, c.String("parent")); err != nil {
fmt.Printf("Failed to create %s: %s\n", id, err)
os.Exit(1)
}
}
func remove(c *cli.Context) {
driver := initDriver(c)
id := c.Args().First()
if err := driver.Remove(id); err != nil {
fmt.Printf("Failed to remove %s: %s\n", id, err)
os.Exit(1)
}
}
func get(c *cli.Context) {
driver := initDriver(c)
id := c.Args().First()
loc, err := driver.Get(id, c.GlobalString("context"))
if err != nil {
fmt.Printf("Failed to Get %s: %s\n", id, err)
os.Exit(1)
}
fmt.Printf("%s is available at %s\n", id, loc)
}
func put(c *cli.Context) {
driver := initDriver(c)
id := c.Args().First()
if err := driver.Put(id); err != nil {
fmt.Printf("Failed to Put %s: %s\n", id, err)
os.Exit(1)
}
}
func clean(c *cli.Context) {
driver := initDriver(c)
if err := driver.Cleanup(); err != nil {
fmt.Printf("Failed to clean up: %s\n", err)
}
}
func main() {
graphc := cli.NewApp()
graphc.Name = "graphc"
graphc.Usage = "manage graphc storage"
graphc.Flags = []cli.Flag{
cli.StringFlag{
Name: "home",
Value: "/var/lib/docker/",
Usage: "home directory for graphdriver storage operations",
EnvVar: "GRAPHDRIVER_HOME",
},
cli.StringFlag{
Name: "driver, s",
Value: "",
Usage: "storage backend to use",
EnvVar: "GRAPHDRIVER_BACKEND",
},
cli.StringFlag{
Name: "context, c",
Value: "",
Usage: "optional mountlabel (SELinux context)",
},
}
graphc.EnableBashCompletion = true
graphc.Commands = []cli.Command{
{
Name: "create",
Aliases: []string{"c"},
Usage: "create a new storage for id",
Flags: []cli.Flag{
cli.StringFlag{
Name: "parent, p",
Value: "",
Usage: "an id of which the new image will initially be a copy",
},
},
Action: create,
},
{
Name: "remove",
Aliases: []string{"r"},
Usage: "remove storage for id",
Action: remove,
},
{
Name: "get",
Aliases: []string{"g"},
Usage: "mount an image to the filesystem",
Action: get,
},
{
Name: "put",
Aliases: []string{"p"},
Usage: "unmount an image from the filesystem",
Action: put,
},
{
Name: "clean",
Aliases: []string{},
Usage: "clean up stateful artifacts",
Action: clean,
},
}
graphc.Run(os.Args)
}