diff --git a/packages/clients/src/api/baremetal/v1/api.gen.ts b/packages/clients/src/api/baremetal/v1/api.gen.ts index f02e82a5f..01ec505f9 100644 --- a/packages/clients/src/api/baremetal/v1/api.gen.ts +++ b/packages/clients/src/api/baremetal/v1/api.gen.ts @@ -21,6 +21,7 @@ import { marshalUpdateIPRequest, marshalUpdateServerRequest, marshalUpdateSettingRequest, + marshalValidatePartitioningSchemaRequest, unmarshalBMCAccess, unmarshalGetServerMetricsResponse, unmarshalIP, @@ -34,6 +35,7 @@ import { unmarshalOS, unmarshalOffer, unmarshalOption, + unmarshalSchema, unmarshalServer, unmarshalServerPrivateNetwork, unmarshalSetServerPrivateNetworksResponse, @@ -46,6 +48,7 @@ import type { DeleteOptionServerRequest, DeleteServerRequest, GetBMCAccessRequest, + GetDefaultPartitioningSchemaRequest, GetOSRequest, GetOfferRequest, GetOptionRequest, @@ -75,6 +78,7 @@ import type { PrivateNetworkApiListServerPrivateNetworksRequest, PrivateNetworkApiSetServerPrivateNetworksRequest, RebootServerRequest, + Schema, Server, ServerPrivateNetwork, SetServerPrivateNetworksResponse, @@ -86,6 +90,7 @@ import type { UpdateIPRequest, UpdateServerRequest, UpdateSettingRequest, + ValidatePartitioningSchemaRequest, } from './types.gen' const jsonContentHeaders = { @@ -357,6 +362,47 @@ export class API extends ParentAPI { listServerEvents = (request: Readonly) => enrichForPagination('events', this.pageOfListServerEvents, request) + /** + * Get default partitioning schema. Get the default partitioning schema for + * the given offer ID and OS ID. + * + * @param request - The request {@link GetDefaultPartitioningSchemaRequest} + * @returns A Promise of Schema + */ + getDefaultPartitioningSchema = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/baremetal/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/partitioning-schemas/default`, + urlParams: urlParams( + ['offer_id', request.offerId], + ['os_id', request.osId], + ), + }, + unmarshalSchema, + ) + + /** + * Validate client partitioning schema. Validate the incoming partitioning + * schema from a user before installing the server. Return default ErrorCode + * if invalid. + * + * @param request - The request {@link ValidatePartitioningSchemaRequest} + */ + validatePartitioningSchema = ( + request: Readonly, + ) => + this.client.fetch({ + body: JSON.stringify( + marshalValidatePartitioningSchemaRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/baremetal/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/partitioning-schemas/validate`, + }) + /** * Start BMC access. Start BMC (Baseboard Management Controller) access * associated with the ID. The BMC (Baseboard Management Controller) access is diff --git a/packages/clients/src/api/baremetal/v1/index.gen.ts b/packages/clients/src/api/baremetal/v1/index.gen.ts index f0ee7b32d..5e662b1a3 100644 --- a/packages/clients/src/api/baremetal/v1/index.gen.ts +++ b/packages/clients/src/api/baremetal/v1/index.gen.ts @@ -13,6 +13,7 @@ export type { DeleteServerRequest, Disk, GetBMCAccessRequest, + GetDefaultPartitioningSchemaRequest, GetOSRequest, GetOfferRequest, GetOptionRequest, @@ -59,6 +60,21 @@ export type { RaidController, RebootServerRequest, RemoteAccessOption, + Schema, + SchemaDisk, + SchemaFilesystem, + SchemaFilesystemFormat, + SchemaLVM, + SchemaLogicalVolume, + SchemaLogicalVolumeType, + SchemaPartition, + SchemaPartitionLabel, + SchemaPool, + SchemaPoolType, + SchemaRAID, + SchemaRAIDLevel, + SchemaVolumeGroup, + SchemaZFS, Server, ServerBootType, ServerEvent, @@ -81,5 +97,6 @@ export type { UpdateIPRequest, UpdateServerRequest, UpdateSettingRequest, + ValidatePartitioningSchemaRequest, } from './types.gen' export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/baremetal/v1/marshalling.gen.ts b/packages/clients/src/api/baremetal/v1/marshalling.gen.ts index 5ae2e5bf4..2de126439 100644 --- a/packages/clients/src/api/baremetal/v1/marshalling.gen.ts +++ b/packages/clients/src/api/baremetal/v1/marshalling.gen.ts @@ -42,6 +42,16 @@ import type { RaidController, RebootServerRequest, RemoteAccessOption, + Schema, + SchemaDisk, + SchemaFilesystem, + SchemaLVM, + SchemaLogicalVolume, + SchemaPartition, + SchemaPool, + SchemaRAID, + SchemaVolumeGroup, + SchemaZFS, Server, ServerEvent, ServerInstall, @@ -55,8 +65,162 @@ import type { UpdateIPRequest, UpdateServerRequest, UpdateSettingRequest, + ValidatePartitioningSchemaRequest, } from './types.gen' +const unmarshalSchemaLogicalVolume = (data: unknown): SchemaLogicalVolume => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaLogicalVolume' failed as data isn't a dictionary.`, + ) + } + + return { + mirrorNumber: data.mirror_number, + name: data.name, + size: data.size, + stripedNumber: data.striped_number, + type: data.type, + } as SchemaLogicalVolume +} + +const unmarshalSchemaPartition = (data: unknown): SchemaPartition => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaPartition' failed as data isn't a dictionary.`, + ) + } + + return { + label: data.label, + number: data.number, + size: data.size, + } as SchemaPartition +} + +const unmarshalSchemaVolumeGroup = (data: unknown): SchemaVolumeGroup => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaVolumeGroup' failed as data isn't a dictionary.`, + ) + } + + return { + logicalVolumes: unmarshalArrayOfObject( + data.logical_volumes, + unmarshalSchemaLogicalVolume, + ), + physicalVolumes: data.physical_volumes, + volumeGroupName: data.volume_group_name, + } as SchemaVolumeGroup +} + +const unmarshalSchemaPool = (data: unknown): SchemaPool => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaPool' failed as data isn't a dictionary.`, + ) + } + + return { + devices: data.devices, + filesystemOptions: data.filesystem_options, + name: data.name, + options: data.options, + type: data.type, + } as SchemaPool +} + +const unmarshalSchemaDisk = (data: unknown): SchemaDisk => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaDisk' failed as data isn't a dictionary.`, + ) + } + + return { + device: data.device, + partitions: unmarshalArrayOfObject( + data.partitions, + unmarshalSchemaPartition, + ), + } as SchemaDisk +} + +const unmarshalSchemaFilesystem = (data: unknown): SchemaFilesystem => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaFilesystem' failed as data isn't a dictionary.`, + ) + } + + return { + device: data.device, + format: data.format, + mountpoint: data.mountpoint, + } as SchemaFilesystem +} + +const unmarshalSchemaLVM = (data: unknown): SchemaLVM => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaLVM' failed as data isn't a dictionary.`, + ) + } + + return { + volumeGroups: unmarshalArrayOfObject( + data.volume_groups, + unmarshalSchemaVolumeGroup, + ), + } as SchemaLVM +} + +const unmarshalSchemaRAID = (data: unknown): SchemaRAID => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaRAID' failed as data isn't a dictionary.`, + ) + } + + return { + devices: data.devices, + level: data.level, + name: data.name, + } as SchemaRAID +} + +const unmarshalSchemaZFS = (data: unknown): SchemaZFS => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SchemaZFS' failed as data isn't a dictionary.`, + ) + } + + return { + pools: unmarshalArrayOfObject(data.pools, unmarshalSchemaPool), + } as SchemaZFS +} + +export const unmarshalSchema = (data: unknown): Schema => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Schema' failed as data isn't a dictionary.`, + ) + } + + return { + disks: unmarshalArrayOfObject(data.disks, unmarshalSchemaDisk), + filesystems: unmarshalArrayOfObject( + data.filesystems, + unmarshalSchemaFilesystem, + ), + lvm: data.lvm ? unmarshalSchemaLVM(data.lvm) : undefined, + raids: unmarshalArrayOfObject(data.raids, unmarshalSchemaRAID), + zfs: data.zfs ? unmarshalSchemaZFS(data.zfs) : undefined, + } as Schema +} + export const unmarshalIP = (data: unknown): IP => { if (!isJSONObject(data)) { throw new TypeError( @@ -757,3 +921,120 @@ export const marshalUpdateSettingRequest = ( ): Record => ({ enabled: request.enabled, }) + +const marshalSchemaLogicalVolume = ( + request: SchemaLogicalVolume, + defaults: DefaultValues, +): Record => ({ + mirror_number: request.mirrorNumber, + name: request.name, + size: request.size, + striped_number: request.stripedNumber, + type: request.type, +}) + +const marshalSchemaPartition = ( + request: SchemaPartition, + defaults: DefaultValues, +): Record => ({ + label: request.label, + number: request.number, + size: request.size, +}) + +const marshalSchemaVolumeGroup = ( + request: SchemaVolumeGroup, + defaults: DefaultValues, +): Record => ({ + logical_volumes: request.logicalVolumes.map(elt => + marshalSchemaLogicalVolume(elt, defaults), + ), + physical_volumes: request.physicalVolumes, + volume_group_name: request.volumeGroupName, +}) + +const marshalSchemaPool = ( + request: SchemaPool, + defaults: DefaultValues, +): Record => ({ + devices: request.devices, + filesystem_options: request.filesystemOptions, + name: request.name, + options: request.options, + type: request.type, +}) + +const marshalSchemaDisk = ( + request: SchemaDisk, + defaults: DefaultValues, +): Record => ({ + device: request.device, + partitions: request.partitions.map(elt => + marshalSchemaPartition(elt, defaults), + ), +}) + +const marshalSchemaFilesystem = ( + request: SchemaFilesystem, + defaults: DefaultValues, +): Record => ({ + device: request.device, + format: request.format, + mountpoint: request.mountpoint, +}) + +const marshalSchemaLVM = ( + request: SchemaLVM, + defaults: DefaultValues, +): Record => ({ + volume_groups: request.volumeGroups.map(elt => + marshalSchemaVolumeGroup(elt, defaults), + ), +}) + +const marshalSchemaRAID = ( + request: SchemaRAID, + defaults: DefaultValues, +): Record => ({ + devices: request.devices, + level: request.level, + name: request.name, +}) + +const marshalSchemaZFS = ( + request: SchemaZFS, + defaults: DefaultValues, +): Record => ({ + pools: request.pools.map(elt => marshalSchemaPool(elt, defaults)), +}) + +export const marshalSchema = ( + request: Schema, + defaults: DefaultValues, +): Record => ({ + disks: request.disks.map(elt => marshalSchemaDisk(elt, defaults)), + filesystems: request.filesystems.map(elt => + marshalSchemaFilesystem(elt, defaults), + ), + lvm: + request.lvm !== undefined + ? marshalSchemaLVM(request.lvm, defaults) + : undefined, + raids: request.raids.map(elt => marshalSchemaRAID(elt, defaults)), + zfs: + request.zfs !== undefined + ? marshalSchemaZFS(request.zfs, defaults) + : undefined, +}) + +export const marshalValidatePartitioningSchemaRequest = ( + request: ValidatePartitioningSchemaRequest, + defaults: DefaultValues, +): Record => ({ + offer_id: request.offerId, + os_id: request.osId, + partitioning_schema: + request.partitioningSchema !== undefined + ? marshalSchema(request.partitioningSchema, defaults) + : undefined, +}) diff --git a/packages/clients/src/api/baremetal/v1/types.gen.ts b/packages/clients/src/api/baremetal/v1/types.gen.ts index 1479764c3..64a31c821 100644 --- a/packages/clients/src/api/baremetal/v1/types.gen.ts +++ b/packages/clients/src/api/baremetal/v1/types.gen.ts @@ -27,6 +27,51 @@ export type OfferSubscriptionPeriod = | 'hourly' | 'monthly' +export type SchemaFilesystemFormat = + | 'unknown_format' + | 'fat32' + | 'ext4' + | 'swap' + | 'zfs' + +export type SchemaLogicalVolumeType = + | 'unknown_raid_type' + | 'striped' + | 'mirror' + | 'raid0' + | 'raid1' + | 'raid5' + | 'raid6' + | 'raid10' + +export type SchemaPartitionLabel = + | 'unknown_partition_label' + | 'uefi' + | 'legacy' + | 'root' + | 'boot' + | 'swap' + | 'data' + | 'home' + | 'raid' + | 'lvm' + | 'zfs' + +export type SchemaPoolType = + | 'unknown_type' + | 'no_raid' + | 'mirror' + | 'raidz1' + | 'raidz2' + +export type SchemaRAIDLevel = + | 'unknown_raid_level' + | 'raid_level_0' + | 'raid_level_1' + | 'raid_level_5' + | 'raid_level_6' + | 'raid_level_10' + export type ServerBootType = 'unknown_boot_type' | 'normal' | 'rescue' export type ServerInstallStatus = @@ -72,6 +117,59 @@ export type ServerStatus = export type SettingType = 'unknown' | 'smtp' +export interface SchemaLogicalVolume { + name: string + type: SchemaLogicalVolumeType + size: number + stripedNumber: number + mirrorNumber: number +} + +export interface SchemaPartition { + label: SchemaPartitionLabel + number: number + size: number +} + +export interface SchemaVolumeGroup { + volumeGroupName: string + physicalVolumes: string[] + logicalVolumes: SchemaLogicalVolume[] +} + +export interface SchemaPool { + name: string + type: SchemaPoolType + devices: string[] + options: string[] + filesystemOptions: string[] +} + +export interface SchemaDisk { + device: string + partitions: SchemaPartition[] +} + +export interface SchemaFilesystem { + device: string + format: SchemaFilesystemFormat + mountpoint: string +} + +export interface SchemaLVM { + volumeGroups: SchemaVolumeGroup[] +} + +export interface SchemaRAID { + name: string + level: SchemaRAIDLevel + devices: string[] +} + +export interface SchemaZFS { + pools: SchemaPool[] +} + export interface CertificationOption {} export interface LicenseOption { @@ -86,6 +184,14 @@ export interface PublicBandwidthOption { export interface RemoteAccessOption {} +export interface Schema { + disks: SchemaDisk[] + raids: SchemaRAID[] + filesystems: SchemaFilesystem[] + lvm?: SchemaLVM + zfs?: SchemaZFS +} + export interface OSOSField { editable: boolean required: boolean @@ -603,6 +709,15 @@ export type GetBMCAccessRequest = { serverId: string } +export type GetDefaultPartitioningSchemaRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** ID of the offer. */ + offerId: string + /** ID of the OS. */ + osId: string +} + export type GetOSRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -923,3 +1038,14 @@ export type UpdateSettingRequest = { /** Defines whether the setting is enabled. */ enabled?: boolean } + +export type ValidatePartitioningSchemaRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** Partitioning schema. */ + partitioningSchema?: Schema + /** Offer ID of the server. */ + offerId: string + /** OS ID. */ + osId: string +}