Skip to content

Commit

Permalink
feat(apple_silicon): add vnc diagnostic api definition (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Nov 8, 2024
1 parent 3eb5cdb commit bd5e31a
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/clients/src/api/applesilicon/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ import { SERVER_TRANSIENT_STATUSES } from './content.gen'
import {
marshalCreateServerRequest,
marshalReinstallServerRequest,
marshalStartConnectivityDiagnosticRequest,
marshalUpdateServerRequest,
unmarshalConnectivityDiagnostic,
unmarshalListOSResponse,
unmarshalListServerTypesResponse,
unmarshalListServersResponse,
unmarshalOS,
unmarshalServer,
unmarshalServerType,
unmarshalStartConnectivityDiagnosticResponse,
} from './marshalling.gen'
import type {
ConnectivityDiagnostic,
CreateServerRequest,
DeleteServerRequest,
GetConnectivityDiagnosticRequest,
GetOSRequest,
GetServerRequest,
GetServerTypeRequest,
Expand All @@ -37,6 +42,8 @@ import type {
ReinstallServerRequest,
Server,
ServerType,
StartConnectivityDiagnosticRequest,
StartConnectivityDiagnosticResponse,
UpdateServerRequest,
} from './types.gen'

Expand Down Expand Up @@ -291,4 +298,33 @@ export class API extends ParentAPI {
},
unmarshalServer,
)

startConnectivityDiagnostic = (
request: Readonly<StartConnectivityDiagnosticRequest>,
) =>
this.client.fetch<StartConnectivityDiagnosticResponse>(
{
body: JSON.stringify(
marshalStartConnectivityDiagnosticRequest(
request,
this.client.settings,
),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/apple-silicon/v1alpha1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/connectivity-diagnostics`,
},
unmarshalStartConnectivityDiagnosticResponse,
)

getConnectivityDiagnostic = (
request: Readonly<GetConnectivityDiagnosticRequest>,
) =>
this.client.fetch<ConnectivityDiagnostic>(
{
method: 'GET',
path: `/apple-silicon/v1alpha1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/connectivity-diagnostics/${validatePathParam('diagnosticId', request.diagnosticId)}`,
},
unmarshalConnectivityDiagnostic,
)
}
7 changes: 7 additions & 0 deletions packages/clients/src/api/applesilicon/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
export { API } from './api.gen'
export * from './content.gen'
export type {
ConnectivityDiagnostic,
ConnectivityDiagnosticActionType,
ConnectivityDiagnosticDiagnosticStatus,
ConnectivityDiagnosticServerHealth,
CreateServerRequest,
DeleteServerRequest,
GetConnectivityDiagnosticRequest,
GetOSRequest,
GetServerRequest,
GetServerTypeRequest,
Expand All @@ -27,5 +32,7 @@ export type {
ServerTypeMemory,
ServerTypeNetwork,
ServerTypeStock,
StartConnectivityDiagnosticRequest,
StartConnectivityDiagnosticResponse,
UpdateServerRequest,
} from './types.gen'
65 changes: 65 additions & 0 deletions packages/clients/src/api/applesilicon/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
ConnectivityDiagnostic,
ConnectivityDiagnosticServerHealth,
CreateServerRequest,
ListOSResponse,
ListServerTypesResponse,
Expand All @@ -21,6 +23,8 @@ import type {
ServerTypeGPU,
ServerTypeMemory,
ServerTypeNetwork,
StartConnectivityDiagnosticRequest,
StartConnectivityDiagnosticResponse,
UpdateServerRequest,
} from './types.gen'

Expand Down Expand Up @@ -159,6 +163,46 @@ export const unmarshalServer = (data: unknown): Server => {
} as Server
}

const unmarshalConnectivityDiagnosticServerHealth = (
data: unknown,
): ConnectivityDiagnosticServerHealth => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ConnectivityDiagnosticServerHealth' failed as data isn't a dictionary.`,
)
}

return {
isAgentAlive: data.is_agent_alive,
isMdmAlive: data.is_mdm_alive,
isServerAlive: data.is_server_alive,
isSshPortUp: data.is_ssh_port_up,
isVncPortUp: data.is_vnc_port_up,
lastCheckinDate: unmarshalDate(data.last_checkin_date),
} as ConnectivityDiagnosticServerHealth
}

export const unmarshalConnectivityDiagnostic = (
data: unknown,
): ConnectivityDiagnostic => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ConnectivityDiagnostic' failed as data isn't a dictionary.`,
)
}

return {
errorMessage: data.error_message,
healthDetails: data.health_details
? unmarshalConnectivityDiagnosticServerHealth(data.health_details)
: undefined,
id: data.id,
isHealthy: data.is_healthy,
status: data.status,
supportedActions: data.supported_actions,
} as ConnectivityDiagnostic
}

export const unmarshalListOSResponse = (data: unknown): ListOSResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -201,6 +245,20 @@ export const unmarshalListServersResponse = (
} as ListServersResponse
}

export const unmarshalStartConnectivityDiagnosticResponse = (
data: unknown,
): StartConnectivityDiagnosticResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'StartConnectivityDiagnosticResponse' failed as data isn't a dictionary.`,
)
}

return {
diagnosticId: data.diagnostic_id,
} as StartConnectivityDiagnosticResponse
}

export const marshalCreateServerRequest = (
request: CreateServerRequest,
defaults: DefaultValues,
Expand All @@ -218,6 +276,13 @@ export const marshalReinstallServerRequest = (
os_id: request.osId,
})

export const marshalStartConnectivityDiagnosticRequest = (
request: StartConnectivityDiagnosticRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
server_id: request.serverId,
})

export const marshalUpdateServerRequest = (
request: UpdateServerRequest,
defaults: DefaultValues,
Expand Down
44 changes: 44 additions & 0 deletions packages/clients/src/api/applesilicon/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// If you have any remark or suggestion do not hesitate to open an issue.
import type { Zone } from '../../../bridge'

export type ConnectivityDiagnosticActionType =
| 'reboot_server'
| 'reinstall_server'

export type ConnectivityDiagnosticDiagnosticStatus =
| 'unknown_status'
| 'processing'
| 'error'
| 'completed'

export type ListServersRequestOrderBy = 'created_at_asc' | 'created_at_desc'

export type ServerStatus =
Expand Down Expand Up @@ -67,6 +77,15 @@ export interface ServerTypeNetwork {
publicBandwidthBps: number
}

export interface ConnectivityDiagnosticServerHealth {
lastCheckinDate?: Date
isServerAlive: boolean
isAgentAlive: boolean
isMdmAlive: boolean
isSshPortUp: boolean
isVncPortUp: boolean
}

export interface ServerType {
/** CPU description. */
cpu?: ServerTypeCPU
Expand Down Expand Up @@ -140,6 +159,15 @@ export interface Server {
delivered: boolean
}

export interface ConnectivityDiagnostic {
id: string
status: ConnectivityDiagnosticDiagnosticStatus
isHealthy: boolean
healthDetails?: ConnectivityDiagnosticServerHealth
supportedActions: ConnectivityDiagnosticActionType[]
errorMessage: string
}

export type CreateServerRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand All @@ -164,6 +192,12 @@ export type DeleteServerRequest = {
serverId: string
}

export type GetConnectivityDiagnosticRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
diagnosticId: string
}

export type GetOSRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand Down Expand Up @@ -265,6 +299,16 @@ export type ReinstallServerRequest = {
osId?: string
}

export type StartConnectivityDiagnosticRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
serverId: string
}

export interface StartConnectivityDiagnosticResponse {
diagnosticId: string
}

export type UpdateServerRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand Down

0 comments on commit bd5e31a

Please sign in to comment.