Skip to content

Conversation

lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Jun 20, 2025

📝 Description

This pull request adds support for users specifying an ExplicitNullValue for the firewall_id field when creating a Linode interface. This is necessary when specifying a Linode interface with no firewall because an unspecified/implicit null value will cause the API to use the account-wide default firewall or raise an error if no default firewall has been configured.

✔️ How to Test

The following test steps assume you have pulled down this PR locally and run make install.

Unit Testing

make test-unit

Integration Testing

make test-int TEST_COMMAND=models/linode

Manual Testing

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

from linode_api4 import (
    LinodeClient,
    LinodeInterfaceOptions,
    LinodeInterfacePublicOptions,
    ExplicitNullValue,
    LinodeInterfaceDefaultRouteOptions,
    ApiError,
)

linode_client = LinodeClient(
    os.getenv("LINODE_TOKEN"), base_url="https://api.linode.com/v4beta"
)

instance_index = 0


def provision_instance(interface_firewall_id):
    global instance_index

    result, _ = linode_client.linode.instance_create(
        ltype="g6-nanode-1",
        region="us-mia",
        image="linode/ubuntu24.04",
        label=f"pythonsdk-test-{instance_index}",
        booted=False,
        linode_interfaces=[
            LinodeInterfaceOptions(
                default_route=LinodeInterfaceDefaultRouteOptions(
                    ipv4=True,
                    ipv6=True,
                ),
                firewall_id=interface_firewall_id,
                public=LinodeInterfacePublicOptions(),
            )
        ],
    )

    instance_index += 1

    return result


firewall = linode_client.networking.firewall_create(
    "pythonsdk-test-firewall",
    rules={
        "outbound_policy": "DROP",
        "inbound_policy": "DROP",
        "inbound": [],
        "outbound": [],
    },
)

# Provision an instance with no attached firewall
no_firewalls = provision_instance(ExplicitNullValue)

# Provision an instance with an implicit firewall
try:
    implicit_firewall = provision_instance(None)
except ApiError as e:
    implicit_firewall = "N/A"

# Provision an instance with an explicit firewall
explicit_firewall = provision_instance(firewall.id)

print(f"Firewall: {firewall.id}")

print(f"No Firewalls: {no_firewalls}")
print(f"Implicit Firewall: {implicit_firewall}")
print(f"Explicit Firewall: {explicit_firewall}")
  1. Ensure the output matches to the following:
Firewall: 

No Firewalls: Instance: 
Implicit Firewall: Instance: 78999982
Explicit Firewall: Instance: 78999983

NOTE: These values may not be correct due to a potential API issue. The POST bodies can be validated manually by adding a print(body) here:

@lgarber-akamai lgarber-akamai added the bugfix for any bug fixes in the changelog. label Jun 20, 2025
@lgarber-akamai lgarber-akamai marked this pull request as ready for review June 20, 2025 19:53
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner June 20, 2025 19:53
@lgarber-akamai lgarber-akamai requested review from ezilber-akamai and jriddle-linode and removed request for a team June 20, 2025 19:53
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tests passed

@lgarber-akamai lgarber-akamai merged commit 221afdc into linode:proj/enhanced-interfaces Jun 25, 2025
12 checks passed
zliang-akamai added a commit that referenced this pull request Sep 22, 2025
* Enhanced Interfaces: Add support for Firewall templates (#529)

* Add support for Firewall Templates

* oops

* Add LA notices

* Enhanced Interfaces: Add account-related fields (#525)

* Enhanced Interfaces: Add account-related fields

* Add setting enum

* Add LA notice

* Drop residual print

* Enhanced Interfaces: Implement endpoints & fields related to VPCs and non-interface networking (#526)

* Implement endpoints & fields related to VPCs and non-interface networking

* Add LA notices

* Enhanced Interfaces: Add support for Linode-related endpoints and fields (#533)

* Add support for Linode-related endpoints and fields

* oops

* tiny fixes

* fix docsa

* Add docs examples

* Docs fixes

* oops

* Remove irrelevant test

* Add LA notices

* Fill in API documentation URLs

* Add return types

* Enable `include_none_values` in FirewallSettingsDefaultFirewallIDs (#558)

* Linode Interfaces: Allow specifying ExplicitNullValue for LinodeInterfaceOptions firewall ID (#565)

* Add ExplicitNullValue support

* Fix failing integration tests

* Add unit tests

* Add docs disclaimer

* Fix

* Update test/fixtures/linode_instances.json

Co-authored-by: Copilot <[email protected]>

* Update test/unit/objects/linode_test.py

Co-authored-by: Copilot <[email protected]>

* Update test/integration/conftest.py

Co-authored-by: Copilot <[email protected]>

* Update linode_api4/objects/linode.py

Co-authored-by: Copilot <[email protected]>

* More fixes

* lint

* Apply suggestion from @Copilot

Co-authored-by: Copilot <[email protected]>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <[email protected]>

* Remove unnecessary local imports

* Fix IPv6 addresses

* Apply suggestion from @Copilot

Co-authored-by: Copilot <[email protected]>

* Update test/unit/objects/networking_test.py

Co-authored-by: Copilot <[email protected]>

* Update test/unit/objects/linode_test.py

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Lena Garber <[email protected]>
Co-authored-by: Lena Garber <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix for any bug fixes in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants