|
13 | 13 | IPAddress, |
14 | 14 | IPv6Pool, |
15 | 15 | IPv6Range, |
| 16 | + NATGateway, |
| 17 | + NATGatewayAddress, |
16 | 18 | NetworkTransferPrice, |
17 | 19 | Region, |
18 | 20 | ) |
19 | 21 | from linode_api4.objects.base import _flatten_request_body_recursive |
20 | | -from linode_api4.objects.networking import ReservedIPAddress, ReservedIPType |
| 22 | +from linode_api4.objects.networking import ( |
| 23 | + NATGatewaySettings, |
| 24 | + NATGatewayType, |
| 25 | + ReservedIPAddress, |
| 26 | + ReservedIPType, |
| 27 | +) |
21 | 28 | from linode_api4.paginated_list import PaginatedList |
22 | 29 | from linode_api4.util import drop_null_keys |
23 | 30 |
|
@@ -622,3 +629,116 @@ def reserved_ip_types(self, *filters) -> PaginatedList: |
622 | 629 | return self.client._get_and_filter( |
623 | 630 | ReservedIPType, *filters, endpoint="/networking/reserved/ips/types" |
624 | 631 | ) |
| 632 | + |
| 633 | + def natgateways(self, *filters): |
| 634 | + """ |
| 635 | + Retrieves the NAT Gateways your user has access to. |
| 636 | +
|
| 637 | + API Documentation: https://techdocs.akamai.com/linode-api/reference/get-natgateways |
| 638 | +
|
| 639 | + :param filters: Any number of filters to apply to this query. |
| 640 | + See :doc:`Filtering Collections</linode_api4/objects/filtering>` |
| 641 | + for more details on filtering. |
| 642 | +
|
| 643 | + :returns: A list of NAT Gateways the acting user can access. |
| 644 | + :rtype: PaginatedList of NATGateway |
| 645 | + """ |
| 646 | + return self.client._get_and_filter(NATGateway, *filters) |
| 647 | + |
| 648 | + def natgateway_create( |
| 649 | + self, |
| 650 | + region: Union[Region, str], |
| 651 | + label: str, |
| 652 | + addresses: Optional[ |
| 653 | + List[Union[NATGatewayAddress, Dict[str, Any]]] |
| 654 | + ] = None, |
| 655 | + default_ports_per_interface: Optional[int] = None, |
| 656 | + use_autoscaling: Optional[bool] = None, |
| 657 | + vpc_subnet_id: Optional[int] = None, |
| 658 | + **kwargs, |
| 659 | + ) -> NATGateway: |
| 660 | + """ |
| 661 | + Create a NAT Gateway in the given region. |
| 662 | +
|
| 663 | + NOTE: NAT Gateways may not currently be available to all users. |
| 664 | +
|
| 665 | + API Documentation: https://techdocs.akamai.com/linode-api/reference/post-natgateways |
| 666 | +
|
| 667 | + :param region: The region in which to create the NAT Gateway. |
| 668 | + :type region: str or Region |
| 669 | + :param label: The label of the NAT Gateway. |
| 670 | + :type label: str |
| 671 | + :param addresses: The reserved IP addresses to assign to this NAT Gateway. |
| 672 | + :type addresses: list of NATGatewayAddress or list of dict |
| 673 | + :param default_ports_per_interface: The default ports per interface to use. |
| 674 | + Defaults to 4096 on the API side. |
| 675 | + :type default_ports_per_interface: int |
| 676 | + :param use_autoscaling: Whether the NAT Gateway should autoscale its address pool. |
| 677 | + :type use_autoscaling: bool |
| 678 | + :param vpc_subnet_id: The ID of the VPC subnet this NAT Gateway should attach to. |
| 679 | + :type vpc_subnet_id: int |
| 680 | +
|
| 681 | + :returns: The new NAT Gateway. |
| 682 | + :rtype: NATGateway |
| 683 | + """ |
| 684 | + params = { |
| 685 | + "region": region.id if isinstance(region, Region) else region, |
| 686 | + "label": label, |
| 687 | + "addresses": addresses, |
| 688 | + "default_ports_per_interface": default_ports_per_interface, |
| 689 | + "use_autoscaling": use_autoscaling, |
| 690 | + "vpc_subnet_id": vpc_subnet_id, |
| 691 | + } |
| 692 | + params.update(kwargs) |
| 693 | + |
| 694 | + result = self.client.post( |
| 695 | + "/networking/natgateways", |
| 696 | + data=drop_null_keys(_flatten_request_body_recursive(params)), |
| 697 | + ) |
| 698 | + |
| 699 | + if "id" not in result: |
| 700 | + raise UnexpectedResponseError( |
| 701 | + "Unexpected response when creating NAT Gateway!", json=result |
| 702 | + ) |
| 703 | + |
| 704 | + return NATGateway(self.client, result["id"], result) |
| 705 | + |
| 706 | + def natgateway_types(self, *filters) -> PaginatedList: |
| 707 | + """ |
| 708 | + Returns a list of NAT Gateway types with pricing information. |
| 709 | +
|
| 710 | + NOTE: NAT Gateways may not currently be available to all users. |
| 711 | +
|
| 712 | + API Documentation: https://techdocs.akamai.com/linode-api/reference/get-natgateway-types |
| 713 | +
|
| 714 | + :param filters: Any number of filters to apply to this query. |
| 715 | + See :doc:`Filtering Collections</linode_api4/objects/filtering>` |
| 716 | + for more details on filtering. |
| 717 | +
|
| 718 | + :returns: A list of NAT Gateway types. |
| 719 | + :rtype: PaginatedList of NATGatewayType |
| 720 | + """ |
| 721 | + return self.client._get_and_filter( |
| 722 | + NATGatewayType, *filters, endpoint="/networking/natgateways/types" |
| 723 | + ) |
| 724 | + |
| 725 | + def natgateway_settings(self) -> NATGatewaySettings: |
| 726 | + """ |
| 727 | + Returns the account-wide NAT Gateway settings and limits for the current user. |
| 728 | +
|
| 729 | + NOTE: NAT Gateways may not currently be available to all users. |
| 730 | +
|
| 731 | + API Documentation: https://techdocs.akamai.com/linode-api/reference/get-natgateway-settings |
| 732 | +
|
| 733 | + :returns: The NAT Gateway settings for the current user. |
| 734 | + :rtype: NATGatewaySettings |
| 735 | + """ |
| 736 | + result = self.client.get("/networking/natgateways/settings") |
| 737 | + |
| 738 | + if "allowed_ports_per_interface" not in result: |
| 739 | + raise UnexpectedResponseError( |
| 740 | + "Unexpected response when getting NAT Gateway settings!", |
| 741 | + json=result, |
| 742 | + ) |
| 743 | + |
| 744 | + return NATGatewaySettings.from_json(result) |
0 commit comments