-
Notifications
You must be signed in to change notification settings - Fork 99
new: Add support for VM Placement #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgarber-akamai
merged 9 commits into
linode:proj/vm-placement
from
lgarber-akamai:new/vm-placement
Apr 16, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8db06e7
Add placement group object
lgarber-akamai d3f428f
Add placement group limits to region response
lgarber-akamai 6f726e3
Implement instance changes
lgarber-akamai af005a6
prefixture
lgarber-akamai 683b525
Add pg basic test
lgarber-akamai c449ac3
finish assignment tests
lgarber-akamai 0b0e0d3
Add regions test
lgarber-akamai 006ca7c
oops
lgarber-akamai 22b8fcf
make tidy
lgarber-akamai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package linodego | ||
|
|
||
| import "context" | ||
|
|
||
| // PlacementGroupAffinityType is an enum that determines the affinity policy | ||
| // for Linodes in a placement group. | ||
| type PlacementGroupAffinityType string | ||
|
|
||
| const ( | ||
| AffinityTypeAntiAffinityLocal PlacementGroupAffinityType = "anti_affinity:local" | ||
| ) | ||
|
|
||
| // 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"` | ||
| AffinityType PlacementGroupAffinityType `json:"affinity_type"` | ||
| IsCompliant bool `json:"is_compliant"` | ||
| IsStrict bool `json:"is_strict"` | ||
| 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"` | ||
| AffinityType PlacementGroupAffinityType `json:"affinity_type"` | ||
| IsStrict bool `json:"is_strict"` | ||
| } | ||
|
|
||
| // 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), | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added in the parent/child project branch (which hasn't been merged to main yet)