forked from thecodeteam/goisilon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_v1_volumes.go
143 lines (124 loc) · 3.16 KB
/
api_v1_volumes.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
138
139
140
141
142
143
package v1
import (
"context"
"path"
"github.com/thecodeteam/goisilon/api"
)
var (
aclQS = api.OrderedValues{{[]byte("acl")}}
metadataQS = api.OrderedValues{{[]byte("metadata")}}
recursiveTrueQS = api.OrderedValues{
{[]byte("recursive"), []byte("true")},
}
createVolumeHeaders = map[string]string{
"x-isi-ifs-target-type": "container",
"x-isi-ifs-access-control": "public_read_write",
}
)
// GetIsiVolumes queries a list of all volumes on the cluster
func GetIsiVolumes(
ctx context.Context,
client api.Client) (resp *getIsiVolumesResp, err error) {
// PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volumes/
err = client.Get(ctx, realNamespacePath(client), "", nil, nil, &resp)
return resp, err
}
// CreateIsiVolume makes a new volume on the cluster
func CreateIsiVolume(
ctx context.Context,
client api.Client,
name string) (resp *getIsiVolumesResp, err error) {
// PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name
// x-isi-ifs-target-type: container
// x-isi-ifs-access-control: public_read_write
//
// PUT https://1.2.3.4:8080/namespace/path/to/volumes/volume_name?acl
// {authoritative: "acl",
// action: "update",
// owner: {name: "username", type: "user"},
// group: {name: "groupname", type: "group"}
// }
// create the volume
err = client.Put(
ctx,
realNamespacePath(client),
name,
nil,
createVolumeHeaders,
nil,
&resp)
if err != nil {
return resp, err
}
var data = &AclRequest{
"acl",
"update",
&Ownership{client.User(), "user"},
nil,
}
if group := client.Group(); group != "" {
data.Group = &Ownership{group, "group"}
}
// set the ownership of the volume
err = client.Put(
ctx,
realNamespacePath(client),
name,
aclQS,
nil,
data,
&resp)
return resp, err
}
// GetIsiVolume queries the attributes of a volume on the cluster
func GetIsiVolume(
ctx context.Context,
client api.Client,
name string) (resp *getIsiVolumeAttributesResp, err error) {
// PAPI call: GET https://1.2.3.4:8080/namespace/path/to/volume/?metadata
err = client.Get(
ctx,
realNamespacePath(client),
name,
metadataQS,
nil,
&resp)
return resp, err
}
// DeleteIsiVolume removes a volume from the cluster
func DeleteIsiVolume(
ctx context.Context,
client api.Client,
name string) (resp *getIsiVolumesResp, err error) {
err = client.Delete(
ctx,
realNamespacePath(client),
name,
recursiveTrueQS,
nil,
&resp)
return resp, err
}
// CopyIsiVolume creates a new volume on the cluster based on an existing volume
func CopyIsiVolume(
ctx context.Context,
client api.Client,
sourceName, destinationName string) (resp *getIsiVolumesResp, err error) {
// PAPI calls: PUT https://1.2.3.4:8080/namespace/path/to/volumes/destination_volume_name
// x-isi-ifs-copy-source: /path/to/volumes/source_volume_name
// copy the volume
err = client.Put(
ctx,
realNamespacePath(client),
destinationName,
nil,
map[string]string{
"x-isi-ifs-copy-source": path.Join(
"/",
realNamespacePath(client),
sourceName),
},
nil,
&resp)
return resp, err
}