-
Notifications
You must be signed in to change notification settings - Fork 82
/
placement_groups.go
161 lines (143 loc) · 4.41 KB
/
placement_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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package linodego
import "context"
// PlacementGroupType is an enum that determines the affinity policy
// for Linodes in a placement group.
type PlacementGroupType string
const (
PlacementGroupTypeAntiAffinityLocal PlacementGroupType = "anti_affinity:local"
)
// PlacementGroupPolicy is an enum for the policy that determines whether a
// Linode can be assigned to a Placement Group.
type PlacementGroupPolicy string
const (
PlacementGroupPolicyStrict PlacementGroupPolicy = "strict"
PlacementGroupPolicyFlexible PlacementGroupPolicy = "flexible"
)
// PlacementGroupMember represents a single Linode assigned to a
// placement group.
type PlacementGroupMember struct {
LinodeID int `json:"linode_id"`
IsCompliant bool `json:"is_compliant"`
}
// PlacementGroup represents a Linode placement group.
type PlacementGroup struct {
ID int `json:"id"`
Label string `json:"label"`
Region string `json:"region"`
PlacementGroupType PlacementGroupType `json:"placement_group_type"`
PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"`
IsCompliant bool `json:"is_compliant"`
Members []PlacementGroupMember `json:"members"`
}
// PlacementGroupCreateOptions represents the options to use
// when creating a placement group.
type PlacementGroupCreateOptions struct {
Label string `json:"label"`
Region string `json:"region"`
PlacementGroupType PlacementGroupType `json:"placement_group_type"`
PlacementGroupPolicy PlacementGroupPolicy `json:"placement_group_policy"`
}
// PlacementGroupUpdateOptions represents the options to use
// when updating a placement group.
type PlacementGroupUpdateOptions struct {
Label string `json:"label,omitempty"`
}
// PlacementGroupAssignOptions represents options used when
// assigning Linodes to a placement group.
type PlacementGroupAssignOptions struct {
Linodes []int `json:"linodes"`
CompliantOnly *bool `json:"compliant_only,omitempty"`
}
// PlacementGroupUnAssignOptions represents options used when
// unassigning Linodes from a placement group.
type PlacementGroupUnAssignOptions struct {
Linodes []int `json:"linodes"`
}
// ListPlacementGroups lists placement groups under the current account
// matching the given list options.
func (c *Client) ListPlacementGroups(
ctx context.Context,
options *ListOptions,
) ([]PlacementGroup, error) {
return getPaginatedResults[PlacementGroup](
ctx,
c,
"placement/groups",
options,
)
}
// GetPlacementGroup gets a placement group with the specified ID.
func (c *Client) GetPlacementGroup(
ctx context.Context,
id int,
) (*PlacementGroup, error) {
return doGETRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d", id),
)
}
// CreatePlacementGroup creates a placement group with the specified options.
func (c *Client) CreatePlacementGroup(
ctx context.Context,
options PlacementGroupCreateOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
"placement/groups",
options,
)
}
// UpdatePlacementGroup updates a placement group with the specified ID using the provided options.
func (c *Client) UpdatePlacementGroup(
ctx context.Context,
id int,
options PlacementGroupUpdateOptions,
) (*PlacementGroup, error) {
return doPUTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d", id),
options,
)
}
// AssignPlacementGroupLinodes assigns the specified Linodes to the given
// placement group.
func (c *Client) AssignPlacementGroupLinodes(
ctx context.Context,
id int,
options PlacementGroupAssignOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d/assign", id),
options,
)
}
// UnassignPlacementGroupLinodes un-assigns the specified Linodes from the given
// placement group.
func (c *Client) UnassignPlacementGroupLinodes(
ctx context.Context,
id int,
options PlacementGroupUnAssignOptions,
) (*PlacementGroup, error) {
return doPOSTRequest[PlacementGroup](
ctx,
c,
formatAPIPath("placement/groups/%d/unassign", id),
options,
)
}
// DeletePlacementGroup deletes a placement group with the specified ID.
func (c *Client) DeletePlacementGroup(
ctx context.Context,
id int,
) error {
return doDELETERequest(
ctx,
c,
formatAPIPath("placement/groups/%d", id),
)
}