-
Notifications
You must be signed in to change notification settings - Fork 50
/
snapshot.go
118 lines (102 loc) · 2.81 KB
/
snapshot.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
package snapshot
import (
gofig "github.com/akutz/gofig/types"
"github.com/codedellemc/libstorage/api/registry"
"github.com/codedellemc/libstorage/api/server/handlers"
"github.com/codedellemc/libstorage/api/server/httputils"
"github.com/codedellemc/libstorage/api/types"
"github.com/codedellemc/libstorage/api/utils/schema"
)
func init() {
registry.RegisterRouter(&router{})
}
type router struct {
config gofig.Config
routes []types.Route
}
func (r *router) Name() string {
return "snapshot-router"
}
func (r *router) Init(config gofig.Config) {
r.config = config
r.initRoutes()
}
// Routes returns the available routes.
func (r *router) Routes() []types.Route {
return r.routes
}
func (r *router) initRoutes() {
r.routes = []types.Route{
// GET
// get all snapshots from all services
httputils.NewGetRoute(
"snapshots",
"/snapshots",
r.snapshots,
handlers.NewAuthAllSvcsHandler(),
handlers.NewSchemaValidator(
nil, schema.ServiceSnapshotMapSchema, nil),
),
// get all snapshots from a specific service
httputils.NewGetRoute(
"snapshotsForService",
"/snapshots/{service}",
r.snapshotsForService,
handlers.NewServiceValidator(),
handlers.NewAuthSvcHandler(),
handlers.NewStorageSessionHandler(),
handlers.NewSchemaValidator(
nil, schema.SnapshotMapSchema, nil),
),
// get a specific snapshot from a specific service
httputils.NewGetRoute(
"snapshotInspect",
"/snapshots/{service}/{snapshotID}",
r.snapshotInspect,
handlers.NewServiceValidator(),
handlers.NewAuthSvcHandler(),
handlers.NewStorageSessionHandler(),
handlers.NewSchemaValidator(nil, schema.SnapshotSchema, nil),
),
// POST
// create volume from snapshot
httputils.NewPostRoute(
"snapshotCreate",
"/snapshots/{service}/{snapshotID}",
r.volumeCreate,
handlers.NewServiceValidator(),
handlers.NewAuthSvcHandler(),
handlers.NewStorageSessionHandler(),
handlers.NewSchemaValidator(
schema.VolumeCreateRequestSchema,
schema.VolumeSchema,
func() interface{} { return &types.VolumeCreateRequest{} }),
handlers.NewPostArgsHandler(r.config),
).Queries("create"),
// copy snapshot
httputils.NewPostRoute(
"snapshotCopy",
"/snapshots/{service}/{snapshotID}",
r.snapshotCopy,
handlers.NewServiceValidator(),
handlers.NewAuthSvcHandler(),
handlers.NewStorageSessionHandler(),
handlers.NewSchemaValidator(
schema.SnapshotCopyRequestSchema,
schema.SnapshotSchema,
func() interface{} {
return &types.SnapshotCopyRequest{}
}),
handlers.NewPostArgsHandler(r.config),
).Queries("copy"),
// DELETE
httputils.NewDeleteRoute(
"snapshotRemove",
"/snapshots/{service}/{snapshotID}",
r.snapshotRemove,
handlers.NewServiceValidator(),
handlers.NewAuthSvcHandler(),
handlers.NewStorageSessionHandler(),
),
}
}