This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
86 lines (73 loc) · 2.7 KB
/
requests.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
package servergroups
import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
// List returns a Pager that allows you to iterate over a collection of
// ServerGroups.
func List(client *golangsdk.ServiceClient) pagination.Pager {
return pagination.NewPager(client, rootURL(client), func(r pagination.PageResult) pagination.Page {
return ServerGroupPage{pagination.SinglePageBase(r)}
})
}
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToServerGroupCreateMap() (map[string]interface{}, error)
}
// CreateOpts specifies Server Group creation parameters.
type CreateOpts struct {
// Name is the name of the server group
Name string `json:"name" required:"true"`
// Policies are the server group policies
Policies []string `json:"policies" required:"true"`
}
// ToServerGroupCreateMap constructs a request body from CreateOpts.
func (opts CreateOpts) ToServerGroupCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "server_group")
}
// Create requests the creation of a new Server Group.
func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToServerGroupCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})
return
}
// Get returns data about a previously created ServerGroup.
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
return
}
// Delete requests the deletion of a previously allocated ServerGroup.
func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(resourceURL(client, id), nil)
return
}
type MemberOptsBuilder interface {
ToServerGroupUpdateMemberMap(string) (map[string]interface{}, error)
}
type MemberOpts struct {
InstanceID string `json:"instance_uuid" required:"true"`
}
func (opts MemberOpts) ToServerGroupUpdateMemberMap(optsType string) (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, optsType)
}
// UpdateMember is used to add and delete members from Server Group.
// (params)optsType: The opts type is title of block in request body.
// Add options is "add_memebr" and remove options is "remove_member".
func UpdateMember(client *golangsdk.ServiceClient, opts MemberOptsBuilder, optsType, id string) (r MemberResult) {
b, err := opts.ToServerGroupUpdateMemberMap(optsType)
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(actionURL(client, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200, 202},
})
return
}