From 050ca6f59fffd0bdc2c432f4940c83d1bacb346e Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Fri, 4 Oct 2024 15:15:21 +0200 Subject: [PATCH] chore(baremetal): generate SDK v3 (#1464) --- .../clients/src/api/baremetal/index.gen.ts | 1 + .../clients/src/api/baremetal/v3/api.gen.ts | 149 ++++++++++++++++++ .../src/api/baremetal/v3/content.gen.ts | 7 + .../clients/src/api/baremetal/v3/index.gen.ts | 15 ++ .../src/api/baremetal/v3/marshalling.gen.ts | 87 ++++++++++ .../clients/src/api/baremetal/v3/types.gen.ts | 103 ++++++++++++ 6 files changed, 362 insertions(+) create mode 100644 packages/clients/src/api/baremetal/v3/api.gen.ts create mode 100644 packages/clients/src/api/baremetal/v3/content.gen.ts create mode 100644 packages/clients/src/api/baremetal/v3/index.gen.ts create mode 100644 packages/clients/src/api/baremetal/v3/marshalling.gen.ts create mode 100644 packages/clients/src/api/baremetal/v3/types.gen.ts diff --git a/packages/clients/src/api/baremetal/index.gen.ts b/packages/clients/src/api/baremetal/index.gen.ts index 552427430..81bee1055 100644 --- a/packages/clients/src/api/baremetal/index.gen.ts +++ b/packages/clients/src/api/baremetal/index.gen.ts @@ -4,3 +4,4 @@ */ export * as v1 from './v1/index' +export * as v3 from './v3/index.gen' diff --git a/packages/clients/src/api/baremetal/v3/api.gen.ts b/packages/clients/src/api/baremetal/v3/api.gen.ts new file mode 100644 index 000000000..cd83736fb --- /dev/null +++ b/packages/clients/src/api/baremetal/v3/api.gen.ts @@ -0,0 +1,149 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API as ParentAPI, + enrichForPagination, + urlParams, + validatePathParam, +} from '../../../bridge' +import type { Zone } from '../../../bridge' +import { + marshalPrivateNetworkApiAddServerPrivateNetworkRequest, + marshalPrivateNetworkApiSetServerPrivateNetworksRequest, + unmarshalListServerPrivateNetworksResponse, + unmarshalServerPrivateNetwork, + unmarshalSetServerPrivateNetworksResponse, +} from './marshalling.gen' +import type { + ListServerPrivateNetworksResponse, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiDeleteServerPrivateNetworkRequest, + PrivateNetworkApiListServerPrivateNetworksRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, + ServerPrivateNetwork, + SetServerPrivateNetworksResponse, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** Elastic Metal - Private Networks API. */ +export class PrivateNetworkAPI extends ParentAPI { + /** Lists the available zones of the API. */ + public static readonly LOCALITIES: Zone[] = [ + 'fr-par-1', + 'fr-par-2', + 'nl-ams-1', + 'nl-ams-2', + 'pl-waw-2', + 'pl-waw-3', + ] + + /** + * Add a server to a Private Network. Add an Elastic Metal server to a Private + * Network. + * + * @param request - The request + * {@link PrivateNetworkApiAddServerPrivateNetworkRequest} + * @returns A Promise of ServerPrivateNetwork + */ + addServerPrivateNetwork = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalPrivateNetworkApiAddServerPrivateNetworkRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v3/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/private-networks`, + }, + unmarshalServerPrivateNetwork, + ) + + /** + * Set multiple Private Networks on a server. Configure multiple Private + * Networks on an Elastic Metal server. + * + * @param request - The request + * {@link PrivateNetworkApiSetServerPrivateNetworksRequest} + * @returns A Promise of SetServerPrivateNetworksResponse + */ + setServerPrivateNetworks = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalPrivateNetworkApiSetServerPrivateNetworksRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/baremetal/v3/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/private-networks`, + }, + unmarshalSetServerPrivateNetworksResponse, + ) + + protected pageOfListServerPrivateNetworks = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v3/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/server-private-networks`, + urlParams: urlParams( + ['ipam_ip_ids', request.ipamIpIds], + ['order_by', request.orderBy], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['private_network_id', request.privateNetworkId], + ['project_id', request.projectId], + ['server_id', request.serverId], + ), + }, + unmarshalListServerPrivateNetworksResponse, + ) + + /** + * List the Private Networks of a server. List the Private Networks of an + * Elastic Metal server. + * + * @param request - The request + * {@link PrivateNetworkApiListServerPrivateNetworksRequest} + * @returns A Promise of ListServerPrivateNetworksResponse + */ + listServerPrivateNetworks = ( + request: Readonly = {}, + ) => + enrichForPagination( + 'serverPrivateNetworks', + this.pageOfListServerPrivateNetworks, + request, + ) + + /** + * Delete a Private Network. + * + * @param request - The request + * {@link PrivateNetworkApiDeleteServerPrivateNetworkRequest} + */ + deleteServerPrivateNetwork = ( + request: Readonly, + ) => + this.client.fetch({ + method: 'DELETE', + path: `/baremetal/v3/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/private-networks/${validatePathParam('privateNetworkId', request.privateNetworkId)}`, + }) +} diff --git a/packages/clients/src/api/baremetal/v3/content.gen.ts b/packages/clients/src/api/baremetal/v3/content.gen.ts new file mode 100644 index 000000000..2bd1607cf --- /dev/null +++ b/packages/clients/src/api/baremetal/v3/content.gen.ts @@ -0,0 +1,7 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { ServerPrivateNetworkStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link ServerPrivateNetworkStatus}. */ +export const SERVER_PRIVATE_NETWORK_TRANSIENT_STATUSES: ServerPrivateNetworkStatus[] = + ['attaching', 'detaching'] diff --git a/packages/clients/src/api/baremetal/v3/index.gen.ts b/packages/clients/src/api/baremetal/v3/index.gen.ts new file mode 100644 index 000000000..664bf95d6 --- /dev/null +++ b/packages/clients/src/api/baremetal/v3/index.gen.ts @@ -0,0 +1,15 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +export { PrivateNetworkAPI } from './api.gen' +export * from './content.gen' +export type { + ListServerPrivateNetworksRequestOrderBy, + ListServerPrivateNetworksResponse, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiDeleteServerPrivateNetworkRequest, + PrivateNetworkApiListServerPrivateNetworksRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, + ServerPrivateNetwork, + ServerPrivateNetworkStatus, + SetServerPrivateNetworksResponse, +} from './types.gen' diff --git a/packages/clients/src/api/baremetal/v3/marshalling.gen.ts b/packages/clients/src/api/baremetal/v3/marshalling.gen.ts new file mode 100644 index 000000000..27a62379e --- /dev/null +++ b/packages/clients/src/api/baremetal/v3/marshalling.gen.ts @@ -0,0 +1,87 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + ListServerPrivateNetworksResponse, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, + ServerPrivateNetwork, + SetServerPrivateNetworksResponse, +} from './types.gen' + +export const unmarshalServerPrivateNetwork = ( + data: unknown, +): ServerPrivateNetwork => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ServerPrivateNetwork' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + ipamIpIds: data.ipam_ip_ids, + privateNetworkId: data.private_network_id, + projectId: data.project_id, + serverId: data.server_id, + status: data.status, + updatedAt: unmarshalDate(data.updated_at), + vlan: data.vlan, + } as ServerPrivateNetwork +} + +export const unmarshalListServerPrivateNetworksResponse = ( + data: unknown, +): ListServerPrivateNetworksResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListServerPrivateNetworksResponse' failed as data isn't a dictionary.`, + ) + } + + return { + serverPrivateNetworks: unmarshalArrayOfObject( + data.server_private_networks, + unmarshalServerPrivateNetwork, + ), + totalCount: data.total_count, + } as ListServerPrivateNetworksResponse +} + +export const unmarshalSetServerPrivateNetworksResponse = ( + data: unknown, +): SetServerPrivateNetworksResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SetServerPrivateNetworksResponse' failed as data isn't a dictionary.`, + ) + } + + return { + serverPrivateNetworks: unmarshalArrayOfObject( + data.server_private_networks, + unmarshalServerPrivateNetwork, + ), + } as SetServerPrivateNetworksResponse +} + +export const marshalPrivateNetworkApiAddServerPrivateNetworkRequest = ( + request: PrivateNetworkApiAddServerPrivateNetworkRequest, + defaults: DefaultValues, +): Record => ({ + ipam_ip_ids: request.ipamIpIds, + private_network_id: request.privateNetworkId, +}) + +export const marshalPrivateNetworkApiSetServerPrivateNetworksRequest = ( + request: PrivateNetworkApiSetServerPrivateNetworksRequest, + defaults: DefaultValues, +): Record => ({ + per_private_network_ipam_ip_ids: request.perPrivateNetworkIpamIpIds, +}) diff --git a/packages/clients/src/api/baremetal/v3/types.gen.ts b/packages/clients/src/api/baremetal/v3/types.gen.ts new file mode 100644 index 000000000..2eb372352 --- /dev/null +++ b/packages/clients/src/api/baremetal/v3/types.gen.ts @@ -0,0 +1,103 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Zone } from '../../../bridge' + +export type ListServerPrivateNetworksRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'updated_at_asc' + | 'updated_at_desc' + +export type ServerPrivateNetworkStatus = + | 'unknown_status' + | 'attaching' + | 'attached' + | 'error' + | 'detaching' + | 'locked' + +export interface ServerPrivateNetwork { + /** UUID of the Server-to-Private Network mapping. */ + id: string + /** Private Network Project UUID. */ + projectId: string + /** Server UUID. */ + serverId: string + /** Private Network UUID. */ + privateNetworkId: string + /** VLAN UUID associated with the Private Network. */ + vlan?: number + /** Configuration status of the Private Network. */ + status: ServerPrivateNetworkStatus + /** Private Network creation date. */ + createdAt?: Date + /** Date the Private Network was last modified. */ + updatedAt?: Date + /** IPAM IP IDs of the server, if it has any. */ + ipamIpIds: string[] +} + +export interface ListServerPrivateNetworksResponse { + serverPrivateNetworks: ServerPrivateNetwork[] + totalCount: number +} + +export type PrivateNetworkApiAddServerPrivateNetworkRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the server. */ + serverId: string + /** UUID of the Private Network. */ + privateNetworkId: string + /** IPAM IDs of an IPs to attach to the server. */ + ipamIpIds?: string[] +} + +export type PrivateNetworkApiDeleteServerPrivateNetworkRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the server. */ + serverId: string + /** UUID of the Private Network. */ + privateNetworkId: string +} + +export type PrivateNetworkApiListServerPrivateNetworksRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** Sort order for the returned Private Networks. */ + orderBy?: ListServerPrivateNetworksRequestOrderBy + /** Page number for the returned Private Networks. */ + page?: number + /** Maximum number of Private Networks per page. */ + pageSize?: number + /** Filter Private Networks by server UUID. */ + serverId?: string + /** Filter Private Networks by Private Network UUID. */ + privateNetworkId?: string + /** Filter Private Networks by organization UUID. */ + organizationId?: string + /** Filter Private Networks by project UUID. */ + projectId?: string + /** Filter Private Networks by IPAM IP UUIDs. */ + ipamIpIds?: string[] +} + +export type PrivateNetworkApiSetServerPrivateNetworksRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the server. */ + serverId: string + /** + * Object where the keys are the UUIDs of Private Networks and the values are + * arrays of IPAM IDs representing the IPs to assign to this Elastic Metal + * server on the Private Network. If the array supplied for a Private Network + * is empty, the next available IP from the Private Network's CIDR block will + * automatically be used for attachment. + */ + perPrivateNetworkIpamIpIds: Record +} + +export interface SetServerPrivateNetworksResponse { + serverPrivateNetworks: ServerPrivateNetwork[] +}