-
Notifications
You must be signed in to change notification settings - Fork 87
new: Add support for Placement Groups #396
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgarber-akamai
merged 23 commits into
linode:proj/vm-placement
from
lgarber-akamai:new/vm-placement
May 1, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7f83c03
WIP
lgarber-akamai c79ef71
progress
lgarber-akamai 926d077
Add affinity type enum
lgarber-akamai 60717a1
Update region
lgarber-akamai 5cc4d6d
progress
lgarber-akamai 2c33b38
various changes
lgarber-akamai 7f0892e
rename obj file
lgarber-akamai 21ea60a
fix pg logic
lgarber-akamai dd1234a
refactor
lgarber-akamai 722d03e
fix lint
lgarber-akamai 485fefb
fix circular dep
lgarber-akamai 1f89944
add ignore
lgarber-akamai 34f6cf9
Add tests; populate on assignment
lgarber-akamai cce1a74
fix imports
lgarber-akamai 5856899
Add inst POST pg test
lgarber-akamai 7c0166f
start e2e
lgarber-akamai 9e252bf
Add int tests
lgarber-akamai 997b72e
Support PG as argument
lgarber-akamai 78ff342
Fix enum compatibility for Python < 3.11
lgarber-akamai 9155bd1
Fix minor issues
lgarber-akamai 49a437d
Fix error message
lgarber-akamai 6943fec
Update region unit test
lgarber-akamai d1e0ac9
Update PG default region
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
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
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,68 @@ | ||
| from typing import Union | ||
|
|
||
| from linode_api4.errors import UnexpectedResponseError | ||
| from linode_api4.groups import Group | ||
| from linode_api4.objects.placement import PlacementGroup | ||
| from linode_api4.objects.region import Region | ||
|
|
||
|
|
||
| class PlacementAPIGroup(Group): | ||
| def groups(self, *filters): | ||
| """ | ||
| Returns a list of Placement Groups on your account. You may filter | ||
| this query to return only Placement Groups that match specific criteria:: | ||
|
|
||
| groups = client.placement.groups(PlacementGroup.label == "test") | ||
|
|
||
| API Documentation: TODO | ||
|
|
||
| :param filters: Any number of filters to apply to this query. | ||
| See :doc:`Filtering Collections</linode_api4/objects/filtering>` | ||
| for more details on filtering. | ||
|
|
||
| :returns: A list of Placement Groups that matched the query. | ||
| :rtype: PaginatedList of PlacementGroup | ||
| """ | ||
| return self.client._get_and_filter(PlacementGroup, *filters) | ||
|
|
||
| def group_create( | ||
| self, | ||
| label: str, | ||
| region: Union[Region, str], | ||
| affinity_type: str, | ||
| is_strict: bool = False, | ||
| **kwargs, | ||
| ) -> PlacementGroup: | ||
| """ | ||
| Create a placement group with the specified parameters. | ||
|
|
||
| :param label: The label for the placement group. | ||
| :type label: str | ||
| :param region: The region where the placement group will be created. Can be either a Region object or a string representing the region ID. | ||
| :type region: Union[Region, str] | ||
| :param affinity_type: The affinity type of the placement group. | ||
| :type affinity_type: PlacementGroupAffinityType | ||
| :param is_strict: Whether the placement group is strict (defaults to False). | ||
| :type is_strict: bool | ||
|
|
||
| :returns: The new Placement Group. | ||
| :rtype: PlacementGroup | ||
| """ | ||
| params = { | ||
| "label": label, | ||
| "region": region.id if isinstance(region, Region) else region, | ||
| "affinity_type": affinity_type, | ||
| "is_strict": is_strict, | ||
| } | ||
|
|
||
| params.update(kwargs) | ||
|
|
||
| result = self.client.post("/placement/groups", data=params) | ||
|
|
||
| if not "id" in result: | ||
| raise UnexpectedResponseError( | ||
| "Unexpected response when creating Placement Group", json=result | ||
| ) | ||
|
|
||
| d = PlacementGroup(self.client, result["id"], result) | ||
| return d | ||
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 |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ | |
| from .database import * | ||
| from .vpc import * | ||
| from .beta import * | ||
| from .placement import * | ||
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.
I'm not quite sure what to name this class given the convention here would be
{route_name}Group, but that conflicts withPlacementGroupThere 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.
Otherwise I can think of
PlacementsGroup, but I think the current namingPlacementAPIGroupis less confusing and probably the best way to go 馃憤