-
Notifications
You must be signed in to change notification settings - Fork 14
/
api_v1_quotas.go
117 lines (98 loc) · 3.14 KB
/
api_v1_quotas.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
package v1
import (
"context"
"errors"
"fmt"
"github.com/thecodeteam/goisilon/api"
)
// GetIsiQuota queries the quota for a directory
func GetIsiQuota(
ctx context.Context,
client api.Client,
path string) (quota *IsiQuota, err error) {
// PAPI call: GET https://1.2.3.4:8080/platform/1/quota/quotas
// This will list out all quotas on the cluster
var quotaResp isiQuotaListResp
err = client.Get(ctx, quotaPath, "", nil, nil, "aResp)
if err != nil {
return nil, err
}
// find the specific quota we are looking for
for _, quota := range quotaResp.Quotas {
if quota.Path == path {
return "a, nil
}
}
return nil, errors.New(fmt.Sprintf("Quota not found: %s", path))
}
// TODO: Add a means to set/update more than just the hard threshold
// SetIsiQuotaHardThreshold sets the hard threshold of a quota for a directory
func SetIsiQuotaHardThreshold(
ctx context.Context,
client api.Client,
path string, size int64) (err error) {
// PAPI call: POST https://1.2.3.4:8080/platform/1/quota/quotas
// { "enforced" : true,
// "include_snapshots" : false,
// "path" : "/ifs/volumes/volume_name",
// "thresholds_include_overhead" : false,
// "type" : "directory",
// "thresholds" : { "advisory" : null,
// "hard" : 1234567890,
// "soft" : null
// }
// }
var data = &IsiQuotaReq{
Enforced: true,
IncludeSnapshots: false,
Path: path,
ThresholdsIncludeOverhead: false,
Type: "directory",
Thresholds: isiThresholdsReq{Advisory: nil, Hard: size, Soft: nil},
}
var quotaResp IsiQuota
err = client.Post(ctx, quotaPath, "", nil, nil, data, "aResp)
return err
}
// UpdateIsiQuotaHardThreshold modifies the hard threshold of a quota for a directory
func UpdateIsiQuotaHardThreshold(
ctx context.Context,
client api.Client,
path string, size int64) (err error) {
// PAPI call: PUT https://1.2.3.4:8080/platform/1/quota/quotas/Id
// { "enforced" : true,
// "thresholds_include_overhead" : false,
// "thresholds" : { "advisory" : null,
// "hard" : 1234567890,
// "soft" : null
// }
// }
var data = &IsiUpdateQuotaReq{
Enforced: true,
ThresholdsIncludeOverhead: false,
Thresholds: isiThresholdsReq{Advisory: nil, Hard: size, Soft: nil},
}
quota, err := GetIsiQuota(ctx, client, path)
if err != nil {
return err
}
var quotaResp IsiQuota
err = client.Put(ctx, quotaPath, quota.Id, nil, nil, data, "aResp)
return err
}
var byteArrPath = []byte("path")
// DeleteIsiQuota removes the quota for a directory
func DeleteIsiQuota(
ctx context.Context,
client api.Client,
path string) (err error) {
// PAPI call: DELETE https://1.2.3.4:8080/platform/1/quota/quotas?path=/path/to/volume
// This will remove a the quota on a volume
return client.Delete(
ctx,
quotaPath,
"",
api.OrderedValues{{byteArrPath, []byte(path)}},
nil,
nil)
}