11import base64
22import os
3- from collections .abc import Iterable
4- from typing import Any , Dict , Optional , Union
3+ from typing import Any , Dict , List , Optional , Union
54
65from linode_api4 .common import load_and_validate_keys
76from linode_api4 .errors import UnexpectedResponseError
87from linode_api4 .groups import Group
98from linode_api4 .objects import (
10- ConfigInterface ,
119 Firewall ,
1210 Instance ,
1311 InstanceDiskEncryptionType ,
2119from linode_api4 .objects .linode import (
2220 Backup ,
2321 InstancePlacementGroupAssignment ,
22+ InterfaceGeneration ,
23+ NetworkInterface ,
2424 _expand_placement_group_assignment ,
2525)
26+ from linode_api4 .objects .linode_interfaces import (
27+ LinodeInterfaceOptions ,
28+ )
2629from linode_api4 .util import drop_null_keys
2730
2831
@@ -153,6 +156,13 @@ def instance_create(
153156 int ,
154157 ]
155158 ] = None ,
159+ interfaces : Optional [
160+ List [
161+ Union [LinodeInterfaceOptions , NetworkInterface , Dict [str , Any ]],
162+ ]
163+ ] = None ,
164+ interface_generation : Optional [Union [InterfaceGeneration , str ]] = None ,
165+ network_helper : Optional [bool ] = None ,
156166 ** kwargs ,
157167 ):
158168 """
@@ -230,6 +240,30 @@ def instance_create(
230240 "us-east",
231241 backup=snapshot)
232242
243+ **Create an Instance with explicit interfaces:**
244+
245+ To create a new Instance with explicit interfaces, provide list of
246+ LinodeInterfaceOptions objects or dicts to the "interfaces" field::
247+
248+ linode, password = client.linode.instance_create(
249+ "g6-standard-1",
250+ "us-mia",
251+ image="linode/ubuntu24.04",
252+
253+ # This can be configured as an account-wide default
254+ interface_generation=InterfaceGeneration.LINODE,
255+
256+ interfaces=[
257+ LinodeInterfaceOptions(
258+ default_route=LinodeInterfaceDefaultRouteOptions(
259+ ipv4=True,
260+ ipv6=True
261+ ),
262+ public=LinodeInterfacePublicOptions
263+ )
264+ ]
265+ )
266+
233267 **Create an empty Instance**
234268
235269 If you want to create an empty Instance that you will configure manually,
@@ -293,9 +327,13 @@ def instance_create(
293327 :type disk_encryption: InstanceDiskEncryptionType or str
294328 :param interfaces: An array of Network Interfaces to add to this Linode’s Configuration Profile.
295329 At least one and up to three Interface objects can exist in this array.
296- :type interfaces: list[ConfigInterface] or list [dict[str, Any]]
330+ :type interfaces: List[LinodeInterfaceOptions], List[NetworkInterface], or List [dict[str, Any]]
297331 :param placement_group: A Placement Group to create this Linode under.
298332 :type placement_group: Union[InstancePlacementGroupAssignment, PlacementGroup, Dict[str, Any], int]
333+ :param interface_generation: The generation of network interfaces this Linode uses.
334+ :type interface_generation: InterfaceGeneration or str
335+ :param network_helper: Whether this instance should have Network Helper enabled.
336+ :type network_helper: bool
299337
300338 :returns: A new Instance object, or a tuple containing the new Instance and
301339 the generated password.
@@ -311,13 +349,6 @@ def instance_create(
311349 ret_pass = Instance .generate_root_password ()
312350 kwargs ["root_pass" ] = ret_pass
313351
314- interfaces = kwargs .get ("interfaces" , None )
315- if interfaces is not None and isinstance (interfaces , Iterable ):
316- kwargs ["interfaces" ] = [
317- i ._serialize () if isinstance (i , ConfigInterface ) else i
318- for i in interfaces
319- ]
320-
321352 params = {
322353 "type" : ltype ,
323354 "region" : region ,
@@ -336,6 +367,9 @@ def instance_create(
336367 if placement_group
337368 else None
338369 ),
370+ "interfaces" : interfaces ,
371+ "interface_generation" : interface_generation ,
372+ "network_helper" : network_helper ,
339373 }
340374
341375 params .update (kwargs )
0 commit comments