1 package linodego
2 3 import (
4 "context"
5 )
6 7 // IPAddressUpdateOptionsV2 fields are those accepted by UpdateIPAddress.
8 // NOTE: An IP's RDNS can be reset to default using the following pattern:
9 //
10 // IPAddressUpdateOptionsV2{
11 // RDNS: linodego.Pointer[*string](nil),
12 // }
13 type IPAddressUpdateOptionsV2 struct {
14 // The reverse DNS assigned to this address. For public IPv4 addresses, this will be set to a default value provided by Linode if set to nil.
15 Reserved *bool `json:"reserved,omitempty"`
16 RDNS **string `json:"rdns,omitempty"`
17 }
18 19 // IPAddressUpdateOptions fields are those accepted by UpdateIPAddress.
20 //
21 // Deprecated: Please use IPAddressUpdateOptionsV2 for all new implementations.
22 type IPAddressUpdateOptions struct {
23 RDNS *string `json:"rdns"`
24 }
25 26 // LinodeIPAssignment stores an assignment between an IP address and a Linode instance.
27 type LinodeIPAssignment struct {
28 Address string `json:"address"`
29 LinodeID int `json:"linode_id"`
30 }
31 32 type AllocateReserveIPOptions struct {
33 Type string `json:"type"`
34 Public bool `json:"public"`
35 Reserved bool `json:"reserved,omitempty"`
36 Region string `json:"region,omitempty"`
37 LinodeID int `json:"linode_id,omitempty"`
38 }
39 40 // LinodesAssignIPsOptions fields are those accepted by InstancesAssignIPs.
41 type LinodesAssignIPsOptions struct {
42 Region string `json:"region"`
43 44 Assignments []LinodeIPAssignment `json:"assignments"`
45 }
46 47 // IPAddressesShareOptions fields are those accepted by ShareIPAddresses.
48 type IPAddressesShareOptions struct {
49 IPs []string `json:"ips"`
50 LinodeID int `json:"linode_id"`
51 }
52 53 // ListIPAddressesQuery fields are those accepted as query params for the
54 // ListIPAddresses function.
55 type ListIPAddressesQuery struct {
56 SkipIPv6RDNS bool `query:"skip_ipv6_rdns"`
57 }
58 59 // GetUpdateOptionsV2 converts a IPAddress to IPAddressUpdateOptionsV2 for use in UpdateIPAddressV2.
60 func (i InstanceIP) GetUpdateOptionsV2() IPAddressUpdateOptionsV2 {
61 rdns := copyString(&i.RDNS)
62 63 return IPAddressUpdateOptionsV2{
64 RDNS: &rdns,
65 Reserved: copyBool(&i.Reserved),
66 }
67 }
68 69 // GetUpdateOptions converts a IPAddress to IPAddressUpdateOptions for use in UpdateIPAddress.
70 //
71 // Deprecated: Please use GetUpdateOptionsV2 for all new implementations.
72 func (i InstanceIP) GetUpdateOptions() (o IPAddressUpdateOptions) {
73 o.RDNS = copyString(&i.RDNS)
74 return o
75 }
76 77 // ListIPAddresses lists IPAddresses.
78 func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]InstanceIP, error) {
79 return getPaginatedResults[InstanceIP](ctx, c, "networking/ips", opts)
80 }
81 82 // GetIPAddress gets the IPAddress with the provided IP.
83 func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, error) {
84 e := formatAPIPath("networking/ips/%s", id)
85 return doGETRequest[InstanceIP](ctx, c, e)
86 }
87 88 // UpdateIPAddressV2 updates the IP address with the specified address.
89 func (c *Client) UpdateIPAddressV2(ctx context.Context, address string, opts IPAddressUpdateOptionsV2) (*InstanceIP, error) {
90 e := formatAPIPath("networking/ips/%s", address)
91 return doPUTRequest[InstanceIP](ctx, c, e, opts)
92 }
93 94 // UpdateIPAddress updates the IP address with the specified id.
95 //
96 // Deprecated: Please use UpdateIPAddressV2 for all new implementation.
97 func (c *Client) UpdateIPAddress(ctx context.Context, id string, opts IPAddressUpdateOptions) (*InstanceIP, error) {
98 e := formatAPIPath("networking/ips/%s", id)
99 return doPUTRequest[InstanceIP](ctx, c, e, opts)
100 }
101 102 // InstancesAssignIPs assigns multiple IPv4 addresses and/or IPv6 ranges to multiple Linodes in one Region.
103 // This allows swapping, shuffling, or otherwise reorganizing IPs to your Linodes.
104 func (c *Client) InstancesAssignIPs(ctx context.Context, opts LinodesAssignIPsOptions) error {
105 return doPOSTRequestNoResponseBody(ctx, c, "networking/ips/assign", opts)
106 }
107 108 // ShareIPAddresses allows IP address reassignment (also referred to as IP failover)
109 // from one Linode to another if the primary Linode becomes unresponsive.
110 func (c *Client) ShareIPAddresses(ctx context.Context, opts IPAddressesShareOptions) error {
111 return doPOSTRequestNoResponseBody(ctx, c, "networking/ips/share", opts)
112 }
113 114 // AllocateReserveIP allocates a new IPv4 address to the Account, with the option to reserve it
115 // and optionally assign it to a Linode.
116 func (c *Client) AllocateReserveIP(ctx context.Context, opts AllocateReserveIPOptions) (*InstanceIP, error) {
117 return doPOSTRequest[InstanceIP](ctx, c, "networking/ips", opts)
118 }
119