-
Notifications
You must be signed in to change notification settings - Fork 8
/
server_group.go
139 lines (109 loc) · 4.14 KB
/
server_group.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package request
import (
"encoding/json"
"fmt"
"github.com/UpCloudLtd/upcloud-go-api/v6/upcloud"
)
const (
serverGroupBasePath string = "/server-group"
)
// GetServerGroupsRequest represents a request to list server groups
type GetServerGroupsRequest struct {
Filters []QueryFilter
}
func (s GetServerGroupsRequest) RequestURL() string {
if len(s.Filters) == 0 {
return serverGroupBasePath
}
return fmt.Sprintf("%s?%s", serverGroupBasePath, encodeQueryFilters(s.Filters))
}
// Deprecated: ServerGroupFilter filter is deprecated. Use QueryFilter instead.
type ServerGroupFilter = QueryFilter
// Deprecated: GetServerGroupsWithFiltersRequest is deprecated. Use GetServerGroupsRequest instead.
type GetServerGroupsWithFiltersRequest struct {
Filters []QueryFilter
}
func (r *GetServerGroupsWithFiltersRequest) RequestURL() string {
if len(r.Filters) == 0 {
return serverGroupBasePath
}
return fmt.Sprintf("%s?%s", serverGroupBasePath, encodeQueryFilters(r.Filters))
}
// GetServerGroupsRequest represents a request to get server group details
type GetServerGroupRequest struct {
UUID string `json:"-"`
}
func (s GetServerGroupRequest) RequestURL() string {
return fmt.Sprintf("%s/%s", serverGroupBasePath, s.UUID)
}
// CreateServerGroupRequest represents a request to create server group
type CreateServerGroupRequest struct {
Labels *upcloud.LabelSlice `json:"labels,omitempty"`
Members upcloud.ServerUUIDSlice `json:"servers,omitempty"`
AntiAffinityPolicy upcloud.ServerGroupAntiAffinityPolicy `json:"anti_affinity,omitempty"`
Title string `json:"title,omitempty"`
}
func (s CreateServerGroupRequest) RequestURL() string {
return serverGroupBasePath
}
// MarshalJSON is a custom marshaller that deals with deeply embedded values.
func (r CreateServerGroupRequest) MarshalJSON() ([]byte, error) {
type c CreateServerGroupRequest
v := struct {
ServerGroup c `json:"server_group"`
}{}
v.ServerGroup = c(r)
return json.Marshal(&v)
}
// ModifyServerGroupRequest represents a request to modify server group
type ModifyServerGroupRequest struct {
Labels *upcloud.LabelSlice `json:"labels,omitempty"`
Members *upcloud.ServerUUIDSlice `json:"servers,omitempty"`
AntiAffinityPolicy upcloud.ServerGroupAntiAffinityPolicy `json:"anti_affinity,omitempty"`
Title string `json:"title,omitempty"`
UUID string `json:"-"`
}
func (s ModifyServerGroupRequest) RequestURL() string {
return fmt.Sprintf("%s/%s", serverGroupBasePath, s.UUID)
}
// MarshalJSON is a custom marshaller that deals with deeply embedded values.
func (r ModifyServerGroupRequest) MarshalJSON() ([]byte, error) {
type c ModifyServerGroupRequest
v := struct {
ServerGroup c `json:"server_group"`
}{}
v.ServerGroup = c(r)
return json.Marshal(&v)
}
// DeleteServerGroupRequest represents a request to delete server group
type DeleteServerGroupRequest struct {
UUID string `json:"-"`
}
func (s DeleteServerGroupRequest) RequestURL() string {
return fmt.Sprintf("%s/%s", serverGroupBasePath, s.UUID)
}
// AddServerToServerGroupRequest represents a request to add server to a server group
type AddServerToServerGroupRequest struct {
ServerUUID string `json:"uuid,omitempty"`
UUID string `json:"-"`
}
func (s AddServerToServerGroupRequest) RequestURL() string {
return fmt.Sprintf("%s/%s/servers", serverGroupBasePath, s.UUID)
}
// MarshalJSON is a custom marshaller that deals with deeply embedded values.
func (r AddServerToServerGroupRequest) MarshalJSON() ([]byte, error) {
type c AddServerToServerGroupRequest
v := struct {
Server c `json:"server"`
}{}
v.Server = c(r)
return json.Marshal(&v)
}
// RemoveServerFromServerGroupRequest represents a request to remove server from a server group
type RemoveServerFromServerGroupRequest struct {
ServerUUID string `json:"-"`
UUID string `json:"-"`
}
func (s RemoveServerFromServerGroupRequest) RequestURL() string {
return fmt.Sprintf("%s/%s/servers/%s", serverGroupBasePath, s.UUID, s.ServerUUID)
}