|
36 | 36 | ) |
37 | 37 |
|
38 | 38 |
|
| 39 | +def _build_network_for_create_runtime( |
| 40 | + vpc_id: Optional[str], |
| 41 | + subnet_ids: Optional[str], |
| 42 | + enable_private_network: bool, |
| 43 | + enable_public_network: bool, |
| 44 | + enable_shared_internet_access: bool, |
| 45 | +) -> Optional[rt.NetworkForCreateRuntime]: |
| 46 | + has_vpc_id = bool((vpc_id or "").strip()) |
| 47 | + has_subnet_ids = bool((subnet_ids or "").strip()) |
| 48 | + |
| 49 | + wants_private_network = ( |
| 50 | + enable_private_network |
| 51 | + or has_vpc_id |
| 52 | + or has_subnet_ids |
| 53 | + or enable_shared_internet_access |
| 54 | + ) |
| 55 | + |
| 56 | + if enable_shared_internet_access and not wants_private_network: |
| 57 | + raise ValueError( |
| 58 | + "enable-shared-internet-access is only effective when private network is enabled." |
| 59 | + ) |
| 60 | + |
| 61 | + if wants_private_network and not has_vpc_id: |
| 62 | + raise ValueError( |
| 63 | + "vpc-id is required when private network is enabled (private/both)." |
| 64 | + ) |
| 65 | + |
| 66 | + if not wants_private_network and enable_public_network is False: |
| 67 | + raise ValueError( |
| 68 | + "At least one network must be enabled. Enable public network or configure private network." |
| 69 | + ) |
| 70 | + |
| 71 | + should_send_network_configuration = ( |
| 72 | + wants_private_network or enable_public_network is False |
| 73 | + ) |
| 74 | + if not should_send_network_configuration: |
| 75 | + return None |
| 76 | + |
| 77 | + vpc = None |
| 78 | + if wants_private_network: |
| 79 | + subs = [s.strip() for s in (subnet_ids or "").split(",") if s.strip()] or None |
| 80 | + vpc = rt.NetworkVpcForCreateRuntime( |
| 81 | + vpc_id=(vpc_id or "").strip(), |
| 82 | + subnet_ids=subs, |
| 83 | + enable_shared_internet_access=( |
| 84 | + True if enable_shared_internet_access else None |
| 85 | + ), |
| 86 | + ) |
| 87 | + |
| 88 | + return rt.NetworkForCreateRuntime( |
| 89 | + vpc_configuration=vpc, |
| 90 | + enable_private_network=wants_private_network, |
| 91 | + enable_public_network=enable_public_network, |
| 92 | + ) |
| 93 | + |
| 94 | + |
39 | 95 | @runtime_app.command("create") |
40 | 96 | def create_runtime_command( |
41 | 97 | name: str = typer.Option(..., "--name", help="Runtime name"), |
@@ -71,7 +127,14 @@ def create_runtime_command( |
71 | 127 | False, "--enable-private-network", help="Enable private network" |
72 | 128 | ), |
73 | 129 | enable_public_network: bool = typer.Option( |
74 | | - True, "--enable-public-network", help="Enable public network" |
| 130 | + True, |
| 131 | + "--enable-public-network/--no-enable-public-network", |
| 132 | + help="Enable public network", |
| 133 | + ), |
| 134 | + enable_shared_internet_access: bool = typer.Option( |
| 135 | + False, |
| 136 | + "--enable-shared-internet-access", |
| 137 | + help="Enable shared internet egress for private network (effective for private/both)", |
75 | 138 | ), |
76 | 139 | api_key_name: Optional[str] = typer.Option( |
77 | 140 | None, "--apikey-name", help="API key name" |
@@ -133,18 +196,13 @@ def create_runtime_command( |
133 | 196 | ) |
134 | 197 |
|
135 | 198 | network = None |
136 | | - if vpc_id or enable_private_network or enable_public_network: |
137 | | - vpc = None |
138 | | - if vpc_id: |
139 | | - subs = [ |
140 | | - s.strip() for s in (subnet_ids or "").split(",") if s.strip() |
141 | | - ] or None |
142 | | - vpc = rt.NetworkVpcForCreateRuntime(vpc_id=vpc_id, subnet_ids=subs) |
143 | | - network = rt.NetworkForCreateRuntime( |
144 | | - vpc_configuration=vpc, |
145 | | - enable_private_network=enable_private_network, |
146 | | - enable_public_network=enable_public_network, |
147 | | - ) |
| 199 | + network = _build_network_for_create_runtime( |
| 200 | + vpc_id=vpc_id, |
| 201 | + subnet_ids=subnet_ids, |
| 202 | + enable_private_network=enable_private_network, |
| 203 | + enable_public_network=enable_public_network, |
| 204 | + enable_shared_internet_access=enable_shared_internet_access, |
| 205 | + ) |
148 | 206 |
|
149 | 207 | envs = None |
150 | 208 | if envs_json: |
|
0 commit comments