Skip to content

Commit 99c8c1a

Browse files
authored
feat(function): add support for VPC integration (#1020)
1 parent b2cc08e commit 99c8c1a

File tree

6 files changed

+156
-24
lines changed

6 files changed

+156
-24
lines changed

scaleway-async/scaleway_async/function/v1beta1/api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ async def wait_for_namespace(
271271
async def create_namespace(
272272
self,
273273
*,
274+
activate_vpc_integration: bool,
274275
region: Optional[ScwRegion] = None,
275276
name: Optional[str] = None,
276277
environment_variables: Optional[Dict[str, str]] = None,
@@ -282,6 +283,7 @@ async def create_namespace(
282283
"""
283284
Create a new namespace.
284285
Create a new namespace in a specified Organization or Project.
286+
:param activate_vpc_integration: When activated, functions in the namespace can be connected to a Private Network.
285287
:param region: Region to target. If none is passed will use default region from the config.
286288
:param name:
287289
:param environment_variables: Environment variables of the namespace.
@@ -294,7 +296,9 @@ async def create_namespace(
294296
Usage:
295297
::
296298
297-
result = await api.create_namespace()
299+
result = await api.create_namespace(
300+
activate_vpc_integration=False,
301+
)
298302
"""
299303

300304
param_region = validate_path_param(
@@ -306,6 +310,7 @@ async def create_namespace(
306310
f"/functions/v1beta1/regions/{param_region}/namespaces",
307311
body=marshal_CreateNamespaceRequest(
308312
CreateNamespaceRequest(
313+
activate_vpc_integration=activate_vpc_integration,
309314
region=region,
310315
name=name or random_name(prefix="ns"),
311316
environment_variables=environment_variables,
@@ -602,6 +607,7 @@ async def create_function(
602607
http_option: Optional[FunctionHttpOption] = None,
603608
sandbox: Optional[FunctionSandbox] = None,
604609
tags: Optional[List[str]] = None,
610+
private_network_id: Optional[str] = None,
605611
) -> Function:
606612
"""
607613
Create a new function.
@@ -624,6 +630,9 @@ async def create_function(
624630
- enabled: Serve both HTTP and HTTPS traffic.
625631
:param sandbox: Execution environment of the function.
626632
:param tags: Tags of the Serverless Function.
633+
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
634+
635+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
627636
:return: :class:`Function <Function>`
628637
629638
Usage:
@@ -659,6 +668,7 @@ async def create_function(
659668
http_option=http_option,
660669
sandbox=sandbox,
661670
tags=tags,
671+
private_network_id=private_network_id,
662672
),
663673
self.client,
664674
),
@@ -686,6 +696,7 @@ async def update_function(
686696
http_option: Optional[FunctionHttpOption] = None,
687697
sandbox: Optional[FunctionSandbox] = None,
688698
tags: Optional[List[str]] = None,
699+
private_network_id: Optional[str] = None,
689700
) -> Function:
690701
"""
691702
Update an existing function.
@@ -708,6 +719,9 @@ async def update_function(
708719
- enabled: Serve both HTTP and HTTPS traffic.
709720
:param sandbox: Execution environment of the function.
710721
:param tags: Tags of the Serverless Function.
722+
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
723+
724+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
711725
:return: :class:`Function <Function>`
712726
713727
Usage:
@@ -744,6 +758,7 @@ async def update_function(
744758
http_option=http_option,
745759
sandbox=sandbox,
746760
tags=tags,
761+
private_network_id=private_network_id,
747762
),
748763
self.client,
749764
),

scaleway-async/scaleway_async/function/v1beta1/marshalling.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ def unmarshal_Function(data: Any) -> Function:
271271
else:
272272
args["ready_at"] = None
273273

274+
field = data.get("private_network_id", None)
275+
if field is not None:
276+
args["private_network_id"] = field
277+
else:
278+
args["private_network_id"] = None
279+
274280
return Function(**args)
275281

276282

@@ -310,6 +316,12 @@ def unmarshal_Namespace(data: Any) -> Namespace:
310316
if field is not None:
311317
args["registry_namespace_id"] = field
312318

319+
field = data.get("error_message", None)
320+
if field is not None:
321+
args["error_message"] = field
322+
else:
323+
args["error_message"] = None
324+
313325
field = data.get("registry_endpoint", None)
314326
if field is not None:
315327
args["registry_endpoint"] = field
@@ -330,12 +342,6 @@ def unmarshal_Namespace(data: Any) -> Namespace:
330342
if field is not None:
331343
args["tags"] = field
332344

333-
field = data.get("error_message", None)
334-
if field is not None:
335-
args["error_message"] = field
336-
else:
337-
args["error_message"] = None
338-
339345
field = data.get("description", None)
340346
if field is not None:
341347
args["description"] = field
@@ -354,6 +360,12 @@ def unmarshal_Namespace(data: Any) -> Namespace:
354360
else:
355361
args["updated_at"] = None
356362

363+
field = data.get("vpc_integration_activated", None)
364+
if field is not None:
365+
args["vpc_integration_activated"] = field
366+
else:
367+
args["vpc_integration_activated"] = None
368+
357369
return Namespace(**args)
358370

359371

@@ -899,6 +911,9 @@ def marshal_CreateFunctionRequest(
899911
if request.tags is not None:
900912
output["tags"] = request.tags
901913

914+
if request.private_network_id is not None:
915+
output["private_network_id"] = request.private_network_id
916+
902917
return output
903918

904919

@@ -908,6 +923,9 @@ def marshal_CreateNamespaceRequest(
908923
) -> Dict[str, Any]:
909924
output: Dict[str, Any] = {}
910925

926+
if request.activate_vpc_integration is not None:
927+
output["activate_vpc_integration"] = request.activate_vpc_integration
928+
911929
if request.name is not None:
912930
output["name"] = request.name
913931

@@ -1114,6 +1132,9 @@ def marshal_UpdateFunctionRequest(
11141132
if request.tags is not None:
11151133
output["tags"] = request.tags
11161134

1135+
if request.private_network_id is not None:
1136+
output["private_network_id"] = request.private_network_id
1137+
11171138
return output
11181139

11191140

scaleway-async/scaleway_async/function/v1beta1/types.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ class Function:
583583
Last date when the function was successfully deployed and set to ready.
584584
"""
585585

586+
private_network_id: Optional[str]
587+
"""
588+
When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
589+
"""
590+
586591

587592
@dataclass
588593
class Namespace:
@@ -621,6 +626,11 @@ class Namespace:
621626
UUID of the registry namespace.
622627
"""
623628

629+
error_message: Optional[str]
630+
"""
631+
Error message if the namespace is in "error" state.
632+
"""
633+
624634
registry_endpoint: str
625635
"""
626636
Registry endpoint of the namespace.
@@ -641,11 +651,6 @@ class Namespace:
641651
List of tags applied to the Serverless Function Namespace.
642652
"""
643653

644-
error_message: Optional[str]
645-
"""
646-
Error message if the namespace is in "error" state.
647-
"""
648-
649654
description: Optional[str]
650655
"""
651656
Description of the namespace.
@@ -661,6 +666,12 @@ class Namespace:
661666
Last update date of the namespace.
662667
"""
663668

669+
vpc_integration_activated: Optional[bool]
670+
"""
671+
When activated, functions in the namespace can be connected to a Private Network.
672+
Note that activating the VPC integration can only be done when creating a new namespace.
673+
"""
674+
664675

665676
@dataclass
666677
class Token:
@@ -877,9 +888,21 @@ class CreateFunctionRequest:
877888
Tags of the Serverless Function.
878889
"""
879890

891+
private_network_id: Optional[str]
892+
"""
893+
When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
894+
895+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
896+
"""
897+
880898

881899
@dataclass
882900
class CreateNamespaceRequest:
901+
activate_vpc_integration: bool
902+
"""
903+
When activated, functions in the namespace can be connected to a Private Network.
904+
"""
905+
883906
region: Optional[ScwRegion]
884907
"""
885908
Region to target. If none is passed will use default region from the config.
@@ -1577,6 +1600,13 @@ class UpdateFunctionRequest:
15771600
Tags of the Serverless Function.
15781601
"""
15791602

1603+
private_network_id: Optional[str]
1604+
"""
1605+
When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
1606+
1607+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
1608+
"""
1609+
15801610

15811611
@dataclass
15821612
class UpdateNamespaceRequest:

scaleway/scaleway/function/v1beta1/api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def wait_for_namespace(
269269
def create_namespace(
270270
self,
271271
*,
272+
activate_vpc_integration: bool,
272273
region: Optional[ScwRegion] = None,
273274
name: Optional[str] = None,
274275
environment_variables: Optional[Dict[str, str]] = None,
@@ -280,6 +281,7 @@ def create_namespace(
280281
"""
281282
Create a new namespace.
282283
Create a new namespace in a specified Organization or Project.
284+
:param activate_vpc_integration: When activated, functions in the namespace can be connected to a Private Network.
283285
:param region: Region to target. If none is passed will use default region from the config.
284286
:param name:
285287
:param environment_variables: Environment variables of the namespace.
@@ -292,7 +294,9 @@ def create_namespace(
292294
Usage:
293295
::
294296
295-
result = api.create_namespace()
297+
result = api.create_namespace(
298+
activate_vpc_integration=False,
299+
)
296300
"""
297301

298302
param_region = validate_path_param(
@@ -304,6 +308,7 @@ def create_namespace(
304308
f"/functions/v1beta1/regions/{param_region}/namespaces",
305309
body=marshal_CreateNamespaceRequest(
306310
CreateNamespaceRequest(
311+
activate_vpc_integration=activate_vpc_integration,
307312
region=region,
308313
name=name or random_name(prefix="ns"),
309314
environment_variables=environment_variables,
@@ -598,6 +603,7 @@ def create_function(
598603
http_option: Optional[FunctionHttpOption] = None,
599604
sandbox: Optional[FunctionSandbox] = None,
600605
tags: Optional[List[str]] = None,
606+
private_network_id: Optional[str] = None,
601607
) -> Function:
602608
"""
603609
Create a new function.
@@ -620,6 +626,9 @@ def create_function(
620626
- enabled: Serve both HTTP and HTTPS traffic.
621627
:param sandbox: Execution environment of the function.
622628
:param tags: Tags of the Serverless Function.
629+
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
630+
631+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
623632
:return: :class:`Function <Function>`
624633
625634
Usage:
@@ -655,6 +664,7 @@ def create_function(
655664
http_option=http_option,
656665
sandbox=sandbox,
657666
tags=tags,
667+
private_network_id=private_network_id,
658668
),
659669
self.client,
660670
),
@@ -682,6 +692,7 @@ def update_function(
682692
http_option: Optional[FunctionHttpOption] = None,
683693
sandbox: Optional[FunctionSandbox] = None,
684694
tags: Optional[List[str]] = None,
695+
private_network_id: Optional[str] = None,
685696
) -> Function:
686697
"""
687698
Update an existing function.
@@ -704,6 +715,9 @@ def update_function(
704715
- enabled: Serve both HTTP and HTTPS traffic.
705716
:param sandbox: Execution environment of the function.
706717
:param tags: Tags of the Serverless Function.
718+
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
719+
720+
Note: this feature is currently in beta and requires a namespace with VPC integration activated, using the `activate_vpc_integration` flag.
707721
:return: :class:`Function <Function>`
708722
709723
Usage:
@@ -740,6 +754,7 @@ def update_function(
740754
http_option=http_option,
741755
sandbox=sandbox,
742756
tags=tags,
757+
private_network_id=private_network_id,
743758
),
744759
self.client,
745760
),

0 commit comments

Comments
 (0)