mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-09-10 22:14:48 -05:00
feat(rest-api): ability to set transient for host.disable (#10040)
This commit is contained in:
@@ -419,8 +419,12 @@ export interface Xapi {
|
||||
pathname: string,
|
||||
params?: { host?: XenApiHost; query?: Record<string, unknown>; task?: boolean | XenApiTask['$ref'] }
|
||||
): Promise<{ body: Readable }>
|
||||
clearHost(host: Pick<XenApiHostWrapped, '$ref' | '$pool'>, force?: boolean): Promise<void>
|
||||
disableHost(hostId: XoHost['id']): Promise<void>
|
||||
clearHost(
|
||||
host: Pick<XenApiHostWrapped, '$ref' | '$pool'>,
|
||||
force?: boolean,
|
||||
opts?: { transient?: boolean }
|
||||
): Promise<void>
|
||||
disableHost(hostId: XoHost['id'], opts?: { transient?: boolean }): Promise<void>
|
||||
enableHost(hostId: XoHost['id']): Promise<void>
|
||||
getRecordByUuid<
|
||||
Type extends WrappedXenApiRecord['$type'],
|
||||
|
||||
@@ -458,6 +458,8 @@ export class HostController extends XapiXoController<XoHost> {
|
||||
*
|
||||
* Disable a host.
|
||||
*
|
||||
* Set `autoEnable` to `true` to re-enable after a toolstack restart automatically
|
||||
*
|
||||
* Set `evacuate` to `true` to also evacuate all running VMs to other hosts in the pool.
|
||||
*
|
||||
* Use `vmIdsToForceMigrate` to unblock VMs whose migration is currently blocked (e.g. by `pool_migrate` or `migrate_send` blocked operations).
|
||||
@@ -493,16 +495,21 @@ export class HostController extends XapiXoController<XoHost> {
|
||||
disable(
|
||||
@Path() id: string,
|
||||
// mark `evacuate` as optional to workaround a TSOA issue. See https://github.com/lukeautry/tsoa/pull/1840
|
||||
@Body() body?: { evacuate?: false } | { evacuate: true; force?: boolean; vmIdsToForceMigrate?: string[] },
|
||||
@Body()
|
||||
body?: { autoEnable?: boolean } & (
|
||||
| { evacuate?: false }
|
||||
| { evacuate: true; force?: boolean; vmIdsToForceMigrate?: string[] }
|
||||
),
|
||||
@Query() sync?: boolean
|
||||
): CreateActionReturnType<void> {
|
||||
const hostId = id as XoHost['id']
|
||||
const isTransient = body?.autoEnable ?? false
|
||||
const action = defer(async ($defer: Defer) => {
|
||||
const xapiHost = this.getXapiObject(hostId)
|
||||
const xapi = xapiHost.$xapi
|
||||
|
||||
if (body?.evacuate !== true) {
|
||||
await xapi.call('host.disable', xapiHost.$ref)
|
||||
await xapi.disableHost(hostId, { transient: isTransient })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -519,7 +526,7 @@ export class HostController extends XapiXoController<XoHost> {
|
||||
})
|
||||
}
|
||||
|
||||
await xapi.clearHost(xapiHost, body.force)
|
||||
await xapi.clearHost(xapiHost, body.force, { transient: isTransient })
|
||||
})
|
||||
|
||||
return this.createAction<void>(action, {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
- `/pools/:id/actions/create_bonded_network` (PR [#9891](https://github.com/vatesfr/xen-orchestra/pull/9891))
|
||||
- `/pools/:id/actions/create_internal_network` (PR [#9891](https://github.com/vatesfr/xen-orchestra/pull/9891))
|
||||
- `/pools/:id/actions/management-reconfigure` (PR [#9891](https://github.com/vatesfr/xen-orchestra/pull/9891))
|
||||
- [REST API] Possibility of sending `autoEnable` in the body of the `/hosts/:id/actions/disable` endpoint (PR [#10040](https://github.com/vatesfr/xen-orchestra/pull/10040))
|
||||
|
||||
### Bug fixes
|
||||
|
||||
@@ -38,8 +39,9 @@
|
||||
|
||||
<!--packages-start-->
|
||||
|
||||
- @vates/types minor
|
||||
- @xen-orchestra/rest-api minor
|
||||
- @xen-orchestra/web patch
|
||||
- xo-server patch
|
||||
- xo-server minor
|
||||
|
||||
<!--packages-end-->
|
||||
|
||||
@@ -201,8 +201,9 @@ export default class Xapi extends XapiBase {
|
||||
//
|
||||
// If `force` is false and the evacuation failed, the host is re-
|
||||
// enabled and the error is thrown.
|
||||
async clearHost({ $ref: hostRef, $pool: pool }, force) {
|
||||
await this.call('host.disable', hostRef)
|
||||
// If `transient` is false, the host will be disabled indefinitely, across toolstack restarts and host reboots, until re-enabled explicitly with Host.enable.
|
||||
async clearHost({ $ref: hostRef, $pool: pool }, force, { transient = true } = {}) {
|
||||
await this.disableHost(hostRef, { transient })
|
||||
|
||||
const migrationNetworkRef = (id => {
|
||||
if (id !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user