diff --git a/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts index 2de8e4ad8..939bba95f 100644 --- a/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts @@ -8,19 +8,27 @@ import { waitForResource, } from '../../../bridge' import type { WaitForOptions, Zone } from '../../../bridge' -import { SERVER_TRANSIENT_STATUSES } from './content.gen' +import { + SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES, + SERVER_TRANSIENT_STATUSES, +} from './content.gen' import { marshalCreateServerRequest, + marshalPrivateNetworkApiAddServerPrivateNetworkRequest, + marshalPrivateNetworkApiSetServerPrivateNetworksRequest, marshalReinstallServerRequest, marshalStartConnectivityDiagnosticRequest, marshalUpdateServerRequest, unmarshalConnectivityDiagnostic, unmarshalListOSResponse, + unmarshalListServerPrivateNetworksResponse, unmarshalListServerTypesResponse, unmarshalListServersResponse, unmarshalOS, unmarshalServer, + unmarshalServerPrivateNetwork, unmarshalServerType, + unmarshalSetServerPrivateNetworksResponse, unmarshalStartConnectivityDiagnosticResponse, } from './marshalling.gen' import type { @@ -33,15 +41,23 @@ import type { GetServerTypeRequest, ListOSRequest, ListOSResponse, + ListServerPrivateNetworksResponse, ListServerTypesRequest, ListServerTypesResponse, ListServersRequest, ListServersResponse, OS, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiDeleteServerPrivateNetworkRequest, + PrivateNetworkApiGetServerPrivateNetworkRequest, + PrivateNetworkApiListServerPrivateNetworksRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, RebootServerRequest, ReinstallServerRequest, Server, + ServerPrivateNetwork, ServerType, + SetServerPrivateNetworksResponse, StartConnectivityDiagnosticRequest, StartConnectivityDiagnosticResponse, UpdateServerRequest, @@ -328,3 +344,152 @@ export class API extends ParentAPI { unmarshalConnectivityDiagnostic, ) } + +/** Apple silicon - 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-3'] + + getServerPrivateNetwork = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/apple-silicon/v1alpha1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/private-networks/${validatePathParam('privateNetworkId', request.privateNetworkId)}`, + }, + unmarshalServerPrivateNetwork, + ) + + /** + * Waits for {@link ServerPrivateNetwork} to be in a final state. + * + * @param request - The request + * {@link PrivateNetworkApiGetServerPrivateNetworkRequest} + * @param options - The waiting options + * @returns A Promise of ServerPrivateNetwork + */ + waitForServerPrivateNetwork = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve( + !SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES.includes( + res.status, + ), + )), + this.getServerPrivateNetwork, + request, + options, + ) + + /** + * Add a server to a Private Network. Add an Apple silicon 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: `/apple-silicon/v1alpha1/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 Apple silicon 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: `/apple-silicon/v1alpha1/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: `/apple-silicon/v1alpha1/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 + * Apple silicon 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: `/apple-silicon/v1alpha1/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/applesilicon/v1alpha1/content.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts index 5f1feed02..32e6d1259 100644 --- a/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts +++ b/packages/clients/src/api/applesilicon/v1alpha1/content.gen.ts @@ -1,6 +1,14 @@ // 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, ServerStatus } from './types.gen' +import type { + ServerPrivateNetworkServerStatus, + ServerPrivateNetworkStatus, + ServerStatus, +} from './types.gen' + +/** Lists transient statutes of the enum {@link ServerPrivateNetworkServerStatus}. */ +export const SERVER_PRIVATE_NETWORK_SERVER_TRANSIENT_STATUSES: ServerPrivateNetworkServerStatus[] = + ['attaching', 'detaching'] /** Lists transient statutes of the enum {@link ServerPrivateNetworkStatus}. */ export const SERVER_PRIVATE_NETWORK_TRANSIENT_STATUSES: ServerPrivateNetworkStatus[] = diff --git a/packages/clients/src/api/applesilicon/v1alpha1/index.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/index.gen.ts index 71e4a9920..da05d6767 100644 --- a/packages/clients/src/api/applesilicon/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/applesilicon/v1alpha1/index.gen.ts @@ -1,6 +1,6 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -export { API } from './api.gen' +export { API, PrivateNetworkAPI } from './api.gen' export * from './content.gen' export type { ConnectivityDiagnostic, @@ -15,15 +15,24 @@ export type { GetServerTypeRequest, ListOSRequest, ListOSResponse, + ListServerPrivateNetworksRequestOrderBy, + ListServerPrivateNetworksResponse, ListServerTypesRequest, ListServerTypesResponse, ListServersRequest, ListServersRequestOrderBy, ListServersResponse, OS, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiDeleteServerPrivateNetworkRequest, + PrivateNetworkApiGetServerPrivateNetworkRequest, + PrivateNetworkApiListServerPrivateNetworksRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, RebootServerRequest, ReinstallServerRequest, Server, + ServerPrivateNetwork, + ServerPrivateNetworkServerStatus, ServerPrivateNetworkStatus, ServerStatus, ServerType, @@ -33,6 +42,7 @@ export type { ServerTypeMemory, ServerTypeNetwork, ServerTypeStock, + SetServerPrivateNetworksResponse, StartConnectivityDiagnosticRequest, StartConnectivityDiagnosticResponse, UpdateServerRequest, diff --git a/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts index 7ddd62ec0..9f48b6b2d 100644 --- a/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts @@ -12,17 +12,22 @@ import type { ConnectivityDiagnosticServerHealth, CreateServerRequest, ListOSResponse, + ListServerPrivateNetworksResponse, ListServerTypesResponse, ListServersResponse, OS, + PrivateNetworkApiAddServerPrivateNetworkRequest, + PrivateNetworkApiSetServerPrivateNetworksRequest, ReinstallServerRequest, Server, + ServerPrivateNetwork, ServerType, ServerTypeCPU, ServerTypeDisk, ServerTypeGPU, ServerTypeMemory, ServerTypeNetwork, + SetServerPrivateNetworksResponse, StartConnectivityDiagnosticRequest, StartConnectivityDiagnosticResponse, UpdateServerRequest, @@ -48,6 +53,28 @@ export const unmarshalOS = (data: unknown): OS => { } as OS } +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 +} + const unmarshalServerTypeCPU = (data: unknown): ServerTypeCPU => { if (!isJSONObject(data)) { throw new TypeError( @@ -217,6 +244,24 @@ export const unmarshalListOSResponse = (data: unknown): ListOSResponse => { } as ListOSResponse } +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 unmarshalListServerTypesResponse = ( data: unknown, ): ListServerTypesResponse => { @@ -246,6 +291,23 @@ export const unmarshalListServersResponse = ( } as ListServersResponse } +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 unmarshalStartConnectivityDiagnosticResponse = ( data: unknown, ): StartConnectivityDiagnosticResponse => { @@ -271,6 +333,21 @@ export const marshalCreateServerRequest = ( type: request.type, }) +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, +}) + export const marshalReinstallServerRequest = ( request: ReinstallServerRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts b/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts index d9c805abf..0eb9d6dbc 100644 --- a/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts @@ -12,8 +12,22 @@ export type ConnectivityDiagnosticDiagnosticStatus = | 'error' | 'completed' +export type ListServerPrivateNetworksRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'updated_at_asc' + | 'updated_at_desc' + export type ListServersRequestOrderBy = 'created_at_asc' | 'created_at_desc' +export type ServerPrivateNetworkServerStatus = + | 'unknown_status' + | 'attaching' + | 'attached' + | 'error' + | 'detaching' + | 'locked' + export type ServerPrivateNetworkStatus = | 'vpc_unknown_status' | 'vpc_enabled' @@ -93,6 +107,27 @@ export interface ConnectivityDiagnosticServerHealth { isVncPortUp: boolean } +export interface ServerPrivateNetwork { + /** ID of the Server-to-Private Network mapping. */ + id: string + /** Private Network Project ID. */ + projectId: string + /** Apple silicon server ID. */ + serverId: string + /** Private Network ID. */ + privateNetworkId: string + /** ID of the VLAN associated with the Private Network. */ + vlan?: number + /** Configuration status of the Private Network. */ + status: ServerPrivateNetworkServerStatus + /** 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 ServerType { /** CPU description. */ cpu?: ServerTypeCPU @@ -262,6 +297,11 @@ export interface ListOSResponse { os: OS[] } +export interface ListServerPrivateNetworksResponse { + serverPrivateNetworks: ServerPrivateNetwork[] + totalCount: number +} + export type ListServerTypesRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -297,6 +337,69 @@ export interface ListServersResponse { servers: Server[] } +export type PrivateNetworkApiAddServerPrivateNetworkRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** ID of the server. */ + serverId: string + /** ID of the Private Network. */ + privateNetworkId: string + /** IPAM IDs of 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 + /** ID of the server. */ + serverId: string + /** ID of the Private Network. */ + privateNetworkId: string +} + +export type PrivateNetworkApiGetServerPrivateNetworkRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + serverId: string + 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 ID. */ + serverId?: string + /** Filter Private Networks by Private Network ID. */ + privateNetworkId?: string + /** Filter Private Networks by Organization ID. */ + organizationId?: string + /** Filter Private Networks by Project ID. */ + projectId?: string + /** Filter Private Networks by IPAM IP IDs. */ + ipamIpIds?: string[] +} + +export type PrivateNetworkApiSetServerPrivateNetworksRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** ID of the server. */ + serverId: string + /** + * Object where the keys are the IDs of Private Networks and the values are + * arrays of IPAM IDs representing the IPs to assign to this Apple silicon + * 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 type RebootServerRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -316,6 +419,10 @@ export type ReinstallServerRequest = { osId?: string } +export interface SetServerPrivateNetworksResponse { + serverPrivateNetworks: ServerPrivateNetwork[] +} + export type StartConnectivityDiagnosticRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone