Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions linode_api4/groups/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def instance_create(
:type metadata: dict
:param firewall: The firewall to attach this Linode to.
:type firewall: int or Firewall
:param interfaces: An array of Network Interfaces to add to this Linode鈥檚 Configuration Profile.
At least one and up to three Interface objects can exist in this array.
:type interfaces: list[ConfigInterface] or list[dict[str, Any]]

:returns: A new Instance object, or a tuple containing the new Instance and
the generated password.
Expand Down Expand Up @@ -303,6 +306,12 @@ def instance_create(
fw = kwargs.pop("firewall")
kwargs["firewall_id"] = fw.id if isinstance(fw, Firewall) else fw

if "interfaces" in kwargs:
kwargs["interfaces"] = [
i._serialize() if isinstance(i, ConfigInterface) else i
for i in kwargs["interfaces"]
]

params = {
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
"region": region.id if issubclass(type(region), Base) else region,
Expand Down
34 changes: 33 additions & 1 deletion test/integration/linode_client/test_linode_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from linode_api4 import ApiError, LinodeClient
from linode_api4.objects import ObjectStorageKeys
from linode_api4.objects import ConfigInterface, ObjectStorageKeys


@pytest.fixture(scope="session", autouse=True)
Expand Down Expand Up @@ -231,6 +231,38 @@ def test_create_linode_instance_with_image(setup_client_and_linode):
assert re.search("linode/debian10", str(linode.image))


def test_create_linode_with_interfaces(test_linode_client):
client = test_linode_client
available_regions = client.regions()
chosen_region = available_regions[4]
label = get_test_label()

linode_instance, password = client.linode.instance_create(
"g6-nanode-1",
chosen_region,
label=label,
image="linode/debian10",
interfaces=[
{"purpose": "public"},
ConfigInterface(
purpose="vlan", label="cool-vlan", ipam_address="10.0.0.4/32"
),
],
)

assert len(linode_instance.configs[0].interfaces) == 2
assert linode_instance.configs[0].interfaces[0].purpose == "public"
assert linode_instance.configs[0].interfaces[1].purpose == "vlan"
assert linode_instance.configs[0].interfaces[1].label == "cool-vlan"
assert (
linode_instance.configs[0].interfaces[1].ipam_address == "10.0.0.4/32"
)

res = linode_instance.delete()

assert res


# LongviewGroupTests
def test_get_longview_clients(test_linode_client, test_longview_client):
client = test_linode_client
Expand Down
29 changes: 29 additions & 0 deletions test/unit/objects/linode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,35 @@ def test_instance_create_with_user_data(self):
},
)

def test_instance_create_with_interfaces(self):
"""
Tests that user can pass a list of interfaces on Linode create.
"""
interfaces = [
{"purpose": "public"},
ConfigInterface(
purpose="vlan", label="cool-vlan", ipam_address="10.0.0.4/32"
),
]
with self.mock_post("linode/instances/123") as m:
self.client.linode.instance_create(
"us-southeast",
"g6-nanode-1",
interfaces=interfaces,
)

self.assertEqual(
m.call_data["interfaces"],
[
{"purpose": "public"},
{
"purpose": "vlan",
"label": "cool-vlan",
"ipam_address": "10.0.0.4/32",
},
],
)

def test_build_instance_metadata(self):
"""
Tests that the metadata field is built correctly.
Expand Down