mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-21 22:37:25 -06:00
Compare commits
68 Commits
fix_retent
...
debug_time
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9829eb58f3 | ||
|
|
2e5ec8c9e2 | ||
|
|
8054d88a88 | ||
|
|
20bedca539 | ||
|
|
f61019b960 | ||
|
|
be960b36b9 | ||
|
|
40dede9e11 | ||
|
|
e9548959c6 | ||
|
|
be94d0d083 | ||
|
|
9c6d10327f | ||
|
|
a94eba4dd1 | ||
|
|
a6970b0150 | ||
|
|
26cd23179d | ||
|
|
03d2af39ad | ||
|
|
be868a307b | ||
|
|
01c00b110e | ||
|
|
65c32014d6 | ||
|
|
69dfeeaaf6 | ||
|
|
4a1269b898 | ||
|
|
498cc7509f | ||
|
|
f98b4c9e4a | ||
|
|
cc7ba53b29 | ||
|
|
1a795970f9 | ||
|
|
59306dce8f | ||
|
|
6ba465be04 | ||
|
|
068c4cdc86 | ||
|
|
93a7c3b509 | ||
|
|
07c42bbd1e | ||
|
|
ada3cf745c | ||
|
|
6a0332a784 | ||
|
|
09bd5c3425 | ||
|
|
26c36d485e | ||
|
|
087fd5d397 | ||
|
|
4636fcf820 | ||
|
|
dd58fed217 | ||
|
|
4aa8a31c25 | ||
|
|
4ca263c10a | ||
|
|
8d58147d66 | ||
|
|
5849844fca | ||
|
|
a5648aede8 | ||
|
|
84ce89d199 | ||
|
|
9140cd273b | ||
|
|
e710135eda | ||
|
|
5509f62ccd | ||
|
|
6c4f7336e1 | ||
|
|
65cd607a49 | ||
|
|
453ffc98d2 | ||
|
|
f8df78c03d | ||
|
|
3613b30aa1 | ||
|
|
58332e6b16 | ||
|
|
9388fa4bb6 | ||
|
|
f683817dec | ||
|
|
51fe6b8920 | ||
|
|
74b952be2b | ||
|
|
efbfb664f7 | ||
|
|
1616ec6f41 | ||
|
|
246e2e4eba | ||
|
|
bcb91e8b4f | ||
|
|
76b45a9b3b | ||
|
|
5f42e437c7 | ||
|
|
b76294a1b1 | ||
|
|
b7bce8e7e7 | ||
|
|
1445f986cf | ||
|
|
83b43a44f6 | ||
|
|
235ff3c455 | ||
|
|
b0194b2c5f | ||
|
|
316122a683 | ||
|
|
954c0aaa9e |
@@ -19,12 +19,12 @@
|
||||
},
|
||||
"main": "./index.mjs",
|
||||
"dependencies": {
|
||||
"@xen-orchestra/fs": "^4.9.2",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"fuse-native": "^2.2.6",
|
||||
"lru-cache": "^7.14.0",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"vhd-lib": "^4.16.0"
|
||||
"vhd-lib": "^4.16.1"
|
||||
},
|
||||
"bin": {
|
||||
"xo-fuse-vhd": "./cli.mjs"
|
||||
|
||||
@@ -19,6 +19,12 @@ export class NbdDisk extends RandomAccessDisk {
|
||||
/** @type {number} */
|
||||
#blockSize
|
||||
|
||||
/** @type {number | undefined} */
|
||||
#hasBlockCursor
|
||||
|
||||
/** @type {number | undefined} */
|
||||
#hasBlockPreviousIndex
|
||||
|
||||
constructor(nbdInfos, blockSize, { dataMap } = {}) {
|
||||
super()
|
||||
this.#blockSize = blockSize
|
||||
@@ -27,11 +33,38 @@ export class NbdDisk extends RandomAccessDisk {
|
||||
}
|
||||
|
||||
#processDatamap(rawDataMap) {
|
||||
return rawDataMap
|
||||
.filter(({ type }) => type === 0)
|
||||
const ranges = rawDataMap
|
||||
.filter(({ type, length }) => type === 0 && length > 0)
|
||||
.map(({ offset, length }) => ({ offset, length }))
|
||||
.sort(({ offset: offset1 }, { offset: offset2 }) => offset1 - offset2)
|
||||
|
||||
// hasBlock()'s forward-only cursor is only correct if the extents are
|
||||
// sorted AND disjoint: an earlier extent must never reach into a block
|
||||
// after a later one, otherwise the cursor could skip it and wrongly report
|
||||
// a block as empty, dropping data and corrupting the output.
|
||||
// Touching extents (cur.offset === prevEnd) are merged
|
||||
const merged = []
|
||||
for (const range of ranges) {
|
||||
const last = merged[merged.length - 1]
|
||||
if (last !== undefined) {
|
||||
const lastEnd = last.offset + last.length
|
||||
if (range.offset < lastEnd) {
|
||||
throw new Error(
|
||||
`overlapping ranges in data map: [${last.offset}, ${lastEnd}) and [${range.offset}, ${range.offset + range.length})`
|
||||
)
|
||||
}
|
||||
if (range.offset === lastEnd) {
|
||||
// touching: extend the previous extent
|
||||
last.length += range.length
|
||||
continue
|
||||
}
|
||||
}
|
||||
// gap (or first range): new extent
|
||||
merged.push(range)
|
||||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @returns {Promise<DiskBlock>}
|
||||
@@ -117,6 +150,34 @@ export class NbdDisk extends RandomAccessDisk {
|
||||
return [...indexes].sort((a, b) => a - b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the allocated blocks without materializing the index list.
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
getBlockIndexesCount() {
|
||||
if (!this.#dataMap) {
|
||||
throw new Error("can't getBlockIndexesCount before init")
|
||||
}
|
||||
|
||||
const blockSize = this.getBlockSize()
|
||||
|
||||
let count = 0
|
||||
let lastCountedBlock = -1
|
||||
for (const { offset, length } of this.#dataMap) {
|
||||
const firstBlockIndex = Math.floor(offset / blockSize)
|
||||
const lastBlockIndex = Math.floor((offset + length - 1) / blockSize)
|
||||
const from = Math.max(firstBlockIndex, lastCountedBlock + 1)
|
||||
|
||||
if (lastBlockIndex >= from) {
|
||||
count += lastBlockIndex - from + 1
|
||||
lastCountedBlock = lastBlockIndex
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @returns {boolean}
|
||||
@@ -125,8 +186,32 @@ export class NbdDisk extends RandomAccessDisk {
|
||||
if (!this.#dataMap) {
|
||||
throw new Error("can't hasBlock before init")
|
||||
}
|
||||
const blockStart = index * this.getBlockSize()
|
||||
const blockEnd = (index + 1) * this.getBlockSize()
|
||||
return this.#dataMap.some(({ offset, length }) => offset + length > blockStart && offset < blockEnd)
|
||||
|
||||
const blockSize = this.getBlockSize()
|
||||
const blockStart = index * blockSize
|
||||
const blockEnd = blockStart + blockSize
|
||||
|
||||
let startExtentIndex = 0
|
||||
if (this.#hasBlockCursor !== undefined && index >= this.#hasBlockPreviousIndex) {
|
||||
startExtentIndex = this.#hasBlockCursor
|
||||
} else {
|
||||
this.#hasBlockCursor = undefined
|
||||
}
|
||||
this.#hasBlockPreviousIndex = index
|
||||
|
||||
const dataMap = this.#dataMap
|
||||
const l = dataMap.length
|
||||
for (let i = startExtentIndex; i < l; i++) {
|
||||
const { offset, length } = dataMap[i]
|
||||
if (offset >= blockEnd) {
|
||||
// extents are sorted: nothing from here on can overlap this block
|
||||
break
|
||||
}
|
||||
if (offset + length > blockStart) {
|
||||
this.#hasBlockCursor = i
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
127
@vates/nbd-client/NbdDisk.test.mjs
Normal file
127
@vates/nbd-client/NbdDisk.test.mjs
Normal file
@@ -0,0 +1,127 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
|
||||
import { NbdDisk } from './NbdDisk.mjs'
|
||||
|
||||
const KiB = 1024
|
||||
const MiB = 1024 * KiB
|
||||
const TiB = 1024 * 1024 * MiB
|
||||
|
||||
const SOURCE_BLOCK_SIZE = 2 * MiB // VHD_BLOCK_SIZE, the block size used when importing from VMware
|
||||
const CLUSTER_SIZE = 64 * KiB // qcow2 cluster size
|
||||
|
||||
// hasBlock() only needs the dataMap (passed through the constructor) and the
|
||||
// block size, so we can exercise it without a live NBD connection.
|
||||
describe('NbdDisk.hasBlock', () => {
|
||||
it('reports allocated and unallocated blocks correctly', () => {
|
||||
const dataMap = [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
|
||||
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
|
||||
]
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
|
||||
assert.strictEqual(disk.hasBlock(0), true)
|
||||
assert.strictEqual(disk.hasBlock(1), false)
|
||||
assert.strictEqual(disk.hasBlock(4), false)
|
||||
assert.strictEqual(disk.hasBlock(5), true)
|
||||
assert.strictEqual(disk.hasBlock(6), false)
|
||||
})
|
||||
|
||||
it('handles repeated and out-of-order queries with the resume cursor', () => {
|
||||
const dataMap = [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
|
||||
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
|
||||
]
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
|
||||
// repeated indexes (the qcow2 path queries each 2MB block ~32 times as it
|
||||
// walks 64KB clusters) must return a stable answer
|
||||
assert.strictEqual(disk.hasBlock(5), true)
|
||||
assert.strictEqual(disk.hasBlock(5), true)
|
||||
assert.strictEqual(disk.hasBlock(6), false)
|
||||
assert.strictEqual(disk.hasBlock(6), false)
|
||||
|
||||
// querying backwards must still be correct (falls back to a full scan)
|
||||
assert.strictEqual(disk.hasBlock(0), true)
|
||||
assert.strictEqual(disk.hasBlock(5), true)
|
||||
})
|
||||
|
||||
it('invalidates the cursor on a backward miss (no stale skip)', () => {
|
||||
const dataMap = [
|
||||
{ type: 0, offset: 3 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 3
|
||||
{ type: 0, offset: 10 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 10
|
||||
]
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
|
||||
assert.strictEqual(disk.hasBlock(10), true) // forward hit: cursor parks on the high extent
|
||||
assert.strictEqual(disk.hasBlock(1), false) // backward miss: must invalidate the cursor
|
||||
assert.strictEqual(disk.hasBlock(3), true) // lower extent must not be skipped
|
||||
})
|
||||
|
||||
it('throws on overlapping ranges (would break the resume cursor)', () => {
|
||||
const dataMap = [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE },
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE }, // overlaps the previous range
|
||||
]
|
||||
assert.throws(() => new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap }), /overlapping ranges/)
|
||||
})
|
||||
|
||||
it('merges touching ranges and drops zero-length / non type-0 entries', () => {
|
||||
const dataMap = [
|
||||
{ type: 0, offset: 2 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // [2, 3)
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 }, // [0, .5)
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // [1, 2)
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE / 2 }, // [.5, 1), touches [0, .5)
|
||||
{ type: 1, offset: 10 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // wrong type: ignored
|
||||
{ type: 0, offset: 7 * SOURCE_BLOCK_SIZE, length: 0 }, // zero length: ignored
|
||||
]
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
|
||||
assert.strictEqual(disk.hasBlock(0), true)
|
||||
assert.strictEqual(disk.hasBlock(1), true)
|
||||
assert.strictEqual(disk.hasBlock(2), true)
|
||||
assert.strictEqual(disk.hasBlock(3), false)
|
||||
assert.strictEqual(disk.hasBlock(7), false) // zero-length range dropped
|
||||
assert.strictEqual(disk.hasBlock(10), false) // non type-0 range dropped
|
||||
})
|
||||
})
|
||||
|
||||
describe('NbdDisk.getBlockIndexesCount', () => {
|
||||
const cases = {
|
||||
'aligned, disjoint blocks': [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE }, // block 0
|
||||
{ type: 0, offset: 5 * SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE }, // block 5
|
||||
],
|
||||
'a range spanning several blocks': [
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: 3 * SOURCE_BLOCK_SIZE }, // blocks 0,1,2,3
|
||||
],
|
||||
'two disjoint extents sharing block 0 (needs dedup)': [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 }, // [0, .5) => block 0
|
||||
{ type: 0, offset: 3 * (SOURCE_BLOCK_SIZE / 4), length: SOURCE_BLOCK_SIZE }, // [.75, 1.75) => blocks 0,1
|
||||
],
|
||||
'touching sub-block fragments': [
|
||||
{ type: 0, offset: 0, length: SOURCE_BLOCK_SIZE / 2 },
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE / 2, length: SOURCE_BLOCK_SIZE / 2 },
|
||||
{ type: 0, offset: SOURCE_BLOCK_SIZE, length: SOURCE_BLOCK_SIZE },
|
||||
],
|
||||
empty: [],
|
||||
}
|
||||
|
||||
for (const [name, dataMap] of Object.entries(cases)) {
|
||||
it(`matches getBlockIndexes().length: ${name}`, () => {
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
|
||||
})
|
||||
}
|
||||
|
||||
it('matches getBlockIndexes().length on the large sparse map', () => {
|
||||
const virtualSize = Math.floor(3.5 * TiB)
|
||||
const NB_RANGES = 113528
|
||||
const dataMap = []
|
||||
for (let i = 0; i < NB_RANGES; i++) {
|
||||
dataMap.push({ type: 0, offset: Math.floor((i / NB_RANGES) * virtualSize), length: CLUSTER_SIZE })
|
||||
}
|
||||
const disk = new NbdDisk({}, SOURCE_BLOCK_SIZE, { dataMap })
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
|
||||
})
|
||||
})
|
||||
@@ -13,7 +13,7 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "3.4.0",
|
||||
"version": "3.5.0",
|
||||
"engines": {
|
||||
"node": ">=14.0"
|
||||
},
|
||||
@@ -22,10 +22,10 @@
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@vates/read-chunk": "^1.2.1",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/disk-transform": "^1.3.1",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"xen-api": "^4.7.8"
|
||||
"xen-api": "^4.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^18.7.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@vates/types",
|
||||
"private": false,
|
||||
"version": "1.28.0",
|
||||
"version": "1.30.1",
|
||||
"main": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
@@ -32,7 +32,8 @@
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.19.0",
|
||||
"typescript": "~5.6.3",
|
||||
"typescript-eslint": "^8.61.0"
|
||||
"typescript-eslint": "^8.61.0",
|
||||
"@types/express": "^5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
|
||||
@@ -5,3 +5,4 @@ export * from './xo-app.mjs'
|
||||
export * from './lib/xen-orchestra-xapi.mjs'
|
||||
export * from './lib/xen-orchestra-acl.mjs'
|
||||
export * from './lib/complex-matcher.mjs'
|
||||
export * from './lib/rest-api.mjs'
|
||||
|
||||
102
@vates/types/src/lib/rest-api.mts
Normal file
102
@vates/types/src/lib/rest-api.mts
Normal file
@@ -0,0 +1,102 @@
|
||||
import type { NextFunction, Request, Response } from 'express'
|
||||
import type { VatesTask } from './vates-task.mjs'
|
||||
import type { XoApp } from '../xo-app.mjs'
|
||||
|
||||
export type SecurityName = '*' | 'token' | 'basic' | 'none'
|
||||
|
||||
export type FieldDefinition =
|
||||
| {
|
||||
type: 'string'
|
||||
example?: string
|
||||
optional?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'boolean'
|
||||
example?: boolean
|
||||
optional?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'number'
|
||||
example?: number
|
||||
optional?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'enum'
|
||||
enum: string[]
|
||||
example?: string
|
||||
optional?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'object'
|
||||
fields: Record<string, FieldDefinition>
|
||||
optional?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'array'
|
||||
items: FieldDefinition
|
||||
example?: unknown[]
|
||||
optional?: boolean
|
||||
}
|
||||
|
||||
export type ParamFieldDefinition = Exclude<
|
||||
FieldDefinition,
|
||||
{ type: 'boolean' } | { type: 'object' } | { type: 'array' }
|
||||
>
|
||||
|
||||
export type QueryFieldDefinition = Exclude<FieldDefinition, { type: 'object' } | { type: 'array' }>
|
||||
type RestApi = object & { xoApp: XoApp }
|
||||
export type CreateAction = <Result>(
|
||||
callback: (task: VatesTask) => MaybePromise<Result>,
|
||||
opts: {
|
||||
sync?: boolean
|
||||
statusCode?: number
|
||||
taskProperties: { name: string; [key: string]: unknown }
|
||||
}
|
||||
) => Promise<Result | undefined>
|
||||
|
||||
export interface BaseRouteDefinition<Middleware> {
|
||||
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
|
||||
endpoint: string
|
||||
description?: string
|
||||
tags?: string[]
|
||||
params?: Record<string, ParamFieldDefinition>
|
||||
query?: Record<string, QueryFieldDefinition>
|
||||
body?: Record<string, FieldDefinition>
|
||||
responses?: Array<{
|
||||
status: number
|
||||
description: string
|
||||
schema?: Record<string, FieldDefinition>
|
||||
}>
|
||||
middlewares?: Middleware[]
|
||||
scope?: 'acl'
|
||||
callback: (params: {
|
||||
req: Request
|
||||
res: Response
|
||||
next: NextFunction
|
||||
restApi: RestApi
|
||||
createAction: CreateAction
|
||||
}) => MaybePromise<unknown>
|
||||
security?: SecurityName
|
||||
}
|
||||
|
||||
export type MiddlewareDescriptor =
|
||||
| { name: 'json' | 'urlencoded' | 'text' | 'raw'; options?: Record<string, unknown> }
|
||||
| { name: 'acl'; acls: LooseAclEntry | LooseAclEntry[] }
|
||||
|
||||
type MaybePromise<T> = T | Promise<T>
|
||||
/**
|
||||
* Loosely-typed mirror of {@link https://github.com/vatesfr/xen-orchestra/blob/master/@xen-orchestra/rest-api/src/middlewares/acl.middleware.mts | AclEntry}
|
||||
* from `@xen-orchestra/rest-api/src/middlewares/acl.middleware.mts`.
|
||||
*/
|
||||
export type LooseAclEntry = {
|
||||
resource: string
|
||||
action?: string | ((opts: { req: object; restApi: RestApi }) => string | undefined)
|
||||
actions?: string[] | ((opts: { req: object; restApi: RestApi }) => string[])
|
||||
objectId?: string | ((opts: { req: object; restApi: RestApi }) => string)
|
||||
objectIds?: string[] | ((opts: { req: object; restApi: RestApi }) => string[])
|
||||
object?: object | ((opts: { req: object; restApi: RestApi }) => MaybePromise<object> | undefined)
|
||||
objects?: object[] | ((opts: { req: object; restApi: RestApi }) => MaybePromise<object[]> | undefined)
|
||||
getObject?: (opts: { restApi: RestApi }) => (id: string) => MaybePromise<object>
|
||||
}
|
||||
|
||||
export type PluginRestRouteDefinition = BaseRouteDefinition<MiddlewareDescriptor>
|
||||
@@ -233,6 +233,36 @@ export interface Xapi {
|
||||
powerOnHost(hostId: XoHost['id']): Promise<void>
|
||||
rebootHost(hostId: XoHost['id'], force?: boolean): Promise<void>
|
||||
shutdownHost(hostId: XoHost['id'], opts?: { force?: boolean; bypassEvacuate?: boolean }): Promise<void>
|
||||
SR_create(params: {
|
||||
content_type?: XoSr['content_type']
|
||||
// index signature, not `Record<string, string>`: tsoa emits an empty schema for `Record`
|
||||
// (https://github.com/lukeautry/tsoa/pull/1858). device_config keys are driver-specific (SR_type).
|
||||
device_config: {
|
||||
chapuser?: string
|
||||
chappassword?: string
|
||||
device?: string
|
||||
legacy_mode?: string
|
||||
location?: string
|
||||
nfsversion?: string
|
||||
options?: string
|
||||
password?: string
|
||||
SCSIid?: string
|
||||
server?: string
|
||||
serverpath?: string
|
||||
target?: string
|
||||
targetIQN?: string
|
||||
username?: string
|
||||
} & {
|
||||
[key: string]: string
|
||||
}
|
||||
host: XenApiHost['$ref']
|
||||
name_description?: XoSr['name_description']
|
||||
name_label: XoSr['name_label']
|
||||
physical_size?: number
|
||||
shared: boolean
|
||||
sm_config?: { [key: string]: string }
|
||||
type: XoSr['SR_type']
|
||||
}): Promise<XenApiSr['$ref']>
|
||||
SR_importVdi(
|
||||
ref: XenApiSr['$ref'],
|
||||
stream: Readable,
|
||||
@@ -381,7 +411,7 @@ export interface Xapi {
|
||||
): Promise<Readable & { length?: number }>
|
||||
VDI_importContent(
|
||||
vdiRef: XenApiVdi['$ref'],
|
||||
stream: Readable,
|
||||
stream: Readable | Buffer,
|
||||
opts: { cancelToken?: unknown; format: SUPPORTED_VDI_FORMAT }
|
||||
): Promise<void>
|
||||
VIF_create(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { EventEmitter } from 'node:stream'
|
||||
import type {
|
||||
AnyXoBackupJob,
|
||||
AnyXoJob,
|
||||
AnyXoLog,
|
||||
XapiXoRecord,
|
||||
@@ -21,6 +20,7 @@ import type {
|
||||
XoVmBackupArchive,
|
||||
} from './xo.mjs'
|
||||
import { VatesTask } from './lib/vates-task.mjs'
|
||||
import type { PluginRestRouteDefinition } from './lib/rest-api.mjs'
|
||||
import {
|
||||
Xapi,
|
||||
XapiHostStats,
|
||||
@@ -195,6 +195,7 @@ export type XoApp = {
|
||||
params?: any
|
||||
}
|
||||
) => () => void // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
registerRestRoutes: (routes: PluginRestRouteDefinition[], base?: string) => () => void
|
||||
authenticateUser: (
|
||||
credentials: { token?: string; username?: string; password?: string },
|
||||
userData?: { ip?: string },
|
||||
@@ -340,8 +341,11 @@ export type XoApp = {
|
||||
readOnly?: XoServer['readOnly']
|
||||
}
|
||||
): Promise<XoServer>
|
||||
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask }): Promise<void>
|
||||
rollingPoolUpdate(pool: XoPool, opts?: { rebootVm?: boolean; parentTask?: VatesTask }): Promise<void>
|
||||
rollingPoolReboot(pool: XoPool, opts?: { parentTask?: VatesTask; shutdownPinnedVms?: boolean }): Promise<void>
|
||||
rollingPoolUpdate(
|
||||
pool: XoPool,
|
||||
opts?: { rebootVm?: boolean; parentTask?: VatesTask; shutdownPinnedVms?: boolean }
|
||||
): Promise<void>
|
||||
setVmResourceSet(vmId: XoVm['id'], resourceSetId: string | null, force?: boolean): Promise<void>
|
||||
shareVmResourceSet(vmId: XoVm['id']): Promise<void>
|
||||
removeUserFromGroup(userId: XoUser['id'], id: XoGroup['id']): Promise<void>
|
||||
|
||||
@@ -614,7 +614,7 @@ export type XoSr = BaseXapiXo & {
|
||||
VDIs: AnyXoVdi['id'][]
|
||||
|
||||
allocationStrategy?: 'thin' | 'thick' | 'unknown'
|
||||
content_type: string
|
||||
content_type: 'user' | 'iso' | 'disk'
|
||||
current_operations: Record<string, STORAGE_OPERATIONS>
|
||||
id: Branded<'SR'>
|
||||
inMaintenanceMode: boolean
|
||||
@@ -625,7 +625,28 @@ export type XoSr = BaseXapiXo & {
|
||||
shared: boolean
|
||||
size: number
|
||||
sm_config: Record<string, string>
|
||||
SR_type: string
|
||||
// SM drivers shipped with XCP-ng/XenServer
|
||||
SR_type:
|
||||
| 'cephfs'
|
||||
| 'dummy'
|
||||
| 'ext'
|
||||
| 'file'
|
||||
| 'glusterfs'
|
||||
| 'hba'
|
||||
| 'iso'
|
||||
| 'largeblock'
|
||||
| 'linstor'
|
||||
| 'lvm'
|
||||
| 'lvmofcoe'
|
||||
| 'lvmohba'
|
||||
| 'lvmoiscsi'
|
||||
| 'moosefs'
|
||||
| 'nfs'
|
||||
| 'shm'
|
||||
| 'smb'
|
||||
| 'udev'
|
||||
| 'xfs'
|
||||
| 'zfs'
|
||||
tags: string[]
|
||||
type: 'SR'
|
||||
usage: number
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"main": "dist/index.mjs",
|
||||
"name": "@xen-orchestra/acl",
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/acl",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
@@ -30,7 +30,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.19.0",
|
||||
"@vates/types": "^1.28.0",
|
||||
"@vates/types": "^1.30.1",
|
||||
"rimraf": "^6.0.1",
|
||||
"typescript": "~5.6",
|
||||
"typescript-eslint": "^8.61.0"
|
||||
|
||||
@@ -16,6 +16,7 @@ export default {
|
||||
smart: true,
|
||||
},
|
||||
'restart-toolstack': true,
|
||||
'scan-pifs': true,
|
||||
shutdown: {
|
||||
clean: true,
|
||||
emergency: true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export default {
|
||||
create: true,
|
||||
delete: true,
|
||||
forget: true,
|
||||
import: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xen-orchestra/backup-archive",
|
||||
"version": "1.0.4",
|
||||
"version": "1.1.1",
|
||||
"description": "Helper to handle generic backup archives",
|
||||
"license": "ISC",
|
||||
"author": "",
|
||||
@@ -21,23 +21,24 @@
|
||||
"tar-stream": "^3.1.8",
|
||||
"@types/tar-stream": "^3.1.4",
|
||||
"tmp": "^0.2.1",
|
||||
"@vates/types": "^1.28.0"
|
||||
"@vates/types": "^1.30.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xen-orchestra/log": "^0.7.1",
|
||||
"@xen-orchestra/fs": "^4.9.2",
|
||||
"@xen-orchestra/disk-transform": "^1.3.1",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3",
|
||||
"@vates/task": "0.7.0",
|
||||
"golike-defer": "0.5.1",
|
||||
"uuid": "^9.0.0",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"@vates/async-each": "^1.0.1",
|
||||
"vhd-lib": "^4.14.7"
|
||||
"vhd-lib": "^4.16.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn run clean && tsc",
|
||||
"dev": "tsc --watch",
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "yarn run clean && tsc && node --test **/*.test.mjs",
|
||||
"test-integration": "yarn run clean && tsc && node --test **/*.integ.mjs",
|
||||
"clean": "rimraf dist/"
|
||||
},
|
||||
|
||||
@@ -331,20 +331,14 @@ export class RemoteDiskLineage {
|
||||
await asyncEach(
|
||||
toMerge,
|
||||
async ({ chain, isResuming }) => {
|
||||
try {
|
||||
const { finalDiskSize, mergeTargetPath } = await limitedMergeChain([...chain], isResuming)
|
||||
mergedSizes.set(mergeTargetPath, (mergedSizes.get(mergeTargetPath) ?? 0) + finalDiskSize)
|
||||
// parentPath alias deleted by parentDisk.rename(mergeTargetPath)
|
||||
// intermediates deleted by childDisk.unlink() when removeUnused=true
|
||||
// Unregister so #cleanOrphanDataFiles does not read already-deleted aliases
|
||||
// and produce false "missing target of alias" warnings.
|
||||
for (const deletedPath of chain.slice(0, -1)) {
|
||||
this.#unregisterDisk(deletedPath)
|
||||
}
|
||||
} catch (error) {
|
||||
// A broken chain (e.g. corrupted parent) must not abort merging of other,
|
||||
// unrelated chains, nor skip #cleanOrphanDataFiles/remove below.
|
||||
this.#opts.logWarn('failed to merge disk chain', { chain, error })
|
||||
const { finalDiskSize, mergeTargetPath } = await limitedMergeChain([...chain], isResuming)
|
||||
mergedSizes.set(mergeTargetPath, (mergedSizes.get(mergeTargetPath) ?? 0) + finalDiskSize)
|
||||
// parentPath alias deleted by parentDisk.rename(mergeTargetPath)
|
||||
// intermediates deleted by childDisk.unlink() when removeUnused=true
|
||||
// Unregister so #cleanOrphanDataFiles does not read already-deleted aliases
|
||||
// and produce false "missing target of alias" warnings.
|
||||
for (const deletedPath of chain.slice(0, -1)) {
|
||||
this.#unregisterDisk(deletedPath)
|
||||
}
|
||||
},
|
||||
{ concurrency: this.#opts.mergeConcurrency ?? DEFAULT_MERGE_CONCURRENCY }
|
||||
|
||||
@@ -10,6 +10,11 @@ export interface PartialBackupMetadata {
|
||||
jobId: string
|
||||
scheduleId: string
|
||||
timestamp: number
|
||||
// 'true' when written by code including the non-NBD qcow2 corruption fix and its force-full
|
||||
// gate; its absence marks a potentially-corrupt older backup and makes the gate re-probe.
|
||||
// Preserved (never stamped) across merges here.
|
||||
// @todo remove this code and the logic associated on 2027 01 01
|
||||
includeNonNbdQcow2Fix?: boolean
|
||||
}
|
||||
export const DEFAULT_MERGE_CONCURRENCY = 1
|
||||
export const DEFAULT_REMOVE_CONCURRENCY = 4
|
||||
|
||||
@@ -39,6 +39,10 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
#checkResult: (CheckResult & { orphans: string[]; linked: string[] }) | undefined = undefined
|
||||
#uniqueLineages: Map<string, RemoteDiskLineage> | undefined = undefined
|
||||
|
||||
// Set by #checkCacheCount(): the on-disk cache did not match the archives found
|
||||
// on disk, so clean() must regenerate it even when nothing was merged/removed.
|
||||
#cacheOutOfSync = false
|
||||
|
||||
constructor(
|
||||
handler: RemoteHandlerAbstract,
|
||||
vmBackupPath: string,
|
||||
@@ -147,22 +151,16 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
const allMergedSizes = new Map<string, number>()
|
||||
await asyncEach(
|
||||
Array.from(this.#uniqueLineages!.entries()),
|
||||
async ([vdiDir, lineage]) => {
|
||||
try {
|
||||
const { mergedSizes, removedFiles, merge: hasPendingMerge } = await lineage.clean({ remove, merge })
|
||||
if (removedFiles.length > 0) {
|
||||
cacheNeedsRegen = true
|
||||
}
|
||||
if (hasPendingMerge) {
|
||||
someLineageMergedOrShouldBe = true
|
||||
}
|
||||
for (const [diskPath, size] of mergedSizes || []) {
|
||||
allMergedSizes.set(diskPath, (allMergedSizes.get(diskPath) ?? 0) + size)
|
||||
}
|
||||
} catch (error) {
|
||||
// One broken/unmergeable VDI lineage must not abort cleanup (prune dirs, archive
|
||||
// metadata clean, cache regen, root-orphan removal) for the rest of this VM.
|
||||
this.opts.logWarn('failed to clean VDI lineage', { vdiDir, error })
|
||||
async ([_vdiDir, lineage]) => {
|
||||
const { mergedSizes, removedFiles, merge: hasPendingMerge } = await lineage.clean({ remove, merge })
|
||||
if (removedFiles.length > 0) {
|
||||
cacheNeedsRegen = true
|
||||
}
|
||||
if (hasPendingMerge) {
|
||||
someLineageMergedOrShouldBe = true
|
||||
}
|
||||
for (const [diskPath, size] of mergedSizes || []) {
|
||||
allMergedSizes.set(diskPath, (allMergedSizes.get(diskPath) ?? 0) + size)
|
||||
}
|
||||
},
|
||||
{ concurrency: DEFAULT_MERGE_CONCURRENCY }
|
||||
@@ -189,7 +187,7 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
{ concurrency: 2 }
|
||||
)
|
||||
|
||||
if (allMergedSizes.size > 0 || cacheNeedsRegen) {
|
||||
if (allMergedSizes.size > 0 || cacheNeedsRegen || this.#cacheOutOfSync) {
|
||||
await this.#regenerateCache()
|
||||
}
|
||||
|
||||
@@ -220,7 +218,8 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
const existingCache = await this.#readCache(cachePath)
|
||||
const actual = existingCache === undefined ? 0 : Object.keys(existingCache).length
|
||||
const expected = this.backupArchives.size
|
||||
if (actual !== expected) {
|
||||
this.#cacheOutOfSync = actual !== expected
|
||||
if (this.#cacheOutOfSync) {
|
||||
this.opts.logWarn('unexpected number of entries in backup cache', { path: cachePath, actual, expected })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ import { MergeRemoteDisk } from '../dist/disks/MergeRemoteDisk.mjs'
|
||||
import { VHDFOOTER, VHDHEADER } from './tests.fixtures.mjs'
|
||||
import { VhdFile, Constants, VhdDirectory, VhdAbstract } from 'vhd-lib'
|
||||
import { dirname, basename } from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
import zlib from 'node:zlib'
|
||||
import { rimraf } from 'rimraf'
|
||||
|
||||
const { beforeEach, afterEach, describe } = test
|
||||
|
||||
const gunzip = promisify(zlib.gunzip)
|
||||
|
||||
let tempDir, handler, jobId, vdiId, basePath, relativePath, vdiId2, basePath2, relativePath2
|
||||
const rootPath = 'xo-vm-backups/VMUUID/'
|
||||
|
||||
@@ -766,67 +770,6 @@ test('it cleans orphan merge states ', async () => {
|
||||
assert.deepEqual(await handler.list(basePath), [])
|
||||
})
|
||||
|
||||
test('a broken merge in one VDI lineage must not block cleanup of a healthy sibling lineage', async () => {
|
||||
// Regression guard: RemoteDiskLineage.clean()'s merge loop and VmBackupDirectory.clean()'s
|
||||
// per-lineage loop used to let an error from #mergeChain (e.g. a real "footer1 !== footer2"
|
||||
// corruption) escape uncaught, aborting the ENTIRE cleanVm call — skipping prune/cache-regen/
|
||||
// orphan-removal for every other, healthy VDI directory of the same VM.
|
||||
|
||||
// --- lineage 1 (basePath): footer-corrupted orphan ancestor with an active child ---
|
||||
const ancestor = await generateVhd(`${basePath}/ancestor.vhd`, { blocks: [0, 1] })
|
||||
await generateVhd(`${basePath}/child.vhd`, {
|
||||
header: { parentUnicodeName: 'ancestor.vhd', parentUuid: ancestor.footer.uuid },
|
||||
blocks: [2, 3],
|
||||
})
|
||||
// Corrupt only the trailing (end-of-file) footer copy; leading footer/header stay intact.
|
||||
// A stray, unparseable `.merge.json` makes RemoteDiskLineage.init() open this disk with
|
||||
// force:true (checkSecondFooter skipped), so the corruption survives the initial scan and
|
||||
// the ancestor is legitimately scheduled to merge into the active child — reproducing the
|
||||
// production crash inside #mergeChain's later, non-resuming (force:false) reopen.
|
||||
const size = await handler.getSize(`${basePath}/ancestor.vhd`)
|
||||
await handler.write(`${basePath}/ancestor.vhd`, Buffer.alloc(512, 0xff), size - 512)
|
||||
await handler.writeFile(`${basePath}/.ancestor.vhd.merge.json`, '')
|
||||
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata1.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/child.vhd`] })
|
||||
)
|
||||
|
||||
// --- lineage 2 (basePath2): healthy orphan + active child, must still merge normally ---
|
||||
const orphan2 = await generateVhd(`${basePath2}/orphan2.vhd`)
|
||||
await generateVhd(`${basePath2}/child2.vhd`, {
|
||||
header: { parentUnicodeName: 'orphan2.vhd', parentUuid: orphan2.footer.uuid },
|
||||
})
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata2.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath2}/child2.vhd`] })
|
||||
)
|
||||
|
||||
const warned = []
|
||||
const logWarn = message => warned.push(message)
|
||||
|
||||
// Must resolve, not reject: before the fix, the corrupted ancestor's merge attempt threw
|
||||
// uncaught and this call rejected instead.
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true, merge: true, logInfo: () => {}, logWarn })
|
||||
|
||||
assert.ok(warned.includes('failed to merge disk chain'), 'broken chain merge failure should be logged, not thrown')
|
||||
|
||||
// lineage 1: merge failed, nothing touched — both disks remain as-is
|
||||
const remaining1 = await handler.list(basePath)
|
||||
assert.ok(remaining1.includes('ancestor.vhd'), 'corrupted ancestor left untouched after failed merge')
|
||||
assert.ok(remaining1.includes('child.vhd'), 'active child left untouched after failed merge')
|
||||
|
||||
// lineage 2: unaffected sibling still merges normally in the same cleanVm call
|
||||
const remaining2 = await handler.list(basePath2)
|
||||
assert.ok(!remaining2.includes('orphan2.vhd'), 'healthy sibling lineage must still merge its own orphan')
|
||||
assert.ok(remaining2.includes('child2.vhd'), 'healthy sibling merge target survives')
|
||||
|
||||
// both metadata files preserved: this VM's cleanup pipeline (cache regen, etc.) completed
|
||||
const rootFiles = await handler.list(rootPath)
|
||||
assert.ok(rootFiles.includes('metadata1.json'))
|
||||
assert.ok(rootFiles.includes('metadata2.json'))
|
||||
})
|
||||
|
||||
test('check all types of aliases, corrupted, missing or not', async () => {
|
||||
// valid alias pointing to an existing data file
|
||||
await handler.mkdir(`${basePath}/data`)
|
||||
@@ -890,117 +833,27 @@ test('it preserves VDI directory when handler.list() throws during lineage init'
|
||||
assert.ok(remaining.includes('snapshot.vhd'), 'VHD must survive when handler.list() throws during lineage init')
|
||||
})
|
||||
|
||||
test('regression: a locked (immutable) VDI chain blocks merging of an unrelated, fully mutable VDI chain', async () => {
|
||||
// Two independent VDI directories for the same VM. basePath's chain is still
|
||||
// immutability-locked (simulated: rename() EPERMs, as it would on a chattr +i remote).
|
||||
// basePath2's chain is fully mutable and has nothing to do with basePath's lock.
|
||||
//
|
||||
// Current behavior: RemoteDiskLineage/MergeRemoteDisk never catch EPERM, and the
|
||||
// asyncEach loops driving both the per-VDI merge (RemoteDiskLineage.mts) and the
|
||||
// cross-VDI merge (VmBackupDirectory.mts, DEFAULT_MERGE_CONCURRENCY = 1, so VDIs are
|
||||
// processed strictly in order) default to stopOnError. So one locked chain aborts
|
||||
// merging of every VDI processed after it in the same cleanVm() call, even though
|
||||
// they're fully independent and fully mergeable.
|
||||
const orphan1 = await generateVhd(`${basePath}/orphan.vhd`, { blocks: [0, 1] })
|
||||
await generateVhd(`${basePath}/child.vhd`, {
|
||||
header: { parentUnicodeName: 'orphan.vhd', parentUuid: orphan1.footer.uuid },
|
||||
blocks: [2, 3],
|
||||
})
|
||||
|
||||
const orphan2 = await generateVhd(`${basePath2}/orphan.vhd`, { blocks: [0, 1] })
|
||||
await generateVhd(`${basePath2}/child.vhd`, {
|
||||
header: { parentUnicodeName: 'orphan.vhd', parentUuid: orphan2.footer.uuid },
|
||||
blocks: [2, 3],
|
||||
})
|
||||
|
||||
test('it regenerates the cache when its entry count is out of sync, even with nothing to merge/remove', async () => {
|
||||
// a referenced disk + its metadata, but no cache.json.gz on disk
|
||||
await generateVhd(`${basePath}/diskA1.vhd`)
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata.json`,
|
||||
JSON.stringify({
|
||||
mode: 'delta',
|
||||
vhds: [`${relativePath}/child.vhd`, `${relativePath2}/child.vhd`],
|
||||
})
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/diskA1.vhd`] })
|
||||
)
|
||||
await assert.rejects(handler.readFile(`${rootPath}/cache.json.gz`), { code: 'ENOENT' })
|
||||
|
||||
const originalRename = handler.rename.bind(handler)
|
||||
handler.rename = async (oldPath, newPath) => {
|
||||
if (typeof newPath === 'string' && newPath.includes(vdiId) && newPath.endsWith('child.vhd')) {
|
||||
throw Object.assign(new Error('simulated immutability lock'), { code: 'EPERM', errno: -1, syscall: 'rename' })
|
||||
}
|
||||
return originalRename(oldPath, newPath)
|
||||
}
|
||||
const logged = []
|
||||
// remove/merge both false: cacheNeedsRegen stays false and no merge happens,
|
||||
// so only the cache-count mismatch can trigger the regeneration
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, {
|
||||
remove: false,
|
||||
merge: false,
|
||||
logInfo: () => {},
|
||||
logWarn: message => logged.push(message),
|
||||
})
|
||||
|
||||
try {
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, {
|
||||
remove: true,
|
||||
merge: true,
|
||||
logWarn: () => {},
|
||||
logInfo: () => {},
|
||||
})
|
||||
} finally {
|
||||
handler.rename = originalRename
|
||||
}
|
||||
assert.ok(logged.includes('unexpected number of entries in backup cache'), 'mismatch should be reported')
|
||||
|
||||
// basePath2's chain is fully mutable and independent of basePath's lock — it must merge
|
||||
// regardless of basePath being stuck.
|
||||
assert.deepEqual(
|
||||
(await handler.list(basePath2)).filter(f => f.endsWith('.vhd')),
|
||||
['child.vhd']
|
||||
)
|
||||
})
|
||||
|
||||
test('it performs two independent merges within a single chain in one cleanVm() call', async () => {
|
||||
// Chain of 5, oldest -> newest: v1 <- v2 <- v3 <- v4 <- v5
|
||||
// v2, v4 and v5 are each an active/retained backup (their own metadata.json).
|
||||
// v1 and v3 are superseded orphans. This should produce exactly two separate
|
||||
// merges in one cleanVm(): (v1 -> v2) and (v3 -> v4) — v5 needs no merge.
|
||||
//
|
||||
// Merge target naming: the parent (older) is always renamed away, the target
|
||||
// (newer/active side of the pair) keeps its name and survives with the merged
|
||||
// data. So after merging (v1,v2) survivor is v2, after merging (v3,v4) survivor
|
||||
// is v4. Expected files on disk at the end: v2.vhd, v4.vhd, v5.vhd.
|
||||
const v1 = await generateVhd(`${basePath}/v1.vhd`)
|
||||
const v2 = await generateVhd(`${basePath}/v2.vhd`, {
|
||||
header: { parentUnicodeName: 'v1.vhd', parentUuid: v1.footer.uuid },
|
||||
})
|
||||
const v3 = await generateVhd(`${basePath}/v3.vhd`, {
|
||||
header: { parentUnicodeName: 'v2.vhd', parentUuid: v2.footer.uuid },
|
||||
})
|
||||
const v4 = await generateVhd(`${basePath}/v4.vhd`, {
|
||||
header: { parentUnicodeName: 'v3.vhd', parentUuid: v3.footer.uuid },
|
||||
})
|
||||
await generateVhd(`${basePath}/v5.vhd`, {
|
||||
header: { parentUnicodeName: 'v4.vhd', parentUuid: v4.footer.uuid },
|
||||
})
|
||||
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata2.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/v2.vhd`] })
|
||||
)
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata4.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/v4.vhd`] })
|
||||
)
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata5.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/v5.vhd`] })
|
||||
)
|
||||
|
||||
const mergeChains = []
|
||||
const logInfo = (message, opts) => {
|
||||
if (message === 'merging disk chain') mergeChains.push(opts.chain.map(p => basename(p)))
|
||||
}
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true, merge: true, logInfo, logWarn: () => {} })
|
||||
|
||||
assert.equal(mergeChains.length, 2, 'exactly two independent merges should occur')
|
||||
assert.deepEqual(
|
||||
mergeChains.sort(),
|
||||
[
|
||||
['v1.vhd', 'v2.vhd'],
|
||||
['v3.vhd', 'v4.vhd'],
|
||||
],
|
||||
'merges must be (v1,v2) and (v3,v4), not one big v1..v5 span'
|
||||
)
|
||||
|
||||
const remaining = (await handler.list(basePath)).filter(f => f.endsWith('.vhd')).sort()
|
||||
assert.deepEqual(remaining, ['v2.vhd', 'v4.vhd', 'v5.vhd'])
|
||||
const cache = JSON.parse((await gunzip(await handler.readFile(`${rootPath}/cache.json.gz`))).toString())
|
||||
assert.equal(Object.keys(cache).length, 1, 'cache should be regenerated to match the archives on disk')
|
||||
})
|
||||
|
||||
@@ -312,4 +312,12 @@ export class RemoteVhdDiskChain extends RemoteDisk {
|
||||
async clean(opts = {}) {
|
||||
throw new Error(`Can't clean a disk chain`)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {RemoteVhdDisk|undefined}
|
||||
*/
|
||||
getRootDisk() {
|
||||
return this.#disks[0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/backups": "^0.73.7",
|
||||
"@xen-orchestra/fs": "^4.9.2",
|
||||
"@xen-orchestra/backups": "^0.73.10",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"filenamify": "^6.0.0",
|
||||
"getopts": "^2.2.5",
|
||||
"lodash": "^4.18.0",
|
||||
|
||||
@@ -315,6 +315,11 @@ export class RemoteAdapter {
|
||||
fn(cache)
|
||||
|
||||
await this._writeCache(path, cache)
|
||||
} else {
|
||||
const regenerated = await this.#getCacheableDataListVmBackups(dirname(path))
|
||||
if (regenerated !== undefined) {
|
||||
await this._writeCache(path, regenerated)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,8 +388,7 @@ export class RemoteAdapter {
|
||||
return
|
||||
}
|
||||
|
||||
// detached async action, will not reject
|
||||
this._writeCache(path, backups)
|
||||
await this._writeCache(path, backups)
|
||||
|
||||
return backups
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { strict as assert } from 'node:assert'
|
||||
import test from 'node:test'
|
||||
import { execFile } from 'node:child_process'
|
||||
import { copyFile, mkdtemp, rm } from 'node:fs/promises'
|
||||
import { copyFile, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { Stream } from 'node:stream'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
@@ -39,6 +40,37 @@ async function createLvmImage(imagePath, vgName, lvName) {
|
||||
})
|
||||
}
|
||||
|
||||
// xo-proxy answers this stream through Koa, which pipes only bodies passing `instanceof Stream`
|
||||
// and JSON-serializes anything else: node-tar >= 7 returns a duck-typed (Minipass) stream, which
|
||||
// silently turned a proxied file restore into a JSON dump of the tar object. Every format must
|
||||
// resolve with a real node stream.
|
||||
test('fetchPartitionFiles resolves with a node:stream for every format', async t => {
|
||||
const tmp = await mkdtemp(join(tmpdir(), 'xo-flr-fetch-'))
|
||||
t.after(() => rm(tmp, { recursive: true, force: true }))
|
||||
await writeFile(join(tmp, 'file.txt'), 'hello')
|
||||
|
||||
const adapter = new RemoteAdapter({})
|
||||
// at this point of a real restore the partition is already mounted
|
||||
adapter.getPartition = Disposable.factory(async function* () {
|
||||
yield tmp
|
||||
})
|
||||
|
||||
for (const [format, magic] of [
|
||||
['tgz', Buffer.from([0x1f, 0x8b])],
|
||||
['zip', Buffer.from('PK')],
|
||||
]) {
|
||||
const stream = await adapter.fetchPartitionFiles('disk', 'partition', ['/file.txt'], format)
|
||||
assert.ok(stream instanceof Stream, `${format}: expected a node:stream instance`)
|
||||
|
||||
const chunks = []
|
||||
for await (const chunk of stream) {
|
||||
chunks.push(chunk)
|
||||
}
|
||||
const archive = Buffer.concat(chunks)
|
||||
assert.deepEqual(archive.subarray(0, magic.length), magic, `${format}: unexpected archive header`)
|
||||
}
|
||||
})
|
||||
|
||||
test('LVM file-restore against real losetup/dmsetup/lvm', { skip }, async t => {
|
||||
const tmp = await mkdtemp(join(tmpdir(), 'xo-flr-'))
|
||||
const adapter = new RemoteAdapter({})
|
||||
|
||||
@@ -12,6 +12,7 @@ import { compose } from '@vates/compose'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { deduped } from '@vates/disposable/deduped.js'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { Readable } from 'node:stream'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { execFile } from 'child_process'
|
||||
import { finished } from 'node:stream/promises'
|
||||
@@ -297,7 +298,15 @@ export const fileRestoreMethods = {
|
||||
// simultaneous reads. Those saturate the libuv threadpool and starve
|
||||
// the underlying vhd/CIFS reads NTFS-3g depends on (FUSE-on-FUSE
|
||||
// threadpool deadlock). Serializing keeps a worker free for them.
|
||||
outputStream = tar.c({ cwd: path, gzip: true, jobs: 1 }, paths.map(makeRelative))
|
||||
const pack = tar.c({ cwd: path, gzip: true, jobs: 1 }, paths.map(makeRelative))
|
||||
|
||||
// node-tar >= 7 returns a Minipass stream: it has `pipe()` but is not a `node:stream`
|
||||
// instance. xo-proxy serves this stream through Koa, which pipes only bodies passing
|
||||
// `instanceof Stream` and JSON-serializes anything else — so a file restore through a
|
||||
// proxy answered a JSON dump of the tar object instead of the archive. Wrapping it in a
|
||||
// real node stream also propagates tar errors to the consumer and aborts the tar job
|
||||
// when the client disconnects.
|
||||
outputStream = Readable.from(pack, { objectMode: false })
|
||||
resolve(outputStream)
|
||||
} else if (format === 'zip') {
|
||||
const zip = new ZipFile()
|
||||
|
||||
@@ -33,6 +33,13 @@ export const VM_UUID = 'xo:backup:vm'
|
||||
// allows direction-agnostic discovery of common base VDIs (e.g. for failback/reverse replication)
|
||||
export const CONTENT_KEY = 'xo:backup:contentKey'
|
||||
|
||||
// in `other_config` of a replicated VM and its VDIs
|
||||
// set to the string 'true' on every write done by code that includes the non-NBD qcow2
|
||||
// corruption fix (fix(disk-transform): erroneous DiskLargerBlock copy offset). Its absence
|
||||
// on a qcow2 full means the replica may be silently corrupt and its chain must be re-based
|
||||
// with a clean full. Named after the specific fix so future fixes get their own flag.
|
||||
export const INCLUDE_NON_NBD_QCOW2_FIX = 'xo:backup:includeNonNbdQcow2Fix'
|
||||
|
||||
async function listVdiRefs(xapi, vmRef) {
|
||||
return xapi.VM_getDisks(vmRef)
|
||||
}
|
||||
@@ -90,6 +97,7 @@ export function resetVmOtherConfig(xapi, vmRef) {
|
||||
[DATETIME]: null,
|
||||
[DELTA_CHAIN_LENGTH]: null,
|
||||
[EXPORTED_SUCCESSFULLY]: null,
|
||||
[INCLUDE_NON_NBD_QCOW2_FIX]: null,
|
||||
[JOB_ID]: null,
|
||||
[SCHEDULE_ID]: null,
|
||||
[VM_UUID]: null,
|
||||
@@ -120,6 +128,10 @@ export async function setVmOtherConfig(xapi, vmRef, { timestamp, jobId, schedule
|
||||
xapi.setFieldEntries(type, ref, 'other_config', {
|
||||
[REPLICATED_TO_SR_UUID]: srUuid,
|
||||
[DATETIME]: formatDateTime(timestamp),
|
||||
// stamped on every write: its presence marks the object as produced by code
|
||||
// that includes the non-NBD qcow2 corruption fix, so a chain rooted in a pre-fix
|
||||
// qcow2 full (missing this flag) can be detected and re-based with a clean full
|
||||
[INCLUDE_NON_NBD_QCOW2_FIX]: 'true',
|
||||
[JOB_ID]: jobId,
|
||||
[SCHEDULE_ID]: scheduleId,
|
||||
[VM_UUID]: vmUuid,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { asyncMap } from '@xen-orchestra/async-map'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { Task } from '@vates/task'
|
||||
|
||||
import { DIR_XO_POOL_METADATA_BACKUPS } from '../RemoteAdapter.mjs'
|
||||
import { forkStreamUnpipe } from './_forkStreamUnpipe.mjs'
|
||||
import { formatFilenameDate } from '../_filenameDate.mjs'
|
||||
|
||||
const { debug } = createLogger('xo:backups:PoolMetadataBackup')
|
||||
|
||||
export const PATH_DB_DUMP = '/pool/xmldbdump'
|
||||
|
||||
export class PoolMetadataBackup {
|
||||
@@ -31,7 +34,22 @@ export class PoolMetadataBackup {
|
||||
const poolDir = `${DIR_XO_POOL_METADATA_BACKUPS}/${schedule.id}/${pool.$id}`
|
||||
const dir = `${poolDir}/${formatFilenameDate(timestamp)}`
|
||||
|
||||
const tasks = Object.values(pool.$xapi.objects.indexes.type.task ?? {})
|
||||
const pendingTasks = tasks.filter(task => task.status === 'pending')
|
||||
debug('pool tasks before export', {
|
||||
total: tasks.length,
|
||||
pending: pendingTasks.length,
|
||||
oldestPendingCreated: pendingTasks.map(task => task.created).sort()[0],
|
||||
})
|
||||
|
||||
const stream = (await this._exportPoolMetadata()).body
|
||||
const startedAt = Date.now()
|
||||
let bytes = 0
|
||||
stream.once('data', () => debug('first byte received', { afterMs: Date.now() - startedAt }))
|
||||
stream.on('data', chunk => (bytes += chunk.length))
|
||||
stream.once('end', () => debug('stream ended', { bytes, durationMs: Date.now() - startedAt }))
|
||||
stream.once('error', error => debug('stream errored', { error, bytes, durationMs: Date.now() - startedAt }))
|
||||
|
||||
const fileName = `${dir}/data`
|
||||
|
||||
const metadata = JSON.stringify(
|
||||
|
||||
@@ -99,6 +99,7 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
|
||||
writer =>
|
||||
writer.transfer({
|
||||
deltaExport: forkDeltaExport(incrementalExport, writer.constructor.name),
|
||||
includeNonNbdQcow2Fix: metadata.includeNonNbdQcow2Fix,
|
||||
isVhdDifferencing,
|
||||
timestamp: metadata.timestamp,
|
||||
vm: metadata.vm,
|
||||
|
||||
@@ -73,6 +73,10 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
||||
writer =>
|
||||
writer.transfer({
|
||||
deltaExport: forkDeltaExport(deltaExport, writer.constructor.name),
|
||||
// freshly exported from XAPI by code that has the fix and the force-full gate
|
||||
// (writer.checkBaseVdis ran before this transfer), so the chain is verified/forced
|
||||
// clean; the tip's flag lets the next run skip re-probing
|
||||
includeNonNbdQcow2Fix: true,
|
||||
isVhdDifferencing,
|
||||
timestamp,
|
||||
vm,
|
||||
|
||||
@@ -22,7 +22,7 @@ export class AggregatedIncrementalRemoteWriter extends AbstractAggregatedRemoteW
|
||||
}
|
||||
// update the parameter with our best candidate
|
||||
// that can be an empty map
|
||||
baseUuidToSrcVdi.forEach(key => {
|
||||
baseUuidToSrcVdi.forEach((_, key) => {
|
||||
if (!selectedCopy.has(key)) {
|
||||
baseUuidToSrcVdi.delete(key)
|
||||
}
|
||||
@@ -50,8 +50,8 @@ export class AggregatedIncrementalRemoteWriter extends AbstractAggregatedRemoteW
|
||||
await Promise.all(this.writers.map(writer => writer.prepare({ isFull })))
|
||||
}
|
||||
// write only on the main writer
|
||||
transfer({ isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
|
||||
return this.mainWriter.transfer({ isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot })
|
||||
transfer(args) {
|
||||
return this.mainWriter.transfer(args)
|
||||
}
|
||||
|
||||
// remove the backups and remove the entries
|
||||
|
||||
@@ -25,7 +25,7 @@ export class AggregatedIncrementalXapiWriter extends AbstractAggregatedXapiWrite
|
||||
}
|
||||
// update the parameter with our best candidate
|
||||
// that can be an empty map
|
||||
baseUuidToSrcVdi.forEach(key => {
|
||||
baseUuidToSrcVdi.forEach((_, key) => {
|
||||
if (!selectedCopy.has(key)) {
|
||||
baseUuidToSrcVdi.delete(key)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
|
||||
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
|
||||
import { checkVhd } from './_checkVhd.mjs'
|
||||
import { packUuid } from './_packUuid.mjs'
|
||||
import { openDiskChain } from '@xen-orchestra/backup-archive/disks'
|
||||
import { VDI_FORMAT_QCOW2 } from '@xen-orchestra/xapi'
|
||||
import { diskHasData } from './_diskHasData.mjs'
|
||||
|
||||
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
|
||||
|
||||
@@ -61,12 +64,77 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
||||
if (parentDestPath === undefined) {
|
||||
baseUuidToSrcVdi.delete(baseUuid)
|
||||
} else {
|
||||
this.#parentVdiPaths[vhdDir] = parentDestPath
|
||||
this.#parentUuids[vhdDir] = parentUuid
|
||||
try {
|
||||
// A delta is only chained onto a qcow2 base when NBD is enabled; without NBD a qcow2
|
||||
// export falls back to a full, so there is no suspect base to worry about.
|
||||
if (this._settings.preferNbd && !(await this.#isBaseChainable(parentDestPath))) {
|
||||
Task.warning('forcing a full: qcow2 base predates the non-NBD qcow2 fix and looks corrupt', {
|
||||
parentDestPath,
|
||||
})
|
||||
baseUuidToSrcVdi.delete(baseUuid)
|
||||
return
|
||||
}
|
||||
this.#parentVdiPaths[vhdDir] = parentDestPath
|
||||
this.#parentUuids[vhdDir] = parentUuid
|
||||
} catch (error) {
|
||||
warn('checkBaseVdis: unexpected error, forcing a full', { error, parentDestPath })
|
||||
baseUuidToSrcVdi.delete(baseUuid)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Decide whether it is safe to chain a delta onto `parentDestPath` (the chain tip).
|
||||
// A qcow2 full exported before the DiskLargerBlock 20260724 fix can be silently corrupt (block 0
|
||||
// valid, following allocated blocks all zero); chaining a delta onto it would extend a
|
||||
// broken chain, so we detect that case and let the caller fall back to a full.
|
||||
async #isBaseChainable(parentDestPath) {
|
||||
// parentDestPath is the chain tip = most-recent backup; its filename is stable under
|
||||
// merges (merges rename the OLDER disks), so unlike the root it maps reliably to its
|
||||
// metadata json.
|
||||
const parentDate = basename(parentDestPath).replace(/\.(alias\.)?vhd$/, '')
|
||||
let metadata
|
||||
try {
|
||||
metadata = await this._adapter.readVmBackupMetadata(`${this._vmBackupDir}/${parentDate}.json`)
|
||||
} catch (error) {
|
||||
warn('checkBaseVdis: cannot read parent metadata, will probe', { error, parentDestPath })
|
||||
}
|
||||
if (metadata?.includeNonNbdQcow2Fix === true) {
|
||||
// written by code that has the fix and this gate, so its chain was already
|
||||
// verified/forced clean — no disk open needed
|
||||
// we can't have includeNonNbdQcow2Fix = false since it would have restarted a clean chain
|
||||
return true
|
||||
}
|
||||
const isQcow2 =
|
||||
metadata === undefined ||
|
||||
Object.values(metadata.vdis ?? {}).some(vdi => vdi?.sm_config?.['image-format'] === VDI_FORMAT_QCOW2)
|
||||
if (!isQcow2) {
|
||||
// only qcow2 exports can carry this corruption
|
||||
return true
|
||||
}
|
||||
return this.#baseHasData(parentDestPath)
|
||||
}
|
||||
|
||||
// Probe the first data blocks of the chain root for the DiskLargerBlock corruption
|
||||
// signature. Returns false only when enough allocated blocks past the first are all zero.
|
||||
async #baseHasData(parentDestPath) {
|
||||
const { handler } = this._adapter
|
||||
// open the chain (with block allocation tables) and probe its root full. This only runs
|
||||
// once per chain — afterwards the includeNonNbdQcow2Fix flag on the tip skips it — so
|
||||
// reading the deltas' BATs here is negligible and lets us reuse the root disk directly.
|
||||
const chain = await openDiskChain({ handler, path: parentDestPath })
|
||||
try {
|
||||
const root = chain.getRootDisk()
|
||||
if (root === undefined) {
|
||||
throw new Error(`can't resolve root of chain ${parentDestPath}`)
|
||||
}
|
||||
|
||||
return await diskHasData(root)
|
||||
} finally {
|
||||
await chain.close()
|
||||
}
|
||||
}
|
||||
|
||||
async beforeBackup() {
|
||||
await super.beforeBackup()
|
||||
return this._cleanVm({ merge: true, remove: true })
|
||||
@@ -139,7 +207,7 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
||||
}
|
||||
}
|
||||
|
||||
async _transfer($defer, { isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
|
||||
async _transfer($defer, { includeNonNbdQcow2Fix, isVhdDifferencing, timestamp, deltaExport, vm, vmSnapshot }) {
|
||||
const adapter = this._adapter
|
||||
const job = this._job
|
||||
const scheduleId = this._schedule.id
|
||||
@@ -168,6 +236,11 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
||||
}
|
||||
|
||||
metadataContent = {
|
||||
// marks whether the disk data is known-good w.r.t. the non-NBD qcow2 corruption bug.
|
||||
// A fresh XAPI export by fixed code passes `true`; the mirror runner propagates the
|
||||
// source backup's value (copying corrupt source data must NOT become "fixed"). Its
|
||||
// absence flags a potentially-corrupt older disk (used by cleanVm and the force-full gate).
|
||||
includeNonNbdQcow2Fix,
|
||||
isVhdDifferencing,
|
||||
jobId,
|
||||
mode: job.mode,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import assert from 'node:assert'
|
||||
import humanFormat from 'human-format'
|
||||
|
||||
import { asyncMapSettled } from '@xen-orchestra/async-map'
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
DATETIME,
|
||||
VM_UUID,
|
||||
CONTENT_KEY,
|
||||
INCLUDE_NON_NBD_QCOW2_FIX,
|
||||
resetVmOtherConfig,
|
||||
} from '../../_otherConfig.mjs'
|
||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||
@@ -27,8 +29,9 @@ import { XapiDiskSource } from '@xen-orchestra/xapi'
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { VM_POWER_STATE } from '@vates/types'
|
||||
import { diskHasData } from './_diskHasData.mjs'
|
||||
|
||||
const { debug } = createLogger('xo:backups:IncrementalXapiWriter')
|
||||
const { debug, warn } = createLogger('xo:backups:IncrementalXapiWriter')
|
||||
|
||||
export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWriter) {
|
||||
// Map of source VDI UUID (COPY_OF) → validated active VDI on the target SR.
|
||||
@@ -93,6 +96,45 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
||||
)
|
||||
}
|
||||
if (target !== undefined) {
|
||||
// A delta is only chained onto a qcow2 base when NBD is enabled; without NBD a qcow2
|
||||
// export falls back to a full, so there is no suspect base.
|
||||
if (this._settings.preferNbd) {
|
||||
// Every copy written by fixed code carries the flag, so the marker on the most recent
|
||||
// link is enough: if it is there, this chain was already verified (or re-based) by a
|
||||
// run that had the fix, and older links need no re-check.
|
||||
const suspect = target.other_config[INCLUDE_NON_NBD_QCOW2_FIX] !== 'true'
|
||||
if (suspect) {
|
||||
const chain = this.#diskReplicaSnapshots(target)
|
||||
// probe the OLDEST link (least-masked view of the corruption — a later delta could
|
||||
// have overwritten the corrupt blocks and hidden the damage on a more recent snapshot).
|
||||
// Re-replicating a full is expensive, so only force one when it actually looks corrupt.
|
||||
let base = target
|
||||
assert.notStrictEqual(base.other_config[DATETIME], undefined)
|
||||
for (const vdi of chain) {
|
||||
const datetime = vdi.other_config[DATETIME]
|
||||
assert.notStrictEqual(datetime, undefined)
|
||||
if (datetime < base.other_config[DATETIME]) {
|
||||
base = vdi
|
||||
}
|
||||
}
|
||||
let chainable
|
||||
try {
|
||||
chainable = await this.#baseVdiHasData(base.$ref)
|
||||
} catch (error) {
|
||||
// can't read the base to decide → don't chain onto it
|
||||
warn('checkBaseVdis: error probing replicated base, forcing a full', { error, baseVdi: base.uuid })
|
||||
chainable = false
|
||||
}
|
||||
if (!chainable) {
|
||||
Task.warning('forcing a full: replicated qcow2 chain predates the non-NBD qcow2 fix and looks corrupt', {
|
||||
baseVdi: base.uuid,
|
||||
})
|
||||
// drop it so neither the snapshot nor the legacy fallback reuses it → full
|
||||
baseUuidToSrcVdi.delete(baseUuid)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
snapshotCandidates.set(baseUuid, target)
|
||||
}
|
||||
}
|
||||
@@ -133,6 +175,42 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// All replica snapshots of a given disk share the same active target VDI ($snapshot_of). Return
|
||||
// them (same job+vm) so the caller can inspect the whole chain: any link missing the fix marker
|
||||
// makes the chain suspect, and the oldest link (by DATETIME) is the least-masked base to probe.
|
||||
// Scoped by $snapshot_of, so history before a CR VM recreation (which resets it) is not included.
|
||||
#diskReplicaSnapshots(target) {
|
||||
const activeUuid = target.$snapshot_of?.uuid
|
||||
const snapshots = []
|
||||
for (const vdi of this._sr.$VDIs) {
|
||||
if (
|
||||
vdi?.managed &&
|
||||
vdi?.is_a_snapshot &&
|
||||
vdi.$snapshot_of?.uuid === activeUuid &&
|
||||
vdi.other_config[JOB_ID] === this._job.id &&
|
||||
vdi.other_config[VM_UUID] === this._vmUuid
|
||||
) {
|
||||
snapshots.push(vdi)
|
||||
}
|
||||
}
|
||||
return snapshots
|
||||
}
|
||||
|
||||
// Probe a replicated base VDI for the DiskLargerBlock corruption signature (block 0 valid,
|
||||
// following allocated blocks all zero). Uses an export (not NBD): block flow is guaranteed
|
||||
// to be in index order, so block 0 comes first and inspecting the first few blocks is enough.
|
||||
// Returns false only when no allocated non-zero block is found among the first ones.
|
||||
async #baseVdiHasData(vdiRef) {
|
||||
const source = new XapiDiskSource({ xapi: this._sr.$xapi, vdiRef, preferNbd: false })
|
||||
try {
|
||||
await source.init()
|
||||
return await diskHasData(source)
|
||||
} finally {
|
||||
await source.close()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 6.3+ snapshot-based validation: for each snapshot candidate, check whether
|
||||
* the active VDI has diverged from the snapshot. Returns a baseVdisBySourceUuid
|
||||
@@ -340,6 +418,10 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
||||
if (baseDeltaVdiUuid !== undefined) {
|
||||
// reuse the validated mapping built by checkBaseVdis
|
||||
vdi.baseVdi = this.#baseVdisBySourceUuid.get(baseDeltaVdiUuid)
|
||||
// BASE_DELTA_VDI is set, so the export is differencing. Without a base to clone,
|
||||
// importIncrementalVm would create a blank VDI and write only the changed blocks
|
||||
// into it, silently producing a corrupt replica: fail the job instead.
|
||||
assert.notStrictEqual(vdi.baseVdi, undefined, `no validated target base for ${baseDeltaVdiUuid}`)
|
||||
} else {
|
||||
// first replication of this disk (full, no base)
|
||||
vdi.baseVdi = undefined
|
||||
|
||||
@@ -16,8 +16,6 @@ export class AbstractIncrementalWriter extends AbstractWriter {
|
||||
async transfer({ deltaExport, ...other }) {
|
||||
try {
|
||||
return await this._transfer({ deltaExport, ...other })
|
||||
} catch (err) {
|
||||
console.error({ err })
|
||||
} finally {
|
||||
// ensure all sources are properly closed
|
||||
for (const disk of Object.values(deltaExport.disks)) {
|
||||
|
||||
26
@xen-orchestra/backups/_runners/_writers/_diskHasData.mjs
Normal file
26
@xen-orchestra/backups/_runners/_writers/_diskHasData.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
// Probe a disk for the DiskLargerBlock corruption signature (block 0 valid,
|
||||
// following allocated blocks all zero). Uses an export (not NBD): block flow is guaranteed
|
||||
// to be in index order, so block 0 comes first and inspecting the first few blocks is enough.
|
||||
|
||||
// Returns false only when no allocated non-zero block is found among the first ones.
|
||||
export async function diskHasData(source) {
|
||||
const empty = Buffer.alloc(source.getBlockSize(), 0)
|
||||
const MAX_EMPTY = 10
|
||||
let nbEmpty = 0
|
||||
// diskBlocks() closes the source when the iteration ends or is broken out of
|
||||
for await (const { index, data } of source.diskBlocks()) {
|
||||
if (index === 0) {
|
||||
// block 0 stays valid even in the corruption signature — skip it
|
||||
continue
|
||||
}
|
||||
if (!data.equals(empty)) {
|
||||
// an allocated block holds real data → not corrupt
|
||||
return true
|
||||
}
|
||||
if (++nbEmpty >= MAX_EMPTY) {
|
||||
break
|
||||
}
|
||||
}
|
||||
// no allocated non-zero block among the first ones → looks corrupt (or empty; a full is cheap then)
|
||||
return false
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"version": "0.73.7",
|
||||
"version": "0.73.10",
|
||||
"engines": {
|
||||
"node": ">=14.18"
|
||||
},
|
||||
@@ -27,17 +27,17 @@
|
||||
"@vates/disposable": "^0.1.6",
|
||||
"@vates/fuse-vhd": "^2.1.3",
|
||||
"@vates/generator-toolbox": "^1.1.3",
|
||||
"@vates/nbd-client": "^3.4.0",
|
||||
"@vates/nbd-client": "^3.5.0",
|
||||
"@vates/parse-duration": "^0.1.1",
|
||||
"@vates/task": "^0.7.0",
|
||||
"@vates/types": "^1.28.0",
|
||||
"@vates/types": "^1.30.1",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/disk-transform": "^1.3.1",
|
||||
"@xen-orchestra/fs": "^4.9.2",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"@xen-orchestra/qcow2": "^1.3.1",
|
||||
"@xen-orchestra/template": "^0.1.1",
|
||||
"@xen-orchestra/backup-archive": "^1.0.4",
|
||||
"@xen-orchestra/backup-archive": "^1.1.1",
|
||||
"app-conf": "^3.0.0",
|
||||
"compare-versions": "^6.0.0",
|
||||
"d3-time-format": "^4.1.0",
|
||||
@@ -55,8 +55,8 @@
|
||||
"tar": "^7.5.3",
|
||||
"uuid": "^9.0.0",
|
||||
"value-matcher": "^0.2.0",
|
||||
"vhd-lib": "^4.16.0",
|
||||
"xen-api": "^4.7.8",
|
||||
"vhd-lib": "^4.16.1",
|
||||
"xen-api": "^4.8.0",
|
||||
"yazl": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -67,7 +67,7 @@
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@xen-orchestra/xapi": "^8.9.0"
|
||||
"@xen-orchestra/xapi": "^8.10.2"
|
||||
},
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"author": {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"golike-defer": "^0.5.1",
|
||||
"xen-api": "^4.7.8"
|
||||
"xen-api": "^4.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@xen-orchestra/disk-cli",
|
||||
"version": "2.1.2",
|
||||
"version": "2.2.0",
|
||||
"description": "CLI tool to inspect and manage disks in backup repositories",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
@@ -20,13 +20,13 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/backups": "^0.73.7",
|
||||
"@xen-orchestra/backup-archive": "^1.0.4",
|
||||
"@xen-orchestra/disk-transform": "^1.3.1",
|
||||
"@xen-orchestra/fs": "^4.9.2",
|
||||
"@xen-orchestra/backups": "^0.73.10",
|
||||
"@xen-orchestra/backup-archive": "^1.1.1",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"@xen-orchestra/qcow2": "^1.3.1",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"vhd-lib": "^4.16.0"
|
||||
"vhd-lib": "^4.16.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.3.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xen-orchestra/disk-transform",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.3",
|
||||
"main": "./dist/index.mjs",
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
|
||||
@@ -31,11 +31,15 @@ export class DiskLargerBlock extends RandomAccessDisk {
|
||||
throw new Error('Method not implemented.')
|
||||
}
|
||||
async readBlock(index: number): Promise<DiskBlock> {
|
||||
if (!this.hasBlock(index)) {
|
||||
throw new Error(`Block ${index} not present in this disk`)
|
||||
}
|
||||
// @todo handle partial block at the end
|
||||
const source = this.source
|
||||
const destinationBlock = Buffer.alloc(this.getBlockSize(), 0)
|
||||
const destinationBlockData = Buffer.alloc(this.getBlockSize(), 0)
|
||||
const blockRatio = this.#blockSize / source.getBlockSize()
|
||||
for (let i = index * blockRatio; i < (index + 1) * blockRatio; i++) {
|
||||
const firstSourceBlockIndex = index * blockRatio
|
||||
for (let i = firstSourceBlockIndex; i < firstSourceBlockIndex + blockRatio; i++) {
|
||||
let data: Buffer | undefined
|
||||
if (source.hasBlock(i)) {
|
||||
data = (await source.readBlock(i)).data
|
||||
@@ -51,12 +55,12 @@ export class DiskLargerBlock extends RandomAccessDisk {
|
||||
}
|
||||
}
|
||||
if (data !== undefined) {
|
||||
data.copy(destinationBlock, i * source.getBlockSize())
|
||||
data.copy(destinationBlockData, (i - firstSourceBlockIndex) * source.getBlockSize())
|
||||
}
|
||||
}
|
||||
return {
|
||||
index,
|
||||
data: destinationBlock,
|
||||
data: destinationBlockData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,22 +70,24 @@ export class DiskLargerBlock extends RandomAccessDisk {
|
||||
|
||||
getBlockIndexes(): Array<number> {
|
||||
const maxBlock = Math.ceil(this.getVirtualSize() / this.getBlockSize())
|
||||
const blockRatio = this.getBlockSize() / this.source.getBlockSize()
|
||||
const indexes = []
|
||||
for (let i = 0; i < maxBlock; i++) {
|
||||
for (let j = 0; j < blockRatio; j++) {
|
||||
if (this.source.hasBlock(i * blockRatio + j)) {
|
||||
indexes.push(i)
|
||||
break
|
||||
}
|
||||
if (this.hasBlock(i)) {
|
||||
indexes.push(i)
|
||||
}
|
||||
}
|
||||
return indexes
|
||||
}
|
||||
|
||||
getBlockIndexesCount(): number {
|
||||
let blockRatio = this.getBlockSize() / this.source.getBlockSize()
|
||||
return this.#source.getBlockIndexesCount() / blockRatio
|
||||
let count = 0
|
||||
const maxBlock = Math.ceil(this.getVirtualSize() / this.getBlockSize())
|
||||
for (let i = 0; i < maxBlock; i++) {
|
||||
if (this.hasBlock(i)) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
hasBlock(index: number): boolean {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import assert from 'node:assert'
|
||||
import assert, { strictEqual } from 'node:assert'
|
||||
import { test } from 'node:test'
|
||||
import { DiskLargerBlock } from './DiskLargerBlock.mjs'
|
||||
import { RandomAccessDisk, DiskBlock, Disk } from './Disk.mjs'
|
||||
@@ -45,7 +45,7 @@ class MockDisk extends RandomAccessDisk {
|
||||
this.closed = true
|
||||
}
|
||||
isDifferencing(): boolean {
|
||||
return this.isDiff
|
||||
return this.parentDisk !== null || this.isDiff
|
||||
}
|
||||
instantiateParent(): RandomAccessDisk {
|
||||
if (!this.parentDisk) throw new Error('No parent disk available')
|
||||
@@ -118,6 +118,29 @@ test('readBlock with simple block mapping', async () => {
|
||||
assert(result.data.subarray(512).equals(block2))
|
||||
})
|
||||
|
||||
test('readBlock at index > 0 places source data at block-relative offsets', async () => {
|
||||
// Regression test: a large block after index 0 must be assembled from its own
|
||||
// source blocks at offsets relative to the start of that large block.
|
||||
// With distinct, non-zero patterns this catches the case where copy() targets an
|
||||
// absolute (disk-wide) offset and silently produces a zeroed block.
|
||||
const blockC = createPatternBuffer(512, 'C')
|
||||
const blockD = createPatternBuffer(512, 'D')
|
||||
const source = new MockDisk(512, 4096, [
|
||||
[2, blockC],
|
||||
[3, blockD],
|
||||
])
|
||||
await source.init()
|
||||
|
||||
const disk = new DiskLargerBlock(source, 1024) // blockRatio = 2, so large block 1 = source blocks 2 & 3
|
||||
await disk.init()
|
||||
|
||||
const result = await disk.readBlock(1)
|
||||
assert.strictEqual(result.index, 1)
|
||||
assert.strictEqual(result.data.length, 1024)
|
||||
assert(result.data.subarray(0, 512).equals(blockC))
|
||||
assert(result.data.subarray(512).equals(blockD))
|
||||
})
|
||||
|
||||
test('hasBlock behavior', async () => {
|
||||
const source = new MockDisk(512, 2048, [
|
||||
[0, Buffer.alloc(512)],
|
||||
@@ -214,6 +237,34 @@ test('close propagation', async () => {
|
||||
await disk.close()
|
||||
assert.strictEqual(source.closed, true)
|
||||
})
|
||||
test('getBlockIndexesCount', async () => {
|
||||
const block = createPatternBuffer(512, 'BLOCK')
|
||||
let source = new MockDisk(512, 4096, [
|
||||
[2, block],
|
||||
[3, block],
|
||||
])
|
||||
await source.init()
|
||||
|
||||
let disk = new DiskLargerBlock(source, 1024)
|
||||
await disk.init()
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), 1)
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
|
||||
|
||||
await disk.close()
|
||||
|
||||
source = new MockDisk(512, 4096, [
|
||||
[0, block],
|
||||
[3, block],
|
||||
])
|
||||
await source.init()
|
||||
|
||||
disk = new DiskLargerBlock(source, 1024)
|
||||
await disk.init()
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), 2)
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), disk.getBlockIndexes().length)
|
||||
|
||||
await disk.close()
|
||||
})
|
||||
|
||||
test('generator', async () => {
|
||||
const source = new MockDisk(512, 1024)
|
||||
@@ -225,3 +276,29 @@ test('generator', async () => {
|
||||
assert.strictEqual(block.data.length, 1024)
|
||||
}
|
||||
})
|
||||
|
||||
test('readblock missing block throws', async () => {
|
||||
const parentBlock = createPatternBuffer(512, 'PARENT')
|
||||
const childBlock = createPatternBuffer(512, 'CHILD')
|
||||
const sourceParent = new MockDisk(512, 2048, [
|
||||
[0, parentBlock],
|
||||
[1, parentBlock],
|
||||
[2, parentBlock],
|
||||
[3, parentBlock],
|
||||
])
|
||||
await sourceParent.init()
|
||||
const source = new MockDisk(512, 2048, [[2, childBlock]])
|
||||
source.parentDisk = sourceParent
|
||||
await source.init()
|
||||
|
||||
const disk = new DiskLargerBlock(source, 1024)
|
||||
await disk.init()
|
||||
assert.strictEqual(disk.getBlockIndexesCount(), 1)
|
||||
for await (const block of disk.diskBlocks()) {
|
||||
assert.strictEqual(block.index, 1)
|
||||
assert.ok(block.data.slice(0, 512).equals(childBlock), 'missing child data ')
|
||||
assert.ok(block.data.slice(512, 1024).equals(parentBlock), 'missing parent data')
|
||||
}
|
||||
|
||||
await assert.rejects(() => disk.readBlock(0))
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@xen-orchestra/fs",
|
||||
"version": "4.9.2",
|
||||
"version": "4.9.3",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"description": "The File System for Xen Orchestra backups.",
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/fs",
|
||||
|
||||
@@ -441,7 +441,11 @@ export default class S3Handler extends RemoteHandlerAbstract {
|
||||
new DeleteObjectsCommand({
|
||||
Bucket: this.#bucket,
|
||||
Delete: {
|
||||
Objects: result.Contents ?? [],
|
||||
// only keep the key: `ETag` and `Size` are also part of `ObjectIdentifier`, where they
|
||||
// mean "delete only if it still matches", and passing the whole listed object would
|
||||
// serialize them in the request. Beyond making the deletion conditional, some
|
||||
// providers reject these elements with a `MalformedXML` error.
|
||||
Objects: (result.Contents ?? []).map(({ Key }) => ({ Key })),
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
@@ -38,8 +38,7 @@ immutabilityDuration = "7d"
|
||||
|
||||
## CLI commands
|
||||
|
||||
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably.
|
||||
- **`xo-lift-remote-immutability`**: Manually trigger a lifting pass. If `liftEvery` is set in the config, the process continues running and repeats the check on that interval.
|
||||
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably. It lifts expired immutability on startup, then every `liftEvery`.
|
||||
|
||||
## How protection works
|
||||
|
||||
@@ -86,6 +85,8 @@ The expiry reference is the **datetime in the filename**, not the file's `mtime`
|
||||
|
||||
On the **first lift run after startup**, all backup files are scanned unconditionally (full scan). This catches orphaned immutable files left by a previous partial or interrupted lock. Subsequent runs use a fast-path: only backups whose `.json` sentinel is currently immutable are processed.
|
||||
|
||||
The first run also walks the disk directories (`xo-vm-backups/<vmUUID>/vdis/<jobId>/<vdiId>/`) directly and lifts any expired disk found there, still using the datetime in its own filename. Both the locking and the regular lifting name a backup's disks from its `<datetime>.json`, so a disk stops being reachable that way once XO's retention has deleted that json — or once a merge has renamed the disk, since the surviving `data/<datetime>.vhd` then carries the datetime of the older backup its blocks came from. Such a disk would otherwise stay immutable forever, and an immutable disk prevents XO from ever merging or deleting the backups of that VDI.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Some files are still immutable after the duration expired
|
||||
@@ -113,8 +114,10 @@ If one or a few VM had an issue and need manual cleanup, you can manually lift t
|
||||
4. As root on the file server, run:
|
||||
```bash
|
||||
chattr +i /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/*.json
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/*.vhd
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/data/*.vhd
|
||||
```
|
||||
Lock the disks, **not** the directories that hold them: `chattr +i -R …/vdis/` also locks `vdis`, the job and VDI directories and `data`, and an immutable directory rejects the files of the next backup, so every later run of that VM would fail. Depending on whether the remote uses VHD directories, one of the two commands above may report that it matched nothing.
|
||||
|
||||
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after.
|
||||
|
||||
@@ -124,7 +127,7 @@ Change the setting. The next lift cycle will use the new duration; files already
|
||||
|
||||
### Reducing the immutability duration
|
||||
|
||||
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
|
||||
Change the setting, then restart `xo-immutable-remote` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
|
||||
|
||||
### Why are my incremental backups not marked as protected in XO?
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ immutabilityDuration = "7d"
|
||||
|
||||
## CLI commands
|
||||
|
||||
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably.
|
||||
- **`xo-lift-remote-immutability`**: Manually trigger a lifting pass. If `liftEvery` is set in the config, the process continues running and repeats the check on that interval.
|
||||
- **`xo-immutable-remote`**: Start the watching daemon. Must be kept running to protect new backups reliably. It lifts expired immutability on startup, then every `liftEvery`.
|
||||
|
||||
## How protection works
|
||||
|
||||
@@ -102,6 +101,8 @@ The expiry reference is the **datetime in the filename**, not the file's `mtime`
|
||||
|
||||
On the **first lift run after startup**, all backup files are scanned unconditionally (full scan). This catches orphaned immutable files left by a previous partial or interrupted lock. Subsequent runs use a fast-path: only backups whose `.json` sentinel is currently immutable are processed.
|
||||
|
||||
The first run also walks the disk directories (`xo-vm-backups/<vmUUID>/vdis/<jobId>/<vdiId>/`) directly and lifts any expired disk found there, still using the datetime in its own filename. Both the locking and the regular lifting name a backup's disks from its `<datetime>.json`, so a disk stops being reachable that way once XO's retention has deleted that json — or once a merge has renamed the disk, since the surviving `data/<datetime>.vhd` then carries the datetime of the older backup its blocks came from. Such a disk would otherwise stay immutable forever, and an immutable disk prevents XO from ever merging or deleting the backups of that VDI.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Some files are still immutable after the duration expired
|
||||
@@ -116,7 +117,7 @@ Restart `xo-immutable-remote`. The first lift run after startup always performs
|
||||
chattr -i -R /path/to/remote/on/fileserver/
|
||||
```
|
||||
|
||||
### Make one VM mutable again temporarly
|
||||
### Make one VM temporarily mutable again
|
||||
|
||||
If one or a few VM had an issue and need manual cleanup, you can manually lift the immutability for one VM.
|
||||
|
||||
@@ -125,14 +126,16 @@ If one or a few VM had an issue and need manual cleanup, you can manually lift t
|
||||
```bash
|
||||
chattr -i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>
|
||||
```
|
||||
3. run the backup job, it will fix what is reparable and purge the non recoverable backups
|
||||
3. Run the backup job, it will fix what is repairable and purge the non recoverable backups
|
||||
4. As root on the file server, run:
|
||||
```bash
|
||||
chattr +i /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/*.json
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/*.vhd
|
||||
chattr +i -R /path/to/remote/on/fileserver/xo-vm-backups/<vm uuid>/vdis/*/*/data/*.vhd
|
||||
```
|
||||
Lock the disks, **not** the directories that hold them: `chattr +i -R …/vdis/` also locks `vdis`, the job and VDI directories and `data`, and an immutable directory rejects the files of the next backup, so every later run of that VM would fail. Depending on whether the remote uses VHD directories, one of the two commands above may report that it matched nothing.
|
||||
|
||||
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after
|
||||
Note that this VM will be mutable between step 2 and 4, it's up to you to document and test the backup after.
|
||||
|
||||
### Increasing the immutability duration
|
||||
|
||||
@@ -140,7 +143,7 @@ Change the setting. The next lift cycle will use the new duration; files already
|
||||
|
||||
### Reducing the immutability duration
|
||||
|
||||
Change the setting, then run `xo-lift-remote-immutability` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
|
||||
Change the setting, then restart `xo-immutable-remote` to apply immediately, or wait for the next scheduled `liftEvery` cycle.
|
||||
|
||||
### Why are my incremental backups not marked as protected in XO?
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
"xo-immutable-remote": "./dist/protectRemotes.mjs"
|
||||
},
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/backups": "^0.73.7",
|
||||
"@xen-orchestra/backups": "^0.73.10",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"app-conf": "^3.0.0",
|
||||
"execa": "^5.0.0",
|
||||
|
||||
@@ -8,17 +8,18 @@ export async function makeImmutable(dirPath: string): Promise<void> {
|
||||
// chattr processes all paths even when some are missing (it does not abort on the first
|
||||
// error), so every existing path is correctly lifted.
|
||||
//
|
||||
// Per-path "while trying to stat" messages (ENOENT) are silently ignored regardless of
|
||||
// locale — these are always expected for optional paths (.xva, .alias.vhd, …) that are
|
||||
// absent in delta backups. chattr localises the error description but "while trying to
|
||||
// stat" is always emitted in English, so we match on that suffix only.
|
||||
// Per-path "while trying to stat" messages (ENOENT) are silently ignored — these are always
|
||||
// expected for optional paths (.xva, .alias.vhd, …) that are absent in delta backups. chattr
|
||||
// translates that whole message, so it is run under `LC_ALL=C`: without it, every batch
|
||||
// containing an optional missing path fails on a localised system, which means no backup ever
|
||||
// gets locked there.
|
||||
//
|
||||
// Any other error (e.g. EAGAIN on NFS when the file is still open, permission denied) is
|
||||
// retried up to 3 times with a 1 s delay before being re-thrown.
|
||||
async function execChattrWithMissingFiles(args: string[]): Promise<void> {
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
try {
|
||||
await execa('chattr', args)
|
||||
await execa('chattr', args, { env: { LC_ALL: 'C' } })
|
||||
return
|
||||
} catch (err) {
|
||||
const stderr = (err as ExecaError).stderr ?? ''
|
||||
|
||||
177
@xen-orchestra/immutable-backups/src/liftProtection.integ.mts
Normal file
177
@xen-orchestra/immutable-backups/src/liftProtection.integ.mts
Normal file
@@ -0,0 +1,177 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { rimraf } from 'rimraf'
|
||||
import execa from 'execa'
|
||||
|
||||
import * as Directory from './directory.mjs'
|
||||
import { liftRemoteImmutability } from './liftProtection.mjs'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const ONE_DAY_MS = 24 * 60 * 60 * 1000
|
||||
|
||||
const VM_UUID = 'aaaaaaaa-0000-0000-0000-000000000001'
|
||||
const JOB_UUID = 'bbbbbbbb-0000-0000-0000-000000000001'
|
||||
const VDI_UUID = 'cccccccc-0000-0000-0000-000000000001'
|
||||
|
||||
/** Well past any reasonable immutabilityDuration. */
|
||||
const EXPIRED_DATE = '20240115T120000Z'
|
||||
/** Inside the window: the expiry reference is the datetime in the name, not the file's dates. */
|
||||
const RECENT_DATE = new Date().toISOString().replace(/[-:.]/g, '').slice(0, 15) + 'Z'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Recursively lift all immutable flags inside `root`, then delete the tree.
|
||||
// Must be run as root since chattr requires elevated privileges.
|
||||
async function cleanupRoot(root: string): Promise<void> {
|
||||
try {
|
||||
await execa('chattr', ['-i', '-R', root])
|
||||
} catch (_err) {}
|
||||
await rimraf(root)
|
||||
}
|
||||
|
||||
async function makeRoot(): Promise<string> {
|
||||
return await fs.mkdtemp(path.join(tmpdir(), 'immut-lift-test-'))
|
||||
}
|
||||
|
||||
function vmDirOf(root: string): string {
|
||||
return path.join(root, 'xo-vm-backups', VM_UUID)
|
||||
}
|
||||
|
||||
function vdiDirOf(root: string): string {
|
||||
return path.join(vmDirOf(root), 'vdis', JOB_UUID, VDI_UUID)
|
||||
}
|
||||
|
||||
// Creates `vdis/<jobId>/<vdiId>/<datetime>.alias.vhd` plus the VHD directory it points at, the way
|
||||
// XO lays them out, and returns both paths along with one block file inside the VHD directory.
|
||||
async function writeDisk(root: string, datetime: string) {
|
||||
const vdiDir = vdiDirOf(root)
|
||||
const dataDir = path.join(vdiDir, 'data')
|
||||
const vhdDir = path.join(dataDir, `${datetime}.vhd`)
|
||||
const blockFile = path.join(vhdDir, 'blocks', '0', '0')
|
||||
|
||||
await fs.mkdir(path.dirname(blockFile), { recursive: true })
|
||||
await fs.writeFile(blockFile, 'block')
|
||||
await fs.writeFile(path.join(vhdDir, 'footer'), 'footer')
|
||||
|
||||
const alias = path.join(vdiDir, `${datetime}.alias.vhd`)
|
||||
await fs.writeFile(alias, path.relative(vdiDir, vhdDir))
|
||||
|
||||
return { alias, vhdDir, blockFile }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('liftProtection/liftRemoteImmutability', async () => {
|
||||
it('lifts expired disks that no metadata json names any more', async () => {
|
||||
const root = await makeRoot()
|
||||
try {
|
||||
// Retention deletes the json first and leaves the disks to the next cleanVm, so nothing names
|
||||
// them: this is the state the sentinel-driven pass cannot reach.
|
||||
const { alias, vhdDir, blockFile } = await writeDisk(root, EXPIRED_DATE)
|
||||
await Directory.makeImmutableBatch([alias, vhdDir])
|
||||
|
||||
assert.strictEqual(await Directory.isImmutable(alias), true, 'alias should start immutable')
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'VHD directory should start immutable')
|
||||
|
||||
await liftRemoteImmutability(root, ONE_DAY_MS, true)
|
||||
|
||||
assert.strictEqual(await Directory.isImmutable(alias), false, 'alias should be lifted')
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'VHD directory should be lifted')
|
||||
// A VHD directory is useless to XO unless its blocks are writable too: the merge moves block
|
||||
// files out of it.
|
||||
assert.strictEqual(await Directory.isImmutable(blockFile), false, 'blocks should be lifted too')
|
||||
|
||||
// and the files are really usable again
|
||||
await fs.unlink(blockFile)
|
||||
await fs.unlink(alias)
|
||||
} finally {
|
||||
await cleanupRoot(root)
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps disks inside the immutability window locked', async () => {
|
||||
const root = await makeRoot()
|
||||
try {
|
||||
const { alias, vhdDir, blockFile } = await writeDisk(root, RECENT_DATE)
|
||||
await Directory.makeImmutableBatch([alias, vhdDir])
|
||||
|
||||
await liftRemoteImmutability(root, ONE_DAY_MS, true)
|
||||
|
||||
assert.strictEqual(await Directory.isImmutable(alias), true, 'recent alias must stay immutable')
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'recent VHD directory must stay immutable')
|
||||
assert.strictEqual(await Directory.isImmutable(blockFile), true, 'recent blocks must stay immutable')
|
||||
|
||||
await assert.rejects(fs.unlink(alias), { code: 'EPERM' })
|
||||
} finally {
|
||||
await cleanupRoot(root)
|
||||
}
|
||||
})
|
||||
|
||||
it('does not sweep the disk directories outside of a full scan', async () => {
|
||||
const root = await makeRoot()
|
||||
try {
|
||||
const { alias, vhdDir } = await writeDisk(root, EXPIRED_DATE)
|
||||
await Directory.makeImmutableBatch([alias, vhdDir])
|
||||
|
||||
await liftRemoteImmutability(root, ONE_DAY_MS, false)
|
||||
|
||||
assert.strictEqual(await Directory.isImmutable(alias), true, 'alias should be untouched')
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), true, 'VHD directory should be untouched')
|
||||
} finally {
|
||||
await cleanupRoot(root)
|
||||
}
|
||||
})
|
||||
|
||||
it('lifts a disk whose name does not match the datetime of the backup referencing it', async () => {
|
||||
const root = await makeRoot()
|
||||
try {
|
||||
// Shape left by a merge: the alias of the recent backup points at the VHD directory of the
|
||||
// older one, whose blocks it now holds.
|
||||
const { vhdDir, blockFile } = await writeDisk(root, EXPIRED_DATE)
|
||||
const alias = path.join(vdiDirOf(root), `${RECENT_DATE}.alias.vhd`)
|
||||
await fs.writeFile(alias, path.relative(vdiDirOf(root), vhdDir))
|
||||
await fs.unlink(path.join(vdiDirOf(root), `${EXPIRED_DATE}.alias.vhd`))
|
||||
await Directory.makeImmutableBatch([alias, vhdDir])
|
||||
|
||||
await liftRemoteImmutability(root, ONE_DAY_MS, true)
|
||||
|
||||
// The VHD directory carries an expired datetime, so it is released and stays mergeable — the
|
||||
// reason mtime cannot be the reference: every merge would push it forward and it would never
|
||||
// expire.
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'merged VHD directory should be lifted')
|
||||
assert.strictEqual(await Directory.isImmutable(blockFile), false, 'its blocks should be lifted')
|
||||
assert.strictEqual(await Directory.isImmutable(alias), true, 'the recent alias keeps its lock')
|
||||
} finally {
|
||||
await cleanupRoot(root)
|
||||
}
|
||||
})
|
||||
|
||||
it('still lifts through the metadata json when it is present', async () => {
|
||||
const root = await makeRoot()
|
||||
try {
|
||||
const { alias, vhdDir } = await writeDisk(root, EXPIRED_DATE)
|
||||
const json = path.join(vmDirOf(root), `${EXPIRED_DATE}.json`)
|
||||
await fs.writeFile(json, '{}')
|
||||
await Directory.makeImmutableBatch([json, alias, vhdDir])
|
||||
|
||||
// not a full scan: the fast path applies, and the json is immutable so it is picked up
|
||||
await liftRemoteImmutability(root, ONE_DAY_MS, false)
|
||||
|
||||
assert.strictEqual(await Directory.isImmutable(json), false, 'json should be lifted')
|
||||
assert.strictEqual(await Directory.isImmutable(alias), false, 'alias should be lifted')
|
||||
assert.strictEqual(await Directory.isImmutable(vhdDir), false, 'VHD directory should be lifted')
|
||||
} finally {
|
||||
await cleanupRoot(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -118,6 +118,68 @@ async function liftExpiredVmBackups(root: string, immutabilityDuration: number,
|
||||
})
|
||||
}
|
||||
|
||||
// `liftExpiredVmBackups` names the files of a backup from the datetime of its `<datetime>.json`,
|
||||
// like the watcher does when locking them. A disk can outlive that name:
|
||||
//
|
||||
// - retention deletes the metadata json first and leaves the disks to the next `cleanVm`, so
|
||||
// nothing names them any more;
|
||||
// - a merge renames a disk, and the surviving `data/<datetime>.vhd` keeps the name of the older
|
||||
// backup its blocks came from.
|
||||
//
|
||||
// Such a disk would stay immutable forever — a full scan does not help, it only bypasses the
|
||||
// `isImmutable` fast-path — and an immutable disk blocks every future merge and deletion in its VDI
|
||||
// directory. So walk the VDI directories themselves and lift what is expired, using the datetime in
|
||||
// each entry's own name, which is the reference the other passes use too.
|
||||
//
|
||||
// Only runs on the first pass after startup: it recovers states that should not happen, and looking
|
||||
// hourly would not make it more effective.
|
||||
async function liftExpiredOrphanDisks(root: string, immutabilityDuration: number): Promise<void> {
|
||||
const threshold = Date.now() - immutabilityDuration
|
||||
const vmDirs = await listDirs(join(root, 'xo-vm-backups'))
|
||||
debug('scanning VDI directories for expired disks', { count: vmDirs.length })
|
||||
await asyncEach(vmDirs, async vmDir => {
|
||||
// disks live under `vdis/<jobId>/<vdiId>/`, so two levels of directories to walk first
|
||||
const jobDirs = await listDirs(join(vmDir, 'vdis'))
|
||||
const vdiDirs = (await Promise.all(jobDirs.map(jobDir => listDirs(jobDir)))).flat()
|
||||
|
||||
await asyncEach(vdiDirs, async vdiDir => {
|
||||
try {
|
||||
// `<datetime>.vhd` (flat VHD or alias) and `<datetime>.alias.vhd`
|
||||
const entries = await fsp.readdir(vdiDir, { withFileTypes: true })
|
||||
const candidates = entries.map(entry => join(vdiDir, entry.name))
|
||||
|
||||
// `data/<datetime>.vhd` VHD directories. They are locked recursively, but the attribute is
|
||||
// set on the directory itself too, so its own entry is enough to decide — no need to look
|
||||
// at the blocks inside.
|
||||
if (entries.some(entry => entry.name === 'data' && entry.isDirectory())) {
|
||||
const dataDir = join(vdiDir, 'data')
|
||||
candidates.push(...(await fsp.readdir(dataDir)).map(name => join(dataDir, name)))
|
||||
}
|
||||
|
||||
const expired: string[] = []
|
||||
for (const path of candidates) {
|
||||
// Entries without a datetime — `data` itself, merge state files — are left alone: there
|
||||
// is nothing to compare them to.
|
||||
const datetime = extractDatetime(basename(path))
|
||||
if (datetime === undefined) continue
|
||||
const backupTimestamp = parseDatetime(datetime)
|
||||
if (backupTimestamp === undefined || backupTimestamp > threshold) continue
|
||||
expired.push(path)
|
||||
}
|
||||
|
||||
if (expired.length === 0) return
|
||||
debug('lifting expired disks', { vdiDir, count: expired.length })
|
||||
// Recursive: a VHD directory must be released together with its blocks, and `-R` is a no-op
|
||||
// on the flat VHDs and aliases sharing the batch.
|
||||
await Directory.liftImmutabilityBatch(expired)
|
||||
} catch (err) {
|
||||
// `cleanVm` may be merging or deleting these files at the same time
|
||||
if (err.code !== 'ENOENT') warn('error lifting expired disks', { err, vdiDir })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Walk `xo-config-backups/<scheduleId>/<datetime>/metadata.json` files and
|
||||
// lift immutability on any backup directory whose metadata mtime is expired.
|
||||
async function liftExpiredConfigBackups(root: string, immutabilityDuration: number, fullScan: boolean): Promise<void> {
|
||||
@@ -180,6 +242,12 @@ export async function liftRemoteImmutability(
|
||||
liftExpiredConfigBackups(root, immutabilityDuration, fullScan),
|
||||
liftExpiredPoolBackups(root, immutabilityDuration, fullScan),
|
||||
])
|
||||
|
||||
// after the passes above: every disk still named by a metadata json has been handled, so this one
|
||||
// only has the leftovers to look at
|
||||
if (fullScan) {
|
||||
await liftExpiredOrphanDisks(root, immutabilityDuration)
|
||||
}
|
||||
}
|
||||
|
||||
// Lift immutability on all expired backups across every configured remote.
|
||||
|
||||
@@ -13,6 +13,7 @@ for (const [remoteId, remote] of Object.entries(remotes)) {
|
||||
}
|
||||
|
||||
info('setup watcher for immutability lifting')
|
||||
await liftImmutability(remotes).catch(error => warn('error while lifting immutability', error))
|
||||
setInterval(async () => {
|
||||
await liftImmutability(remotes).catch(error => warn('error while lifting immutability', error))
|
||||
}, liftEvery)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# ChangeLog
|
||||
|
||||
## **next**
|
||||
## **0.24.0** (2026-07-30)
|
||||
|
||||
- [Host/dashboard] Switch CPU and RAM panels order to match Pool dashboard layout (PR [#10059](https://github.com/vatesfr/xen-orchestra/pull/10059))
|
||||
- Remove all "coming soon" disabled button placeholders from network, VM, and pool components (PR [#10068](https://github.com/vatesfr/xen-orchestra/pull/10068))
|
||||
@@ -20,6 +20,7 @@
|
||||
- [SidePanels] Add and use new `VtsCardObjectTitle` component to display object title and ID in side panels (PR [#9755](https://github.com/vatesfr/xen-orchestra/pull/9755))
|
||||
- Replacement of the UiSpinner component with UiLoader from web-core (PR [#10023](https://github.com/vatesfr/xen-orchestra/pull/10023))
|
||||
- [Pool,Host/Storage] Add Storage tabs (PR [#10005](https://github.com/vatesfr/xen-orchestra/pull/10005))
|
||||
- [Pool,Host/Storage] Storage repositories can now be connected, disconnected and deleted from the Storage tabs (PR [#10006](https://github.com/vatesfr/xen-orchestra/pull/10006))
|
||||
|
||||
## **0.22.0** (2026-05-28)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xen-orchestra/lite",
|
||||
"version": "0.23.0",
|
||||
"version": "0.24.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
|
||||
@@ -28,13 +28,13 @@
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^18.19.80",
|
||||
"@vates/types": "^1.28.0",
|
||||
"@vates/types": "^1.30.1",
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"@vue/tsconfig": "^0.9.0",
|
||||
"@vueuse/core": "^14.0.0",
|
||||
"@vueuse/math": "^14.0.0",
|
||||
"@vueuse/shared": "^14.0.0",
|
||||
"@xen-orchestra/web-core": "^0.56.0",
|
||||
"@xen-orchestra/web-core": "^0.58.0",
|
||||
"complex-matcher": "^1.1.1",
|
||||
"d3-time-format": "^4.1.0",
|
||||
"decorator-synchronized": "^0.6.0",
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<VtsModalList />
|
||||
<VtsDrawerList />
|
||||
<VtsOverlayList />
|
||||
<VtsTooltipList />
|
||||
</template>
|
||||
|
||||
@@ -23,8 +22,7 @@ import AppNavigation from '@/components/AppNavigation.vue'
|
||||
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsDrawerList from '@core/components/drawer/VtsDrawerList.vue'
|
||||
import VtsModalList from '@core/components/modal/VtsModalList.vue'
|
||||
import VtsOverlayList from '@core/components/overlay/VtsOverlayList.vue'
|
||||
import VtsTooltipList from '@core/components/tooltip-list/VtsTooltipList.vue'
|
||||
import { useChartTheme } from '@core/composables/chart-theme.composable'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
|
||||
@@ -20,8 +20,7 @@ import UiActionButton from '@/components/ui/UiActionButton.vue'
|
||||
import UiFilter from '@/components/ui/UiFilter.vue'
|
||||
import UiFilterGroup from '@/components/ui/UiFilterGroup.vue'
|
||||
import type { Filters } from '@/types/filter'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { availableFilters } = defineProps<{
|
||||
@@ -36,18 +35,25 @@ const emit = defineEmits<{
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const openFilterModal = useModal((editedFilter?: string) => ({
|
||||
component: import('@/components/modals/CollectionFilterModal.vue'),
|
||||
props: {
|
||||
editedFilter,
|
||||
availableFilters: computed(() => availableFilters),
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/components/modals/CollectionFilterModal.vue'),
|
||||
events: {
|
||||
onCancel: true,
|
||||
},
|
||||
onConfirm: async newFilter => {
|
||||
if (editedFilter !== undefined) {
|
||||
emit('removeFilter', editedFilter)
|
||||
}
|
||||
})
|
||||
|
||||
emit('addFilter', newFilter)
|
||||
},
|
||||
}))
|
||||
function openFilterModal(editedFilter?: string) {
|
||||
return open({
|
||||
props: { editedFilter, availableFilters },
|
||||
events: {
|
||||
onConfirm: newFilter => {
|
||||
if (editedFilter !== undefined) {
|
||||
emit('removeFilter', editedFilter)
|
||||
}
|
||||
|
||||
emit('addFilter', newFilter)
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="inputs">
|
||||
<UiInput v-if="newFilter.isAdvanced" v-model="filterContent" accent="brand" class="advanced-input" />
|
||||
<template v-else>
|
||||
<VtsSelect :id="builderPropertySelectId" accent="brand" :icon="currentFilterIcon" />
|
||||
<VtsSelect :id="builderPropertySelectId" accent="brand" />
|
||||
<VtsSelect v-if="hasComparisonSelect" :id="builderComparisonSelectId" accent="brand" />
|
||||
<VtsSelect v-if="currentFilter?.type === 'enum'" :id="builderValueSelectId" accent="brand" />
|
||||
<UiInput v-else-if="hasValueInput" v-model="newFilter.builder.value" accent="brand" />
|
||||
@@ -20,7 +20,6 @@
|
||||
<script lang="ts" setup>
|
||||
import UiActionButton from '@/components/ui/UiActionButton.vue'
|
||||
import { buildComplexMatcherNode } from '@/libs/complex-matcher.utils'
|
||||
import { getFilterIcon } from '@/libs/utils'
|
||||
import type { Filter, FilterComparisons, FilterComparisonType, Filters, FilterType, NewFilter } from '@/types/filter'
|
||||
import VtsSelect from '@core/components/select/VtsSelect.vue'
|
||||
import UiInput from '@core/components/ui/input/UiInput.vue'
|
||||
@@ -104,8 +103,6 @@ function getDefaultComparisonType(property: string) {
|
||||
|
||||
const currentFilter = computed<Filter | undefined>(() => availableFilters[builderProperty.value])
|
||||
|
||||
const currentFilterIcon = computed(() => getFilterIcon(currentFilter.value))
|
||||
|
||||
const hasValueInput = computed(() =>
|
||||
currentFilter.value ? ['string', 'number'].includes(currentFilter.value?.type) : false
|
||||
)
|
||||
|
||||
@@ -24,8 +24,7 @@ import UiFilter from '@/components/ui/UiFilter.vue'
|
||||
import UiFilterGroup from '@/components/ui/UiFilterGroup.vue'
|
||||
import type { ActiveSorts, Sorts } from '@/types/sort'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { availableSorts } = defineProps<{
|
||||
@@ -41,11 +40,17 @@ const emit = defineEmits<{
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const openFormModal = useModal({
|
||||
component: import('@/components/modals/CollectionSorterModal.vue'),
|
||||
props: { availableSorts: computed(() => availableSorts) },
|
||||
onConfirm: ({ property, isAscending }) => emit('addSort', property as TProperty, isAscending),
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/components/modals/CollectionSorterModal.vue'),
|
||||
events: {
|
||||
onConfirm: ({ property, isAscending }) => emit('addSort', property as TProperty, isAscending),
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
function openFormModal() {
|
||||
return open({ props: { availableSorts } })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -87,7 +87,7 @@ import useSortedCollection from '@/composables/sorted-collection.composable'
|
||||
import type { PropParam } from '@/libs/story/story-param'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { toRef } from 'vue'
|
||||
|
||||
@@ -111,10 +111,16 @@ const params = useSortedCollection(toRef(props, 'params'), (p1, p2) => {
|
||||
|
||||
const model = useVModel(props, 'modelValue', emit)
|
||||
|
||||
const openRawValueModal = useModal((code: string) => ({
|
||||
component: import('@/components/modals/CodeHighlightModal.vue'),
|
||||
props: { code },
|
||||
}))
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/components/modals/CodeHighlightModal.vue'),
|
||||
events: {
|
||||
onClose: true,
|
||||
},
|
||||
})
|
||||
|
||||
function openRawValueModal(code: string) {
|
||||
return open({ props: { code } })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import FormInput from '@/components/form/FormInput.vue'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -20,11 +20,17 @@ const model = useVModel(props, 'modelValue', emit)
|
||||
|
||||
const jsonValue = computed(() => JSON.stringify(model.value, undefined, 2))
|
||||
|
||||
const openJsonModal = useModal({
|
||||
component: import('@/components/modals/JsonEditorModal.vue'),
|
||||
props: { initialValue: computed(() => jsonValue.value) },
|
||||
onConfirm: newValue => {
|
||||
model.value = JSON.parse(newValue)
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/components/modals/JsonEditorModal.vue'),
|
||||
events: {
|
||||
onConfirm: (newValue: string) => {
|
||||
model.value = JSON.parse(newValue)
|
||||
},
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
function openJsonModal() {
|
||||
return open({ props: { initialValue: jsonValue.value } })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -91,6 +91,7 @@
|
||||
</template>
|
||||
<template #addons>
|
||||
<VtsCopyButton :value="ip" />
|
||||
<VtsCopyAllMenuItem v-if="index === 0 && ipAddresses.length > 1" :values="ipAddresses" />
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
@@ -174,6 +175,7 @@
|
||||
</template>
|
||||
<template v-if="device" #addons>
|
||||
<VtsCopyButton :value="device" />
|
||||
<VtsCopyAllMenuItem v-if="index === 0 && bondDevices.length > 1" :values="bondDevicesFiltered" />
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
@@ -229,6 +231,7 @@ import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store'
|
||||
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
|
||||
import VtsCardObjectTitle from '@core/components/card-object-title/VtsCardObjectTitle.vue'
|
||||
import VtsCopyAllMenuItem from '@core/components/copy-all-menu-item/VtsCopyAllMenuItem.vue'
|
||||
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
@@ -291,6 +294,10 @@ const ipConfigurationMode = computed(() => {
|
||||
|
||||
const bondDevices = computed(() => (pif !== undefined ? getBondsDevices(pif) : []))
|
||||
|
||||
const bondDevicesFiltered = computed(() => {
|
||||
return bondDevices.value.filter((bondDevice): bondDevice is string => bondDevice !== undefined)
|
||||
})
|
||||
|
||||
const isBond = computed(() => (pif !== undefined ? isBondMaster(pif) : false))
|
||||
|
||||
const speed = computed(() => {
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
<template>
|
||||
<VtsModal accent="info" dismissible>
|
||||
<UiModal accent="info" @dismiss="emit('close')">
|
||||
<template #content>
|
||||
<CodeHighlight :code />
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import CodeHighlight from '@/components/CodeHighlight.vue'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
|
||||
defineProps<{
|
||||
code: any
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="info" dismissible @confirm="emit('confirm', generatedFilter)">
|
||||
<UiModal accent="info" @dismiss="emit('cancel')" @confirm="emit('confirm', generatedFilter)">
|
||||
<template #content>
|
||||
<div class="rows">
|
||||
<CollectionFilterRow
|
||||
@@ -10,9 +10,9 @@
|
||||
@remove="removeNewFilter($event)"
|
||||
/>
|
||||
<div>
|
||||
<VtsModalButton variant="tertiary" @click="addNewFilter()">
|
||||
<VtsOverlayButton variant="tertiary" @click="addNewFilter()">
|
||||
{{ t('add-or') }}
|
||||
</VtsModalButton>
|
||||
</VtsOverlayButton>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="newFilters.some(filter => filter.isAdvanced)" class="available-properties">
|
||||
@@ -25,12 +25,12 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton :disabled="!isFilterValid">
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton :disabled="!isFilterValid">
|
||||
{{ editedFilter ? t('action:update') : t('action:add') }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -38,10 +38,10 @@ import CollectionFilterRow from '@/components/CollectionFilterRow.vue'
|
||||
import UiBadge from '@/components/ui/UiBadge.vue'
|
||||
import { getFilterIcon } from '@/libs/utils'
|
||||
import type { Filters, NewFilter } from '@/types/filter'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalButton from '@core/components/modal/VtsModalButton.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { Or, parse } from 'complex-matcher'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -53,6 +53,7 @@ const { editedFilter } = defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [filter: string]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="info" dismissible @confirm="handleSubmit()">
|
||||
<UiModal accent="info" @dismiss="emit('cancel')" @confirm="handleSubmit()">
|
||||
<template #content>
|
||||
<div class="form-selects">
|
||||
<VtsSelect :id="sortPropertySelectId" accent="brand" />
|
||||
@@ -8,18 +8,18 @@
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton :disabled="!newSortProperty">{{ t('action:add') }}</VtsModalConfirmButton>
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton :disabled="!newSortProperty">{{ t('action:add') }}</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { NewSort, Sorts } from '@/types/sort'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import VtsSelect from '@core/components/select/VtsSelect.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -30,6 +30,7 @@ const { availableSorts } = defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [sort: NewSort]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
<template>
|
||||
<VtsModal accent="danger" dismissible icon="fa:exclamation-circle">
|
||||
<UiModal accent="danger" icon="fa:exclamation-circle" @dismiss="emit('close')" @confirm="emit('close')">
|
||||
<template #title>{{ t('invalid-field') }}</template>
|
||||
<template #content>{{ message }}</template>
|
||||
<template #buttons>
|
||||
<VtsModalConfirmButton>
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ t('ok') }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
message: string
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
<template>
|
||||
<VtsModal
|
||||
<UiModal
|
||||
:accent="isJsonValid ? 'info' : 'danger'"
|
||||
class="json-editor-modal"
|
||||
icon="fa:code"
|
||||
dismissible
|
||||
@confirm="handleSubmit()"
|
||||
@dismiss="emit('cancel')"
|
||||
>
|
||||
<template #content>
|
||||
<UiTextarea v-model="editedJson" accent="brand" class="modal-textarea" />
|
||||
<VtsModalButton variant="tertiary" @click="formatJson()">
|
||||
<VtsOverlayButton variant="tertiary" @click="formatJson()">
|
||||
{{ t('action:reformat') }}
|
||||
</VtsModalButton>
|
||||
</VtsOverlayButton>
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton :disabled="!isJsonValid">
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton :disabled="!isJsonValid">
|
||||
{{ t('action:save') }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalButton from '@core/components/modal/VtsModalButton.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import UiTextarea from '@core/components/ui/text-area/UiTextarea.vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -37,6 +37,7 @@ const { initialValue } = defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [editedJson: string]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="danger" icon="object:host">
|
||||
<UiModal accent="danger" icon="object:host" @confirm="emit('confirm')">
|
||||
<template #title>{{ t('unreachable-hosts') }}</template>
|
||||
<template #content>
|
||||
<div class="description">
|
||||
@@ -13,25 +13,30 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton>
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ t('unreachable-hosts-reload-page') }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
urls: string[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: []
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<template>
|
||||
<VtsDeleteModal>
|
||||
<template #title>
|
||||
{{ t('n-vms', { n: count }) }}
|
||||
</template>
|
||||
|
||||
<template #confirm>
|
||||
{{ t(`action:delete-n-vms`, { n: count }) }}
|
||||
</template>
|
||||
</VtsDeleteModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import VtsDeleteModal from '@core/components/modal/VtsDeleteModal.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
count: number
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="info" icon="object:vm" dismissible>
|
||||
<UiModal accent="info" icon="object:vm" @confirm="emit('close')" @dismiss="emit('close')">
|
||||
<template #title>
|
||||
{{ t('action:export-n-vms-manually', { n: labelWithUrl.length }) }}
|
||||
</template>
|
||||
@@ -18,16 +18,16 @@
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsModalConfirmButton>{{ t('action:close') }}</VtsModalConfirmButton>
|
||||
<VtsOverlayConfirmButton>{{ t('action:close') }}</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -35,6 +35,10 @@ const { blockedUrls } = defineProps<{
|
||||
blockedUrls: URL[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getByOpaqueRef } = useVmStore().subscribe()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="info" icon="object:vm" dismissible @confirm="emit('confirm', compressionType)">
|
||||
<UiModal accent="info" icon="object:vm" @confirm="emit('confirm', compressionType)" @dismiss="emit('cancel')">
|
||||
<template #title>
|
||||
{{ t('action:export-n-vms', { n: count }) }}
|
||||
</template>
|
||||
@@ -12,21 +12,21 @@
|
||||
</VtsInputWrapper>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton>
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton>
|
||||
{{ t('action:export-n-vms', { n: count }) }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums'
|
||||
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import VtsSelect from '@core/components/select/VtsSelect.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -37,6 +37,7 @@ defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [compressionType: VM_COMPRESSION_TYPE]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<VtsModal accent="info" dismissible @confirm="emit('confirm', selectedHost)">
|
||||
<UiModal accent="info" @confirm="emit('confirm', selectedHost)" @dismiss="emit('cancel')">
|
||||
<template #title>
|
||||
{{ t('action:migrate-n-vms', { n: count }) }}
|
||||
</template>
|
||||
@@ -13,21 +13,21 @@
|
||||
</template>
|
||||
|
||||
<template #buttons>
|
||||
<VtsModalCancelButton />
|
||||
<VtsModalConfirmButton :disabled="!selectedHost">
|
||||
<VtsOverlayCancelButton @click="emit('cancel')" />
|
||||
<VtsOverlayConfirmButton :disabled="!selectedHost">
|
||||
{{ t('action:migrate-n-vms', { n: count }) }}
|
||||
</VtsModalConfirmButton>
|
||||
</VtsOverlayConfirmButton>
|
||||
</template>
|
||||
</VtsModal>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
|
||||
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
|
||||
import VtsModal from '@core/components/modal/VtsModal.vue'
|
||||
import VtsModalCancelButton from '@core/components/modal/VtsModalCancelButton.vue'
|
||||
import VtsModalConfirmButton from '@core/components/modal/VtsModalConfirmButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import VtsSelect from '@core/components/select/VtsSelect.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -39,6 +39,7 @@ const { availableHosts } = defineProps<{
|
||||
|
||||
const emit = defineEmits<{
|
||||
confirm: [selectedHost: XenApiHost | undefined]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
const selectedHost = ref<XenApiHost>()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
v-tooltip="areSomeVmsInExecution && t('selected-vms-in-execution')"
|
||||
:disabled="isDisabled"
|
||||
icon="fa:trash"
|
||||
@click="openDeleteModal"
|
||||
@click="openDeleteModal()"
|
||||
>
|
||||
{{ t('action:delete') }}
|
||||
</MenuItem>
|
||||
@@ -15,8 +15,8 @@ import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { useDeleteModal } from '@core/composables/modals/use-delete-modal.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -36,9 +36,15 @@ const isDisabled = computed(() => vms.value.length === 0 || areSomeVmsInExecutio
|
||||
|
||||
const xenApi = useXenApiStore().getXapi()
|
||||
|
||||
const openDeleteModal = useModal({
|
||||
component: import('@/components/modals/VmDeleteModal.vue'),
|
||||
props: { count: computed(() => vmRefs.length) },
|
||||
onConfirm: () => xenApi.vm.delete(vmRefs),
|
||||
})
|
||||
const { open: openModal } = useDeleteModal()
|
||||
|
||||
function openDeleteModal() {
|
||||
return openModal({
|
||||
events: { onConfirm: () => xenApi.vm.delete(vmRefs) },
|
||||
props: {
|
||||
subject: t('n-vms', { n: vmRefs.length }),
|
||||
confirmLabel: t('action:delete-n-vms', { n: vmRefs.length }),
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -5,22 +5,22 @@
|
||||
"
|
||||
:disabled="isDisabled"
|
||||
icon="action:download"
|
||||
@click="openExportModal"
|
||||
@click="openExportModal()"
|
||||
>
|
||||
{{ t('action:export-vm', isSingleAction ? 1 : 2) }}
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useVmExport } from '@/composables/vm-export.composable.ts'
|
||||
import { areSomeVmOperationAllowed } from '@/libs/vm'
|
||||
import { VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -39,13 +39,17 @@ const isSomeExportable = computed(() =>
|
||||
|
||||
const isDisabled = useDisabled(() => !isSomeExportable.value)
|
||||
|
||||
const xenApi = useXenApiStore().getXapi()
|
||||
const { exportVms } = useVmExport()
|
||||
|
||||
const openModal = useModal()
|
||||
|
||||
const openExportModal = useModal({
|
||||
component: import('@/components/modals/VmExportModal.vue'),
|
||||
props: { count: computed(() => vmRefs.length) },
|
||||
onConfirm: compressionType => xenApi.vm.export(vmRefs, compressionType, openModal),
|
||||
const { open: openModal } = useOverlay({
|
||||
component: () => import('@/components/modals/VmExportModal.vue'),
|
||||
events: {
|
||||
onConfirm: compressionType => exportVms(vmRefs, compressionType),
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
function openExportModal() {
|
||||
return openModal({ props: { count: vmRefs.length } })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -23,8 +23,9 @@ import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { ABORT_MODAL } from '@core/packages/modal/types.ts'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { KEEP_OVERLAY_OPEN } from '@core/packages/overlay/symbols.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { reactiveComputed } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -53,20 +54,28 @@ const isDisabled = useDisabled(() => !isMigratable.value)
|
||||
|
||||
const { selectedHost, availableHosts, isValid, migrate } = useVmMigration(() => selectedRefs)
|
||||
|
||||
const openMigrateModal = useModal({
|
||||
component: import('@/components/modals/VmMigrateModal.vue'),
|
||||
props: {
|
||||
count: computed(() => selectedRefs.length),
|
||||
availableHosts,
|
||||
},
|
||||
onConfirm: async host => {
|
||||
selectedHost.value = host
|
||||
const { open: openModal } = useOverlay({
|
||||
component: () => import('@/components/modals/VmMigrateModal.vue'),
|
||||
events: {
|
||||
onConfirm: async host => {
|
||||
selectedHost.value = host
|
||||
|
||||
if (!isValid.value) {
|
||||
return ABORT_MODAL
|
||||
}
|
||||
if (!isValid.value) {
|
||||
return KEEP_OVERLAY_OPEN
|
||||
}
|
||||
|
||||
await migrate()
|
||||
await migrate()
|
||||
},
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
const modalProps = reactiveComputed(() => ({
|
||||
count: selectedRefs.length,
|
||||
availableHosts: availableHosts.value,
|
||||
}))
|
||||
|
||||
function openMigrateModal() {
|
||||
return openModal({ props: modalProps })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
<template #value>{{ ip }}</template>
|
||||
<template #addons>
|
||||
<VtsCopyButton :value="ip" />
|
||||
<VtsCopyAllMenuItem v-if="index === 0 && ipAddresses.length > 1" :values="ipAddresses" />
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
@@ -113,6 +114,7 @@ import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
|
||||
import VtsCardObjectTitle from '@core/components/card-object-title/VtsCardObjectTitle.vue'
|
||||
import VtsCopyAllMenuItem from '@core/components/copy-all-menu-item/VtsCopyAllMenuItem.vue'
|
||||
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
import VtsStatus from '@core/components/status/VtsStatus.vue'
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiNetwork, XenApiVif, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVifConnectionToggleModal } from '@/modules/vif/composables/use-vif-connection-toggle-modal.composable.ts'
|
||||
import { useVifConnection } from '@/modules/vif/composables/use-vif-connection.composable.ts'
|
||||
import { useNetworkStore } from '@/stores/xen-api/network.store'
|
||||
import { useVifStore } from '@/stores/xen-api/vif.store'
|
||||
import { useVmGuestMetricsStore } from '@/stores/xen-api/vm-guest-metrics.store'
|
||||
@@ -36,6 +36,8 @@ import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable'
|
||||
import { useTableState } from '@core/composables/table-state.composable'
|
||||
import { useMapper } from '@core/packages/mapper'
|
||||
import { type ActionItem } from '@core/tables/column-definitions/action-column.ts'
|
||||
import { useVifColumns } from '@core/tables/column-sets/vif-columns'
|
||||
import { CONNECTION_ACTION } from '@core/types/connection.ts'
|
||||
import { getUniqueIpAddressesForDevice } from '@core/utils/ip-address.utils.ts'
|
||||
@@ -95,14 +97,40 @@ const { HeadCells, BodyCells } = useVifColumns({
|
||||
const ipAddresses = computed(() => getIpAddresses(vif))
|
||||
|
||||
const {
|
||||
openModal: openVifConnectionToggleModal,
|
||||
canRun: canToggleVifConnection,
|
||||
isRunning: isTogglingVifConnection,
|
||||
errorMessage: toggleConnectionErrorMessage,
|
||||
} = useVifConnectionToggleModal(
|
||||
connectVifs,
|
||||
disconnectVifs,
|
||||
canConnectVifs,
|
||||
canDisconnectVifs,
|
||||
isConnectingVifs,
|
||||
isDisconnectingVifs,
|
||||
connectVifsErrorMessage,
|
||||
disconnectVifsErrorMessage,
|
||||
} = useVifConnection({
|
||||
vifs: () => [vif],
|
||||
vm: () => vm,
|
||||
})
|
||||
|
||||
const connectionAction = useMapper(
|
||||
() => (vif.currently_attached ? CONNECTION_ACTION.DISCONNECT : CONNECTION_ACTION.CONNECT),
|
||||
() => [vif],
|
||||
() => vm
|
||||
() => ({
|
||||
connect: {
|
||||
label: t('action:connect'),
|
||||
icon: 'action:connect',
|
||||
onClick: () => connectVifs(),
|
||||
disabled: !canConnectVifs.value,
|
||||
busy: isConnectingVifs.value,
|
||||
hint: canConnectVifs.value ? undefined : connectVifsErrorMessage.value,
|
||||
} satisfies ActionItem,
|
||||
disconnect: {
|
||||
label: t('action:disconnect'),
|
||||
icon: 'action:disconnect',
|
||||
onClick: () => disconnectVifs(),
|
||||
disabled: !canDisconnectVifs.value,
|
||||
busy: isDisconnectingVifs.value,
|
||||
hint: canDisconnectVifs.value ? undefined : disconnectVifsErrorMessage.value,
|
||||
} satisfies ActionItem,
|
||||
}),
|
||||
'connect'
|
||||
)
|
||||
|
||||
return {
|
||||
@@ -116,16 +144,7 @@ const { HeadCells, BodyCells } = useVifColumns({
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedVifId.value = vif.uuid),
|
||||
actions: [
|
||||
{
|
||||
label: vif.currently_attached ? t('action:disconnect') : t('action:connect'),
|
||||
hint: !canToggleVifConnection.value ? toggleConnectionErrorMessage.value : undefined,
|
||||
icon: vif.currently_attached ? 'action:disconnect' : 'action:connect',
|
||||
onClick: () => openVifConnectionToggleModal(),
|
||||
disabled: !canToggleVifConnection.value,
|
||||
busy: isTogglingVifConnection.value,
|
||||
},
|
||||
],
|
||||
actions: [connectionAction.value],
|
||||
}),
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ipToHostname } from '@/libs/utils'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { whenever } from '@vueuse/core'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { reactiveComputed, whenever } from '@vueuse/core'
|
||||
import { difference } from 'lodash-es'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
export const useUnreachableHosts = () => {
|
||||
const { records: hosts } = useHostStore().subscribe()
|
||||
@@ -18,15 +18,33 @@ export const useUnreachableHosts = () => {
|
||||
})
|
||||
})
|
||||
|
||||
const openModal = useModal({
|
||||
keepOpenOnRouteChange: true,
|
||||
component: import('@/components/modals/UnreachableHostsModal.vue'),
|
||||
props: { urls: computed(() => Array.from(unreachableHostsUrls.value.values())) },
|
||||
onConfirm: () => window.location.reload(),
|
||||
onCancel: () => unreachableHostsUrls.value.clear(),
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@/components/modals/UnreachableHostsModal.vue'),
|
||||
events: {
|
||||
onConfirm: true,
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
whenever(() => unreachableHostsUrls.value.size > 0, openModal, {
|
||||
immediate: true,
|
||||
})
|
||||
const modalProps = reactiveComputed(() => ({
|
||||
urls: Array.from(unreachableHostsUrls.value.values()),
|
||||
}))
|
||||
|
||||
async function openModal() {
|
||||
const { event } = await open({ props: modalProps })
|
||||
|
||||
if (event === 'onConfirm') {
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
unreachableHostsUrls.value.clear()
|
||||
}
|
||||
|
||||
whenever(
|
||||
() => unreachableHostsUrls.value.size > 0,
|
||||
() => openModal(),
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
27
@xen-orchestra/lite/src/composables/vm-export.composable.ts
Normal file
27
@xen-orchestra/lite/src/composables/vm-export.composable.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums.ts'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
|
||||
export function useVmExport() {
|
||||
const xapi = useXenApiStore().getXapi()
|
||||
|
||||
const { open: openBlockedUrlsModal } = useOverlay({
|
||||
component: () => import('@/components/modals/VmExportBlockedUrlsModal.vue'),
|
||||
events: {
|
||||
onClose: true,
|
||||
},
|
||||
})
|
||||
|
||||
async function exportVms(vmRefs: XenApiVm['$ref'][], compression: VM_COMPRESSION_TYPE) {
|
||||
const { blockedUrls } = await xapi.vm.export(vmRefs, compression)
|
||||
|
||||
if (blockedUrls.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
openBlockedUrlsModal({ props: { blockedUrls } })
|
||||
}
|
||||
|
||||
return { exportVms }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { XenApiHost, XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import type { XenApiHost, XenApiPbd, XenApiSr, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { defineJobArg } from '@core/packages/job'
|
||||
|
||||
export const vmsArg = defineJobArg({
|
||||
@@ -10,3 +10,13 @@ export const hostArg = defineJobArg({
|
||||
identify: (host: XenApiHost) => host.$ref,
|
||||
toArray: false,
|
||||
})
|
||||
|
||||
export const srsArg = defineJobArg({
|
||||
identify: (sr: XenApiSr) => sr.$ref,
|
||||
toArray: true,
|
||||
})
|
||||
|
||||
export const pbdsArg = defineJobArg({
|
||||
identify: (pbd: XenApiPbd) => pbd.$ref,
|
||||
toArray: true,
|
||||
})
|
||||
|
||||
26
@xen-orchestra/lite/src/jobs/pbd-plug.job.ts
Normal file
26
@xen-orchestra/lite/src/jobs/pbd-plug.job.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { pbdsArg } from '@/jobs/args.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const usePbdPlugJob = defineJob('pbd.plug', [pbdsArg], () => {
|
||||
const xapi = useXenApiStore().getXapi()
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
run: pbds => xapi.pbd.plug(pbds.map(pbd => pbd.$ref)),
|
||||
validate: (isRunning, pbds) => {
|
||||
if (pbds.length === 0) {
|
||||
throw new JobError(t('job:pbd-plug:missing-pbd'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:connect:in-progress'))
|
||||
}
|
||||
|
||||
if (pbds.some(pbd => pbd.currently_attached)) {
|
||||
throw new JobError(t('job:pbd-plug:pbd-connected'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
26
@xen-orchestra/lite/src/jobs/pbd-unplug.job.ts
Normal file
26
@xen-orchestra/lite/src/jobs/pbd-unplug.job.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { pbdsArg } from '@/jobs/args.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const usePbdUnplugJob = defineJob('pbd.unplug', [pbdsArg], () => {
|
||||
const xapi = useXenApiStore().getXapi()
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
run: pbds => xapi.pbd.unplug(pbds.map(pbd => pbd.$ref)),
|
||||
validate: (isRunning, pbds) => {
|
||||
if (pbds.length === 0) {
|
||||
throw new JobError(t('job:pbd-unplug:missing-pbd'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:disconnect:in-progress'))
|
||||
}
|
||||
|
||||
if (pbds.some(pbd => !pbd.currently_attached)) {
|
||||
throw new JobError(t('job:pbd-unplug:pbd-disconnected'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
22
@xen-orchestra/lite/src/jobs/sr-delete.job.ts
Normal file
22
@xen-orchestra/lite/src/jobs/sr-delete.job.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { srsArg } from '@/jobs/args.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { defineJob, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export const useSrDeleteJob = defineJob('sr.delete', [srsArg], () => {
|
||||
const xapi = useXenApiStore().getXapi()
|
||||
const { t } = useI18n()
|
||||
|
||||
return {
|
||||
run: srs => xapi.sr.delete(srs.map(sr => sr.$ref)),
|
||||
validate: (isRunning, srs) => {
|
||||
if (srs.length === 0) {
|
||||
throw new JobError(t('job:sr-delete:missing-sr'))
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
throw new JobRunningError(t('job:delete:in-progress'))
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useVmExport } from '@/composables/vm-export.composable.ts'
|
||||
import { vmsArg } from '@/jobs/args'
|
||||
import { areSomeVmOperationAllowed, isVmOperationPending } from '@/libs/vm'
|
||||
import { VM_COMPRESSION_TYPE, VM_OPERATION } from '@/libs/xen-api/xen-api.enums'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import { defineJob, defineJobArg, JobError, JobRunningError } from '@core/packages/job'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const compressionArg = defineJobArg<VM_COMPRESSION_TYPE>({
|
||||
@@ -12,16 +11,15 @@ const compressionArg = defineJobArg<VM_COMPRESSION_TYPE>({
|
||||
})
|
||||
|
||||
export const useVmExportJob = defineJob('vm.export', [vmsArg, compressionArg], () => {
|
||||
const xapi = useXenApiStore().getXapi()
|
||||
const { t } = useI18n()
|
||||
const openModal = useModal()
|
||||
|
||||
const { exportVms } = useVmExport()
|
||||
|
||||
return {
|
||||
run: (vms, compression) =>
|
||||
xapi.vm.export(
|
||||
exportVms(
|
||||
vms.map(vm => vm.$ref),
|
||||
compression,
|
||||
openModal
|
||||
compression
|
||||
),
|
||||
validate: (isRunning, vms, compression) => {
|
||||
if (vms.length === 0) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type XenApi from '@/libs/xen-api/xen-api.ts'
|
||||
import type { XenApiPbd } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { MaybeArray } from '@core/types/utility.type.ts'
|
||||
import { toArray } from '@core/utils/to-array.utils.ts'
|
||||
|
||||
export function createPbdOperations(xenApi: XenApi) {
|
||||
type PbdRefs = MaybeArray<XenApiPbd['$ref']>
|
||||
|
||||
return {
|
||||
plug: (pbdRefs: PbdRefs) => Promise.all(toArray(pbdRefs).map(pbdRef => xenApi.call('PBD.plug', [pbdRef]))),
|
||||
|
||||
unplug: (pbdRefs: PbdRefs) => Promise.all(toArray(pbdRefs).map(pbdRef => xenApi.call('PBD.unplug', [pbdRef]))),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import type XenApi from '@/libs/xen-api/xen-api.ts'
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { MaybeArray } from '@core/types/utility.type.ts'
|
||||
import { toArray } from '@core/utils/to-array.utils.ts'
|
||||
|
||||
export function createSrOperations(xenApi: XenApi) {
|
||||
type SrRefs = MaybeArray<XenApiSr['$ref']>
|
||||
|
||||
return {
|
||||
delete: async (srRefs: SrRefs) => {
|
||||
await Promise.all(
|
||||
toArray(srRefs).map(async srRef => {
|
||||
const pbdRefs = await xenApi.getField<XenApiSr['PBDs']>('SR', srRef, 'PBDs')
|
||||
|
||||
const attachedRefs = (
|
||||
await Promise.all(
|
||||
pbdRefs.map(async pbdRef => ({
|
||||
pbdRef,
|
||||
attached: await xenApi.getField<boolean>('PBD', pbdRef, 'currently_attached'),
|
||||
}))
|
||||
)
|
||||
)
|
||||
.filter(({ attached }) => attached)
|
||||
.map(({ pbdRef }) => pbdRef)
|
||||
|
||||
if (attachedRefs.length > 0) {
|
||||
await xenApi.pbd.unplug(attachedRefs)
|
||||
}
|
||||
|
||||
await xenApi.call('SR.destroy', [srRef])
|
||||
})
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import type XenApi from '@/libs/xen-api/xen-api'
|
||||
import type { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { XenApiHost, XenApiSr, XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import type { OpenModal } from '@core/packages/modal/types.ts'
|
||||
import type { MaybeArray } from '@core/types/utility.type.ts'
|
||||
import { toArray } from '@core/utils/to-array.utils'
|
||||
import type { OPAQUE_REF_NULL } from '@vates/types/common'
|
||||
@@ -42,7 +41,7 @@ export function createVmOperations(xenApi: XenApi) {
|
||||
|
||||
delete: (vmRefs: VmRefs) => Promise.all(toArray(vmRefs).map(vmRef => xenApi.call('VM.destroy', [vmRef]))),
|
||||
|
||||
export: async (vmRefs: VmRefs, compression: VM_COMPRESSION_TYPE, openModal: OpenModal) => {
|
||||
export: async (vmRefs: VmRefs, compression: VM_COMPRESSION_TYPE) => {
|
||||
const blockedUrls: URL[] = []
|
||||
|
||||
toArray(vmRefs).forEach(vmRef => {
|
||||
@@ -54,22 +53,14 @@ export function createVmOperations(xenApi: XenApi) {
|
||||
use_compression: compression,
|
||||
}).toString()
|
||||
|
||||
const _window = window.open(url.href, '_blank')
|
||||
const openedWindow = window.open(url.href, '_blank')
|
||||
|
||||
if (_window === null) {
|
||||
if (openedWindow === null) {
|
||||
blockedUrls.push(url)
|
||||
} else {
|
||||
URL.revokeObjectURL(url.toString())
|
||||
}
|
||||
})
|
||||
|
||||
if (blockedUrls.length > 0) {
|
||||
await openModal('blocked-urls', {
|
||||
component: import('@/components/modals/VmExportBlockedUrlsModal.vue'),
|
||||
props: { blockedUrls },
|
||||
onConfirm: () => blockedUrls.forEach(url => URL.revokeObjectURL(url.toString())),
|
||||
})
|
||||
}
|
||||
return { blockedUrls }
|
||||
},
|
||||
|
||||
getAllowedVbdDevices: (vmRefs: VmRefs): Promise<string[][]> =>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ipToHostname } from '@/libs/utils'
|
||||
import { createVbdOperations } from '@/libs/xen-api/operations/vbd-operations'
|
||||
import { createVdiOperations } from '@/libs/xen-api/operations/vdi-operations'
|
||||
import { createVifOperations } from '@/libs/xen-api/operations/vif-operations'
|
||||
import { createVmOperations } from '@/libs/xen-api/operations/vm-operations'
|
||||
import { createVtpmOperations } from '@/libs/xen-api/operations/vtpm-operations'
|
||||
import { ipToHostname } from '@/libs/utils.ts'
|
||||
import { createPbdOperations } from '@/libs/xen-api/operations/pbd-operations.ts'
|
||||
import { createSrOperations } from '@/libs/xen-api/operations/sr-operations.ts'
|
||||
import { createVbdOperations } from '@/libs/xen-api/operations/vbd-operations.ts'
|
||||
import { createVdiOperations } from '@/libs/xen-api/operations/vdi-operations.ts'
|
||||
import { createVifOperations } from '@/libs/xen-api/operations/vif-operations.ts'
|
||||
import { createVmOperations } from '@/libs/xen-api/operations/vm-operations.ts'
|
||||
import { createVtpmOperations } from '@/libs/xen-api/operations/vtpm-operations.ts'
|
||||
import type {
|
||||
ObjectType,
|
||||
ObjectTypeToRecord,
|
||||
@@ -18,8 +20,8 @@ import type {
|
||||
XenApiRecordEvent,
|
||||
XenApiRecordLoadErrorEvent,
|
||||
XenApiRecordModEvent,
|
||||
} from '@/libs/xen-api/xen-api.types'
|
||||
import { buildXoObject, typeToRawType } from '@/libs/xen-api/xen-api.utils'
|
||||
} from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { buildXoObject, typeToRawType } from '@/libs/xen-api/xen-api.utils.ts'
|
||||
import { JSONRPCClient } from 'json-rpc-2.0'
|
||||
|
||||
export default class XenApi {
|
||||
@@ -273,6 +275,14 @@ export default class XenApi {
|
||||
return createVbdOperations(this)
|
||||
}
|
||||
|
||||
get pbd() {
|
||||
return createPbdOperations(this)
|
||||
}
|
||||
|
||||
get sr() {
|
||||
return createSrOperations(this)
|
||||
}
|
||||
|
||||
get vtpm() {
|
||||
return createVtpmOperations(this)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import App from '@/App.vue'
|
||||
import i18n from '@core/i18n'
|
||||
import { useOverlayStore } from '@core/packages/overlay/use-overlay-store.ts'
|
||||
import { noop } from '@vueuse/core'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
@@ -11,6 +13,13 @@ const router = createRouter({
|
||||
routes,
|
||||
})
|
||||
|
||||
router
|
||||
.isReady()
|
||||
.catch(noop)
|
||||
.then(() => {
|
||||
router.afterEach(() => useOverlayStore().abortAll())
|
||||
})
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
app.use(i18n)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<UiButton
|
||||
v-tooltip="!canConnectSrs && connectSrsErrorMessage"
|
||||
size="medium"
|
||||
variant="tertiary"
|
||||
accent="brand"
|
||||
:disabled="!canConnectSrs"
|
||||
left-icon="action:connect"
|
||||
:busy="isConnectingSrs"
|
||||
@click="connectSrs()"
|
||||
>
|
||||
{{ t('action:connect') }}
|
||||
<UiCounter
|
||||
v-if="isPartiallyConnectedInScope"
|
||||
:value="connectionTargetCount"
|
||||
accent="brand"
|
||||
variant="secondary"
|
||||
size="small"
|
||||
/>
|
||||
</UiButton>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useSrUtils } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import { useSrConnection } from '@/modules/storage-repository/composables/use-sr-connection.composable.ts'
|
||||
import type { SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { sr, scope } = defineProps<{
|
||||
sr: XenApiSr
|
||||
scope: SrScope
|
||||
}>()
|
||||
|
||||
const { isPartiallyConnectedInScope } = useSrUtils(
|
||||
() => sr,
|
||||
() => scope
|
||||
)
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { connectSrs, canConnectSrs, isConnectingSrs, connectSrsErrorMessage, connectionTargetCount } = useSrConnection({
|
||||
srs: () => [sr],
|
||||
scope: () => scope,
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<MenuItem
|
||||
v-tooltip="!canDeleteSrs && deleteSrsErrorMessage"
|
||||
icon="action:delete"
|
||||
:disabled="!canDeleteSrs"
|
||||
:busy="isDeletingSrs"
|
||||
class="delete"
|
||||
@click="deleteSrs()"
|
||||
>
|
||||
{{ t('action:delete') }}
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useSrDelete } from '@/modules/storage-repository/composables/use-sr-delete.composable.ts'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { sr } = defineProps<{
|
||||
sr: XenApiSr
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { deleteSrs, canDeleteSrs, isDeletingSrs, deleteSrsErrorMessage } = useSrDelete(() => [sr])
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
.delete {
|
||||
color: var(--color-danger-item-base);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<MenuItem
|
||||
v-tooltip="!canDisconnectSrs && disconnectSrsErrorMessage"
|
||||
icon="action:disconnect"
|
||||
:disabled="!canDisconnectSrs"
|
||||
:busy="isDisconnectingSrs"
|
||||
@click="disconnectSrs()"
|
||||
>
|
||||
{{ t('action:disconnect') }}
|
||||
<UiCounter
|
||||
v-if="shouldShowTargetCount(scope, disconnectionTargetCount)"
|
||||
:value="disconnectionTargetCount"
|
||||
accent="brand"
|
||||
variant="secondary"
|
||||
size="small"
|
||||
/>
|
||||
<i v-if="hint">{{ hint }}</i>
|
||||
</MenuItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useSrConnection } from '@/modules/storage-repository/composables/use-sr-connection.composable.ts'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { type SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { shouldShowTargetCount } from '@core/utils/sr.utils.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { sr, scope } = defineProps<{
|
||||
sr: XenApiSr
|
||||
scope: SrScope
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { disconnectSrs, canDisconnectSrs, isDisconnectingSrs, disconnectSrsErrorMessage, disconnectionTargetCount } =
|
||||
useSrConnection({
|
||||
srs: () => [sr],
|
||||
scope: () => scope,
|
||||
})
|
||||
|
||||
const hint = computed(() => (!canDisconnectSrs.value ? disconnectSrsErrorMessage.value : undefined))
|
||||
</script>
|
||||
@@ -13,7 +13,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<VtsRow v-for="sr of paginatedSrs" :key="sr.uuid" :selected="selectedSrId === sr.uuid">
|
||||
<BodyCells :item="sr" />
|
||||
<BodyCells :key="getSrPbdsSignature(sr, scope)" :item="sr" />
|
||||
</VtsRow>
|
||||
</tbody>
|
||||
</VtsTable>
|
||||
@@ -23,8 +23,9 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiPool, XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { usePbdUtils } from '@/modules/storage-repository/composables/pbd-utils.composable.ts'
|
||||
import { usePbdStore } from '@/stores/xen-api/pbd.store.ts'
|
||||
import { useGetPbdsInScope, useSrUtils } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import { useSrConnection } from '@/modules/storage-repository/composables/use-sr-connection.composable.ts'
|
||||
import { useSrDelete } from '@/modules/storage-repository/composables/use-sr-delete.composable.ts'
|
||||
import { useSrStore } from '@/stores/xen-api/sr.store.ts'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
@@ -33,19 +34,23 @@ import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { usePagination } from '@core/composables/pagination.composable.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { icon, objectIcon } from '@core/icons'
|
||||
import { icon } from '@core/icons'
|
||||
import { useSrColumns } from '@core/tables/column-sets/sr-columns.ts'
|
||||
import { type SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { shouldShowTargetCount } from '@core/utils/sr.utils.ts'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const {
|
||||
srs: rawSrs,
|
||||
pool,
|
||||
scope,
|
||||
busy,
|
||||
error,
|
||||
} = defineProps<{
|
||||
srs: XenApiSr[]
|
||||
pool: XenApiPool
|
||||
scope: SrScope
|
||||
busy?: boolean
|
||||
error?: boolean
|
||||
}>()
|
||||
@@ -53,7 +58,6 @@ const {
|
||||
const { t } = useI18n()
|
||||
|
||||
const { isReady, hasError, isDefaultSr } = useSrStore().subscribe()
|
||||
const { getPbdsForSr } = usePbdStore().subscribe()
|
||||
|
||||
const selectedSrId = useRouteQuery('id')
|
||||
|
||||
@@ -87,6 +91,8 @@ const state = useTableState({
|
||||
|
||||
const { pageRecords: paginatedSrs, paginationBindings } = usePagination('srs', filteredSrs)
|
||||
|
||||
const { getSrPbdsSignature } = useGetPbdsInScope()
|
||||
|
||||
function getPrimaryIcon(sr: XenApiSr) {
|
||||
if (!isDefaultSr(sr, pool)) {
|
||||
return undefined
|
||||
@@ -102,20 +108,79 @@ const { HeadCells, BodyCells } = useSrColumns({
|
||||
body: (sr: XenApiSr) => {
|
||||
const rightIcon = computed(() => getPrimaryIcon(sr))
|
||||
|
||||
const { allPbdsConnectionStatus } = usePbdUtils(() => getPbdsForSr(sr.$ref))
|
||||
const { srStatusIcon } = useSrUtils(sr, () => scope)
|
||||
|
||||
const { deleteSrs, canDeleteSrs, isDeletingSrs, deleteSrsErrorMessage } = useSrDelete(() => [sr])
|
||||
|
||||
const {
|
||||
connectSrs,
|
||||
disconnectSrs,
|
||||
canConnectSrs,
|
||||
canDisconnectSrs,
|
||||
isConnectingSrs,
|
||||
isDisconnectingSrs,
|
||||
connectSrsErrorMessage,
|
||||
disconnectSrsErrorMessage,
|
||||
connectionTargetCount,
|
||||
disconnectionTargetCount,
|
||||
} = useSrConnection({
|
||||
srs: () => [sr],
|
||||
scope: () => scope,
|
||||
})
|
||||
|
||||
const connectLabel = computed(() =>
|
||||
shouldShowTargetCount(scope, connectionTargetCount.value)
|
||||
? t('action:connect-n', { n: connectionTargetCount.value })
|
||||
: t('action:connect')
|
||||
)
|
||||
|
||||
const disconnectLabel = computed(() =>
|
||||
shouldShowTargetCount(scope, disconnectionTargetCount.value)
|
||||
? t('action:disconnect-n', { n: disconnectionTargetCount.value })
|
||||
: t('action:disconnect')
|
||||
)
|
||||
|
||||
return {
|
||||
storageRepository: r =>
|
||||
r({
|
||||
label: sr.name_label,
|
||||
icon: objectIcon('sr', allPbdsConnectionStatus.value),
|
||||
icon: srStatusIcon.value,
|
||||
rightIcon: rightIcon.value,
|
||||
}),
|
||||
description: r => r(sr.name_description),
|
||||
storageFormat: r => r(sr.type),
|
||||
accessMode: r => r(sr.shared ? t('shared') : t('local')),
|
||||
usedSpace: r => r(sr.physical_utilisation, sr.physical_size),
|
||||
actions: r => r({ onClick: () => (selectedSrId.value = sr.uuid) }),
|
||||
actions: r =>
|
||||
r({
|
||||
onClick: () => (selectedSrId.value = sr.uuid),
|
||||
actions: [
|
||||
{
|
||||
label: connectLabel.value,
|
||||
icon: 'action:connect',
|
||||
onClick: () => connectSrs(),
|
||||
busy: isConnectingSrs.value,
|
||||
disabled: !canConnectSrs.value,
|
||||
hint: connectSrsErrorMessage.value,
|
||||
},
|
||||
{
|
||||
label: disconnectLabel.value,
|
||||
icon: 'action:disconnect',
|
||||
onClick: () => disconnectSrs(),
|
||||
busy: isDisconnectingSrs.value,
|
||||
disabled: !canDisconnectSrs.value,
|
||||
hint: disconnectSrsErrorMessage.value,
|
||||
},
|
||||
{
|
||||
label: t('action:delete'),
|
||||
icon: 'action:delete',
|
||||
onClick: () => deleteSrs(),
|
||||
busy: isDeletingSrs.value,
|
||||
disabled: !canDeleteSrs.value,
|
||||
hint: deleteSrsErrorMessage.value,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
<template>
|
||||
<VtsSidePanel :has-selection="!!sr" @close="emit('close')">
|
||||
<template v-if="sr">
|
||||
<VtsSidePanel :key="panelSignature" :has-selection="!!sr" @close="emit('close')">
|
||||
<template v-if="sr" #actions>
|
||||
<SrConnectButton :scope :sr />
|
||||
<MenuList placement="bottom-end">
|
||||
<template #trigger="{ open }">
|
||||
<UiButtonIcon accent="brand" icon="action:more-actions" size="medium" @click="open($event)" />
|
||||
</template>
|
||||
<SrDisconnectButton :scope :sr />
|
||||
<SrDeleteButton :sr />
|
||||
</MenuList>
|
||||
</template>
|
||||
<template v-if="sr" #default>
|
||||
<VtsStateHero v-if="!isReady" format="panel" type="busy" size="medium" />
|
||||
<template v-else>
|
||||
<StorageRepositoryInfosCard :pool :sr />
|
||||
<StorageRepositoryInfosCard :pool :scope :sr />
|
||||
<StorageRepositorySpaceCard :sr />
|
||||
<StorageRepositoryVdisCard :vdis :vdi-snapshots />
|
||||
<StorageRepositoryHostsCard :hosts />
|
||||
<StorageRepositoryPbdsCard :pbds />
|
||||
<StorageRepositoryPbdsCard :scope :sr />
|
||||
<StorageRepositoryCustomFieldsCard :custom-fields />
|
||||
</template>
|
||||
</template>
|
||||
@@ -16,23 +26,31 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiHost, XenApiPool, XenApiSr, XenApiVdi } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import SrConnectButton from '@/modules/storage-repository/components/actions/connect/SrConnectButton.vue'
|
||||
import SrDeleteButton from '@/modules/storage-repository/components/actions/delete/SrDeleteButton.vue'
|
||||
import SrDisconnectButton from '@/modules/storage-repository/components/actions/disconnect/SrDisconnectButton.vue'
|
||||
import StorageRepositoryCustomFieldsCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositoryCustomFieldsCard.vue'
|
||||
import StorageRepositoryHostsCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositoryHostsCard.vue'
|
||||
import StorageRepositoryInfosCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositoryInfosCard.vue'
|
||||
import StorageRepositoryPbdsCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositoryPbdsCard.vue'
|
||||
import StorageRepositorySpaceCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositorySpaceCard.vue'
|
||||
import StorageRepositoryVdisCard from '@/modules/storage-repository/components/list/panel/cards/StorageRepositoryVdisCard.vue'
|
||||
import { useGetPbdsInScope } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store.ts'
|
||||
import { usePbdStore } from '@/stores/xen-api/pbd.store.ts'
|
||||
import { useVdiStore } from '@/stores/xen-api/vdi.store.ts'
|
||||
import type { SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const { sr, pool } = defineProps<{
|
||||
const { sr, pool, scope } = defineProps<{
|
||||
sr?: XenApiSr
|
||||
pool: XenApiPool
|
||||
scope: SrScope
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -63,6 +81,9 @@ const pbds = computed(() => {
|
||||
|
||||
return getPbdsForSr(sr.$ref)
|
||||
})
|
||||
const { getSrPbdsSignature } = useGetPbdsInScope()
|
||||
|
||||
const panelSignature = computed(() => getSrPbdsSignature(sr, scope))
|
||||
|
||||
const hosts = computed(() =>
|
||||
pbds.value.map(pbd => getHostByOpaqueRef(pbd.host)).filter((host): host is XenApiHost => host !== undefined)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<UiCard class="card-container">
|
||||
<UiCardTitle>
|
||||
<div v-if="sr.name_label" class="title">
|
||||
<VtsIcon :name="`object:sr:${allPbdsConnectionStatus}`" size="medium" />
|
||||
<VtsIcon :name="srStatusIcon" size="medium" />
|
||||
{{ sr.name_label }}
|
||||
</div>
|
||||
</UiCardTitle>
|
||||
@@ -11,7 +11,7 @@
|
||||
<VtsCardRowKeyValue>
|
||||
<template #key>{{ t('status') }}</template>
|
||||
<template #value>
|
||||
<VtsStatus :status="allPbdsConnectionStatus" />
|
||||
<VtsStatus :status="srConnectionStatus" />
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
<VtsCardRowKeyValue truncate align-top>
|
||||
@@ -63,9 +63,9 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiPool, XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { usePbdUtils } from '@/modules/storage-repository/composables/pbd-utils.composable.ts'
|
||||
import { usePbdStore } from '@/stores/xen-api/pbd.store.ts'
|
||||
import { useSrUtils } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import { useSrStore } from '@/stores/xen-api/sr.store.ts'
|
||||
import type { SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
|
||||
import VtsCodeSnippet from '@core/components/code-snippet/VtsCodeSnippet.vue'
|
||||
import VtsCopyButton from '@core/components/copy-button/VtsCopyButton.vue'
|
||||
@@ -78,17 +78,20 @@ import UiTagsList from '@core/components/ui/tag/UiTagsList.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { sr, pool } = defineProps<{
|
||||
const { sr, pool, scope } = defineProps<{
|
||||
sr: XenApiSr
|
||||
pool: XenApiPool
|
||||
scope: SrScope
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getPbdsForSr } = usePbdStore().subscribe()
|
||||
const { isHaSr: isHaSrForPool, getAllocationStrategy } = useSrStore().subscribe()
|
||||
|
||||
const { allPbdsConnectionStatus } = usePbdUtils(() => getPbdsForSr(sr.$ref))
|
||||
const { srConnectionStatus, srStatusIcon } = useSrUtils(
|
||||
() => sr,
|
||||
() => scope
|
||||
)
|
||||
|
||||
const isSrSharedI18nValue = computed(() => (sr.shared ? t('shared') : t('local')))
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
<UiCardTitle>
|
||||
{{ t('pbd-details') }}
|
||||
</UiCardTitle>
|
||||
<VtsStateHero v-if="pbds.length === 0" type="no-data" format="card" horizontal size="extra-small">
|
||||
<VtsStateHero v-if="pbdsInScope.length === 0" type="no-data" format="card" horizontal size="extra-small">
|
||||
{{ t('no-pbd-attached') }}
|
||||
</VtsStateHero>
|
||||
<template v-else>
|
||||
<div class="content">
|
||||
<VtsStatus :status="allPbdsConnectionStatus" />
|
||||
<VtsStatus :status="srConnectionStatus" />
|
||||
</div>
|
||||
<div v-if="areSomePbdsDisconnected" class="content">
|
||||
<template v-for="(pbd, index) in disconnectedPbds" :key="pbd.uuid">
|
||||
@@ -39,9 +39,11 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiPbd } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import StorageRepositoryPbdHost from '@/modules/storage-repository/components/list/panel/card-items/StorageRepositoryPbdHost.vue'
|
||||
import { usePbdUtils } from '@/modules/storage-repository/composables/pbd-utils.composable.ts'
|
||||
import { useSrUtils } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import type { SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import VtsCardRowKeyValue from '@core/components/card/VtsCardRowKeyValue.vue'
|
||||
import VtsDivider from '@core/components/divider/VtsDivider.vue'
|
||||
import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
@@ -52,13 +54,19 @@ import UiLogEntryViewer from '@core/components/ui/log-entry-viewer/UiLogEntryVie
|
||||
import { CONNECTION_STATUS } from '@core/types/connection.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { pbds } = defineProps<{
|
||||
pbds: XenApiPbd[]
|
||||
const { sr, scope } = defineProps<{
|
||||
sr: XenApiSr
|
||||
scope: SrScope
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { areSomePbdsDisconnected, allPbdsConnectionStatus, disconnectedPbds } = usePbdUtils(() => pbds)
|
||||
const { pbdsInScope, srConnectionStatus } = useSrUtils(
|
||||
() => sr,
|
||||
() => scope
|
||||
)
|
||||
|
||||
const { areSomePbdsDisconnected, disconnectedPbds } = usePbdUtils(pbdsInScope)
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import type { XenApiPbd, XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { usePbdUtils } from '@/modules/storage-repository/composables/pbd-utils.composable.ts'
|
||||
import { usePbdStore } from '@/stores/xen-api/pbd.store.ts'
|
||||
import { type IconName, objectIcon } from '@core/icons'
|
||||
import { SR_SCOPE_TYPE, type SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import { computed, type MaybeRefOrGetter } from 'vue'
|
||||
|
||||
export function useGetPbdsInScope() {
|
||||
const { getPbdsForSr } = usePbdStore().subscribe()
|
||||
|
||||
function getPbdsInScope(sr: XenApiSr, scope: SrScope): XenApiPbd[] {
|
||||
const pbds = getPbdsForSr(sr.$ref)
|
||||
|
||||
if (scope.type === SR_SCOPE_TYPE.POOL) {
|
||||
return pbds
|
||||
}
|
||||
|
||||
const { hostId } = scope
|
||||
|
||||
return pbds.filter(pbd => pbd.host === hostId)
|
||||
}
|
||||
|
||||
function getAttachedPbdsInScope(sr: XenApiSr, scope: SrScope): XenApiPbd[] {
|
||||
return getPbdsInScope(sr, scope).filter(pbd => pbd.currently_attached)
|
||||
}
|
||||
|
||||
function getDetachedPbdsInScope(sr: XenApiSr, scope: SrScope): XenApiPbd[] {
|
||||
return getPbdsInScope(sr, scope).filter(pbd => !pbd.currently_attached)
|
||||
}
|
||||
|
||||
function getSrPbdsSignature(sr: XenApiSr | undefined, scope: SrScope) {
|
||||
if (sr === undefined) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const scopedPbds = getPbdsInScope(sr, scope)
|
||||
|
||||
return scopedPbds.map(pbd => `${pbd.uuid}:${pbd.currently_attached}`).join('|') || sr.uuid
|
||||
}
|
||||
|
||||
function isPartiallyConnectedInScope(sr: XenApiSr, scope: SrScope) {
|
||||
const pbds = getPbdsInScope(sr, scope)
|
||||
|
||||
return pbds.some(pbd => pbd.currently_attached) && pbds.some(pbd => !pbd.currently_attached)
|
||||
}
|
||||
|
||||
return {
|
||||
getPbdsInScope,
|
||||
getAttachedPbdsInScope,
|
||||
getDetachedPbdsInScope,
|
||||
getSrPbdsSignature,
|
||||
isPartiallyConnectedInScope,
|
||||
}
|
||||
}
|
||||
|
||||
export function useSrUtils(
|
||||
rawSr?: MaybeRefOrGetter<XenApiSr | undefined>,
|
||||
rawScope: MaybeRefOrGetter<SrScope> = { type: SR_SCOPE_TYPE.POOL }
|
||||
) {
|
||||
const sr = toComputed(rawSr)
|
||||
const scope = toComputed(rawScope)
|
||||
|
||||
const { getPbdsInScope, isPartiallyConnectedInScope: getIsPartiallyConnectedInScope } = useGetPbdsInScope()
|
||||
|
||||
const pbdsInScope = computed(() => {
|
||||
if (sr.value === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
return getPbdsInScope(sr.value, scope.value)
|
||||
})
|
||||
|
||||
const isPartiallyConnectedInScope = computed(() => {
|
||||
if (sr.value === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
return getIsPartiallyConnectedInScope(sr.value, scope.value)
|
||||
})
|
||||
|
||||
const { allPbdsConnectionStatus } = usePbdUtils(pbdsInScope)
|
||||
|
||||
const srStatusIcon = computed<IconName>(() => objectIcon('sr', allPbdsConnectionStatus.value))
|
||||
|
||||
return {
|
||||
pbdsInScope,
|
||||
srConnectionStatus: allPbdsConnectionStatus,
|
||||
isPartiallyConnectedInScope,
|
||||
srStatusIcon,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import { usePbdPlugJob } from '@/jobs/pbd-plug.job.ts'
|
||||
import { usePbdUnplugJob } from '@/jobs/pbd-unplug.job.ts'
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useGetPbdsInScope } from '@/modules/storage-repository/composables/sr-utils.composable.ts'
|
||||
import type { SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { CONNECTION_ACTION } from '@core/types/connection.ts'
|
||||
import { getSrAccessMode } from '@core/utils/sr.utils.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import { computed, type MaybeRefOrGetter } from 'vue'
|
||||
|
||||
export function useSrConnection(options: { srs: MaybeRefOrGetter<XenApiSr[]>; scope: MaybeRefOrGetter<SrScope> }) {
|
||||
const srs = toComputed(options.srs)
|
||||
const scope = toComputed(options.scope)
|
||||
|
||||
const { getAttachedPbdsInScope, getDetachedPbdsInScope } = useGetPbdsInScope()
|
||||
|
||||
const connectionTargets = computed(() => srs.value.flatMap(sr => getDetachedPbdsInScope(sr, scope.value)))
|
||||
const disconnectionTargets = computed(() => srs.value.flatMap(sr => getAttachedPbdsInScope(sr, scope.value)))
|
||||
|
||||
const connectionTargetCount = computed(() => connectionTargets.value.length)
|
||||
const disconnectionTargetCount = computed(() => disconnectionTargets.value.length)
|
||||
|
||||
const {
|
||||
run: runConnect,
|
||||
canRun: canConnectSrs,
|
||||
isRunning: isConnectingSrs,
|
||||
errorMessage: connectSrsErrorMessage,
|
||||
} = usePbdPlugJob(connectionTargets)
|
||||
|
||||
const {
|
||||
run: runDisconnect,
|
||||
canRun: canDisconnectSrs,
|
||||
isRunning: isDisconnectingSrs,
|
||||
errorMessage: disconnectSrsErrorMessage,
|
||||
} = usePbdUnplugJob(disconnectionTargets)
|
||||
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@core/components/sr-connection-modal/VtsSrConnectionModal.vue'),
|
||||
events: {
|
||||
onConfirm: true,
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
function connectSrs() {
|
||||
return open({
|
||||
props: {
|
||||
action: CONNECTION_ACTION.CONNECT,
|
||||
count: srs.value.length,
|
||||
scope: scope.value,
|
||||
accessMode: getSrAccessMode(srs.value),
|
||||
hostsCount: connectionTargetCount.value,
|
||||
},
|
||||
events: {
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await runConnect()
|
||||
} catch (error) {
|
||||
console.error('Error when connecting SR:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function disconnectSrs() {
|
||||
return open({
|
||||
props: {
|
||||
action: CONNECTION_ACTION.DISCONNECT,
|
||||
count: srs.value.length,
|
||||
scope: scope.value,
|
||||
accessMode: getSrAccessMode(srs.value),
|
||||
hostsCount: disconnectionTargetCount.value,
|
||||
},
|
||||
events: {
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await runDisconnect()
|
||||
} catch (error) {
|
||||
console.error('Error when disconnecting SR:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
connectSrs,
|
||||
disconnectSrs,
|
||||
canConnectSrs,
|
||||
canDisconnectSrs,
|
||||
isConnectingSrs,
|
||||
isDisconnectingSrs,
|
||||
connectSrsErrorMessage,
|
||||
disconnectSrsErrorMessage,
|
||||
connectionTargetCount,
|
||||
disconnectionTargetCount,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { useSrDeleteJob } from '@/jobs/sr-delete.job.ts'
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useDeleteModal } from '@core/composables/modals/use-delete-modal.ts'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import type { MaybeRefOrGetter } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
export function useSrDelete(rawSrs: MaybeRefOrGetter<XenApiSr[]>) {
|
||||
const srs = toComputed(rawSrs)
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const selectedSrId = useRouteQuery('id')
|
||||
|
||||
const {
|
||||
run,
|
||||
canRun: canDeleteSrs,
|
||||
isRunning: isDeletingSrs,
|
||||
errorMessage: deleteSrsErrorMessage,
|
||||
} = useSrDeleteJob(srs)
|
||||
|
||||
const { open } = useDeleteModal()
|
||||
|
||||
function deleteSrs() {
|
||||
const count = srs.value.length
|
||||
|
||||
// TODO Add a type-to-confirm input if count > 1
|
||||
return open({
|
||||
props: {
|
||||
subject: t('n-srs', { n: count }),
|
||||
description: t('sr-delete-info', { n: count }),
|
||||
confirmLabel: t('action:delete-n-srs', { n: count }),
|
||||
},
|
||||
events: {
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await run()
|
||||
|
||||
if (srs.value.some(sr => sr.uuid === selectedSrId.value)) {
|
||||
selectedSrId.value = ''
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error when deleting SR:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return { deleteSrs, canDeleteSrs, isDeletingSrs, deleteSrsErrorMessage }
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<UiButton
|
||||
v-tooltip="!canToggleVifConnection && toggleConnectionErrorMessage"
|
||||
v-tooltip="!connection.canToggle && connection.errorMessage"
|
||||
size="medium"
|
||||
variant="tertiary"
|
||||
accent="brand"
|
||||
:disabled="!canToggleVifConnection"
|
||||
:disabled="!connection.canToggle"
|
||||
:left-icon="connection.icon"
|
||||
:busy="isTogglingVifConnection"
|
||||
@click="openVifConnectionToggleModal()"
|
||||
:busy="connection.isToggling"
|
||||
@click="connection.toggle()"
|
||||
>
|
||||
{{ connection.label }}
|
||||
</UiButton>
|
||||
@@ -15,12 +15,11 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiVif, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVifConnectionToggleModal } from '@/modules/vif/composables/use-vif-connection-toggle-modal.composable.ts'
|
||||
import { useVifConnection } from '@/modules/vif/composables/use-vif-connection.composable.ts'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { useMapper } from '@core/packages/mapper'
|
||||
import { CONNECTION_ACTION } from '@core/types/connection.ts'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { vif, vm } = defineProps<{
|
||||
@@ -30,25 +29,40 @@ const { vif, vm } = defineProps<{
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const action = computed(() => (vif.currently_attached ? CONNECTION_ACTION.DISCONNECT : CONNECTION_ACTION.CONNECT))
|
||||
const {
|
||||
connectVifs,
|
||||
disconnectVifs,
|
||||
canConnectVifs,
|
||||
canDisconnectVifs,
|
||||
isConnectingVifs,
|
||||
isDisconnectingVifs,
|
||||
connectVifsErrorMessage,
|
||||
disconnectVifsErrorMessage,
|
||||
} = useVifConnection({
|
||||
vifs: () => [vif],
|
||||
vm: () => vm,
|
||||
})
|
||||
|
||||
const connection = useMapper(
|
||||
() => action.value,
|
||||
() => (vif.currently_attached ? CONNECTION_ACTION.DISCONNECT : CONNECTION_ACTION.CONNECT),
|
||||
() => ({
|
||||
connect: { label: t('action:connect'), icon: 'action:connect' },
|
||||
disconnect: { label: t('action:disconnect'), icon: 'action:disconnect' },
|
||||
connect: {
|
||||
label: t('action:connect'),
|
||||
icon: 'action:connect' as const,
|
||||
toggle: connectVifs,
|
||||
canToggle: canConnectVifs.value,
|
||||
isToggling: isConnectingVifs.value,
|
||||
errorMessage: connectVifsErrorMessage.value,
|
||||
},
|
||||
disconnect: {
|
||||
label: t('action:disconnect'),
|
||||
icon: 'action:disconnect' as const,
|
||||
toggle: disconnectVifs,
|
||||
canToggle: canDisconnectVifs.value,
|
||||
isToggling: isDisconnectingVifs.value,
|
||||
errorMessage: disconnectVifsErrorMessage.value,
|
||||
},
|
||||
}),
|
||||
'connect'
|
||||
)
|
||||
|
||||
const {
|
||||
openModal: openVifConnectionToggleModal,
|
||||
canRun: canToggleVifConnection,
|
||||
isRunning: isTogglingVifConnection,
|
||||
errorMessage: toggleConnectionErrorMessage,
|
||||
} = useVifConnectionToggleModal(
|
||||
action,
|
||||
() => [vif],
|
||||
() => vm
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import type { XenApiVif, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVifConnectJob } from '@/modules/vif/jobs/vif-connect.job.ts'
|
||||
import { useVifDisconnectJob } from '@/modules/vif/jobs/vif-disconnect.job.ts'
|
||||
import { useModal } from '@core/packages/modal/use-modal.ts'
|
||||
import { CONNECTION_ACTION, type ConnectionAction } from '@core/types/connection.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import { computed, type MaybeRefOrGetter } from 'vue'
|
||||
|
||||
export function useVifConnectionToggleModal(
|
||||
rawAction: MaybeRefOrGetter<ConnectionAction>,
|
||||
rawVifs: MaybeRefOrGetter<XenApiVif[]>,
|
||||
rawVm: MaybeRefOrGetter<XenApiVm>
|
||||
) {
|
||||
const action = toComputed(rawAction)
|
||||
const vifs = toComputed(rawVifs)
|
||||
const vm = toComputed(rawVm)
|
||||
|
||||
const connectJob = useVifConnectJob(vifs, vm)
|
||||
const disconnectJob = useVifDisconnectJob(vifs, vm)
|
||||
|
||||
const job = computed(() => (action.value === CONNECTION_ACTION.CONNECT ? connectJob : disconnectJob))
|
||||
|
||||
const canRun = computed(() => job.value.canRun.value)
|
||||
const isRunning = computed(() => job.value.isRunning.value)
|
||||
const errorMessage = computed(() => job.value.errorMessage.value)
|
||||
|
||||
const openModal = useModal(() => ({
|
||||
component: import('@core/components/vif-connection-toggle-modal/VtsVifConnectionToggleModal.vue'),
|
||||
props: { action: action.value, count: vifs.value.length },
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await job.value.run()
|
||||
} catch (error) {
|
||||
console.error(`Error when ${action.value}ing VIF:`, error)
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
return { openModal, canRun, isRunning, errorMessage }
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { XenApiVif, XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVifConnectJob } from '@/modules/vif/jobs/vif-connect.job.ts'
|
||||
import { useVifDisconnectJob } from '@/modules/vif/jobs/vif-disconnect.job.ts'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { CONNECTION_ACTION } from '@core/types/connection.ts'
|
||||
import { toComputed } from '@core/utils/to-computed.util.ts'
|
||||
import type { MaybeRefOrGetter } from 'vue'
|
||||
|
||||
export function useVifConnection(options: { vifs: MaybeRefOrGetter<XenApiVif[]>; vm: MaybeRefOrGetter<XenApiVm> }) {
|
||||
const vifs = toComputed(options.vifs)
|
||||
const vm = toComputed(options.vm)
|
||||
|
||||
const {
|
||||
run: runConnect,
|
||||
canRun: canConnectVifs,
|
||||
isRunning: isConnectingVifs,
|
||||
errorMessage: connectVifsErrorMessage,
|
||||
} = useVifConnectJob(vifs, vm)
|
||||
|
||||
const {
|
||||
run: runDisconnect,
|
||||
canRun: canDisconnectVifs,
|
||||
isRunning: isDisconnectingVifs,
|
||||
errorMessage: disconnectVifsErrorMessage,
|
||||
} = useVifDisconnectJob(vifs, vm)
|
||||
|
||||
const { open } = useOverlay({
|
||||
component: () => import('@core/components/vif-connection-modal/VtsVifConnectionModal.vue'),
|
||||
events: {
|
||||
onConfirm: true,
|
||||
onCancel: true,
|
||||
},
|
||||
})
|
||||
|
||||
function connectVifs() {
|
||||
return open({
|
||||
props: {
|
||||
action: CONNECTION_ACTION.CONNECT,
|
||||
count: vifs.value.length,
|
||||
},
|
||||
events: {
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await runConnect()
|
||||
} catch (error) {
|
||||
console.error('Error when connecting VIF:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function disconnectVifs() {
|
||||
return open({
|
||||
props: {
|
||||
action: CONNECTION_ACTION.DISCONNECT,
|
||||
count: vifs.value.length,
|
||||
},
|
||||
events: {
|
||||
onConfirm: async () => {
|
||||
try {
|
||||
await runDisconnect()
|
||||
} catch (error) {
|
||||
console.error('Error when disconnecting VIF:', error)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
connectVifs,
|
||||
disconnectVifs,
|
||||
canConnectVifs,
|
||||
canDisconnectVifs,
|
||||
isConnectingVifs,
|
||||
isDisconnectingVifs,
|
||||
connectVifsErrorMessage,
|
||||
disconnectVifsErrorMessage,
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
<template>
|
||||
<VtsContentSidePanel class="host-storage-view" :class="{ mobile: uiStore.isSmall }">
|
||||
<UiCard class="container">
|
||||
<StorageRepositoriesTable v-if="pool" :srs :pool :busy="!isReady" :error="hasError" />
|
||||
<StorageRepositoriesTable v-if="pool && host && scope" :srs :pool :scope :busy="!isReady" :error="hasError" />
|
||||
</UiCard>
|
||||
<StorageRepositorySidePanel v-if="pool" :sr="selectedSr" :pool @close="selectedSr = undefined" />
|
||||
<StorageRepositorySidePanel
|
||||
v-if="pool && host && scope"
|
||||
:sr="selectedSr"
|
||||
:pool
|
||||
:scope
|
||||
@close="selectedSr = undefined"
|
||||
/>
|
||||
</VtsContentSidePanel>
|
||||
</template>
|
||||
|
||||
@@ -20,6 +26,7 @@ import VtsContentSidePanel from '@core/components/layout/VtsContentSidePanel.vue
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { SR_SCOPE_TYPE, type SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { sortByNameLabel } from '@core/utils/sort-by-name-label.util.ts'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
@@ -42,7 +49,18 @@ const isReady = logicAnd(areSrsReady, arePbdsReady)
|
||||
|
||||
const host = computed(() => getHostByUuid(route.params.uuid as XenApiHost['uuid']))
|
||||
|
||||
const srs = computed(() => {
|
||||
const scope = computed((): SrScope | undefined => {
|
||||
if (host.value === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return {
|
||||
type: SR_SCOPE_TYPE.HOST,
|
||||
hostId: host.value.$ref,
|
||||
}
|
||||
})
|
||||
|
||||
const srs = computed((): XenApiSr[] => {
|
||||
if (host.value === undefined) {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<template>
|
||||
<VtsContentSidePanel class="pool-storage-view" :class="{ mobile: uiStore.isSmall }">
|
||||
<UiCard class="container">
|
||||
<StorageRepositoriesTable v-if="pool" :srs="sortedSrs" :pool :busy="!isReady" :error="hasError" />
|
||||
<StorageRepositoriesTable v-if="pool" :srs="sortedSrs" :pool :scope :busy="!isReady" :error="hasError" />
|
||||
</UiCard>
|
||||
<StorageRepositorySidePanel v-if="pool" :sr="selectedSr" :pool @close="selectedSr = undefined" />
|
||||
<StorageRepositorySidePanel v-if="pool" :sr="selectedSr" :pool :scope @close="selectedSr = undefined" />
|
||||
</VtsContentSidePanel>
|
||||
</template>
|
||||
|
||||
@@ -19,6 +19,7 @@ import VtsContentSidePanel from '@core/components/layout/VtsContentSidePanel.vue
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable.ts'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { SR_SCOPE_TYPE, type SrScope } from '@core/types/storage-repository.type.ts'
|
||||
import { sortByNameLabel } from '@core/utils/sort-by-name-label.util.ts'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
@@ -35,6 +36,8 @@ const uiStore = useUiStore()
|
||||
|
||||
const isReady = logicAnd(areSrsReady, arePbdsReady)
|
||||
|
||||
const scope: SrScope = { type: SR_SCOPE_TYPE.POOL }
|
||||
|
||||
const sortedSrs = computed(() => [...srs.value].sort(sortByNameLabel))
|
||||
|
||||
const selectedSr = useRouteQuery<XenApiSr | undefined>('id', {
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
<VtsKeyValueList>
|
||||
<VtsKeyValueRow>
|
||||
<template #label>
|
||||
<VtsSelect :id="localeSelectId" icon="fa:earth-americas" accent="brand" />
|
||||
<VtsSelect :id="localeSelectId" accent="brand" />
|
||||
</template>
|
||||
<template #value>
|
||||
<UiLink size="medium" href="https://translate.vates.tech/engage/xen-orchestra/">
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user