|
6 | 6 | from types import SimpleNamespace |
7 | 7 |
|
8 | 8 |
|
9 | | -def create_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, models: SimpleNamespace): |
| 9 | +def create_nat_gateway_profile( |
| 10 | + managed_outbound_ip_count, |
| 11 | + idle_timeout, |
| 12 | + models: SimpleNamespace, |
| 13 | + managed_outbound_ipv6_count=None, |
| 14 | + outbound_ip_ids=None, |
| 15 | + outbound_ip_prefix_ids=None, |
| 16 | +): |
10 | 17 | """parse and build NAT gateway profile""" |
11 | | - if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout): |
| 18 | + if not is_nat_gateway_profile_provided( |
| 19 | + managed_outbound_ip_count, idle_timeout, |
| 20 | + managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids, |
| 21 | + ): |
12 | 22 | return None |
13 | 23 |
|
14 | 24 | profile = models.ManagedClusterNATGatewayProfile() |
15 | | - return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models) |
| 25 | + return configure_nat_gateway_profile( |
| 26 | + managed_outbound_ip_count, idle_timeout, profile, models, |
| 27 | + managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids, |
| 28 | + ) |
16 | 29 |
|
17 | 30 |
|
18 | | -def update_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace): |
| 31 | +def update_nat_gateway_profile( |
| 32 | + managed_outbound_ip_count, |
| 33 | + idle_timeout, |
| 34 | + profile, |
| 35 | + models: SimpleNamespace, |
| 36 | + managed_outbound_ipv6_count=None, |
| 37 | + outbound_ip_ids=None, |
| 38 | + outbound_ip_prefix_ids=None, |
| 39 | +): |
19 | 40 | """parse and update an existing NAT gateway profile""" |
20 | | - if not is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout): |
| 41 | + if not is_nat_gateway_profile_provided( |
| 42 | + managed_outbound_ip_count, idle_timeout, |
| 43 | + managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids, |
| 44 | + ): |
21 | 45 | return profile |
22 | 46 | if not profile: |
23 | 47 | profile = models.ManagedClusterNATGatewayProfile() |
24 | | - return configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models) |
| 48 | + return configure_nat_gateway_profile( |
| 49 | + managed_outbound_ip_count, idle_timeout, profile, models, |
| 50 | + managed_outbound_ipv6_count, outbound_ip_ids, outbound_ip_prefix_ids, |
| 51 | + ) |
25 | 52 |
|
26 | 53 |
|
27 | | -def is_nat_gateway_profile_provided(managed_outbound_ip_count, idle_timeout): |
28 | | - return any([managed_outbound_ip_count is not None, idle_timeout]) |
| 54 | +def is_nat_gateway_profile_provided( |
| 55 | + managed_outbound_ip_count, |
| 56 | + idle_timeout, |
| 57 | + managed_outbound_ipv6_count=None, |
| 58 | + outbound_ip_ids=None, |
| 59 | + outbound_ip_prefix_ids=None, |
| 60 | +): |
| 61 | + return any([ |
| 62 | + managed_outbound_ip_count is not None, |
| 63 | + idle_timeout, |
| 64 | + managed_outbound_ipv6_count is not None, |
| 65 | + outbound_ip_ids is not None, |
| 66 | + outbound_ip_prefix_ids is not None, |
| 67 | + ]) |
29 | 68 |
|
30 | 69 |
|
31 | | -def configure_nat_gateway_profile(managed_outbound_ip_count, idle_timeout, profile, models: SimpleNamespace): |
| 70 | +def configure_nat_gateway_profile( |
| 71 | + managed_outbound_ip_count, |
| 72 | + idle_timeout, |
| 73 | + profile, |
| 74 | + models: SimpleNamespace, |
| 75 | + managed_outbound_ipv6_count=None, |
| 76 | + outbound_ip_ids=None, |
| 77 | + outbound_ip_prefix_ids=None, |
| 78 | +): |
32 | 79 | """configure a NAT Gateway with customer supplied values""" |
33 | | - if managed_outbound_ip_count is not None: |
| 80 | + if managed_outbound_ip_count is not None or managed_outbound_ipv6_count is not None: |
34 | 81 | ManagedClusterManagedOutboundIPProfile = models.ManagedClusterManagedOutboundIPProfile |
35 | | - profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile( |
36 | | - count=managed_outbound_ip_count |
37 | | - ) |
| 82 | + if not profile.managed_outbound_ip_profile: |
| 83 | + profile.managed_outbound_ip_profile = ManagedClusterManagedOutboundIPProfile() |
| 84 | + if managed_outbound_ip_count is not None: |
| 85 | + profile.managed_outbound_ip_profile.count = managed_outbound_ip_count |
| 86 | + if managed_outbound_ipv6_count is not None: |
| 87 | + profile.managed_outbound_ip_profile.count_i_pv6 = managed_outbound_ipv6_count |
38 | 88 |
|
39 | 89 | if idle_timeout: |
40 | 90 | profile.idle_timeout_in_minutes = idle_timeout |
41 | 91 |
|
| 92 | + if outbound_ip_ids is not None: |
| 93 | + ManagedClusterNATGatewayProfileOutboundIPs = models.ManagedClusterNATGatewayProfileOutboundIPs |
| 94 | + profile.outbound_i_ps = ManagedClusterNATGatewayProfileOutboundIPs( |
| 95 | + public_i_ps=outbound_ip_ids |
| 96 | + ) |
| 97 | + |
| 98 | + if outbound_ip_prefix_ids is not None: |
| 99 | + ManagedClusterNATGatewayProfileOutboundIPPrefixes = models.ManagedClusterNATGatewayProfileOutboundIPPrefixes |
| 100 | + profile.outbound_ip_prefixes = ManagedClusterNATGatewayProfileOutboundIPPrefixes( |
| 101 | + public_ip_prefixes=outbound_ip_prefix_ids |
| 102 | + ) |
| 103 | + |
42 | 104 | return profile |
0 commit comments