-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresourcegroup.go
More file actions
96 lines (82 loc) · 2.57 KB
/
resourcegroup.go
File metadata and controls
96 lines (82 loc) · 2.57 KB
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
package hdsstorage
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"github.com/tidwall/gjson"
)
//锁定分配给用户的资源组
func (s *Storage) LockResourceGroup(waitTime int) Job {
/*
请求参数:
waitTime int, lock timeout in seconds; range: 0-7200; default: 0
*/
url := BaseURL + "/v1" + s.StorageDeviceId + "/services/resource-group-service/actions/lock/invoke"
tmpMap := make(map[string]interface{})
tmpMap["parameters"] = map[string]int{"waitTime": waitTime}
content, _ := json.Marshal(tmpMap)
postContent := bytes.NewBuffer(content)
response, err := PostRequest(url, s.Token, postContent)
if err != nil {
if response.StatusCode == 503 {
log.Println("LockResourceGroup error:", err)
return Job{}
}
log.Fatalf("LockResourceGroup error: %v\n", err)
// return Job{}
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
job := Job{}
json.Unmarshal(body, &job)
return job
}
// 解锁resource group
func (s *Storage) UnlockResourceGroup() Job {
url := BaseURL + "/v1" + s.StorageDeviceId + "/services/resource-group-service/actions/unlock/invoke"
response, err := PostRequest(url, s.Token, nil)
if err != nil {
if response.StatusCode == 503 {
log.Println("UnlockResourceGroup error:", err)
return Job{}
}
log.Fatalf("UnlockResourceGroup error: %v\n", err)
// return Job{}
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
job := Job{}
json.Unmarshal(body, &job)
return job
}
// 获取存储的所有resource group
func (s *Storage) GetAllResourceGroups() []ResourceGroup {
url := BaseURL + "/v1/objects/storages" + s.StorageDeviceId + "/resource-groups"
resp, err := GetRequest(url, s.Token)
if err != nil {
log.Printf("Get Resource Groups error: %v\n", err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var rgroups []ResourceGroup
for _, r := range gjson.Get(string(body), "data").Array() {
rgroup := ResourceGroup{}
json.Unmarshal([]byte(r.String()), &rgroup)
rgroups = append(rgroups, rgroup)
}
return rgroups
}
// 定义ResourGroup结构体
type ResourceGroup struct {
ResourceGroupId int64 `json:"resourceGroupId"`
ResourceGroupName string `json:"resourceGroupName"`
LockStatus string `json:"lockStatus"`
VirtualStorageId int64 `json:"virtualStorageId"`
LdevIds []int64 `json:"ldevIds"`
ParityGroupIds []string `json:"parityGroupIds"`
PortIds []string `json:"portIds"`
HostGroupIds []string `json:"hostGroupIds"`
LockOwner string `json:"lockOwner"`
LockHost string `json:"lockHost"`
}