1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package client
19
20 import (
21 "context"
22 "strconv"
23 )
24
25 type ResourceGroup struct {
26 Name string `json:"name,omitempty"`
27 Description string `json:"description,omitempty"`
28
29 Props map[string]string `json:"props,omitempty"`
30 SelectFilter AutoSelectFilter `json:"select_filter,omitempty"`
31
32 Uuid string `json:"uuid,omitempty"`
33 }
34
35 type ResourceGroupModify struct {
36 Description string `json:"description,omitempty"`
37
38 OverrideProps map[string]string `json:"override_props,omitempty"`
39 DeleteProps []string `json:"delete_props,omitempty"`
40 DeleteNamespaces []string `json:"delete_namespaces,omitempty"`
41 SelectFilter AutoSelectFilter `json:"select_filter,omitempty"`
42 }
43
44 type ResourceGroupSpawn struct {
45
46 ResourceDefinitionName string `json:"resource_definition_name"`
47
48 ResourceDefinitionExternalName string `json:"resource_definition_external_name,omitempty"`
49
50 VolumeSizes []int64 `json:"volume_sizes,omitempty"`
51 SelectFilter AutoSelectFilter `json:"select_filter,omitempty"`
52
53 Partial bool `json:"partial,omitempty"`
54
55 DefinitionsOnly bool `json:"definitions_only,omitempty"`
56 }
57
58 type ResourceGroupAdjust struct {
59 SelectFilter *AutoSelectFilter `json:"select_filter,omitempty"`
60 }
61
62 type VolumeGroup struct {
63 VolumeNumber int32 `json:"volume_number,omitempty"`
64
65 Props map[string]string `json:"props,omitempty"`
66
67 Uuid string `json:"uuid,omitempty"`
68 Flags []string `json:"flags,omitempty"`
69 }
70
71 type VolumeGroupModify struct {
72
73 OverrideProps map[string]string `json:"override_props,omitempty"`
74
75 Flags []string `json:"flags,omitempty"`
76 DeleteProps []string `json:"delete_props,omitempty"`
77 DeleteNamespaces []string `json:"delete_namespaces,omitempty"`
78 }
79
80
81
82
83
84
85 type ResourceGroupProvider interface {
86
87 GetAll(ctx context.Context, opts ...*ListOpts) ([]ResourceGroup, error)
88
89 Get(ctx context.Context, resGrpName string, opts ...*ListOpts) (ResourceGroup, error)
90
91 Create(ctx context.Context, resGrp ResourceGroup) error
92
93 Modify(ctx context.Context, resGrpName string, props ResourceGroupModify) error
94
95 Delete(ctx context.Context, resGrpName string) error
96
97 Spawn(ctx context.Context, resGrpName string, resGrpSpwn ResourceGroupSpawn) error
98
99 GetVolumeGroups(ctx context.Context, resGrpName string, opts ...*ListOpts) ([]VolumeGroup, error)
100
101 GetVolumeGroup(ctx context.Context, resGrpName string, volNr int, opts ...*ListOpts) (VolumeGroup, error)
102
103 CreateVolumeGroup(ctx context.Context, resGrpName string, volGrp VolumeGroup) error
104
105 ModifyVolumeGroup(ctx context.Context, resGrpName string, volNr int, props VolumeGroupModify) error
106 DeleteVolumeGroup(ctx context.Context, resGrpName string, volNr int) error
107
108
109 GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error)
110
111
112 GetVolumeGroupPropsInfos(ctx context.Context, resGrpName string, opts ...*ListOpts) ([]PropsInfo, error)
113
114 Adjust(ctx context.Context, resGrpName string, adjust ResourceGroupAdjust) error
115
116 AdjustAll(ctx context.Context, adjust ResourceGroupAdjust) error
117 }
118
119 var _ ResourceGroupProvider = &ResourceGroupService{}
120
121
122 type ResourceGroupService struct {
123 client *Client
124 }
125
126
127 func (n *ResourceGroupService) GetAll(ctx context.Context, opts ...*ListOpts) ([]ResourceGroup, error) {
128 var resGrps []ResourceGroup
129 _, err := n.client.doGET(ctx, "/v1/resource-groups", &resGrps, opts...)
130 return resGrps, err
131 }
132
133
134 func (n *ResourceGroupService) Get(ctx context.Context, resGrpName string, opts ...*ListOpts) (ResourceGroup, error) {
135 var resGrp ResourceGroup
136 _, err := n.client.doGET(ctx, "/v1/resource-groups/"+resGrpName, &resGrp, opts...)
137 return resGrp, err
138 }
139
140
141 func (n *ResourceGroupService) Create(ctx context.Context, resGrp ResourceGroup) error {
142 _, err := n.client.doPOST(ctx, "/v1/resource-groups", resGrp)
143 return err
144 }
145
146
147 func (n *ResourceGroupService) Modify(ctx context.Context, resGrpName string, props ResourceGroupModify) error {
148 _, err := n.client.doPUT(ctx, "/v1/resource-groups/"+resGrpName, props)
149 return err
150 }
151
152
153 func (n *ResourceGroupService) Delete(ctx context.Context, resGrpName string) error {
154 _, err := n.client.doDELETE(ctx, "/v1/resource-groups/"+resGrpName, nil)
155 return err
156 }
157
158
159 func (n *ResourceGroupService) Spawn(ctx context.Context, resGrpName string, resGrpSpwn ResourceGroupSpawn) error {
160 _, err := n.client.doPOST(ctx, "/v1/resource-groups/"+resGrpName+"/spawn", resGrpSpwn)
161 return err
162 }
163
164
165 func (n *ResourceGroupService) GetVolumeGroups(ctx context.Context, resGrpName string, opts ...*ListOpts) ([]VolumeGroup, error) {
166 var volGrps []VolumeGroup
167 _, err := n.client.doGET(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups", &volGrps, opts...)
168 return volGrps, err
169 }
170
171
172 func (n *ResourceGroupService) GetVolumeGroup(ctx context.Context, resGrpName string, volNr int, opts ...*ListOpts) (VolumeGroup, error) {
173 var volGrp VolumeGroup
174 _, err := n.client.doGET(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups/"+strconv.Itoa(volNr), &volGrp, opts...)
175 return volGrp, err
176 }
177
178
179 func (n *ResourceGroupService) CreateVolumeGroup(ctx context.Context, resGrpName string, volGrp VolumeGroup) error {
180 _, err := n.client.doPOST(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups", volGrp)
181 return err
182 }
183
184
185 func (n *ResourceGroupService) ModifyVolumeGroup(ctx context.Context, resGrpName string, volNr int, props VolumeGroupModify) error {
186 _, err := n.client.doPUT(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups/"+strconv.Itoa(volNr), props)
187 return err
188 }
189
190 func (n *ResourceGroupService) DeleteVolumeGroup(ctx context.Context, resGrpName string, volNr int) error {
191 _, err := n.client.doDELETE(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups/"+strconv.Itoa(volNr), nil)
192 return err
193 }
194
195
196
197 func (n *ResourceGroupService) GetPropsInfos(ctx context.Context, opts ...*ListOpts) ([]PropsInfo, error) {
198 var infos []PropsInfo
199 _, err := n.client.doGET(ctx, "/v1/resource-groups/properties/info", &infos, opts...)
200 return infos, err
201 }
202
203
204
205 func (n *ResourceGroupService) GetVolumeGroupPropsInfos(ctx context.Context, resGrpName string, opts ...*ListOpts) ([]PropsInfo, error) {
206 var infos []PropsInfo
207 _, err := n.client.doGET(ctx, "/v1/resource-groups/"+resGrpName+"/volume-groups/properties/info", &infos, opts...)
208 return infos, err
209 }
210
211
212 func (n *ResourceGroupService) Adjust(ctx context.Context, resGrpName string, adjust ResourceGroupAdjust) error {
213 _, err := n.client.doPOST(ctx, "/v1/resource-groups/"+resGrpName+"/adjust", adjust)
214 return err
215 }
216
217
218 func (n *ResourceGroupService) AdjustAll(ctx context.Context, adjust ResourceGroupAdjust) error {
219 _, err := n.client.doPOST(ctx, "/v1/resource-groups/adjustall", adjust)
220 return err
221 }
222
View as plain text