linode / linode_api4-python

Official Python bindings for the Linode API
https://linode-api4.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
135 stars 75 forks source link

ref: PG affinity_type, is_strict -> placement_group_type, placement_group_policy #437

Closed lgarber-akamai closed 1 month ago

lgarber-akamai commented 2 months ago

📝 Description

This pull request implements the following upcoming breaking changes for the VM Placement GA:

NOTE: We will need communication around this breaking change in the release notes.

✔️ How to Test

The following test steps assume you have pulled down this PR locally and have pointed your local environment at an API instance where PGs are available:

export LINODE_API_URL=https://.../v4beta
export LINODE_API_CA=$PWD/cacert.pem
export LINODE_TOKEN=...

Integration Testing

make INTEGRATION_TEST_PATH=models/test_placement.py testint

Unit Testing

make testunit

Manual Testing

  1. In a linode_api4 sandbox environment (e.g. dx-devenv), run the following:
import os

from linode_api4 import LinodeClient, PlacementGroupType, PlacementGroupPolicy

client = LinodeClient(
    os.getenv("LINODE_TOKEN"),
    base_url="https://.../v4beta",
    ca_path="cacert.pem"
)

placement_group = client.placement.group_create(
    "test-pg",
    "eu-west",
    PlacementGroupType.anti_affinity_local,
    PlacementGroupPolicy.flexible
)

instance = client.linode.instance_create(
    "g6-nanode-1",
    placement_group.region,
    label="test-instance",
    placement_group=placement_group,
)

# Invalidate the placement group to refresh the members
placement_group.invalidate()

print(instance)
print(placement_group)
print("Instance.placement_group:", instance.placement_group)
print("PG.members:", placement_group.members)
  1. Ensure the output looks similar to the following:

    Instance: 25137082
    PlacementGroup: 597
    Instance.placement_group: PlacementGroup: 597
    PG.members: [PlacementGroupMember(linode_id=25137082, is_compliant=True)]
  2. Navigate to the PG & Instance in Cloud Manager and ensure everything is configured as expected.

  3. Alter the script to test other features added in this PR.