Skip to content

Commit dd94cde

Browse files
progress
1 parent 1d1a04a commit dd94cde

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

linode_api4/objects/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
nullable=False,
3636
unordered=False,
3737
json_object=None,
38+
json_object_options=None,
3839
):
3940
"""
4041
A Property is an attribute returned from the API, and defines metadata
@@ -56,6 +57,8 @@ def __init__(
5657
NOTE: This field is currently only for annotations purposes
5758
and does not influence any update or decoding/encoding logic.
5859
json_object - The JSONObject class this property should be decoded into.
60+
json_object_options - The JSONObject class this property should use when
61+
serializing for PUT requests.
5962
"""
6063
self.mutable = mutable
6164
self.identifier = identifier
@@ -68,6 +71,7 @@ def __init__(
6871
self.nullable = nullable
6972
self.unordered = unordered
7073
self.json_class = json_object
74+
self.json_class_options = json_object_options
7175

7276

7377
class MappedObject:
@@ -282,6 +286,17 @@ def save(self, force=True) -> bool:
282286
else:
283287
data = self._serialize()
284288

289+
for key, value in data.items():
290+
key_property = getattr(type(self).properties, key, None)
291+
if key_property is None:
292+
continue
293+
294+
json_class = key_property.json_class
295+
if json_class is None:
296+
continue
297+
298+
data[key] = json_class.from_json(value).dict
299+
285300
resp = self._client.put(type(self).api_endpoint, model=self, data=data)
286301

287302
if "error" in resp:

linode_api4/objects/linode.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ class NetworkInterface(DerivedBase):
359359
"vpc_id": Property(id_relationship=VPC),
360360
"subnet_id": Property(),
361361
"ipv4": Property(mutable=True, json_object=ConfigInterfaceIPv4),
362-
"ipv6": Property(mutable=True, json_object=ConfigInterfaceIPv6),
362+
"ipv6": Property(
363+
mutable=True,
364+
json_object=ConfigInterfaceIPv6,
365+
json_object_options=ConfigInterfaceIPv6Options,
366+
),
363367
"ip_ranges": Property(mutable=True),
364368
}
365369

@@ -385,6 +389,17 @@ def __init__(self, client, id, parent_id, instance_id=None, json=None):
385389
def __repr__(self):
386390
return f"Interface: {self.purpose} {self.id}"
387391

392+
def _serialize(self):
393+
result = DerivedBase._serialize(self)
394+
395+
ipv6 = result.get("ipv6", None)
396+
397+
if isinstance(ipv6, ConfigInterfaceIPv6):
398+
print("SDF")
399+
result["ipv6"] = ConfigInterfaceIPv6Options.from_json(ipv6.dict)
400+
401+
return result
402+
388403
@property
389404
def subnet(self) -> VPCSubnet:
390405
"""
@@ -460,6 +475,11 @@ def _serialize(self):
460475
if isinstance(self.ipv4, ConfigInterfaceIPv4)
461476
else self.ipv4
462477
),
478+
"ipv6": (
479+
self.ipv6.dict
480+
if isinstance(self.ipv4, ConfigInterfaceIPv6)
481+
else self.ipv6
482+
),
463483
"ip_ranges": self.ip_ranges,
464484
},
465485
}

0 commit comments

Comments
 (0)