Skip to content

v5.19.0 #442

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
merged 10 commits into from
Jul 24, 2024
3 changes: 3 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
- name: new-feature
description: for new features in the changelog.
color: 225fee
- name: project
description: for new projects in the changelog.
color: 46BAF0
- name: improvement
description: for improvements in existing functionality in the changelog.
color: 22ee47
Expand Down
7 changes: 5 additions & 2 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ changelog:
labels:
- ignore-for-release
categories:
- title: ⚠️ Breaking Change
- title: 📋 New Project
labels:
- project
- title: ⚠️ Breaking Change
labels:
- breaking-change
- title: 🐛 Bug Fixes
Expand All @@ -18,7 +21,7 @@ changelog:
- title: 🧪 Testing Improvements
labels:
- testing
- title: ⚙️ Repo/CI Improvements
- title: ⚙️ Repo/CI Improvements
labels:
- repo-ci-improvement
- title: 📖 Documentation
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/release-cross-repo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
steps:
- name: Checkout linode_api4 repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'

- name: update packages
run: sudo apt-get update -y
Expand All @@ -26,11 +29,13 @@ jobs:
with:
python-version: '3.10'

- name: checkout repo
uses: actions/checkout@v3
- name: Checkout ansible repo
uses: actions/checkout@v4
with:
repository: linode/ansible_linode
path: .ansible/collections/ansible_collections/linode/cloud
fetch-depth: 0
submodules: 'recursive'

- name: install dependencies
run: |
Expand Down
22 changes: 13 additions & 9 deletions linode_api4/groups/placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects.placement import PlacementGroup
from linode_api4.objects.placement import (
PlacementGroup,
PlacementGroupPolicy,
PlacementGroupType,
)
from linode_api4.objects.region import Region


Expand Down Expand Up @@ -31,8 +35,8 @@ def group_create(
self,
label: str,
region: Union[Region, str],
affinity_type: str,
is_strict: bool = False,
placement_group_type: PlacementGroupType,
placement_group_policy: PlacementGroupPolicy,
**kwargs,
) -> PlacementGroup:
"""
Expand All @@ -44,19 +48,19 @@ def group_create(
: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
:param placement_group_type: The type of the placement group.
:type placement_group_type: PlacementGroupType
:param placement_group_policy: The policy for assignments to this placement group.
:type placement_group_policy: PlacementGroupPolicy

: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,
"placement_group_type": placement_group_type,
"placement_group_policy": placement_group_policy,
}

params.update(kwargs)
Expand Down
18 changes: 13 additions & 5 deletions linode_api4/objects/placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
from linode_api4.objects.serializable import JSONObject, StrEnum


class PlacementGroupAffinityType(StrEnum):
class PlacementGroupType(StrEnum):
"""
An enum class that represents the available affinity policies for Linodes
in a Placement Group.
An enum class that represents the available types of a Placement Group.
"""

anti_affinity_local = "anti_affinity:local"


class PlacementGroupPolicy(StrEnum):
"""
An enum class that represents the policy for Linode assignments to a Placement Group.
"""

strict = "strict"
flexible = "flexible"


@dataclass
class PlacementGroupMember(JSONObject):
"""
Expand All @@ -42,9 +50,9 @@ class PlacementGroup(Base):
"id": Property(identifier=True),
"label": Property(mutable=True),
"region": Property(slug_relationship=Region),
"affinity_type": Property(),
"placement_group_type": Property(),
"placement_group_policy": Property(),
"is_compliant": Property(),
"is_strict": Property(),
"members": Property(json_object=PlacementGroupMember),
}

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/linode_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"placement_group": {
"id": 123,
"label": "test",
"affinity_type": "anti_affinity:local",
"is_strict": true
"placement_group_type": "anti_affinity:local",
"placement_group_policy": "strict"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/placement_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"id": 123,
"label": "test",
"region": "eu-west",
"affinity_type": "anti_affinity:local",
"is_strict": true,
"placement_group_type": "anti_affinity:local",
"placement_group_policy": "strict",
"is_compliant": true,
"members": [
{
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/placement_groups_123.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"id": 123,
"label": "test",
"region": "eu-west",
"affinity_type": "anti_affinity:local",
"is_strict": true,
"placement_group_type": "anti_affinity:local",
"placement_group_policy": "strict",
"is_compliant": true,
"members": [
{
Expand Down
5 changes: 3 additions & 2 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests
from requests.exceptions import ConnectionError, RequestException

from linode_api4 import ApiError, PlacementGroupAffinityType
from linode_api4 import ApiError, PlacementGroupPolicy, PlacementGroupType
from linode_api4.linode_client import LinodeClient
from linode_api4.objects import Region

Expand Down Expand Up @@ -465,7 +465,8 @@ def create_placement_group(test_linode_client):
pg = client.placement.group_create(
"pythonsdk-" + timestamp,
get_region(test_linode_client, {"Placement Group"}),
PlacementGroupAffinityType.anti_affinity_local,
PlacementGroupType.anti_affinity_local,
PlacementGroupPolicy.flexible,
)
yield pg

Expand Down
4 changes: 2 additions & 2 deletions test/unit/objects/linode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def test_get_placement_group(self):

assert pg.id == 123
assert pg.label == "test"
assert pg.affinity_type == "anti_affinity:local"
assert pg.placement_group_type == "anti_affinity:local"

# Invalidate the instance and try again
# This makes sure the implicit refresh/cache logic works
Expand All @@ -497,7 +497,7 @@ def test_get_placement_group(self):

assert pg.id == 123
assert pg.label == "test"
assert pg.affinity_type == "anti_affinity:local"
assert pg.placement_group_type == "anti_affinity:local"

def test_create_with_placement_group(self):
"""
Expand Down
17 changes: 9 additions & 8 deletions test/unit/objects/placement_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from test.unit.base import ClientBaseCase

from linode_api4 import PlacementGroupPolicy
from linode_api4.objects import (
PlacementGroup,
PlacementGroupAffinityType,
PlacementGroupMember,
PlacementGroupType,
)


Expand Down Expand Up @@ -42,8 +43,8 @@ def test_create_pg(self):
pg = self.client.placement.group_create(
"test",
"eu-west",
PlacementGroupAffinityType.anti_affinity_local,
is_strict=True,
PlacementGroupType.anti_affinity_local,
PlacementGroupPolicy.strict,
)

assert m.call_url == "/placement/groups"
Expand All @@ -53,10 +54,10 @@ def test_create_pg(self):
{
"label": "test",
"region": "eu-west",
"affinity_type": str(
PlacementGroupAffinityType.anti_affinity_local
"placement_group_type": str(
PlacementGroupType.anti_affinity_local
),
"is_strict": True,
"placement_group_policy": PlacementGroupPolicy.strict,
},
)

Expand Down Expand Up @@ -109,8 +110,8 @@ def validate_pg_123(self, pg: PlacementGroup):
assert pg.id == 123
assert pg.label == "test"
assert pg.region.id == "eu-west"
assert pg.affinity_type == "anti_affinity:local"
assert pg.is_strict
assert pg.placement_group_type == "anti_affinity:local"
assert pg.placement_group_policy == "strict"
assert pg.is_compliant
assert pg.members[0] == PlacementGroupMember(
linode_id=123, is_compliant=True
Expand Down
Loading