Skip to content

Commit 1d1a04a

Browse files
progress
1 parent c556cd9 commit 1d1a04a

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test-int:
6666

6767
.PHONY: test-unit
6868
test-unit:
69-
$(PYTHON) -m pytest test/unit
69+
$(PYTHON) -m pytest test/unit -vv
7070

7171
.PHONY: test-smoke
7272
test-smoke:

linode_api4/objects/linode.py

+31-10
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ class ConfigInterfaceIPv6(JSONObject):
313313
is_public: bool = False
314314

315315

316+
@dataclass
317+
class ConfigInterfaceIPv6SLAACOptions(JSONObject):
318+
range: str = ""
319+
320+
321+
@dataclass
322+
class ConfigInterfaceIPv6RangeOptions(JSONObject):
323+
range: str = ""
324+
325+
326+
@dataclass
327+
class ConfigInterfaceIPv6Options(JSONObject):
328+
slaac: List[ConfigInterfaceIPv6SLAACOptions] = field(
329+
default_factory=lambda: []
330+
)
331+
ranges: List[ConfigInterfaceIPv6RangeOptions] = field(
332+
default_factory=lambda: []
333+
)
334+
is_public: bool = False
335+
336+
316337
class NetworkInterface(DerivedBase):
317338
"""
318339
This class represents a Configuration Profile's network interface object.
@@ -593,6 +614,7 @@ def interface_create_vpc(
593614
subnet: Union[int, VPCSubnet],
594615
primary=False,
595616
ipv4: Union[Dict[str, Any], ConfigInterfaceIPv4] = None,
617+
ipv6: Union[Dict[str, Any], ConfigInterfaceIPv6Options] = None,
596618
ip_ranges: Optional[List[str]] = None,
597619
) -> NetworkInterface:
598620
"""
@@ -606,6 +628,8 @@ def interface_create_vpc(
606628
:type primary: bool
607629
:param ipv4: The IPv4 configuration of the interface for the associated subnet.
608630
:type ipv4: Dict or ConfigInterfaceIPv4
631+
:param ipv6: The IPv6 configuration of the interface for the associated subnet.
632+
:type ipv6: Dict or ConfigInterfaceIPv6Options
609633
:param ip_ranges: A list of IPs or IP ranges in the VPC subnet.
610634
Packets to these CIDRs are routed through the
611635
VPC network interface.
@@ -616,19 +640,16 @@ def interface_create_vpc(
616640
"""
617641
params = {
618642
"purpose": "vpc",
619-
"subnet_id": subnet.id if isinstance(subnet, VPCSubnet) else subnet,
643+
"subnet_id": subnet,
620644
"primary": primary,
645+
"ipv4": ipv4,
646+
"ipv6": ipv6,
647+
"ip_ranges": ip_ranges,
621648
}
622649

623-
if ipv4 is not None:
624-
params["ipv4"] = (
625-
ipv4.dict if isinstance(ipv4, ConfigInterfaceIPv4) else ipv4
626-
)
627-
628-
if ip_ranges is not None:
629-
params["ip_ranges"] = ip_ranges
630-
631-
return self._interface_create(params)
650+
return self._interface_create(
651+
drop_null_keys(_flatten_request_body_recursive(params))
652+
)
632653

633654
def interface_reorder(self, interfaces: List[Union[int, NetworkInterface]]):
634655
"""

test/unit/objects/linode_test.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
ConfigInterface,
88
ConfigInterfaceIPv4,
99
ConfigInterfaceIPv6,
10+
ConfigInterfaceIPv6Options,
11+
ConfigInterfaceIPv6RangeOptions,
12+
ConfigInterfaceIPv6SLAACOptions,
1013
Disk,
1114
Image,
1215
Instance,
@@ -764,8 +767,8 @@ def test_create_interface_vpc(self):
764767
primary=True,
765768
ipv4=ConfigInterfaceIPv4(vpc="10.0.0.4", nat_1_1="any"),
766769
ipv6=ConfigInterfaceIPv6Options(
767-
slaac=[ConfigInterfaceIPv6OptionsSLAAC(range="auto")],
768-
ranges=[ConfigInterfaceIPv6OptionsRange(range="auto")],
770+
slaac=[ConfigInterfaceIPv6SLAACOptions(range="auto")],
771+
ranges=[ConfigInterfaceIPv6RangeOptions(range="auto")],
769772
is_public=True,
770773
),
771774
ip_ranges=["10.0.0.0/24"],
@@ -833,9 +836,9 @@ def test_update(self):
833836
"primary": False,
834837
"ipv4": {"vpc": "10.0.0.3", "nat_1_1": "any"},
835838
"ipv6": {
836-
"slaac": [{"range": "auto"}],
837-
"ranges": [{"range": "auto"}],
838-
"is_public": True,
839+
"slaac": [{"range": "1234::5678/64"}],
840+
"ranges": [{"range": "1234::5678/64"}],
841+
"is_public": False,
839842
},
840843
"ip_ranges": ["10.0.0.2/32"],
841844
}

0 commit comments

Comments
 (0)