feat(@xen-orchestra/rest-api): expose delete vdi*/:id (#8961)

This commit is contained in:
Mathieu
2025-09-15 14:16:40 +02:00
committed by GitHub
parent 44bfc28a44
commit ee74a640b4
5 changed files with 29 additions and 12 deletions

View File

@@ -159,6 +159,7 @@ export interface Xapi {
creatorId?: XoUser['id'],
opts?: { destroyAllVifs: boolean }
): Promise<XenApiVmWrapped>
VDI_destroy(vdiRef: XenApiVdi['$ref']): Promise<void>
VDI_destroyCloudInitConfig(vdiRef: XenApiVdi['$ref'], opts?: { timeLimit?: number }): Promise<void>
VDI_exportContent(
vdiRef: XenApiVdi['$ref'],

View File

@@ -1,4 +1,4 @@
import { Example, Get, Path, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa'
import { Delete, Example, Get, Path, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa'
import { inject } from 'inversify'
import { provide } from 'inversify-binding-decorators'
import type { Readable } from 'node:stream'
@@ -6,7 +6,7 @@ import type { Request as ExRequest, Response as ExResponse } from 'express'
import type { XoAlarm, XoVdiSnapshot } from '@vates/types'
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs'
import { notFoundResp, unauthorizedResp, type Unbrand } from '../open-api/common/response.common.mjs'
import { noContentResp, notFoundResp, unauthorizedResp, type Unbrand } from '../open-api/common/response.common.mjs'
import { RestApi } from '../rest-api/rest-api.mjs'
import type { SendObjects } from '../helpers/helper.type.mjs'
import { partialVdiSnapshots, vdiSnapshot, vdiSnapshotIds } from '../open-api/oa-examples/vdi-snapshot.oa-example.mjs'
@@ -112,4 +112,15 @@ export class VdiSnapshotController extends XapiXoController<XoVdiSnapshot> {
return this.sendObjects(Object.values(alarms), req, 'alarms')
}
/**
* @example id "d2727772-735b-478f-b6f9-11e7db56dfd0"
*/
@Delete('{id}')
@SuccessResponse(noContentResp.status, noContentResp.description)
@Response(notFoundResp.status, notFoundResp.description)
async deleteVdiSnapshot(@Path() id: string): Promise<void> {
const xapiVdiSnapshot = this.getXapiObject(id as XoVdiSnapshot['id'])
await xapiVdiSnapshot.$xapi.VDI_destroy(xapiVdiSnapshot.$ref)
}
}

View File

@@ -1,4 +1,4 @@
import { Example, Get, Path, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa'
import { Delete, Example, Get, Path, Query, Request, Response, Route, Security, SuccessResponse, Tags } from 'tsoa'
import { inject } from 'inversify'
import { provide } from 'inversify-binding-decorators'
import type { Readable } from 'node:stream'
@@ -8,7 +8,7 @@ import type { XoAlarm, XoVdi } from '@vates/types'
import { AlarmService } from '../alarms/alarm.service.mjs'
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs'
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs'
import { notFoundResp, unauthorizedResp, type Unbrand } from '../open-api/common/response.common.mjs'
import { noContentResp, notFoundResp, unauthorizedResp, type Unbrand } from '../open-api/common/response.common.mjs'
import { RestApi } from '../rest-api/rest-api.mjs'
import type { SendObjects } from '../helpers/helper.type.mjs'
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs'
@@ -108,4 +108,15 @@ export class VdiController extends XapiXoController<XoVdi> {
return this.sendObjects(Object.values(alarms), req, 'alarms')
}
/**
* @example id "c77f9955-c1d2-4b39-aa1c-73cdb2dacb7e"
*/
@Delete('{id}')
@SuccessResponse(noContentResp.status, noContentResp.description)
@Response(notFoundResp.status, notFoundResp.description)
async deleteVdi(@Path() id: string): Promise<void> {
const xapiVdi = this.getXapiObject(id as XoVdi['id'])
await xapiVdi.$xapi.VDI_destroy(xapiVdi.$ref)
}
}

View File

@@ -17,6 +17,8 @@
- `DELETE /rest/v0/vms/<vm-id>` (PR [#8938](https://github.com/vatesfr/xen-orchestra/pull/8938))
- `DELETE /rest/v0/vm-templates/<vm-template-id>` (PR [#8938](https://github.com/vatesfr/xen-orchestra/pull/8938))
- `DELETE /rest/v0/vm-snapshots/<vm-snapshot-id>` (PR [#8938](https://github.com/vatesfr/xen-orchestra/pull/8938))
- `DELETE /rest/v0/vdis/<vdi-id>` (PR [#8961](https://github.com/vatesfr/xen-orchestra/pull/8961))
- `DELETE /rest/v0/vdi-snapshots/<vdi-snapshot-id>` (PR [#8961](https://github.com/vatesfr/xen-orchestra/pull/8961))
- `POST /rest/v0/tasks/<task-id>/actions/abort` (PR [#8908](https://github.com/vatesfr/xen-orchestra/pull/8908))
- `GET /rest/v0/vdis/<vdi-id>.(raw|vhd)` (PR [#8923](http://github.com/vatesfr/xen-orchestra/pull/8923))
- `GET /rest/v0/vdi-snapshots/<vdi-snapshot-id>.(raw|vhd)` (PR [#8923](http://github.com/vatesfr/xen-orchestra/pull/8923))

View File

@@ -1063,14 +1063,6 @@ export default class RestApi {
})
)
api.delete(
'/:collection(vdis|vdi-snapshots)/:object',
wrap(async (req, res) => {
await req.xapiObject.$destroy()
res.sendStatus(200)
})
)
setupRestApi(express, app)
}