-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver_groups.go
74 lines (66 loc) · 2.13 KB
/
server_groups.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
package brightbox
import (
"context"
"path"
"time"
)
// ServerGroup represents a server group
// https://api.gb1.brightbox.com/1.0/#server_group
type ServerGroup struct {
ResourceRef
ID string
Name string
Description string
Default bool
Fqdn string
CreatedAt *time.Time `json:"created_at"`
Account *Account
FirewallPolicy *FirewallPolicy `json:"firewall_policy"`
Servers []Server
}
// ServerGroupOptions is used in combination with CreateServerGroup and
// UpdateServerGroup to create and update server groups
type ServerGroupOptions struct {
ID string `json:"-"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
}
// ServerGroupMember is used to add, remove and move a server between server groups
type ServerGroupMember struct {
Server string `json:"server"`
}
// ServerGroupMemberList is used to add, remove and move servers between server groups
type ServerGroupMemberList struct {
Servers []ServerGroupMember `json:"servers"`
}
// AddServersToServerGroup adds servers to an existing server group
func (c *Client) AddServersToServerGroup(ctx context.Context, identifier string, attachment ServerGroupMemberList) (*ServerGroup, error) {
return apiPost[ServerGroup](
ctx,
c,
path.Join(servergroupAPIPath, identifier, "add_servers"),
attachment,
)
}
// RemoveServersFromServerGroup remove servers from an existing server group
func (c *Client) RemoveServersFromServerGroup(ctx context.Context, identifier string, attachment ServerGroupMemberList) (*ServerGroup, error) {
return apiPost[ServerGroup](
ctx,
c,
path.Join(servergroupAPIPath, identifier, "remove_servers"),
attachment,
)
}
// MoveServersToServerGroup moves servers between two existing server groups
func (c *Client) MoveServersToServerGroup(ctx context.Context, from string, to string, servers ServerGroupMemberList) (*ServerGroup, error) {
opts := struct {
ServerGroupMemberList
Destination string `json:"destination"`
}{servers, to}
return apiPost[ServerGroup](
ctx,
c,
path.Join(servergroupAPIPath, from, "move_servers"),
opts,
)
}