11import {
22 allocateIPSchema ,
33 assignAddressesSchema ,
4+ reserveIPSchema ,
45 shareAddressesSchema ,
56 updateIPSchema ,
67} from '@linode/validation/lib/networking.schema' ;
@@ -14,14 +15,16 @@ import Request, {
1415 setXFilter ,
1516} from '../request' ;
1617
17- import type { Filter , ResourcePage as Page , Params } from '../types' ;
18+ import type { Filter , ResourcePage as Page , Params , PriceType } from '../types' ;
1819import type {
20+ AllocateIPPayload ,
1921 CreateIPv6RangePayload ,
2022 IPAddress ,
2123 IPAssignmentPayload ,
2224 IPRange ,
2325 IPRangeInformation ,
2426 IPSharingPayload ,
27+ ReserveIPPayload ,
2528} from './types' ;
2629
2730/**
@@ -52,16 +55,24 @@ export const getIP = (address: string) =>
5255 * Sets RDNS on an IP Address. Forward DNS must already be set up for reverse
5356 * DNS to be applied. If you set the RDNS to null for public IPv4 addresses,
5457 * it will be reset to the default members.linode.com RDNS value.
58+ * Also setting “reserved” field to true converts an Ephemeral IP to an Reserved IP.
59+ * setting “reserved” field set to false converts a Reserved IP to an Ephemeral IP.
60+ * An Ephemeral IP is an IP that’s assigned to a Linode but not reserved.
5561 *
5662 * @param address { string } The address to operate on.
5763 * @param rdns { string } The reverse DNS assigned to this address. For public
5864 * IPv4 addresses, this will be set to a default value provided by Linode if not
5965 * explicitly set.
66+ * @param reserved { boolean } Whether to reserve the IP address.
6067 */
61- export const updateIP = ( address : string , rdns : null | string = null ) =>
68+ export const updateIP = (
69+ address : string ,
70+ rdns : null | string = null ,
71+ reserved ?: boolean ,
72+ ) =>
6273 Request < IPAddress > (
6374 setURL ( `${ API_ROOT } /networking/ips/${ encodeURIComponent ( address ) } ` ) ,
64- setData ( { rdns } , updateIPSchema ) ,
75+ setData ( { rdns, reserved } , updateIPSchema ) ,
6576 setMethod ( 'PUT' ) ,
6677 ) ;
6778
@@ -77,8 +88,11 @@ export const updateIP = (address: string, rdns: null | string = null) =>
7788 * address.
7889 * @param payload.linode_id { number } The ID of a Linode you you have access to
7990 * that this address will be allocated to.
91+ * @param payload.reserved { boolean } Whether to reserve the IP address.
92+ * @param payload.region { string } The ID of the Region in which this address * will be allocated.
93+ * Required when reserving an IP address, not required when allocating an ephemeral IP address.
8094 */
81- export const allocateIp = ( payload : any ) =>
95+ export const allocateIp = ( payload : AllocateIPPayload ) =>
8296 Request < IPAddress > (
8397 setURL ( `${ API_ROOT } /networking/ips/` ) ,
8498 setData ( payload , allocateIPSchema ) ,
@@ -194,3 +208,93 @@ export const createIPv6Range = (payload: CreateIPv6RangePayload) => {
194208 setData ( payload ) ,
195209 ) ;
196210} ;
211+
212+ // Reserve IP queries
213+ /**
214+ * getReservedIps
215+ *
216+ * Returns a paginated list of all Reserved IP addresses on this account.
217+ */
218+ export const getReservedIPs = ( params ?: Params , filters ?: Filter ) =>
219+ Request < Page < IPAddress > > (
220+ setMethod ( 'GET' ) ,
221+ setParams ( params ) ,
222+ setXFilter ( filters ) ,
223+ setURL ( `${ BETA_API_ROOT } /networking/reserved/ips` ) ,
224+ ) ;
225+
226+ /**
227+ * Returns information about a single Reserved IP Address on your Account.
228+ *
229+ * @param address { string } The address to operate on.
230+ */
231+ export const getReservedIP = ( address : string ) =>
232+ Request < IPAddress > (
233+ setURL (
234+ `${ BETA_API_ROOT } /networking/reserved/ips/${ encodeURIComponent ( address ) } ` ,
235+ ) ,
236+ setMethod ( 'GET' ) ,
237+ ) ;
238+
239+ /**
240+ * Tags associated with the reserved IP can be updated.
241+ * The tags associated with the reserved IP will be completely replaced with the values specified in the request body,
242+ * rather than just adding additional tags to what’s already there
243+ *
244+ * @param address { string } The address to operate on.
245+ * @param tags { string[] | null } The tags to associate with this reserved IP. If null, all tags will be removed.
246+ */
247+ export const updateReservedIP = (
248+ address : string ,
249+ tags : null | string [ ] = null ,
250+ ) =>
251+ Request < IPAddress > (
252+ setURL (
253+ `${ BETA_API_ROOT } /networking/reserved/ips/${ encodeURIComponent ( address ) } ` ,
254+ ) ,
255+ setData ( { tags } ) ,
256+ setMethod ( 'PUT' ) ,
257+ ) ;
258+
259+ /**
260+ * Makes one of the IP address available in the provided region as reserved.
261+ * Only IPv4 addresses may be reserved through this endpoint.
262+ *
263+ * @param payload { Object }
264+ * @param payload.region { string } The ID of the Region in which these
265+ * assignments are to take place. All IPs and Linodes must exist in this Region.
266+ * @param payload.tags { string[] } A list of tags to associate with this reserved IP.
267+ */
268+ export const reserveIP = ( payload : ReserveIPPayload ) =>
269+ Request < IPAddress > (
270+ setURL ( `${ BETA_API_ROOT } /networking/reserved/ips` ) ,
271+ setData ( payload , reserveIPSchema ) ,
272+ setMethod ( 'POST' ) ,
273+ ) ;
274+
275+ /**
276+ * unReserveIP
277+ *
278+ * Unreserves an IP address, making it available for general use.
279+ * Any Tag associations will be removed when the IP address is un-reserved via this endpoint.
280+ *
281+ */
282+ export const unReserveIP = ( ipAddress : string ) =>
283+ Request < object > (
284+ setURL (
285+ `${ BETA_API_ROOT } /networking/reserved/ips/${ encodeURIComponent ( ipAddress ) } ` ,
286+ ) ,
287+ setMethod ( 'DELETE' ) ,
288+ ) ;
289+
290+ /**
291+ * getReservedIPsTypes
292+ *
293+ * Returns a paginated list of available Reserved IP types; used for pricing.
294+ */
295+ export const getReservedIPsTypes = ( params ?: Params ) =>
296+ Request < Page < PriceType > > (
297+ setURL ( `${ API_ROOT } /networking/reserved/ips/types` ) ,
298+ setMethod ( 'GET' ) ,
299+ setParams ( params ) ,
300+ ) ;
0 commit comments