mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-16 20:11:12 -06:00
Compare commits
1 Commits
fix_ldap_u
...
debug_time
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9829eb58f3 |
16
.eslintrc.js
16
.eslintrc.js
@@ -85,21 +85,6 @@ module.exports = {
|
||||
XO_LITE_GIT_HEAD: true,
|
||||
},
|
||||
rules: {
|
||||
'import/extensions': [
|
||||
'error',
|
||||
'ignorePackages',
|
||||
{
|
||||
pattern: { ts: 'always', vue: 'always' },
|
||||
checkTypeImports: true,
|
||||
// '@core/*' and '@/*' look like scoped packages to the plugin, which 'ignorePackages' would skip
|
||||
pathGroupOverrides: [
|
||||
{ pattern: '@core/packages/*', action: 'ignore' }, // barrel files
|
||||
{ pattern: '@core/icons', action: 'ignore' },
|
||||
{ pattern: '@core/**', action: 'enforce' },
|
||||
{ pattern: '@/**', action: 'enforce' },
|
||||
],
|
||||
},
|
||||
],
|
||||
'import/order': [
|
||||
'error',
|
||||
{
|
||||
@@ -269,7 +254,6 @@ module.exports = {
|
||||
'zh-Hans',
|
||||
'sk',
|
||||
'pt',
|
||||
'ar',
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -5,7 +5,3 @@
|
||||
# Generated files
|
||||
/@xen-orchestra/web/src/route-map.d.ts
|
||||
/@xen-orchestra/lite/src/route-map.d.ts
|
||||
|
||||
# Docusaurus MDX content: prettier's markdown parser corrupts JSX
|
||||
# comments ({/* … */} becomes {/_ … _/}) and other MDX constructs
|
||||
/docs/docs/**/*.md
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/multi-key-map": "^0.2.0",
|
||||
"@xen-orchestra/async-map": "^0.1.4",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"ensure-array": "^1.0.0"
|
||||
},
|
||||
|
||||
@@ -7,7 +7,6 @@ const { warn } = createLogger('vates:nbd-client:multi')
|
||||
export default class MultiNbdClient {
|
||||
#clients = []
|
||||
#nbdConcurrency
|
||||
#nextClient = 0
|
||||
#options
|
||||
#readAhead
|
||||
#settings
|
||||
@@ -98,31 +97,8 @@ export default class MultiNbdClient {
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
async readBlock(index, size = NBD_DEFAULT_BLOCK_SIZE) {
|
||||
const clientId = this.#nextClient++ % this.#clients.length
|
||||
const client = this.#clients[clientId]
|
||||
try {
|
||||
return await client.readBlock(index, size)
|
||||
} catch (err) {
|
||||
// client.readBlock() already exhausted its own retries/reconnects: this connection is dead.
|
||||
// Evict it so future reads stop being routed to it, and retry this read on a surviving
|
||||
// client, since the data is usually still reachable through the others.
|
||||
this.#evict(client)
|
||||
if (this.#clients.length === 0) {
|
||||
throw err
|
||||
}
|
||||
warn(`evicted a dead nbd client, retrying block ${index} on a remaining client`, { err })
|
||||
return this.readBlock(index, size)
|
||||
}
|
||||
}
|
||||
|
||||
// no-op if `client` was already evicted by a concurrent failed read on the same client
|
||||
#evict(client) {
|
||||
const i = this.#clients.indexOf(client)
|
||||
if (i === -1) {
|
||||
return
|
||||
}
|
||||
this.#clients.splice(i, 1)
|
||||
client.disconnect().catch(() => {})
|
||||
const clientId = index % this.#clients.length
|
||||
return this.#clients[clientId].readBlock(index, size)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
import { describe, it, mock } from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
|
||||
// MultiNbdClient instantiates NbdClient itself (`import NbdClient from './index.mjs'`), so the
|
||||
// only way to control individual connections from a unit test is to replace that module with a
|
||||
// fake before importing multi.mjs.
|
||||
const created = []
|
||||
class FakeNbdClient {
|
||||
constructor(nbdInfo) {
|
||||
this.nbdInfo = nbdInfo
|
||||
this.disconnected = false
|
||||
// overridden per-test after connect() to script this instance's behavior
|
||||
this.readBlock = async () => {
|
||||
throw new Error('readBlock not configured for this fake client')
|
||||
}
|
||||
created.push(this)
|
||||
}
|
||||
|
||||
async connect() {}
|
||||
|
||||
async disconnect() {
|
||||
this.disconnected = true
|
||||
}
|
||||
|
||||
async getMap() {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
mock.module('./index.mjs', {
|
||||
defaultExport: FakeNbdClient,
|
||||
})
|
||||
|
||||
const { default: MultiNbdClient } = await import('./multi.mjs')
|
||||
|
||||
// a single settings entry is enough: connect() reuses candidates across concurrent slots, so
|
||||
// nbdConcurrency still yields that many distinct FakeNbdClient instances
|
||||
async function connectWithFakes(nbdConcurrency) {
|
||||
created.length = 0
|
||||
const client = new MultiNbdClient({ address: 'fake-host' }, { nbdConcurrency })
|
||||
await client.connect()
|
||||
return { client, fakes: created.slice() }
|
||||
}
|
||||
|
||||
describe('MultiNbdClient.readBlock eviction', () => {
|
||||
it('evicts a client whose readBlock rejects and retries on a surviving client', async () => {
|
||||
const { client, fakes } = await connectWithFakes(2)
|
||||
const [dead, alive] = fakes
|
||||
dead.readBlock = async () => {
|
||||
throw new Error('connection is dead')
|
||||
}
|
||||
alive.readBlock = async index => Buffer.from([index])
|
||||
|
||||
// index 0 initially routes to `dead` (0 % 2 === 0)
|
||||
const data = await client.readBlock(0)
|
||||
|
||||
assert.deepStrictEqual(data, Buffer.from([0]))
|
||||
assert.strictEqual(dead.disconnected, true, 'the dead client should have been disconnected')
|
||||
|
||||
// future reads must no longer be routed to the evicted client: with only `alive` left,
|
||||
// every index should now succeed through it
|
||||
alive.readBlock = async index => Buffer.from([index])
|
||||
const data2 = await client.readBlock(1)
|
||||
assert.deepStrictEqual(data2, Buffer.from([1]))
|
||||
})
|
||||
|
||||
it('rejects once every client has been evicted, instead of retrying forever', async () => {
|
||||
const { client, fakes } = await connectWithFakes(2)
|
||||
const boom = new Error('connection is dead')
|
||||
for (const fake of fakes) {
|
||||
fake.readBlock = async () => {
|
||||
throw boom
|
||||
}
|
||||
}
|
||||
|
||||
await assert.rejects(() => client.readBlock(0), boom)
|
||||
assert.ok(
|
||||
fakes.every(fake => fake.disconnected),
|
||||
'every client should have been evicted (and disconnected) before giving up'
|
||||
)
|
||||
})
|
||||
|
||||
it('evicting the same dead client from concurrent failed reads is idempotent', async () => {
|
||||
const { client, fakes } = await connectWithFakes(2)
|
||||
const [dead, alive] = fakes
|
||||
dead.readBlock = async () => {
|
||||
throw new Error('connection is dead')
|
||||
}
|
||||
alive.readBlock = async index => Buffer.from([index])
|
||||
|
||||
let disconnectCalls = 0
|
||||
dead.disconnect = async () => {
|
||||
disconnectCalls++
|
||||
dead.disconnected = true
|
||||
}
|
||||
|
||||
// routing is round-robin by call order (0, 1, 0) over a 2-client pool: the 1st and 3rd
|
||||
// calls both land on `dead` before either failure has been handled, so they race to evict
|
||||
// the same client. The exact interleaving isn't guaranteed, only that eviction is safe
|
||||
// either way and every read still completes.
|
||||
const [data0, data1, data2] = await Promise.all([client.readBlock(10), client.readBlock(11), client.readBlock(12)])
|
||||
|
||||
assert.deepStrictEqual(data0, Buffer.from([10]))
|
||||
assert.deepStrictEqual(data1, Buffer.from([11]))
|
||||
assert.deepStrictEqual(data2, Buffer.from([12]))
|
||||
assert.strictEqual(disconnectCalls, 1, 'the dead client must only be evicted/disconnected once')
|
||||
})
|
||||
})
|
||||
|
||||
describe('MultiNbdClient.readBlock routing', () => {
|
||||
it('distributes reads round-robin by call order, not by index residue', async () => {
|
||||
const { client, fakes } = await connectWithFakes(4)
|
||||
const readsPerClient = fakes.map(() => 0)
|
||||
fakes.forEach((fake, i) => {
|
||||
fake.readBlock = async index => {
|
||||
readsPerClient[i]++
|
||||
return Buffer.from([index])
|
||||
}
|
||||
})
|
||||
|
||||
// a CBT-style changed-block set striding by exactly `nbdConcurrency`: under the old
|
||||
// `index % clients.length` routing this would collapse entirely onto a single client
|
||||
const stridedIndexes = Array.from({ length: 20 }, (_, i) => i * 4)
|
||||
for (const index of stridedIndexes) {
|
||||
await client.readBlock(index)
|
||||
}
|
||||
|
||||
assert.deepStrictEqual(readsPerClient, [5, 5, 5, 5])
|
||||
})
|
||||
})
|
||||
@@ -13,7 +13,7 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "3.5.1",
|
||||
"version": "3.5.0",
|
||||
"engines": {
|
||||
"node": ">=14.0"
|
||||
},
|
||||
@@ -21,11 +21,11 @@
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@vates/read-chunk": "^1.2.1",
|
||||
"@xen-orchestra/async-map": "^0.1.4",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"xen-api": "^4.9.0"
|
||||
"xen-api": "^4.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^18.7.0",
|
||||
@@ -33,7 +33,6 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --experimental-test-module-mocks --test",
|
||||
"test-integration": "tap --allow-incomplete-coverage tests/*.integ.mjs"
|
||||
"test-integration": "tap --allow-incomplete-coverage"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,13 +153,7 @@ CYu1Xn/FVPx1HoRgWc7E8wFhDcA/P3SJtfIQWHB9FzSaBflKGR4t8WCE2eE8+cTB
|
||||
nbdServer = await spawnNbdKit(path)
|
||||
}
|
||||
}
|
||||
// reading past the end of the export must reject: a single client so the failure isn't
|
||||
// multiplied by nbdConcurrency evicting and retrying on every other (equally healthy, equally
|
||||
// unable to satisfy this out-of-range request) client
|
||||
const singleClient = new MultiNbdClient(connectionSettings, { nbdConcurrency: 1, readAhead: 2 })
|
||||
await singleClient.connect()
|
||||
await assert.rejects(() => singleClient.readBlock(100, CHUNK_SIZE))
|
||||
await singleClient.disconnect()
|
||||
assert.rejects(() => client.readBlock(100, CHUNK_SIZE))
|
||||
|
||||
await client.disconnect()
|
||||
// double disconnection shouldn't pose any problem
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@vates/types",
|
||||
"private": false,
|
||||
"version": "2.0.1",
|
||||
"version": "1.30.1",
|
||||
"main": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
@@ -33,8 +33,7 @@
|
||||
"@eslint/js": "^9.19.0",
|
||||
"typescript": "~5.6.3",
|
||||
"typescript-eslint": "^8.61.0",
|
||||
"@types/express": "^5.0.0",
|
||||
"@xen-orchestra/disk-transform": "^1.3.3"
|
||||
"@types/express": "^5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { XapiXoRecord, XoHost, XoNetwork, XoVif } from './xo.mjs'
|
||||
import type { XoHost, XoNetwork, XoVif } from './xo.mjs'
|
||||
|
||||
declare const __brand: unique symbol
|
||||
|
||||
@@ -755,9 +755,9 @@ export type TrafficRuleDirection = 'from' | 'to' | 'from/to'
|
||||
|
||||
export type RawTrafficRule = {
|
||||
allow: boolean
|
||||
protocol: TrafficRuleProtocol
|
||||
protocol: string
|
||||
ipRange: string
|
||||
direction: TrafficRuleDirection
|
||||
direction: string
|
||||
port?: string
|
||||
}
|
||||
|
||||
@@ -769,29 +769,3 @@ type BaseTrafficRule = RawTrafficRule & {
|
||||
export type TrafficRule =
|
||||
| (BaseTrafficRule & { type: XoVif['type']; sourceId: XoVif['id'] })
|
||||
| (BaseTrafficRule & { type: XoNetwork['type']; sourceId: XoNetwork['id'] })
|
||||
|
||||
export const XAPI_TYPES: readonly string[] = [
|
||||
'network',
|
||||
'VIF',
|
||||
'message',
|
||||
'gpuGroup',
|
||||
'host',
|
||||
'PBD',
|
||||
'PCI',
|
||||
'PGPU',
|
||||
'PIF',
|
||||
'pool',
|
||||
'SR',
|
||||
'VBD',
|
||||
'VDI',
|
||||
'VDI-snapshot',
|
||||
'VDI-unmanaged',
|
||||
'vgpu',
|
||||
'vgpuType',
|
||||
'VM',
|
||||
'VM-controller',
|
||||
'VM-snapshot',
|
||||
'VM-template',
|
||||
'VTPM',
|
||||
'SM',
|
||||
] satisfies readonly XapiXoRecord['type'][]
|
||||
|
||||
@@ -4,34 +4,40 @@ import type { XoApp } from '../xo-app.mjs'
|
||||
|
||||
export type SecurityName = '*' | 'token' | 'basic' | 'none'
|
||||
|
||||
export type FieldDefinition = { optional?: boolean; nullable?: boolean } & (
|
||||
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' }
|
||||
|
||||
@@ -24,7 +24,6 @@ import type {
|
||||
VIF_LOCKING_MODE,
|
||||
VM_OPERATIONS,
|
||||
} from '../common.mjs'
|
||||
import type { DiskPassthrough } from '@xen-orchestra/disk-transform'
|
||||
import type { PassThrough, Readable } from 'node:stream'
|
||||
import type {
|
||||
XapiXoRecord,
|
||||
@@ -477,42 +476,3 @@ export interface Xapi {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters accepted by the `XapiDiskSource` constructor.
|
||||
*
|
||||
* `baseRef` turns the export into a differencing one: leaving it out exports the whole disk.
|
||||
* `preferNbd` only expresses a preference, {@link XapiDiskSource} silently falls back to a plain
|
||||
* stream export — and, when `baseRef` can't be used as a base, to a full one.
|
||||
*/
|
||||
export interface XapiDiskSourceOptions {
|
||||
baseRef?: XenApiVdi['$ref']
|
||||
blockSize?: number
|
||||
nbdConcurrency?: number
|
||||
/** When true, only `getBlockIndexes()` may be called: `readBlock()` throws. */
|
||||
onlyListChangedBlocks?: boolean
|
||||
preferNbd?: boolean
|
||||
timeout?: number
|
||||
vdiRef: XenApiVdi['$ref']
|
||||
xapi: Xapi
|
||||
}
|
||||
|
||||
/**
|
||||
* Disk source handling the fallback logic of a VDI export: NBD + CBT, then NBD + stream export
|
||||
* for the block list, then plain stream export.
|
||||
*
|
||||
* {@link XapiDiskSourceOptions.preferNbd} is a preference, not a guarantee: call
|
||||
* {@link XapiDiskSource.useNbd} and {@link XapiDiskSource.useCbt} after `init()` to know what the
|
||||
* export actually used.
|
||||
*/
|
||||
export interface XapiDiskSource extends DiskPassthrough {
|
||||
useCbt(): boolean
|
||||
useNbd(): boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Signature of `@xen-orchestra/xapi`'s `parseDateTime`.
|
||||
*
|
||||
* Returns a Unix timestamp in seconds, or `null` if the field is empty (as encoded by XAPI).
|
||||
*/
|
||||
export type ParseDateTime = (input: string | number | Date) => number | null
|
||||
|
||||
@@ -204,8 +204,6 @@ export type XoApp = {
|
||||
backupGuard(poolId: XoPool['id']): Promise<void>
|
||||
/* Throw if no authorization */
|
||||
checkFeatureAuthorization(featureCode: FeatureCode): Promise<void>
|
||||
/* validate, apply and persist the configuration of a plugin */
|
||||
configurePlugin(id: string, configuration: unknown, mergeWithExisting?: boolean): Promise<void>
|
||||
/* connect a server (XCP-ng/XenServer) */
|
||||
connectXenServer(id: XoServer['id']): Promise<void>
|
||||
// TODO: replace all XoAclBasePrivilege with a more strict type. (discriminate union)
|
||||
@@ -293,7 +291,7 @@ export type XoApp = {
|
||||
>
|
||||
>
|
||||
getAllSchedules(): Promise<XoSchedule[]>
|
||||
getAllUsers(opts?: { obfuscatePassword?: boolean }): Promise<XoUser[]>
|
||||
getAllUsers(): Promise<XoUser[]>
|
||||
getAllXenServers(): Promise<XoServer[]>
|
||||
getAuthenticationTokensForUser(userId: XoUser['id']): Promise<XoAuthenticationToken[]>
|
||||
getBackupNgLogs(): Promise<Record<string, AnyXoLog>>
|
||||
@@ -314,7 +312,7 @@ export type XoApp = {
|
||||
) => Record<T['id'], T> | undefined
|
||||
getTotalBackupSizeOnRemote(id: XoBackupRepository['id']): Promise<{ onDisk: number }>
|
||||
getSchedule(id: XoSchedule['id']): Promise<XoSchedule>
|
||||
getUser: (id: XoUser['id'], opts?: { obfuscatePassword?: boolean }) => Promise<XoUser>
|
||||
getUser: (id: XoUser['id']) => Promise<XoUser>
|
||||
getXapi(maybeId: XapiXoRecord['id'] | XapiXoRecord): Xapi
|
||||
getXapiHostStats: (hostId: XoHost['id'], granularity?: XapiStatsGranularity) => Promise<XapiHostStats>
|
||||
getXapiObject: <T extends XapiXoRecord>(
|
||||
@@ -324,18 +322,16 @@ export type XoApp = {
|
||||
getXapiPoolStats(poolId: XoPool['id'], granularity?: XapiStatsGranularity): Promise<XapiPoolStats>
|
||||
getXapiVmStats: (vmId: XoVm['id'], granularity?: XapiStatsGranularity) => Promise<XapiVmStats>
|
||||
getXenServer(id: XoServer['id']): Promise<XoServer>
|
||||
getXoEventEmitterByType(type: string): EventEmitter
|
||||
hasFeatureAuthorization(featureCode: string): Promise<boolean>
|
||||
hasObject<T extends XapiXoRecord>(id: T['id'], type: T['type']): boolean
|
||||
listMetadataBackups(backupRepositoryIds: XoBackupRepository['id'][]): Promise<{
|
||||
xo: Record<XoBackupRepository['id'], XoConfigBackupArchive[]>
|
||||
pool: Record<XoBackupRepository['id'], Record<XoPool['id'], XoPoolBackupArchive[]>>
|
||||
}>
|
||||
/** `null` when the listing of a backup repository failed */
|
||||
listVmBackupsNg(
|
||||
backupRepositoryIds: XoBackupRepository['id'][],
|
||||
opts?: { _forceRefresh?: boolean; vmId?: XoVm['id'] }
|
||||
): Promise<Record<XoBackupRepository['id'], Record<XoVm['id'], XoVmBackupArchive[]> | null>>
|
||||
opts?: { _forceRefresh?: boolean; vmId: XoVm['id'] }
|
||||
): Promise<Record<XoBackupRepository['id'], Record<XoVm['id'], XoVmBackupArchive[]>>>
|
||||
pingRemote(id: XoBackupRepository['id']): Promise<{ success: true }>
|
||||
/** Allow to add a new server in the DB (XCP-ng/XenServer) */
|
||||
registerXenServer(
|
||||
|
||||
@@ -19,7 +19,7 @@ import type {
|
||||
VM_POWER_STATE,
|
||||
} from './common.mjs'
|
||||
import type * as CMType from './lib/complex-matcher.mjs'
|
||||
import { XoAclBasePrivilege, XoAclRole } from './lib/xen-orchestra-acl.mjs'
|
||||
import { XoAclPrivilege, XoAclRole, XoAclSupportedActionsByResource } from './lib/xen-orchestra-acl.mjs'
|
||||
import type { XenApiHost, XenApiPool } from './xen-api.mjs'
|
||||
|
||||
type BaseXapiXo = {
|
||||
@@ -140,7 +140,6 @@ export type XoAlarm = Omit<XoMessage, '$object' | 'body'> & {
|
||||
}
|
||||
|
||||
// TODO: to be typed when Bastien.N has finished working on the XO task
|
||||
// Once the [key:string]: unknown is removed, remove the `as XoMessage` in event.class.mts
|
||||
type BaseXoLog = {
|
||||
id: Branded<'xo-log'>
|
||||
infos?: { data: unknown; message: string }[]
|
||||
@@ -603,7 +602,7 @@ export type XoServer = {
|
||||
poolNameDescription?: string
|
||||
poolNameLabel?: string
|
||||
readOnly: boolean
|
||||
status: 'connected' | 'disconnecting' | 'disconnected' | 'connecting'
|
||||
status: 'connected' | 'disconnected' | 'connecting'
|
||||
username: string
|
||||
}
|
||||
|
||||
@@ -890,7 +889,10 @@ export type XapiXoRecord =
|
||||
| XoVtpm
|
||||
| XoSm
|
||||
|
||||
export type NonXapiXoRecord =
|
||||
export type NonXapiXoRecord<
|
||||
TActionsByResource extends XoAclSupportedActionsByResource = never,
|
||||
TResource extends string = never,
|
||||
> =
|
||||
| AnyXoBackupArchive
|
||||
| AnyXoJob
|
||||
| AnyXoLog
|
||||
@@ -903,9 +905,12 @@ export type NonXapiXoRecord =
|
||||
| XoTask
|
||||
| XoUser
|
||||
| XoAclRole
|
||||
| XoAclBasePrivilege
|
||||
| XoAclPrivilege<TActionsByResource, TResource>
|
||||
|
||||
export type XoRecord = XapiXoRecord | NonXapiXoRecord
|
||||
export type XoRecord<
|
||||
TActionsByResource extends XoAclSupportedActionsByResource = never,
|
||||
TResource extends string = never,
|
||||
> = XapiXoRecord | NonXapiXoRecord<TActionsByResource, TResource>
|
||||
|
||||
export type AnyXoVm = XoVm | XoVmSnapshot | XoVmTemplate | XoVmController
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"target": "ES2022",
|
||||
"skipLibCheck": true,
|
||||
"types": ["node"] // Only use types from Node.js and packages that are explicitly imported
|
||||
|
||||
@@ -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.6.1",
|
||||
"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": "^2.0.1",
|
||||
"@vates/types": "^1.30.1",
|
||||
"rimraf": "^6.0.1",
|
||||
"typescript": "~5.6",
|
||||
"typescript-eslint": "^8.61.0"
|
||||
|
||||
@@ -13,11 +13,11 @@ const wrapCall = (fn, arg, thisArg) => {
|
||||
*
|
||||
* WARNING: Does not handle plain objects
|
||||
*
|
||||
* @template Item, Result, [This=Iterable<Item>]
|
||||
* @template Item,This
|
||||
* @param {Iterable<Item>} iterable
|
||||
* @param {(this: This, item: Item) => (Result | PromiseLike<Result>)} mapFn
|
||||
* @param {This} [thisArg] defaults to `iterable`
|
||||
* @returns {Promise<Result[]>}
|
||||
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
|
||||
* @param {This} [thisArg]
|
||||
* @returns {Promise<Item[]>}
|
||||
*/
|
||||
exports.asyncMap = function asyncMap(iterable, mapFn, thisArg = iterable) {
|
||||
return Promise.all(Array.from(iterable, mapFn, thisArg))
|
||||
@@ -26,11 +26,11 @@ exports.asyncMap = function asyncMap(iterable, mapFn, thisArg = iterable) {
|
||||
/**
|
||||
* Like `asyncMap` but wait for all promises to settle before rejecting
|
||||
*
|
||||
* @template Item, Result, [This=Iterable<Item>]
|
||||
* @template Item,This
|
||||
* @param {Iterable<Item>} iterable
|
||||
* @param {(this: This, item: Item) => (Result | PromiseLike<Result>)} mapFn
|
||||
* @param {This} [thisArg] defaults to `iterable`
|
||||
* @returns {Promise<Result[]>}
|
||||
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
|
||||
* @param {This} [thisArg]
|
||||
* @returns {Promise<Item[]>}
|
||||
*/
|
||||
exports.asyncMapSettled = function asyncMapSettled(iterable, mapFn, thisArg = iterable) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@xen-orchestra/async-map",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.3",
|
||||
"license": "ISC",
|
||||
"description": "Promise.all + map for all iterables",
|
||||
"keywords": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xen-orchestra/backup-archive",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.1",
|
||||
"description": "Helper to handle generic backup archives",
|
||||
"license": "ISC",
|
||||
"author": "",
|
||||
@@ -21,7 +21,7 @@
|
||||
"tar-stream": "^3.1.8",
|
||||
"@types/tar-stream": "^3.1.4",
|
||||
"tmp": "^0.2.1",
|
||||
"@vates/types": "^2.0.1"
|
||||
"@vates/types": "^1.30.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@xen-orchestra/log": "^0.7.1",
|
||||
@@ -39,7 +39,7 @@
|
||||
"dev": "tsc --watch",
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "yarn run clean && tsc && node --test **/*.test.mjs",
|
||||
"test-integration": "tsc && node --test **/*.integ.mjs",
|
||||
"test-integration": "yarn run clean && tsc && node --test **/*.integ.mjs",
|
||||
"clean": "rimraf dist/"
|
||||
},
|
||||
"private": false,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
import { promisify } from 'node:util'
|
||||
import zlib from 'node:zlib'
|
||||
|
||||
const gzip = promisify(zlib.gzip)
|
||||
const gunzip = promisify(zlib.gunzip)
|
||||
|
||||
type LogWarn = (message: any, opts?: object) => void
|
||||
|
||||
/**
|
||||
* Reads a gzip-compressed JSON cache file, tolerant of a missing or corrupt file.
|
||||
* Shared with the legacy @xen-orchestra/backups RemoteAdapter.
|
||||
*/
|
||||
export async function readBackupCache(
|
||||
handler: RemoteHandlerAbstract,
|
||||
path: string,
|
||||
logWarn: LogWarn
|
||||
): Promise<Record<string, unknown> | undefined> {
|
||||
try {
|
||||
return JSON.parse((await gunzip(await handler.readFile(path))).toString())
|
||||
} catch (error) {
|
||||
if (error?.code !== 'ENOENT') {
|
||||
logWarn('failed to read cache', { error, path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data as a gzip-compressed JSON cache file.
|
||||
* Shared with the legacy @xen-orchestra/backups RemoteAdapter.
|
||||
*
|
||||
* No-op on immutable remotes: the cache file may not be modifiable there,
|
||||
* and callers should be regenerating/reading the data directly instead.
|
||||
*/
|
||||
export async function writeBackupCache(
|
||||
handler: RemoteHandlerAbstract,
|
||||
path: string,
|
||||
data: Record<string, unknown>,
|
||||
logWarn: LogWarn
|
||||
): Promise<void> {
|
||||
if (handler.isImmutable()) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await handler.writeFile(path, await gzip(JSON.stringify(data)), { flags: 'w' })
|
||||
} catch (error) {
|
||||
logWarn('failed to write cache', { error, path })
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
|
||||
const METADATA_BACKUP_ID_REGEXP =
|
||||
/^xo-(config|pool-metadata)-backups\/\w{8}(-\w{4}){3}-\w{12}(\/\w{8}(-\w{4}){3}-\w{12})?\/\d{8}T\d{6}Z/
|
||||
|
||||
/**
|
||||
* Deletes an XO config or pool metadata backup directory (not a VM backup).
|
||||
* Shared with the legacy @xen-orchestra/backups RemoteAdapter.
|
||||
*/
|
||||
export async function deleteMetadataBackup(handler: RemoteHandlerAbstract, backupId: string): Promise<void> {
|
||||
if (!METADATA_BACKUP_ID_REGEXP.test(backupId)) {
|
||||
throw new Error(`The id (${backupId}) not correspond to a metadata folder`)
|
||||
}
|
||||
|
||||
await handler.rmtree(backupId)
|
||||
}
|
||||
@@ -55,8 +55,6 @@ export interface CheckResult {
|
||||
|
||||
export type CleanResult = {
|
||||
removedFiles: string[]
|
||||
// Files rewritten in place (e.g. metadata whose size was updated after a merge)
|
||||
changedFiles?: string[]
|
||||
merge?: boolean
|
||||
size?: number
|
||||
mergedSizes?: Map<string, number>
|
||||
|
||||
@@ -17,8 +17,11 @@ import {
|
||||
import { cleanOrphanDiskDirs } from '@xen-orchestra/backup-archive/disks'
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { readBackupCache, writeBackupCache } from './BackupCache.mjs'
|
||||
import { unlinkTolerant } from './_unlinkTolerant.mjs'
|
||||
import { promisify } from 'node:util'
|
||||
import zlib from 'node:zlib'
|
||||
|
||||
const gzip = promisify(zlib.gzip)
|
||||
const gunzip = promisify(zlib.gunzip)
|
||||
|
||||
const { info: logInfo, warn: logWarn } = createLogger('xo:backup-archive')
|
||||
|
||||
@@ -27,7 +30,7 @@ const FILES_TO_KEEP = ['cache.json.gz', 'vdis']
|
||||
export class VmBackupDirectory implements VmBackupInterface {
|
||||
handler: RemoteHandlerAbstract
|
||||
rootPath: string
|
||||
files: Array<string> = []
|
||||
files: Array<string> = new Array()
|
||||
orphans: Set<string> = new Set()
|
||||
backupArchives: Map<string, VmBackupInterface> = new Map()
|
||||
opts: ResolvedBackupCleanOptions
|
||||
@@ -40,9 +43,6 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
// on disk, so clean() must regenerate it even when nothing was merged/removed.
|
||||
#cacheOutOfSync = false
|
||||
|
||||
// Set by #checkCacheCount(): whether cache.json.gz existed at the start of the run.
|
||||
#cacheExisted = false
|
||||
|
||||
constructor(
|
||||
handler: RemoteHandlerAbstract,
|
||||
vmBackupPath: string,
|
||||
@@ -67,11 +67,21 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
}
|
||||
|
||||
async #readCache(path: string): Promise<Record<string, unknown> | undefined> {
|
||||
return readBackupCache(this.handler, path, logWarn)
|
||||
try {
|
||||
return JSON.parse((await gunzip(await this.handler.readFile(path))).toString())
|
||||
} catch (error) {
|
||||
if (error?.code !== 'ENOENT') {
|
||||
logWarn('failed to read cache', { error, path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async #writeCache(path: string, data: Record<string, unknown>): Promise<void> {
|
||||
return writeBackupCache(this.handler, path, data, logWarn)
|
||||
try {
|
||||
await this.handler.writeFile(path, await gzip(JSON.stringify(data)), { flags: 'w' })
|
||||
} catch (error) {
|
||||
logWarn('failed to write cache', { error, path })
|
||||
}
|
||||
}
|
||||
|
||||
async init() {
|
||||
@@ -80,7 +90,7 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
this.#uniqueLineages = new Map()
|
||||
|
||||
for (const fullPath of this.files.filter(path => path.endsWith('.json'))) {
|
||||
let metadata: PartialBackupMetadata | undefined
|
||||
let metadata: PartialBackupMetadata | undefined = undefined
|
||||
try {
|
||||
metadata = JSON.parse(await this.handler.readFile(fullPath)) satisfies PartialBackupMetadata
|
||||
} catch (error) {
|
||||
@@ -166,35 +176,18 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
|
||||
// Let each archive clean its own files (e.g. remove metadata for incomplete backups)
|
||||
// and update metadata with merged sizes if applicable
|
||||
const archiveRemovedFiles = new Set<string>()
|
||||
const changedFiles = new Set<string>()
|
||||
const goneArchives: string[] = []
|
||||
await asyncEach(
|
||||
Array.from(this.backupArchives.entries()),
|
||||
async ([metadataPath, archive]: [string, VmBackupInterface]) => {
|
||||
const { removedFiles, changedFiles: archiveChangedFiles } = await archive.clean({
|
||||
remove,
|
||||
mergedSizes: allMergedSizes,
|
||||
})
|
||||
Array.from(this.backupArchives.values()),
|
||||
async (archive: VmBackupInterface) => {
|
||||
const { removedFiles } = await archive.clean({ remove, mergedSizes: allMergedSizes })
|
||||
if (removedFiles.length > 0) {
|
||||
cacheNeedsRegen = true
|
||||
removedFiles.forEach(file => archiveRemovedFiles.add(file))
|
||||
}
|
||||
if (removedFiles.includes(metadataPath)) {
|
||||
goneArchives.push(metadataPath)
|
||||
}
|
||||
archiveChangedFiles?.forEach(file => changedFiles.add(file))
|
||||
},
|
||||
{ concurrency: 2 }
|
||||
)
|
||||
|
||||
// an archive whose metadata has just been deleted is not a backup anymore: it must not be
|
||||
// advertised by the regenerated cache
|
||||
for (const metadataPath of goneArchives) {
|
||||
this.backupArchives.delete(metadataPath)
|
||||
}
|
||||
|
||||
if (this.#cacheExisted && (allMergedSizes.size > 0 || cacheNeedsRegen || this.#cacheOutOfSync)) {
|
||||
if (allMergedSizes.size > 0 || cacheNeedsRegen || this.#cacheOutOfSync) {
|
||||
await this.#regenerateCache()
|
||||
}
|
||||
|
||||
@@ -217,50 +210,13 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
)
|
||||
}
|
||||
const size = [...allMergedSizes.values()].reduce((total, merged) => total + merged, 0)
|
||||
// `removedFiles` lists the files this run removed, or would have removed if `remove` were set:
|
||||
// root-level orphans plus the files each archive deemed removable (e.g. the metadata of an
|
||||
// incomplete backup). Callers acting on it must therefore check `remove` themselves.
|
||||
orphans.forEach(orphan => archiveRemovedFiles.add(orphan))
|
||||
return {
|
||||
removedFiles: Array.from(archiveRemovedFiles),
|
||||
changedFiles: Array.from(changedFiles),
|
||||
merge: someLineageMergedOrShouldBe,
|
||||
size: size,
|
||||
}
|
||||
return { removedFiles: orphans, merge: someLineageMergedOrShouldBe, size: size }
|
||||
}
|
||||
|
||||
async #checkCacheCount(): Promise<void> {
|
||||
const cachePath = `${this.rootPath}/cache.json.gz`
|
||||
|
||||
this.#cacheExisted = false
|
||||
this.#cacheOutOfSync = false
|
||||
|
||||
if (!this.files.includes(normalize(cachePath))) {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.handler.isImmutable()) {
|
||||
// RemoteAdapter never creates cache.json.gz on immutable repositories: remove the
|
||||
// leftover, readable or not, and never regenerate it. Best effort: some remotes
|
||||
// (e.g. S3) may not normalize a permission error to EPERM, so tolerate any error.
|
||||
try {
|
||||
await this.handler.unlink(cachePath)
|
||||
} catch (error) {
|
||||
this.opts.logWarn('error while deleting leftover backup cache', { path: cachePath, error })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const existingCache = await this.#readCache(cachePath)
|
||||
if (existingCache === undefined) {
|
||||
// present but unreadable: drop it, RemoteAdapter will recreate a valid one
|
||||
this.opts.logWarn('removing unreadable backup cache', { path: cachePath })
|
||||
await unlinkTolerant(this.handler, cachePath)
|
||||
return
|
||||
}
|
||||
|
||||
this.#cacheExisted = true
|
||||
const actual = Object.keys(existingCache).length
|
||||
const actual = existingCache === undefined ? 0 : Object.keys(existingCache).length
|
||||
const expected = this.backupArchives.size
|
||||
this.#cacheOutOfSync = actual !== expected
|
||||
if (this.#cacheOutOfSync) {
|
||||
@@ -327,6 +283,7 @@ export class VmBackupDirectory implements VmBackupInterface {
|
||||
const dir = new VmBackupDirectory(handler, vmBackupPath, cleanOpts)
|
||||
await dir.init()
|
||||
await dir.check()
|
||||
return await dir.clean({ remove: cleanOpts.remove, merge: cleanOpts.merge })
|
||||
const { merge, size } = await dir.clean({ remove: cleanOpts.remove, merge: cleanOpts.merge })
|
||||
return { merge, size }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,8 @@ import { rimraf } from 'rimraf'
|
||||
// eslint-disable-next-line n/no-missing-import
|
||||
import { VmBackupDirectory } from '../dist/VmBackupDirectory.mjs'
|
||||
import tar from 'tar-stream'
|
||||
import { promisify } from 'node:util'
|
||||
import zlib from 'node:zlib'
|
||||
const { beforeEach, afterEach, describe } = test
|
||||
|
||||
const gzip = promisify(zlib.gzip)
|
||||
const gunzip = promisify(zlib.gunzip)
|
||||
|
||||
let tempDir, handler, vmBackupDir
|
||||
const vmUuid = 'test-vm-uuid'
|
||||
const rootPath = `xo-vm-backups/${vmUuid}`
|
||||
@@ -129,10 +124,7 @@ describe('VmBackupDirectory with full backups', { concurrency: 1 }, () => {
|
||||
|
||||
test('clean() preserves cache.json.gz', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(
|
||||
`${rootPath}/cache.json.gz`,
|
||||
await gzip(JSON.stringify({ [`/${rootPath}/backup1.json`]: {} }))
|
||||
)
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, 'cache')
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath)
|
||||
|
||||
@@ -141,104 +133,6 @@ describe('VmBackupDirectory with full backups', { concurrency: 1 }, () => {
|
||||
assert.ok(remainingFiles.includes('cache.json.gz'))
|
||||
})
|
||||
|
||||
test('clean() removes an unreadable cache.json.gz', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, 'not gzipped json')
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { logWarn: () => {} })
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(!remainingFiles.includes('cache.json.gz'), 'an unreadable cache.json.gz should be removed, not kept')
|
||||
})
|
||||
|
||||
test('clean() on an immutable remote never creates cache.json.gz', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(`${rootPath}/orphan.xva`, 'orphan-content')
|
||||
handler.isImmutable = () => true
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true })
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(!remainingFiles.includes('cache.json.gz'), 'cache.json.gz should never be created on an immutable remote')
|
||||
})
|
||||
|
||||
test('clean() removes a leftover cache.json.gz found on an immutable remote', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, await gzip(JSON.stringify({})))
|
||||
handler.isImmutable = () => true
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath)
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(!remainingFiles.includes('cache.json.gz'), 'erroneous cache.json.gz should be removed, not rewritten')
|
||||
})
|
||||
|
||||
test('clean() removes an unreadable leftover cache.json.gz found on an immutable remote', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, 'not gzipped json')
|
||||
handler.isImmutable = () => true
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath)
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(
|
||||
!remainingFiles.includes('cache.json.gz'),
|
||||
'an unreadable cache.json.gz should be removed from an immutable remote'
|
||||
)
|
||||
})
|
||||
|
||||
test('clean() tolerates an EPERM while removing the cache of an immutable remote', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, await gzip(JSON.stringify({})))
|
||||
handler.isImmutable = () => true
|
||||
handler.unlink = () => {
|
||||
const error = new Error('EPERM: operation not permitted')
|
||||
error.code = 'EPERM'
|
||||
throw error
|
||||
}
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath)
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(remainingFiles.includes('cache.json.gz'), 'the immutable cache.json.gz could not be removed')
|
||||
})
|
||||
|
||||
test('clean() keeps maintaining a pre-existing cache.json.gz across a remove', async () => {
|
||||
await createFullBackupMetadata('backup1.json', 'backup1.xva')
|
||||
await createFullBackupMetadata('backup2.json', 'backup2.xva')
|
||||
|
||||
// a cache with the expected number of entries: only the removal can trigger the regeneration
|
||||
const cachePath = `${rootPath}/cache.json.gz`
|
||||
await handler.writeFile(
|
||||
cachePath,
|
||||
await gzip(
|
||||
JSON.stringify({
|
||||
[`/${rootPath}/backup1.json`]: { stale: true },
|
||||
[`/${rootPath}/backup2.json`]: { stale: true },
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
// backup2 loses its XVA: its metadata will be removed by clean()
|
||||
await handler.unlink(`${rootPath}/backup2.xva`)
|
||||
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true, logInfo: () => {}, logWarn: () => {} })
|
||||
|
||||
const remainingFiles = await handler.list(rootPath)
|
||||
assert.ok(remainingFiles.includes('backup1.json'))
|
||||
assert.ok(remainingFiles.includes('backup1.xva'))
|
||||
assert.ok(!remainingFiles.includes('backup2.json'), 'metadata of the backup with a missing XVA should be removed')
|
||||
assert.ok(remainingFiles.includes('cache.json.gz'), 'an existing cache.json.gz must not be dropped by a remove')
|
||||
|
||||
const cache = JSON.parse((await gunzip(await handler.readFile(cachePath))).toString())
|
||||
assert.deepEqual(
|
||||
Object.keys(cache),
|
||||
[`/${rootPath}/backup1.json`],
|
||||
'cache.json.gz should have been regenerated with the surviving backup only'
|
||||
)
|
||||
assert.equal(cache[`/${rootPath}/backup1.json`].stale, undefined, 'the entry must come from the archive on disk')
|
||||
})
|
||||
|
||||
test('clean() removes an orphan XVA checksum file (no matching metadata or XVA)', async () => {
|
||||
await handler.writeFile(`${rootPath}/stray.xva.checksum`, 'sha256:deadbeef')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { basename, normalize, resolveFromFile } from '@xen-orchestra/fs/path'
|
||||
import { basename, normalize } from '@xen-orchestra/fs/path'
|
||||
import assert from 'node:assert'
|
||||
import { FileDescriptor, RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
import { FileDescriptor } from '@xen-orchestra/fs'
|
||||
import {
|
||||
ArchiveCleanOptions,
|
||||
CheckResult,
|
||||
@@ -8,10 +8,8 @@ import {
|
||||
VmBackupInterface,
|
||||
PartialBackupMetadata,
|
||||
ResolvedBackupCleanOptions,
|
||||
DEFAULT_REMOVE_CONCURRENCY,
|
||||
} from './VmBackup.types.mjs'
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import { unlinkTolerant } from './_unlinkTolerant.mjs'
|
||||
import { RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
|
||||
const COMPRESSED_MAGIC_NUMBERS: Buffer[] = [
|
||||
// https://tools.ietf.org/html/rfc1952.html#page-5
|
||||
@@ -82,29 +80,6 @@ export async function isValidXva(
|
||||
|
||||
const noop = (): void => {}
|
||||
|
||||
/**
|
||||
* Deletes a full VM backup's metadata json and, when provided, its xva and checksum.
|
||||
* `xva` is the path as stored in the metadata, i.e. relative to the metadata file.
|
||||
* Shared with the legacy @xen-orchestra/backups RemoteAdapter.
|
||||
*/
|
||||
export async function deleteFullVmBackups(
|
||||
handler: RemoteHandlerAbstract,
|
||||
backups: Array<{ metadataPath: string; xva?: string }>
|
||||
): Promise<void> {
|
||||
await asyncEach(
|
||||
backups,
|
||||
async ({ metadataPath, xva }) => {
|
||||
await unlinkTolerant(handler, metadataPath)
|
||||
if (xva !== undefined) {
|
||||
const xvaPath = resolveFromFile(metadataPath, xva)
|
||||
await unlinkTolerant(handler, xvaPath)
|
||||
await unlinkTolerant(handler, `${xvaPath}.checksum`)
|
||||
}
|
||||
},
|
||||
{ concurrency: DEFAULT_REMOVE_CONCURRENCY, stopOnError: false }
|
||||
)
|
||||
}
|
||||
|
||||
export class VmFullBackupArchive implements VmBackupInterface {
|
||||
handler: RemoteHandlerAbstract
|
||||
rootPath: string
|
||||
@@ -183,10 +158,12 @@ export class VmFullBackupArchive implements VmBackupInterface {
|
||||
files: this.getAssociatedFiles({ prefix: false }),
|
||||
})
|
||||
} else {
|
||||
try {
|
||||
await deleteFullVmBackups(this.handler, [{ metadataPath: this.metadataPath, xva: this.metadata.xva }])
|
||||
} catch (error) {
|
||||
this.opts.logWarn(`Issue removing backup files`, { error, metadataPath: this.metadataPath })
|
||||
for (const file of removedFiles) {
|
||||
try {
|
||||
await this.handler.unlink(file)
|
||||
} catch (error) {
|
||||
this.opts.logWarn(`Issue removing ${file}`, { error })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +173,7 @@ export class VmFullBackupArchive implements VmBackupInterface {
|
||||
}
|
||||
|
||||
getAssociatedFiles({ prefix = false }): Array<string> {
|
||||
const validFiles = [this.metadataPath, this.xvaPath, `${this.xvaPath}.checksum`]
|
||||
let validFiles = [this.metadataPath, this.xvaPath, `${this.xvaPath}.checksum`]
|
||||
return prefix ? validFiles : validFiles.map(file => basename(file))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@ import fs from 'fs-extra'
|
||||
import * as uuid from 'uuid'
|
||||
import { getHandler } from '@xen-orchestra/fs'
|
||||
import { pFromCallback } from 'promise-toolbox'
|
||||
// `dist/` is built by the `test-integration` script, which starts by removing it: these imports
|
||||
// cannot be resolved when linting a working tree that has not been built yet
|
||||
/* eslint-disable n/no-missing-import */
|
||||
// eslint-disable-next-line n/no-missing-import
|
||||
import { VmBackupDirectory } from '../dist/VmBackupDirectory.mjs'
|
||||
import { RemoteVhdDisk } from '../dist/disks/RemoteVhdDisk.mjs'
|
||||
import { MergeRemoteDisk } from '../dist/disks/MergeRemoteDisk.mjs'
|
||||
/* eslint-enable n/no-missing-import */
|
||||
import { VHDFOOTER, VHDHEADER } from './tests.fixtures.mjs'
|
||||
import { VhdFile, Constants, VhdDirectory, VhdAbstract } from 'vhd-lib'
|
||||
import { dirname, basename } from 'node:path'
|
||||
@@ -23,7 +20,6 @@ import { rimraf } from 'rimraf'
|
||||
const { beforeEach, afterEach, describe } = test
|
||||
|
||||
const gunzip = promisify(zlib.gunzip)
|
||||
const gzip = promisify(zlib.gzip)
|
||||
|
||||
let tempDir, handler, jobId, vdiId, basePath, relativePath, vdiId2, basePath2, relativePath2
|
||||
const rootPath = 'xo-vm-backups/VMUUID/'
|
||||
@@ -209,8 +205,8 @@ test('it remove backup metadata referencing a missing vhd in delta backup', asyn
|
||||
assert.equal(matched.length, 2) // all vhds (orphan and child ) should have been deleted
|
||||
|
||||
assert.ok(
|
||||
!(await handler.list(rootPath)).includes('cache.json.gz'),
|
||||
'cache.json.gz should not be created when none existed before the clean'
|
||||
(await handler.list(rootPath)).includes('cache.json.gz'),
|
||||
'cache.json.gz should be regenerated after metadata deletion'
|
||||
)
|
||||
})
|
||||
|
||||
@@ -368,6 +364,7 @@ test('it merges delta of non destroyed chain', async () => {
|
||||
logged.push(message)
|
||||
}
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true, logInfo, logWarn: logInfo })
|
||||
assert.equal(logged[0], `unexpected number of entries in backup cache`)
|
||||
|
||||
logged = []
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, { remove: true, merge: true, logInfo, logWarn: () => {} })
|
||||
@@ -729,10 +726,10 @@ describe('tests multiple combination ', { concurrency: 1 }, () => {
|
||||
const metadata = JSON.parse(await handler.readFile(`${rootPath}/metadata.json`))
|
||||
// size should be the size of children + grand children + clean after the merge
|
||||
assert.deepEqual(metadata.size, 6501888)
|
||||
// no cache.json.gz existed before this run, so a merge must not create one
|
||||
// cache.json.gz must be regenerated when metadata changes after a merge
|
||||
assert.ok(
|
||||
!(await handler.list(rootPath)).includes('cache.json.gz'),
|
||||
'cache.json.gz should not be created when none existed before the merge'
|
||||
(await handler.list(rootPath)).includes('cache.json.gz'),
|
||||
'cache.json.gz should be regenerated after a merge'
|
||||
)
|
||||
|
||||
// broken vhd, non referenced, abandoned should be deleted ( alias and data)
|
||||
@@ -836,7 +833,7 @@ 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('it does not create nor warn about the cache when none existed, even with a count mismatch', async () => {
|
||||
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(
|
||||
@@ -845,79 +842,6 @@ test('it does not create nor warn about the cache when none existed, even with a
|
||||
)
|
||||
await assert.rejects(handler.readFile(`${rootPath}/cache.json.gz`), { code: 'ENOENT' })
|
||||
|
||||
const logged = []
|
||||
// remove/merge both false: cacheNeedsRegen stays false and no merge happens,
|
||||
// so only a pre-existing cache's count mismatch could trigger regeneration
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, {
|
||||
remove: false,
|
||||
merge: false,
|
||||
logInfo: () => {},
|
||||
logWarn: message => logged.push(message),
|
||||
})
|
||||
|
||||
assert.ok(!logged.includes('unexpected number of entries in backup cache'), 'no cache to be mismatched, no warning')
|
||||
await assert.rejects(handler.readFile(`${rootPath}/cache.json.gz`), { code: 'ENOENT' })
|
||||
})
|
||||
|
||||
test('it regenerates a pre-existing cache after a merge', async () => {
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata.json`,
|
||||
JSON.stringify({
|
||||
mode: 'delta',
|
||||
size: 12000, // a size too small, the merge will fix it
|
||||
vhds: [`${relativePath}/grandchild.vhd`, `${relativePath}/child.vhd`],
|
||||
})
|
||||
)
|
||||
|
||||
// one orphan, which is a full vhd, no parent
|
||||
const orphan = await generateVhd(`${basePath}/orphan.vhd`)
|
||||
// a child to the orphan, orphan will be merged into it
|
||||
const child = await generateVhd(`${basePath}/child.vhd`, {
|
||||
header: {
|
||||
parentUnicodeName: 'orphan.vhd',
|
||||
parentUuid: orphan.footer.uuid,
|
||||
},
|
||||
blocks: [0, 1],
|
||||
})
|
||||
await generateVhd(`${basePath}/grandchild.vhd`, {
|
||||
header: {
|
||||
parentUnicodeName: 'child.vhd',
|
||||
parentUuid: child.footer.uuid,
|
||||
},
|
||||
})
|
||||
|
||||
// a cache with the expected number of entries: it is not out of sync, only the merge can trigger the regeneration
|
||||
await handler.writeFile(
|
||||
`${rootPath}/cache.json.gz`,
|
||||
await gzip(JSON.stringify({ [`/${rootPath}metadata.json`]: { size: 12000 } }))
|
||||
)
|
||||
|
||||
const result = await VmBackupDirectory.cleanVm(handler, rootPath, {
|
||||
remove: true,
|
||||
merge: true,
|
||||
logInfo: () => {},
|
||||
logWarn: () => {},
|
||||
})
|
||||
|
||||
const metadata = JSON.parse(await handler.readFile(`${rootPath}/metadata.json`))
|
||||
// size of child + grandchild after orphan has been merged into child
|
||||
assert.equal(metadata.size, 4299776, 'metadata.size should be updated after merge')
|
||||
assert.deepEqual(result.changedFiles, [`/${rootPath}metadata.json`], 'the rewritten metadata should be reported')
|
||||
|
||||
const cache = JSON.parse((await gunzip(await handler.readFile(`${rootPath}/cache.json.gz`))).toString())
|
||||
assert.equal(Object.keys(cache).length, 1)
|
||||
assert.equal(Object.values(cache)[0].size, metadata.size, 'cache entry should carry the post-merge size')
|
||||
})
|
||||
|
||||
test('it regenerates a pre-existing cache when its entry count is out of sync, even with nothing to merge/remove', async () => {
|
||||
// a referenced disk + its metadata, and a pre-existing cache with the wrong entry count
|
||||
await generateVhd(`${basePath}/diskA1.vhd`)
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/diskA1.vhd`] })
|
||||
)
|
||||
await handler.writeFile(`${rootPath}/cache.json.gz`, await gzip(JSON.stringify({})))
|
||||
|
||||
const logged = []
|
||||
// remove/merge both false: cacheNeedsRegen stays false and no merge happens,
|
||||
// so only the cache-count mismatch can trigger the regeneration
|
||||
@@ -933,53 +857,3 @@ test('it regenerates a pre-existing cache when its entry count is out of sync, e
|
||||
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')
|
||||
})
|
||||
|
||||
test('it regenerates a pre-existing cache after a metadata removal', async () => {
|
||||
// two backups, each on its own VDI directory, so removing one does not touch the other's disks
|
||||
await generateVhd(`${basePath}/diskA1.vhd`)
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata1.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath}/diskA1.vhd`] })
|
||||
)
|
||||
// metadata2 references a vhd missing from disk: clean() removes it
|
||||
await handler.writeFile(
|
||||
`${rootPath}/metadata2.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: [`${relativePath2}/deleted.vhd`] })
|
||||
)
|
||||
|
||||
// a cache with the expected number of entries: only the removal can trigger the regeneration
|
||||
await handler.writeFile(
|
||||
`${rootPath}/cache.json.gz`,
|
||||
await gzip(
|
||||
JSON.stringify({
|
||||
[`/${rootPath}metadata1.json`]: { stale: true },
|
||||
[`/${rootPath}metadata2.json`]: { stale: true },
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
const logged = []
|
||||
await VmBackupDirectory.cleanVm(handler, rootPath, {
|
||||
remove: true,
|
||||
merge: false,
|
||||
logInfo: () => {},
|
||||
logWarn: message => logged.push(message),
|
||||
})
|
||||
|
||||
const rootFiles = await handler.list(rootPath)
|
||||
assert.ok(rootFiles.includes('metadata1.json'), 'the complete backup must survive')
|
||||
assert.ok(!rootFiles.includes('metadata2.json'), 'the backup with a missing vhd must be removed')
|
||||
assert.ok(rootFiles.includes('cache.json.gz'), 'an existing cache.json.gz must not be dropped by a remove')
|
||||
assert.ok(
|
||||
!logged.includes('unexpected number of entries in backup cache'),
|
||||
'the cache matched the archives before the clean: the removal alone must trigger the regeneration'
|
||||
)
|
||||
|
||||
const cache = JSON.parse((await gunzip(await handler.readFile(`${rootPath}/cache.json.gz`))).toString())
|
||||
assert.deepEqual(
|
||||
Object.keys(cache),
|
||||
[`/${rootPath}metadata1.json`],
|
||||
'the removed backup must be gone from the regenerated cache'
|
||||
)
|
||||
assert.equal(cache[`/${rootPath}metadata1.json`].stale, undefined, 'the entry must come from the archive on disk')
|
||||
})
|
||||
|
||||
@@ -5,27 +5,10 @@ import {
|
||||
ResolvedBackupCleanOptions,
|
||||
VmBackupInterface,
|
||||
PartialBackupMetadata,
|
||||
DEFAULT_REMOVE_CONCURRENCY,
|
||||
} from './VmBackup.types.mjs'
|
||||
import { RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
import { basename, dirname, normalize } from '@xen-orchestra/fs/path'
|
||||
import { RemoteDiskLineage } from './RemoteDiskLineage.mjs'
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
|
||||
/**
|
||||
* Deletes a delta VM backup's metadata json. Unused VHDs are detected and removed
|
||||
* separately by VmBackupDirectory's clean(). Shared with the legacy @xen-orchestra/backups
|
||||
* RemoteAdapter.
|
||||
*/
|
||||
export async function deleteDeltaVmBackups(
|
||||
handler: RemoteHandlerAbstract,
|
||||
backups: Array<{ metadataPath: string }>
|
||||
): Promise<void> {
|
||||
await asyncEach(backups, ({ metadataPath }) => handler.unlink(metadataPath), {
|
||||
concurrency: DEFAULT_REMOVE_CONCURRENCY,
|
||||
stopOnError: false,
|
||||
})
|
||||
}
|
||||
|
||||
export class VmIncrementalBackupArchive implements VmBackupInterface {
|
||||
handler: RemoteHandlerAbstract
|
||||
@@ -149,7 +132,6 @@ export class VmIncrementalBackupArchive implements VmBackupInterface {
|
||||
}
|
||||
}
|
||||
|
||||
const changedFiles: string[] = []
|
||||
let mergedSize = 0
|
||||
if (mergedSizes !== undefined) {
|
||||
for (const diskPath of this.diskPaths) {
|
||||
@@ -157,11 +139,10 @@ export class VmIncrementalBackupArchive implements VmBackupInterface {
|
||||
}
|
||||
if (mergedSize > 0) {
|
||||
await this.updateMetadata(mergedSize)
|
||||
changedFiles.push(this.metadataPath)
|
||||
}
|
||||
}
|
||||
|
||||
return { removedFiles, changedFiles }
|
||||
return { removedFiles }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { RemoteHandlerAbstract } from '@xen-orchestra/fs'
|
||||
|
||||
/**
|
||||
* Deletes a file, ignoring the given error codes.
|
||||
* By default only a missing file is tolerated.
|
||||
*/
|
||||
export async function unlinkTolerant(
|
||||
handler: RemoteHandlerAbstract,
|
||||
path: string,
|
||||
ignoredCodes: string[] = ['ENOENT']
|
||||
): Promise<void> {
|
||||
try {
|
||||
await handler.unlink(path)
|
||||
} catch (error) {
|
||||
if (!ignoredCodes.includes(error?.code)) {
|
||||
error.path ??= path
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1 @@
|
||||
export { VmBackupDirectory } from './VmBackupDirectory.mjs'
|
||||
export { deleteFullVmBackups } from './VmFullBackupArchive.mjs'
|
||||
export { deleteDeltaVmBackups } from './VmIncrementalBackupArchive.mjs'
|
||||
export { deleteMetadataBackup } from './MetadataBackup.mjs'
|
||||
export { readBackupCache, writeBackupCache } from './BackupCache.mjs'
|
||||
|
||||
@@ -14,6 +14,5 @@
|
||||
"types": ["node"] // Only use types from Node.js and packages that are explicitly imported
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
// *.integ.mjs deliberately imports from the built dist/ output to test it
|
||||
"exclude": ["node_modules", "dist", "**/*.integ.mjs"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/async-map": "^0.1.4",
|
||||
"@xen-orchestra/backups": "^0.74.2",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@xen-orchestra/backups": "^0.73.10",
|
||||
"@xen-orchestra/fs": "^4.9.3",
|
||||
"filenamify": "^6.0.0",
|
||||
"getopts": "^2.2.5",
|
||||
@@ -28,7 +28,7 @@
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public"
|
||||
},
|
||||
"version": "1.1.14",
|
||||
"version": "1.1.13",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
import test from 'node:test'
|
||||
import { strict as assert } from 'node:assert'
|
||||
|
||||
import tmp from 'tmp'
|
||||
import * as uuid from 'uuid'
|
||||
import { getHandler } from '@xen-orchestra/fs'
|
||||
import { pFromCallback } from 'promise-toolbox'
|
||||
import { rimraf } from 'rimraf'
|
||||
|
||||
import { RemoteAdapter } from './RemoteAdapter.mjs'
|
||||
import { formatFilenameDate } from './_filenameDate.mjs'
|
||||
|
||||
const { beforeEach, afterEach, describe } = test
|
||||
|
||||
const vmUuid = 'a1b2c3d4-0000-0000-0000-000000000000'
|
||||
const rootPath = `xo-vm-backups/${vmUuid}`
|
||||
|
||||
let tempDir, adapter, handler
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = await pFromCallback(cb => tmp.dir(cb))
|
||||
handler = getHandler({ url: `file://${tempDir}` })
|
||||
await handler.sync()
|
||||
adapter = new RemoteAdapter(handler)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await rimraf(tempDir)
|
||||
await handler.forget()
|
||||
})
|
||||
|
||||
const listVmDir = () => handler.list(rootPath, { ignoreMissing: true })
|
||||
|
||||
// write a full backup the way a backup job would, i.e. through the adapter
|
||||
function writeFullBackup(timestamp = Date.now()) {
|
||||
return adapter.writeVmBackupMetadata(vmUuid, {
|
||||
mode: 'full',
|
||||
xva: `./${formatFilenameDate(timestamp)}.xva`,
|
||||
vm: { uuid: vmUuid },
|
||||
jobId: uuid.v1(),
|
||||
scheduleId: uuid.v1(),
|
||||
timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
describe('cache.json.gz on an immutable remote', { concurrency: 1 }, () => {
|
||||
test('writing a backup does not create it', async () => {
|
||||
handler.isImmutable = () => true
|
||||
|
||||
await writeFullBackup()
|
||||
|
||||
assert.ok(
|
||||
!(await listVmDir()).includes('cache.json.gz'),
|
||||
'cache.json.gz must never be created on an immutable remote'
|
||||
)
|
||||
})
|
||||
|
||||
// deleteFullVmBackups() rather than deleteVmBackup(), because the latter also runs cleanVm()
|
||||
// which removes a leftover cache and would hide a cache wrongly written by the deletion itself
|
||||
test('deleting a backup does not create it', async () => {
|
||||
handler.isImmutable = () => true
|
||||
await writeFullBackup()
|
||||
const backups = await adapter.listVmBackups(vmUuid)
|
||||
assert.equal(backups.length, 1)
|
||||
|
||||
await adapter.deleteFullVmBackups(backups)
|
||||
|
||||
assert.ok(
|
||||
!(await listVmDir()).includes('cache.json.gz'),
|
||||
'cache.json.gz must never be created on an immutable remote'
|
||||
)
|
||||
})
|
||||
|
||||
test('it is still created on a mutable remote', async () => {
|
||||
await writeFullBackup()
|
||||
|
||||
assert.ok((await listVmDir()).includes('cache.json.gz'), 'a mutable remote must keep using the cache')
|
||||
})
|
||||
})
|
||||
@@ -3,26 +3,20 @@ import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { VhdDirectory, VhdSynthetic } from 'vhd-lib'
|
||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||
import { basename, dirname, join, resolve } from 'node:path'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { synchronized } from 'decorator-synchronized'
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
import fromCallback from 'promise-toolbox/fromCallback'
|
||||
import groupBy from 'lodash/groupBy.js'
|
||||
import pickBy from 'lodash/pickBy.js'
|
||||
import reduce from 'lodash/reduce.js'
|
||||
import zlib from 'zlib'
|
||||
|
||||
import { BACKUP_DIR } from './_getVmBackupDir.mjs'
|
||||
import {
|
||||
VmBackupDirectory,
|
||||
deleteFullVmBackups as deleteFullVmBackupFiles,
|
||||
deleteDeltaVmBackups as deleteDeltaVmBackupFiles,
|
||||
deleteMetadataBackup as deleteMetadataBackupFiles,
|
||||
readBackupCache,
|
||||
writeBackupCache,
|
||||
} from '@xen-orchestra/backup-archive'
|
||||
import { VmBackupDirectory } from '@xen-orchestra/backup-archive'
|
||||
import { fileRestoreDecorators, fileRestoreMethods } from './_fileRestore.mjs'
|
||||
import { formatFilenameDate } from './_filenameDate.mjs'
|
||||
import { isMetadataFile } from './_backupType.mjs'
|
||||
import { readBackupJournal, writeBackupJournalEntries, writeBackupJournalEntry } from './_backupJournal.mjs'
|
||||
import { isValidXva } from './_isValidXva.mjs'
|
||||
import { watchStreamSize } from './_watchStreamSize.mjs'
|
||||
|
||||
@@ -42,6 +36,8 @@ export const compareTimestamp = (a, b) => a.timestamp - b.timestamp
|
||||
|
||||
const noop = Function.prototype
|
||||
|
||||
const resolveRelativeFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)
|
||||
|
||||
const createSafeReaddir = (handler, methodName) => (path, options) =>
|
||||
handler.list(path, options).catch(error => {
|
||||
if (error?.code !== 'ENOENT') {
|
||||
@@ -84,15 +80,7 @@ export class RemoteAdapter {
|
||||
})
|
||||
}
|
||||
|
||||
// Single funnel for all the backup deletions triggered by a user or by retention: forgets them
|
||||
// from `cache.json.gz` and records them in the journal.
|
||||
/**
|
||||
* @param {{ _filename: string, jobId?: string, scheduleId?: string }[]} backups the metadata of
|
||||
* the deleted backups, or `{ _filename }` alone when it could not be read
|
||||
* @param {import('./_backupJournal.mjs').BackupJournalReason} reason
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async #forgetVmBackups(backups, reason) {
|
||||
async #removeVmBackupsFromCache(backups) {
|
||||
await asyncEach(
|
||||
Object.entries(
|
||||
groupBy(
|
||||
@@ -109,39 +97,27 @@ export class RemoteAdapter {
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// will not reject
|
||||
await writeBackupJournalEntries(
|
||||
this._handler,
|
||||
backups.map(({ _filename, jobId, scheduleId }) => ({
|
||||
event: 'del',
|
||||
vmUuid: basename(dirname(_filename)),
|
||||
filename: _filename,
|
||||
who: jobId === undefined ? undefined : { jobId, scheduleId },
|
||||
reason,
|
||||
})),
|
||||
{ dirMode: this._dirMode }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object[]} backups metadata of the backups to delete
|
||||
* @param {object} [opts]
|
||||
* @param {import('./_backupJournal.mjs').BackupJournalReason} [opts.reason] what triggered the
|
||||
* deletion, as recorded in the journal
|
||||
*/
|
||||
async deleteDeltaVmBackups(backups, { reason = 'retention' } = {}) {
|
||||
// this will delete the json, unused VHDs will be detected by `cleanVm`
|
||||
await deleteDeltaVmBackupFiles(
|
||||
this._handler,
|
||||
backups.map(({ _filename }) => ({ metadataPath: _filename }))
|
||||
)
|
||||
async deleteDeltaVmBackups(backups) {
|
||||
const handler = this._handler
|
||||
|
||||
await this.#forgetVmBackups(backups, reason)
|
||||
// this will delete the json, unused VHDs will be detected by `cleanVm`
|
||||
await asyncMapSettled(backups, ({ _filename }) => handler.unlink(_filename))
|
||||
|
||||
await this.#removeVmBackupsFromCache(backups)
|
||||
}
|
||||
|
||||
async deleteMetadataBackup(backupId) {
|
||||
await deleteMetadataBackupFiles(this._handler, backupId)
|
||||
const uuidReg = '\\w{8}(-\\w{4}){3}-\\w{12}'
|
||||
const metadataDirReg = 'xo-(config|pool-metadata)-backups'
|
||||
const timestampReg = '\\d{8}T\\d{6}Z'
|
||||
const regexp = new RegExp(`^${metadataDirReg}/${uuidReg}(/${uuidReg})?/${timestampReg}`)
|
||||
if (!regexp.test(backupId)) {
|
||||
throw new Error(`The id (${backupId}) not correspond to a metadata folder`)
|
||||
}
|
||||
|
||||
await this._handler.rmtree(backupId)
|
||||
}
|
||||
|
||||
async deleteOldMetadataBackups(dir, retention) {
|
||||
@@ -152,23 +128,26 @@ export class RemoteAdapter {
|
||||
await asyncMapSettled(list, timestamp => handler.rmtree(`${dir}/${timestamp}`))
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object[]} backups metadata of the backups to delete
|
||||
* @param {object} [opts]
|
||||
* @param {import('./_backupJournal.mjs').BackupJournalReason} [opts.reason] what triggered the
|
||||
* deletion, as recorded in the journal
|
||||
*/
|
||||
async deleteFullVmBackups(backups, { reason = 'retention' } = {}) {
|
||||
await asyncMapSettled(backups, async ({ _filename, xva }) => {
|
||||
try {
|
||||
await deleteFullVmBackupFiles(this._handler, [{ metadataPath: _filename, xva }])
|
||||
} catch (error) {
|
||||
warn('error while removing full vm backup', { error, filename: _filename, failedPath: error.path })
|
||||
throw error
|
||||
}
|
||||
})
|
||||
async deleteFullVmBackups(backups) {
|
||||
const handler = this._handler
|
||||
await asyncMapSettled(backups, ({ _filename, xva }) =>
|
||||
Promise.all([
|
||||
handler.unlink(_filename).catch(error => {
|
||||
warn('error while removing full vm backup metadata', { error, filename: _filename })
|
||||
if (error.code !== 'ENOENT') throw error
|
||||
}),
|
||||
handler.unlink(resolveRelativeFromFile(_filename, xva)).catch(error => {
|
||||
warn('error while removing full vm backup file', { error, filename: _filename })
|
||||
if (error.code !== 'ENOENT') throw error
|
||||
}),
|
||||
handler.unlink(resolveRelativeFromFile(_filename, `${xva}.checksum`)).catch(error => {
|
||||
// checksum can be missing , it's not an issue
|
||||
if (error.code !== 'ENOENT') throw error
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
await this.#forgetVmBackups(backups, reason)
|
||||
await this.#removeVmBackupsFromCache(backups)
|
||||
}
|
||||
|
||||
deleteVmBackup(file) {
|
||||
@@ -207,13 +186,13 @@ export class RemoteAdapter {
|
||||
}
|
||||
const promises = []
|
||||
if (delta !== undefined) {
|
||||
promises.push(this.deleteDeltaVmBackups(delta, { reason: 'user' }))
|
||||
promises.push(this.deleteDeltaVmBackups(delta))
|
||||
}
|
||||
if (full !== undefined) {
|
||||
promises.push(this.deleteFullVmBackups(full, { reason: 'user' }))
|
||||
promises.push(this.deleteFullVmBackups(full))
|
||||
}
|
||||
if (missingFiles.length) {
|
||||
promises.push(this.#forgetVmBackups(missingFiles, 'user'))
|
||||
promises.push(this.#removeVmBackupsFromCache(missingFiles))
|
||||
}
|
||||
await Promise.all(promises)
|
||||
|
||||
@@ -319,18 +298,18 @@ export class RemoteAdapter {
|
||||
}
|
||||
|
||||
async _readCache(path) {
|
||||
return readBackupCache(this.handler, path, warn)
|
||||
try {
|
||||
return JSON.parse(await fromCallback(zlib.gunzip, await this.handler.readFile(path)))
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
warn('#readCache', { error, path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_updateCache = synchronized.withKey()(this._updateCache)
|
||||
// eslint-disable-next-line no-dupe-class-members
|
||||
async _updateCache(path, fn) {
|
||||
// immutable remote can't use any caching
|
||||
// since the cache file may be non modifiable, and would then stay billed forever
|
||||
if (this._handler.isImmutable()) {
|
||||
return
|
||||
}
|
||||
|
||||
const cache = await this._readCache(path)
|
||||
if (cache !== undefined) {
|
||||
fn(cache)
|
||||
@@ -345,7 +324,11 @@ export class RemoteAdapter {
|
||||
}
|
||||
|
||||
async _writeCache(path, data) {
|
||||
return writeBackupCache(this.handler, path, data, warn)
|
||||
try {
|
||||
await this.handler.writeFile(path, await fromCallback(zlib.gzip, JSON.stringify(data)), { flags: 'w' })
|
||||
} catch (error) {
|
||||
warn('#writeCache', { error, path })
|
||||
}
|
||||
}
|
||||
|
||||
async #getCacheableDataListVmBackups(dir) {
|
||||
@@ -448,16 +431,6 @@ export class RemoteAdapter {
|
||||
return backups.sort(compareTimestamp)
|
||||
}
|
||||
|
||||
// read the backup events which happened on this remote after `since` (timestamp in ms),
|
||||
// oldest first
|
||||
/**
|
||||
* @param {number} [since] timestamp in ms, exclusive
|
||||
* @returns {Promise<import('./_backupJournal.mjs').BackupJournalEntry[]>}
|
||||
*/
|
||||
async readBackupJournal(since) {
|
||||
return readBackupJournal(this._handler, since)
|
||||
}
|
||||
|
||||
async writeVmBackupMetadata(vmUuid, metadata) {
|
||||
const path = `/${BACKUP_DIR}/${vmUuid}/${formatFilenameDate(metadata.timestamp)}.json`
|
||||
|
||||
@@ -465,19 +438,6 @@ export class RemoteAdapter {
|
||||
dirMode: this._dirMode,
|
||||
})
|
||||
|
||||
// will not throw
|
||||
await writeBackupJournalEntry(
|
||||
this._handler,
|
||||
{
|
||||
event: 'add',
|
||||
vmUuid,
|
||||
filename: path,
|
||||
who: { jobId: metadata.jobId, scheduleId: metadata.scheduleId },
|
||||
reason: 'backup',
|
||||
},
|
||||
{ dirMode: this._dirMode }
|
||||
)
|
||||
|
||||
// will not throw
|
||||
await this._updateCache(this.#getVmBackupsCache(vmUuid), backups => {
|
||||
debug('adding cache entry', { entry: path })
|
||||
@@ -681,51 +641,15 @@ export class RemoteAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// journal the metadata files `cleanVm` removed and rewrote
|
||||
//
|
||||
// `removedFiles` also lists the files which would have been removed if `remove` were set, and files
|
||||
// which are not backup metadata (stray xva, checksums, …), hence the filtering.
|
||||
/**
|
||||
* @param {RemoteAdapter} adapter
|
||||
* @param {string} vmBackupPath directory of the cleaned VM, e.g. `xo-vm-backups/<vmUuid>`
|
||||
* @param {object} cleanOpts the options `cleanVm()` ran with
|
||||
* @param {boolean} [cleanOpts.remove] whether the removals were actually applied
|
||||
* @param {object} result the result of `cleanVm()`
|
||||
* @param {string[]} [result.removedFiles]
|
||||
* @param {string[]} [result.changedFiles]
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function journalCleanVm(adapter, vmBackupPath, { remove }, { removedFiles = [], changedFiles = [] }) {
|
||||
const dir = resolve('/', vmBackupPath)
|
||||
const vmUuid = basename(dir)
|
||||
const isVmMetadata = file => isMetadataFile(file) && dirname(resolve('/', file)) === dir
|
||||
|
||||
const entries = []
|
||||
if (remove) {
|
||||
for (const filename of new Set(removedFiles.filter(isVmMetadata))) {
|
||||
entries.push({ event: 'del', vmUuid, filename, reason: 'clean-vm' })
|
||||
}
|
||||
}
|
||||
for (const filename of new Set(changedFiles.filter(isVmMetadata))) {
|
||||
entries.push({ event: 'change', vmUuid, filename, reason: 'merge' })
|
||||
}
|
||||
|
||||
// will not reject
|
||||
await writeBackupJournalEntries(adapter._handler, entries, { dirMode: adapter._dirMode })
|
||||
}
|
||||
|
||||
Object.assign(RemoteAdapter.prototype, {
|
||||
cleanVm(vmBackupPath, opts = {}) {
|
||||
const { lock = true, ...cleanOpts } = opts
|
||||
const run = async () => {
|
||||
const result = await VmBackupDirectory.cleanVm(this._handler, vmBackupPath, cleanOpts)
|
||||
await journalCleanVm(this, vmBackupPath, cleanOpts, result)
|
||||
return result
|
||||
}
|
||||
if (lock) {
|
||||
return Disposable.use(this._handler.lock(vmBackupPath), run)
|
||||
return Disposable.use(this._handler.lock(vmBackupPath), () => {
|
||||
return VmBackupDirectory.cleanVm(this._handler, vmBackupPath, cleanOpts)
|
||||
})
|
||||
} else {
|
||||
return run()
|
||||
return VmBackupDirectory.cleanVm(this._handler, vmBackupPath, cleanOpts)
|
||||
}
|
||||
},
|
||||
isValidXva,
|
||||
|
||||
@@ -1,408 +0,0 @@
|
||||
import test from 'node:test'
|
||||
import { strict as assert } from 'node:assert'
|
||||
|
||||
import tmp from 'tmp'
|
||||
import fs from 'fs-extra'
|
||||
import * as uuid from 'uuid'
|
||||
import { getHandler } from '@xen-orchestra/fs'
|
||||
import { pFromCallback } from 'promise-toolbox'
|
||||
import { setTimeout as sleep } from 'node:timers/promises'
|
||||
import { RemoteAdapter } from './RemoteAdapter.mjs'
|
||||
import { VHDFOOTER, VHDHEADER } from './tests.fixtures.mjs'
|
||||
import { VhdFile, Constants } from 'vhd-lib'
|
||||
import { rimraf } from 'rimraf'
|
||||
|
||||
import { BACKUP_JOURNAL_DIR, formatJournalDay, formatJournalTime } from './_backupJournal.mjs'
|
||||
import { formatFilenameDate } from './_filenameDate.mjs'
|
||||
|
||||
const { beforeEach, afterEach, describe } = test
|
||||
|
||||
const noop = Function.prototype
|
||||
const byFilename = (a, b) => (a.filename < b.filename ? -1 : 1)
|
||||
|
||||
const vmUuid = 'a1b2c3d4-0000-0000-0000-000000000000'
|
||||
const rootPath = `xo-vm-backups/${vmUuid}`
|
||||
|
||||
let tempDir, adapter, handler, jobId, scheduleId, relativePath, basePath
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = await pFromCallback(cb => tmp.dir(cb))
|
||||
handler = getHandler({ url: `file://${tempDir}` })
|
||||
await handler.sync()
|
||||
adapter = new RemoteAdapter(handler)
|
||||
jobId = uniqueId()
|
||||
scheduleId = uniqueId()
|
||||
relativePath = `vdis/${jobId}/${uniqueId()}`
|
||||
basePath = `${rootPath}/${relativePath}`
|
||||
await fs.mkdirp(`${tempDir}/${basePath}`)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await rimraf(tempDir)
|
||||
await handler.forget()
|
||||
})
|
||||
|
||||
const uniqueId = () => uuid.v1()
|
||||
const uniqueIdBuffer = () => uuid.v1({}, Buffer.alloc(16))
|
||||
|
||||
const listJournalDays = () => handler.list(`/${BACKUP_JOURNAL_DIR}`, { ignoreMissing: true })
|
||||
|
||||
// paths of the journal entries of every day, oldest first
|
||||
async function listJournal() {
|
||||
const paths = []
|
||||
for (const day of (await listJournalDays()).filter(name => /^\d{8}$/.test(name))) {
|
||||
paths.push(...(await handler.list(`/${BACKUP_JOURNAL_DIR}/${day}`, { prependDir: true })))
|
||||
}
|
||||
return paths.sort()
|
||||
}
|
||||
|
||||
// writes a journal entry the way a past run would have, i.e. in the directory of its own day
|
||||
function writeJournalEntryAt(timestamp, entry) {
|
||||
const name = `${formatJournalTime(timestamp)}-000000-${entry.event}-${entry.vmUuid}-${entry.filename.split('/').pop()}`
|
||||
return handler.outputFile(
|
||||
`/${BACKUP_JOURNAL_DIR}/${formatJournalDay(timestamp)}/${name}`,
|
||||
JSON.stringify({ ...entry, timestamp })
|
||||
)
|
||||
}
|
||||
|
||||
// journal entries are stamped with the writer's clock, therefore a watermark used in an assertion
|
||||
// must be strictly between the entries written before it and the ones written after it
|
||||
async function mark() {
|
||||
await sleep(5)
|
||||
const since = Date.now()
|
||||
await sleep(5)
|
||||
return since
|
||||
}
|
||||
|
||||
async function generateVhd(path, opts = {}) {
|
||||
const fd = await handler.openFile(path, 'wx')
|
||||
const vhd = new VhdFile(handler, fd)
|
||||
|
||||
vhd.header = { ...VHDHEADER, ...opts.header }
|
||||
vhd.footer = { ...VHDFOOTER, ...opts.footer, uuid: uniqueIdBuffer() }
|
||||
vhd.footer.diskType = vhd.header.parentUuid ? Constants.DISK_TYPES.DIFFERENCING : Constants.DISK_TYPES.DYNAMIC
|
||||
|
||||
for (const blockId of opts.blocks ?? []) {
|
||||
await vhd.writeEntireBlock({ id: blockId, buffer: Buffer.alloc(2 * 1024 * 1024 + 512, blockId) })
|
||||
}
|
||||
await vhd.writeBlockAllocationTable()
|
||||
await vhd.writeHeader()
|
||||
await vhd.writeFooter()
|
||||
return vhd
|
||||
}
|
||||
|
||||
// enough to satisfy isValidXva(): uncompressed, more than 1024 bytes, a multiple of 512, and ending
|
||||
// with 1024 zeroed bytes
|
||||
const createMinimalXva = () => Buffer.alloc(2048)
|
||||
|
||||
// write backups the way a backup job would, i.e. through the adapter
|
||||
async function writeFullBackup(timestamp = Date.now()) {
|
||||
const xva = `${formatFilenameDate(timestamp)}.xva`
|
||||
await handler.outputFile(`/${rootPath}/${xva}`, createMinimalXva())
|
||||
return adapter.writeVmBackupMetadata(vmUuid, {
|
||||
mode: 'full',
|
||||
xva: `./${xva}`,
|
||||
vm: { uuid: vmUuid },
|
||||
jobId,
|
||||
scheduleId,
|
||||
timestamp,
|
||||
size: await handler.getSize(`/${rootPath}/${xva}`),
|
||||
})
|
||||
}
|
||||
|
||||
async function writeDeltaBackup(timestamp = Date.now()) {
|
||||
const vhd = `${formatFilenameDate(timestamp)}.vhd`
|
||||
await generateVhd(`${basePath}/${vhd}`, { blocks: [0] })
|
||||
return adapter.writeVmBackupMetadata(vmUuid, {
|
||||
mode: 'delta',
|
||||
vhds: { vdi: `${relativePath}/${vhd}` },
|
||||
vdis: { vdi: {} },
|
||||
vm: { uuid: vmUuid },
|
||||
jobId,
|
||||
scheduleId,
|
||||
timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
describe('backup journal', { concurrency: 1 }, () => {
|
||||
test('writeVmBackupMetadata() records an `add` event', async () => {
|
||||
const path = await writeFullBackup()
|
||||
|
||||
const entries = await adapter.readBackupJournal(0)
|
||||
assert.equal(entries.length, 1)
|
||||
|
||||
const { date, timestamp, _filename, ...entry } = entries[0]
|
||||
assert.deepEqual(entry, {
|
||||
event: 'add',
|
||||
vmUuid,
|
||||
filename: path,
|
||||
who: { jobId, scheduleId },
|
||||
reason: 'backup',
|
||||
})
|
||||
assert.equal(date.getTime(), timestamp)
|
||||
assert.equal(_filename, (await listJournal())[0])
|
||||
})
|
||||
|
||||
test('the entry is stored in the directory of its day, named after the time, the event and the backup', async () => {
|
||||
const path = await writeFullBackup()
|
||||
|
||||
const [entryPath] = await listJournal()
|
||||
const { timestamp } = (await adapter.readBackupJournal(0))[0]
|
||||
|
||||
const name = entryPath.split('/').pop()
|
||||
assert.equal(entryPath, `/${BACKUP_JOURNAL_DIR}/${formatJournalDay(timestamp)}/${name}`)
|
||||
assert.equal(name.slice(0, 11), formatJournalTime(timestamp), 'the day must not be repeated in the name')
|
||||
assert.ok(name.endsWith(`-add-${vmUuid}-${path.split('/').pop()}`), name)
|
||||
})
|
||||
|
||||
test('deleting a backup records a `del` event', async () => {
|
||||
const full = await writeFullBackup(Date.now() - 2000)
|
||||
const delta = await writeDeltaBackup(Date.now() - 1000)
|
||||
|
||||
const since = await mark()
|
||||
await adapter.deleteVmBackups([full, delta])
|
||||
|
||||
const entries = await adapter.readBackupJournal(since)
|
||||
assert.deepEqual(
|
||||
entries
|
||||
.map(({ event, filename, vmUuid, reason, who }) => ({ event, filename, vmUuid, reason, who }))
|
||||
.sort(byFilename),
|
||||
[
|
||||
{ event: 'del', filename: full, vmUuid, reason: 'user', who: { jobId, scheduleId } },
|
||||
{ event: 'del', filename: delta, vmUuid, reason: 'user', who: { jobId, scheduleId } },
|
||||
].sort(byFilename)
|
||||
)
|
||||
})
|
||||
|
||||
test('deleting a backup through the retention path records the `retention` reason', async () => {
|
||||
await writeDeltaBackup()
|
||||
const [backup] = await adapter.listVmBackups(vmUuid)
|
||||
|
||||
const since = await mark()
|
||||
await adapter.deleteDeltaVmBackups([backup])
|
||||
|
||||
const entries = await adapter.readBackupJournal(since)
|
||||
assert.equal(entries.length, 1)
|
||||
assert.equal(entries[0].event, 'del')
|
||||
assert.equal(entries[0].reason, 'retention')
|
||||
})
|
||||
|
||||
test('deleting an already deleted backup still records a `del` event', async () => {
|
||||
const path = await writeFullBackup()
|
||||
await handler.unlink(path)
|
||||
|
||||
const since = await mark()
|
||||
await adapter.deleteVmBackup(path)
|
||||
|
||||
const entries = await adapter.readBackupJournal(since)
|
||||
assert.equal(entries.length, 1)
|
||||
assert.equal(entries[0].event, 'del')
|
||||
assert.equal(entries[0].filename, path)
|
||||
assert.equal(entries[0].vmUuid, vmUuid)
|
||||
assert.equal(entries[0].who, undefined)
|
||||
})
|
||||
|
||||
test('a merge records a `change` event, and cleaning an incomplete backup a `del` one', async () => {
|
||||
// an incomplete delta backup: its disk is missing
|
||||
await handler.outputFile(
|
||||
`/${rootPath}/incomplete.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: { vdi: `${relativePath}/gone.vhd` }, vdis: { vdi: {} } })
|
||||
)
|
||||
|
||||
// a complete one whose disk has an orphan ancestor to merge
|
||||
const parent = await generateVhd(`${basePath}/parent.vhd`, { blocks: [0] })
|
||||
await generateVhd(`${basePath}/child.vhd`, {
|
||||
header: { parentUnicodeName: 'parent.vhd', parentUuid: parent.footer.uuid },
|
||||
blocks: [1],
|
||||
})
|
||||
await handler.outputFile(
|
||||
`/${rootPath}/complete.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: { vdi: `${relativePath}/child.vhd` }, vdis: { vdi: {} }, size: 1 })
|
||||
)
|
||||
|
||||
const since = await mark()
|
||||
const result = await adapter.cleanVm(rootPath, {
|
||||
remove: true,
|
||||
merge: true,
|
||||
logInfo: noop,
|
||||
logWarn: noop,
|
||||
lock: false,
|
||||
})
|
||||
assert.ok(result.size > 0, 'nothing was merged')
|
||||
|
||||
const entries = await adapter.readBackupJournal(since)
|
||||
assert.deepEqual(
|
||||
entries.map(({ event, filename, vmUuid, reason }) => ({ event, filename, vmUuid, reason })).sort(byFilename),
|
||||
[
|
||||
{ event: 'change', filename: `/${rootPath}/complete.json`, vmUuid, reason: 'merge' },
|
||||
{ event: 'del', filename: `/${rootPath}/incomplete.json`, vmUuid, reason: 'clean-vm' },
|
||||
]
|
||||
)
|
||||
})
|
||||
|
||||
test('a dry run of cleanVm() records nothing', async () => {
|
||||
await handler.outputFile(
|
||||
`/${rootPath}/incomplete.json`,
|
||||
JSON.stringify({ mode: 'delta', vhds: { vdi: `${relativePath}/gone.vhd` }, vdis: { vdi: {} } })
|
||||
)
|
||||
|
||||
const since = await mark()
|
||||
await adapter.cleanVm(rootPath, { remove: false, logInfo: noop, logWarn: noop, lock: false })
|
||||
|
||||
assert.deepEqual(await adapter.readBackupJournal(since), [])
|
||||
})
|
||||
|
||||
test('a failure to journal does not fail the operation it journals', async () => {
|
||||
const outputFile = handler._outputFile.bind(handler)
|
||||
handler._outputFile = async (path, ...rest) => {
|
||||
if (path.startsWith(`/${BACKUP_JOURNAL_DIR}/`)) {
|
||||
const error = new Error('EACCES: permission denied')
|
||||
error.code = 'EACCES'
|
||||
throw error
|
||||
}
|
||||
return outputFile(path, ...rest)
|
||||
}
|
||||
|
||||
const path = await writeFullBackup()
|
||||
|
||||
assert.ok(await handler.getSize(path))
|
||||
assert.deepEqual(await listJournal(), [])
|
||||
})
|
||||
})
|
||||
|
||||
describe('readBackupJournal()', { concurrency: 1 }, () => {
|
||||
const DAY = 24 * 60 * 60 * 1e3
|
||||
|
||||
test('returns nothing on a repository without a journal', async () => {
|
||||
assert.deepEqual(await adapter.readBackupJournal(0), [])
|
||||
})
|
||||
|
||||
test('replays the days since `since`, oldest first', async () => {
|
||||
const old = `/${rootPath}/old.json`
|
||||
const twoDaysAgo = Date.now() - 2 * DAY
|
||||
await writeJournalEntryAt(twoDaysAgo, { event: 'add', vmUuid, filename: old, reason: 'backup' })
|
||||
const recent = await writeFullBackup()
|
||||
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(twoDaysAgo - 1000)).map(_ => _.filename),
|
||||
[old, recent]
|
||||
)
|
||||
})
|
||||
|
||||
test('does not read the days older than `since`', async () => {
|
||||
await writeJournalEntryAt(Date.now() - 2 * DAY, {
|
||||
event: 'add',
|
||||
vmUuid,
|
||||
filename: `/${rootPath}/old.json`,
|
||||
reason: 'backup',
|
||||
})
|
||||
const recent = await writeFullBackup()
|
||||
|
||||
const listed = []
|
||||
const list = handler.list.bind(handler)
|
||||
handler.list = (dir, ...rest) => {
|
||||
listed.push(dir)
|
||||
return list(dir, ...rest)
|
||||
}
|
||||
|
||||
const since = Date.now() - 60e3
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(since)).map(_ => _.filename),
|
||||
[recent]
|
||||
)
|
||||
|
||||
// only the journal root and today's directory, whatever the number of days the journal holds
|
||||
assert.deepEqual(listed, [`/${BACKUP_JOURNAL_DIR}`, `/${BACKUP_JOURNAL_DIR}/${formatJournalDay(since)}`])
|
||||
})
|
||||
|
||||
test('`since` only bounds the time of its own day, not of the days after it', async () => {
|
||||
// regression guard: entries are named after their time only, so the time of `since` must be
|
||||
// compared with the entries of its own day and with no other, otherwise an entry of an early
|
||||
// hour of a later day looks older than a `since` of a late hour
|
||||
const midnight = Math.floor(Date.now() / DAY) * DAY
|
||||
const lateYesterday = `/${rootPath}/late-yesterday.json`
|
||||
const earlyToday = `/${rootPath}/early-today.json`
|
||||
await writeJournalEntryAt(midnight - 30 * 60e3, { event: 'add', vmUuid, filename: lateYesterday })
|
||||
await writeJournalEntryAt(midnight + 30 * 60e3, { event: 'add', vmUuid, filename: earlyToday })
|
||||
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(midnight - 60 * 60e3)).map(_ => _.filename),
|
||||
[lateYesterday, earlyToday]
|
||||
)
|
||||
|
||||
// 23:45 of yesterday: its own day is bounded, today is not
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(midnight - 15 * 60e3)).map(_ => _.filename),
|
||||
[earlyToday]
|
||||
)
|
||||
})
|
||||
|
||||
test('returns the entries stamped after `since`, oldest first', async () => {
|
||||
const first = await writeFullBackup(Date.now() - 2000)
|
||||
const since = await mark()
|
||||
const second = await writeDeltaBackup(Date.now() - 1000)
|
||||
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(0)).map(_ => _.filename),
|
||||
[first, second]
|
||||
)
|
||||
assert.deepEqual(
|
||||
(await adapter.readBackupJournal(since)).map(_ => _.filename),
|
||||
[second]
|
||||
)
|
||||
assert.deepEqual(await adapter.readBackupJournal(Date.now() + 1000), [])
|
||||
})
|
||||
|
||||
test('skips truncated entries and unrecognized filenames without hiding their siblings', async () => {
|
||||
const path = await writeFullBackup()
|
||||
const [entryPath] = await listJournal()
|
||||
const day = formatJournalDay(Date.now())
|
||||
|
||||
// a partially written entry
|
||||
await handler.writeFile(
|
||||
`/${BACKUP_JOURNAL_DIR}/${day}/${formatJournalTime(Date.now())}-000000-add-${vmUuid}-truncated.json`,
|
||||
'{"ev'
|
||||
)
|
||||
// a file which is not a journal entry at all
|
||||
await handler.writeFile(`/${BACKUP_JOURNAL_DIR}/${day}/README`, 'hello')
|
||||
// a stray file where only day directories are expected
|
||||
await handler.writeFile(`/${BACKUP_JOURNAL_DIR}/README`, 'hello')
|
||||
|
||||
const entries = await adapter.readBackupJournal(0)
|
||||
assert.deepEqual(
|
||||
entries.map(_ => _.filename),
|
||||
[path]
|
||||
)
|
||||
assert.equal(entries[0]._filename, entryPath)
|
||||
})
|
||||
})
|
||||
|
||||
describe('backup journal on an encrypted remote', { concurrency: 1 }, () => {
|
||||
test('entries are readable without the encryption key', async () => {
|
||||
const encryptedDir = await pFromCallback(cb => tmp.dir(cb))
|
||||
const encryptedHandler = getHandler({
|
||||
url: `file://${encryptedDir}?encryptionKey="73c1838d7d8a6088ca2317fb5f29cd00"`,
|
||||
})
|
||||
try {
|
||||
await encryptedHandler.sync()
|
||||
assert.equal(encryptedHandler.isEncrypted, true)
|
||||
|
||||
const encryptedAdapter = new RemoteAdapter(encryptedHandler)
|
||||
await encryptedAdapter.writeVmBackupMetadata(vmUuid, {
|
||||
mode: 'full',
|
||||
vm: { uuid: vmUuid },
|
||||
jobId,
|
||||
scheduleId,
|
||||
timestamp: Date.now(),
|
||||
})
|
||||
|
||||
const [day] = await encryptedHandler.list(`/${BACKUP_JOURNAL_DIR}`)
|
||||
const [name] = await encryptedHandler.list(`/${BACKUP_JOURNAL_DIR}/${day}`)
|
||||
const raw = await fs.readFile(`${encryptedDir}/${BACKUP_JOURNAL_DIR}/${day}/${name}`)
|
||||
assert.equal(JSON.parse(String(raw)).event, 'add')
|
||||
} finally {
|
||||
await encryptedHandler.forget()
|
||||
await rimraf(encryptedDir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,272 +0,0 @@
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import { basename, normalize } from '@xen-orchestra/fs/path'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { utcFormat, utcParse } from 'd3-time-format'
|
||||
|
||||
const { debug, warn } = createLogger('xo:backups:backupJournal')
|
||||
|
||||
/**
|
||||
* A remote handler, plus the two unencrypted read/write primitives this module relies on to keep
|
||||
* the journal readable without the encryption key. They are not part of the handler's declared
|
||||
* public surface (`@xen-orchestra/fs/src/types/fs.mts`), hence the intersection.
|
||||
*
|
||||
* @typedef {import('@xen-orchestra/fs').RemoteHandlerAbstract & {
|
||||
* _outputFile(file: string, data: string, opts?: { dirMode?: number, flags?: string }): Promise<void>
|
||||
* _readFile(file: string): Promise<Buffer>
|
||||
* }} RemoteHandler
|
||||
*/
|
||||
|
||||
/**
|
||||
* What happened to the backup metadata this entry is about.
|
||||
*
|
||||
* - `add`: the backup was written
|
||||
* - `change`: the metadata was rewritten in place, the backup itself still exists
|
||||
* - `del`: the backup was removed
|
||||
*
|
||||
* @typedef {'add'|'change'|'del'} BackupJournalEvent
|
||||
*/
|
||||
|
||||
/**
|
||||
* What triggered the event.
|
||||
*
|
||||
* - `backup`: a backup job wrote it
|
||||
* - `retention`: it was rotated out by a retention setting
|
||||
* - `user`: a user explicitly deleted it
|
||||
* - `clean-vm`: `cleanVm()` removed it, e.g. the metadata of an incomplete backup
|
||||
* - `merge`: `cleanVm()` rewrote its size after merging its disks
|
||||
*
|
||||
* @typedef {'backup'|'retention'|'user'|'clean-vm'|'merge'} BackupJournalReason
|
||||
*/
|
||||
|
||||
/**
|
||||
* The XO entities responsible for the event, when they are known.
|
||||
*
|
||||
* @typedef {object} BackupJournalWho
|
||||
* @property {string} [jobId]
|
||||
* @property {string} [scheduleId]
|
||||
*/
|
||||
|
||||
/**
|
||||
* An event to append to the journal.
|
||||
*
|
||||
* @typedef {object} NewBackupJournalEntry
|
||||
* @property {BackupJournalEvent} event
|
||||
* @property {string} vmUuid
|
||||
* @property {string} filename path of the backup metadata this event is about
|
||||
* @property {BackupJournalWho} [who]
|
||||
* @property {BackupJournalReason} [reason]
|
||||
*/
|
||||
|
||||
/**
|
||||
* An event read back from the journal: what was written, plus the fields derived from the entry
|
||||
* itself.
|
||||
*
|
||||
* `timestamp` is the writer's clock at the time of the write; `date` is that same instant, parsed
|
||||
* back from the entry name.
|
||||
*
|
||||
* @typedef {NewBackupJournalEntry & {
|
||||
* timestamp: number
|
||||
* date: Date
|
||||
* _filename: string
|
||||
* }} BackupJournalEntry
|
||||
*/
|
||||
|
||||
// Append-only event log of the backups present on a repository.
|
||||
//
|
||||
// Entries are never modified nor overwritten, which makes the journal usable on immutable
|
||||
// (Object Lock) repositories, where `cache.json.gz` cannot be rewritten.
|
||||
export const BACKUP_JOURNAL_DIR = 'xo-backup-log'
|
||||
|
||||
// Same idea as `formatFilenameDate` but with milliseconds, so that two events on the same VM
|
||||
// within the same second keep distinct, ordered names.
|
||||
const formatDate = utcFormat('%Y%m%dT%H%M%S.%LZ')
|
||||
|
||||
// the time part alone, which is what an entry is named after: its day is already the name of the
|
||||
// directory holding it
|
||||
const formatTime = utcFormat('%H%M%S.%LZ')
|
||||
|
||||
/**
|
||||
* Formats a timestamp into the date part of a journal entry name.
|
||||
*
|
||||
* Takes a timestamp rather than a `Date` because that is what every caller has; `d3-time-format`
|
||||
* would coerce it anyway, but its declared signature does not say so.
|
||||
*
|
||||
* @param {number} timestamp in ms
|
||||
* @returns {string}
|
||||
*/
|
||||
export const formatJournalDate = timestamp => formatDate(new Date(timestamp))
|
||||
|
||||
/**
|
||||
* Formats a timestamp into the day part of a journal entry path, i.e. the name of the directory
|
||||
* holding it.
|
||||
*
|
||||
* @param {number} timestamp in ms
|
||||
* @returns {string} `YYYYMMDD`
|
||||
*/
|
||||
export const formatJournalDay = timestamp => dayOfDate(formatJournalDate(timestamp))
|
||||
|
||||
/**
|
||||
* Formats a timestamp into the time part of a journal entry name.
|
||||
*
|
||||
* @param {number} timestamp in ms
|
||||
* @returns {string} `HHMMSS.mmmZ`
|
||||
*/
|
||||
export const formatJournalTime = timestamp => formatTime(new Date(timestamp))
|
||||
|
||||
/**
|
||||
* Reads back the date of a journal entry, from its day and the time part of its name.
|
||||
*
|
||||
* @param {string} date `YYYYMMDDTHHMMSS.mmmZ`, i.e. `<day>T<time>`
|
||||
* @returns {Date | null} `null` when the name is not a journal entry
|
||||
*/
|
||||
export const parseJournalDate = utcParse('%Y%m%dT%H%M%S.%LZ')
|
||||
|
||||
// `YYYYMMDDTHHMMSS.mmmZ`, a day and a time joined by a `T`
|
||||
const DATE_LENGTH = formatJournalDate(0).length
|
||||
|
||||
// `YYYYMMDD`, the leading part of a formatted date
|
||||
const DAY_LENGTH = 8
|
||||
|
||||
// `HHMMSS.mmmZ`, a formatted date without its day nor the `T` separating the two
|
||||
//
|
||||
// it has a fixed width, therefore sorting the entry names of a day lexicographically sorts them
|
||||
// chronologically, and so does sorting whole paths across days
|
||||
const TIME_LENGTH = DATE_LENGTH - DAY_LENGTH - 1
|
||||
|
||||
const dayOfDate = date => date.slice(0, DAY_LENGTH)
|
||||
|
||||
const isDayName = name => /^\d{8}$/.test(name)
|
||||
|
||||
// reassembles what `parseJournalDate()` expects from where each part is stored
|
||||
const dateOfEntry = (day, name) => parseJournalDate(`${day}T${name.slice(0, TIME_LENGTH)}`)
|
||||
|
||||
// `/xo-backup-log/<day>/<time>-<random>-<event>-<vmUuid>-<metadata filename>`
|
||||
//
|
||||
// Entries are grouped in one directory per UTC day, so that a reader lists only the days it is
|
||||
// missing instead of the whole history of the repository, and a purge removes whole directories.
|
||||
// The day is therefore not repeated in the name: an entry is named after its time only.
|
||||
//
|
||||
// Everything after the time is only there to make the journal readable by a human: the date is read
|
||||
// back from the day and the time, all the other fields are read back from the entry itself.
|
||||
/**
|
||||
* @param {object} entry
|
||||
* @param {number} entry.timestamp the event date, in ms
|
||||
* @param {BackupJournalEvent} entry.event
|
||||
* @param {string} entry.vmUuid
|
||||
* @param {string} entry.filename path of the backup metadata this event is about
|
||||
* @returns {string} path of the journal entry, unique thanks to a random part
|
||||
*/
|
||||
function getEntryPath({ timestamp, event, vmUuid, filename }) {
|
||||
const unique = randomBytes(3).toString('hex')
|
||||
const name = `${formatJournalTime(timestamp)}-${unique}-${event}-${vmUuid}-${basename(filename)}`
|
||||
return `/${BACKUP_JOURNAL_DIR}/${formatJournalDay(timestamp)}/${name}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an event to the journal.
|
||||
*
|
||||
* Never rejects: journaling is best effort, a failure here must not fail the backup or the deletion
|
||||
* that triggered it. The resulting drift is bounded by the periodic full rebuild of the readers.
|
||||
*
|
||||
* The entry is stamped with the writer's clock at the time of this call.
|
||||
*
|
||||
* @param {RemoteHandler} handler
|
||||
* @param {NewBackupJournalEntry} entry
|
||||
* @param {object} [opts]
|
||||
* @param {number} [opts.dirMode] mode of the journal directory, if it has to be created
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function writeBackupJournalEntry(handler, { event, vmUuid, filename, who, reason }, { dirMode } = {}) {
|
||||
const timestamp = Date.now()
|
||||
const path = getEntryPath({ timestamp, event, vmUuid, filename })
|
||||
try {
|
||||
// this file is not encrypted, so that it stays readable by tools which don't have the
|
||||
// encryption key (e.g. the `immutable-backups` daemon)
|
||||
await handler._outputFile(normalize(path), JSON.stringify({ event, vmUuid, filename, timestamp, who, reason }), {
|
||||
dirMode,
|
||||
flags: 'wx',
|
||||
})
|
||||
debug('journal entry written', { path })
|
||||
} catch (error) {
|
||||
warn('failed to write journal entry', { error, path })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends multiple events to the journal, concurrently.
|
||||
*
|
||||
* Never rejects, see `writeBackupJournalEntry()`. Entries are not written atomically as a group: a
|
||||
* reader can observe a subset of them.
|
||||
*
|
||||
* @param {RemoteHandler} handler
|
||||
* @param {NewBackupJournalEntry[]} entries
|
||||
* @param {object} [opts]
|
||||
* @param {number} [opts.dirMode] mode of the journal directory, if it has to be created
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function writeBackupJournalEntries(handler, entries, opts) {
|
||||
await asyncEach(entries, entry => writeBackupJournalEntry(handler, entry, opts))
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the journal entries stamped after `since`, oldest first.
|
||||
*
|
||||
* Corrupt or partially written entries are skipped, they must not hide their siblings. Computing the
|
||||
* watermark to pass as `since` on the next call is the caller's responsibility.
|
||||
*
|
||||
* `since` is exclusive: entries stamped exactly at `since` are not returned.
|
||||
*
|
||||
* @param {RemoteHandler} handler
|
||||
* @param {number} [since] timestamp in ms
|
||||
* @returns {Promise<BackupJournalEntry[]>} oldest first
|
||||
*/
|
||||
export async function readBackupJournal(handler, since = 0) {
|
||||
const minDay = formatJournalDay(since)
|
||||
const minTime = formatJournalTime(since)
|
||||
|
||||
// only the days which can hold entries newer than `since` are listed, therefore the cost of a read
|
||||
// does not grow with the whole history of the repository
|
||||
const days = (
|
||||
await handler.list(`/${BACKUP_JOURNAL_DIR}`, {
|
||||
filter: name => isDayName(name) && name >= minDay,
|
||||
ignoreMissing: true,
|
||||
})
|
||||
).sort()
|
||||
|
||||
/** @type {Array<{ day: string, path: string }>} */
|
||||
const found = []
|
||||
for (const day of days) {
|
||||
// entries are named after their time only: `since` bounds the day it falls into, every later
|
||||
// day is taken whole
|
||||
const names = await handler.list(`/${BACKUP_JOURNAL_DIR}/${day}`, {
|
||||
filter: day === minDay ? name => name.slice(0, TIME_LENGTH) > minTime : undefined,
|
||||
ignoreMissing: true,
|
||||
})
|
||||
for (const name of names) {
|
||||
found.push({ day, path: `/${BACKUP_JOURNAL_DIR}/${day}/${name}` })
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {BackupJournalEntry[]} */
|
||||
const entries = []
|
||||
await asyncEach(found, async ({ day, path }) => {
|
||||
const date = dateOfEntry(day, basename(path))
|
||||
if (date === null) {
|
||||
debug('ignoring unrecognized journal entry', { path })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// this file is not encrypted
|
||||
entries.push({ ...JSON.parse(String(await handler._readFile(normalize(path)))), date, _filename: path })
|
||||
} catch (error) {
|
||||
warn(`can't read journal entry`, { error, path })
|
||||
}
|
||||
})
|
||||
|
||||
// `asyncEach` does not preserve the order of its input
|
||||
entries.sort((a, b) => (a._filename < b._filename ? -1 : 1))
|
||||
|
||||
return entries
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
import test from 'node:test'
|
||||
import { strict as assert } from 'node:assert'
|
||||
|
||||
import { formatJournalDate, formatJournalDay, formatJournalTime, parseJournalDate } from './_backupJournal.mjs'
|
||||
|
||||
const { describe } = test
|
||||
|
||||
describe('formatJournalDate()', () => {
|
||||
test('round trips through parseJournalDate()', () => {
|
||||
for (const timestamp of [0, 1786373412482, Date.UTC(2026, 11, 31, 23, 59, 59, 999)]) {
|
||||
assert.equal(parseJournalDate(formatJournalDate(timestamp)).getTime(), timestamp)
|
||||
}
|
||||
})
|
||||
|
||||
test('is fixed width, therefore lexicographically sortable', () => {
|
||||
const timestamps = [
|
||||
0,
|
||||
// same second
|
||||
Date.UTC(2026, 7, 10, 10, 30, 12, 1),
|
||||
Date.UTC(2026, 7, 10, 10, 30, 12, 482),
|
||||
// day boundary
|
||||
Date.UTC(2026, 7, 10, 23, 59, 59, 999),
|
||||
Date.UTC(2026, 7, 11, 0, 0, 0, 0),
|
||||
// year boundary
|
||||
Date.UTC(2026, 11, 31, 23, 59, 59, 999),
|
||||
Date.UTC(2027, 0, 1, 0, 0, 0, 0),
|
||||
]
|
||||
|
||||
const dates = timestamps.map(formatJournalDate)
|
||||
assert.equal(new Set(dates.map(_ => _.length)).size, 1)
|
||||
assert.deepEqual([...dates].sort(), dates)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatJournalTime()', () => {
|
||||
test('is the date without its day, which names the directory holding the entry', () => {
|
||||
for (const timestamp of [0, 1786373412482, Date.UTC(2026, 11, 31, 23, 59, 59, 999)]) {
|
||||
const day = formatJournalDay(timestamp)
|
||||
const time = formatJournalTime(timestamp)
|
||||
assert.equal(`${day}T${time}`, formatJournalDate(timestamp))
|
||||
assert.equal(parseJournalDate(`${day}T${time}`).getTime(), timestamp)
|
||||
}
|
||||
})
|
||||
|
||||
test('is fixed width, therefore sorts the entries of a day chronologically', () => {
|
||||
const times = [
|
||||
Date.UTC(2026, 7, 10, 0, 0, 0, 0),
|
||||
// same second
|
||||
Date.UTC(2026, 7, 10, 10, 30, 12, 1),
|
||||
Date.UTC(2026, 7, 10, 10, 30, 12, 482),
|
||||
// last instant of the day
|
||||
Date.UTC(2026, 7, 10, 23, 59, 59, 999),
|
||||
].map(formatJournalTime)
|
||||
|
||||
assert.equal(new Set(times.map(_ => _.length)).size, 1)
|
||||
assert.deepEqual([...times].sort(), times)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseJournalDate()', () => {
|
||||
test('returns null on names which are not journal entries', () => {
|
||||
for (const name of ['', 'README', '20260810T103012Z.json', 'cache.json.gz'.slice(0, 20)]) {
|
||||
assert.equal(parseJournalDate(name), null)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -230,6 +230,7 @@ test('it merges delta of non destroyed chain', async () => {
|
||||
logged.push(message)
|
||||
}
|
||||
await adapter.cleanVm(rootPath, { remove: true, logInfo, logWarn: logInfo, lock: false })
|
||||
assert.equal(logged[0], `unexpected number of entries in backup cache`)
|
||||
|
||||
logged = []
|
||||
const result = await adapter.cleanVm(rootPath, { remove: true, merge: true, logInfo, logWarn: () => {}, lock: false })
|
||||
|
||||
@@ -16,15 +16,42 @@ import { toQcow2Stream } from '@xen-orchestra/qcow2'
|
||||
|
||||
const ensureArray = value => (value === undefined ? [] : Array.isArray(value) ? value : [value])
|
||||
|
||||
// The dynamic memory range MUST respect this inequality at any moment: static_min <= dynamic_min <= dynamic_max <= static_max.
|
||||
// VM.set_memory_limits sets all four fields atomically, so there is no intermediate state for XAPI to reject
|
||||
export async function updateMemoryFields(xapi, targetVm, vmRecord) {
|
||||
const staticMin = vmRecord.memory_static_min ?? targetVm.memory_static_min
|
||||
const staticMax = vmRecord.memory_static_max ?? targetVm.memory_static_max
|
||||
const dynamicMin = vmRecord.memory_dynamic_min ?? targetVm.memory_dynamic_min
|
||||
const dynamicMax = vmRecord.memory_dynamic_max ?? targetVm.memory_dynamic_max
|
||||
const orderedMemoryLimits = ['memory_static_min', 'memory_dynamic_min', 'memory_dynamic_max', 'memory_static_max']
|
||||
|
||||
await xapi.call('VM.set_memory_limits', targetVm.$ref, staticMin, staticMax, dynamicMin, dynamicMax)
|
||||
// The dynamic memory range MUST respect this inequality at any moment: static_min <= dynamic_min <= dynamic_max <= static_max.
|
||||
// We must update these properties in the right order to avoid XAPI error.
|
||||
// The order depends on the values. It can be an increase, a decrease or a mix of both, so any order could be required.
|
||||
export async function updateMemoryFields(xapi, targetVm, vmRecord) {
|
||||
const memoryValues = {}
|
||||
for (const key of orderedMemoryLimits) {
|
||||
memoryValues[key] = {
|
||||
currentValue: targetVm[key],
|
||||
newValue: vmRecord[key] ?? targetVm[key],
|
||||
}
|
||||
}
|
||||
|
||||
while (await updateNextMemoryField(xapi, memoryValues, targetVm.$ref)) {
|
||||
/* execute until all memory fields are updated */
|
||||
}
|
||||
}
|
||||
|
||||
// Update one more memory field if needed, then return a boolean describing if a field was updated or if all fields are up to date
|
||||
async function updateNextMemoryField(xapi, memoryValues, vmRef) {
|
||||
for (let i = 0; i < orderedMemoryLimits.length; i++) {
|
||||
const currentField = memoryValues[orderedMemoryLimits[i]]
|
||||
const nextField = i === orderedMemoryLimits.length - 1 ? undefined : memoryValues[orderedMemoryLimits[i + 1]]
|
||||
if (
|
||||
currentField.newValue !== currentField.currentValue &&
|
||||
(nextField === undefined || currentField.newValue <= nextField.currentValue)
|
||||
) {
|
||||
// no need to check that previousField.currentValue <= currentField.newValue, as we can deduce it
|
||||
await xapi.setField('VM', vmRef, orderedMemoryLimits[i], currentField.newValue)
|
||||
await xapi.barrier()
|
||||
currentField.currentValue = currentField.newValue
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function exportIncrementalVm(
|
||||
|
||||
122
@xen-orchestra/backups/_incrementalVm.test.mjs
Normal file
122
@xen-orchestra/backups/_incrementalVm.test.mjs
Normal file
@@ -0,0 +1,122 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { updateMemoryFields } from './_incrementalVm.mjs'
|
||||
|
||||
const MOCK_REF = 'mockRef'
|
||||
|
||||
function mockXapiVm(initialMemoryValues) {
|
||||
const res = {
|
||||
...initialMemoryValues,
|
||||
updates: [],
|
||||
barrier: () => {},
|
||||
setField: (type, ref, field, value) => {
|
||||
assert(type === 'VM')
|
||||
assert(ref === MOCK_REF)
|
||||
res.updates.push({ field, value })
|
||||
res[field] = value
|
||||
assert(res.memory_static_min <= res.memory_dynamic_min)
|
||||
assert(res.memory_dynamic_min <= res.memory_dynamic_max)
|
||||
assert(res.memory_dynamic_max <= res.memory_static_max)
|
||||
},
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
const tests = [
|
||||
{
|
||||
label: 'handles a memory increase',
|
||||
targetVm: {
|
||||
memory_static_min: 2,
|
||||
memory_dynamic_min: 4,
|
||||
memory_dynamic_max: 4,
|
||||
memory_static_max: 8,
|
||||
},
|
||||
vmRecord: {
|
||||
memory_static_min: 16,
|
||||
memory_dynamic_min: 16,
|
||||
memory_dynamic_max: 16,
|
||||
memory_static_max: 16,
|
||||
},
|
||||
expectedUpdates: [
|
||||
{ field: 'memory_static_max', value: 16 },
|
||||
{ field: 'memory_dynamic_max', value: 16 },
|
||||
{ field: 'memory_dynamic_min', value: 16 },
|
||||
{ field: 'memory_static_min', value: 16 },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'handles a memory decrease',
|
||||
targetVm: {
|
||||
memory_static_min: 4,
|
||||
memory_dynamic_min: 8,
|
||||
memory_dynamic_max: 16,
|
||||
memory_static_max: 16,
|
||||
},
|
||||
vmRecord: {
|
||||
memory_static_min: 2,
|
||||
memory_dynamic_min: 2,
|
||||
memory_dynamic_max: 2,
|
||||
memory_static_max: 2,
|
||||
},
|
||||
expectedUpdates: [
|
||||
{ field: 'memory_static_min', value: 2 },
|
||||
{ field: 'memory_dynamic_min', value: 2 },
|
||||
{ field: 'memory_dynamic_max', value: 2 },
|
||||
{ field: 'memory_static_max', value: 2 },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'handles a more complex case',
|
||||
targetVm: {
|
||||
memory_static_min: 1,
|
||||
memory_dynamic_min: 2,
|
||||
memory_dynamic_max: 8,
|
||||
memory_static_max: 16,
|
||||
},
|
||||
vmRecord: {
|
||||
memory_static_min: 4,
|
||||
memory_dynamic_min: 4,
|
||||
memory_dynamic_max: 4,
|
||||
memory_static_max: 4,
|
||||
},
|
||||
expectedUpdates: [
|
||||
{ field: 'memory_dynamic_min', value: 4 },
|
||||
{ field: 'memory_static_min', value: 4 },
|
||||
{ field: 'memory_dynamic_max', value: 4 },
|
||||
{ field: 'memory_static_max', value: 4 },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'avoids updating identical value',
|
||||
targetVm: {
|
||||
memory_static_min: 1,
|
||||
memory_dynamic_min: 2,
|
||||
memory_dynamic_max: 4,
|
||||
memory_static_max: 8,
|
||||
},
|
||||
vmRecord: {
|
||||
memory_static_min: 1,
|
||||
memory_dynamic_min: 2,
|
||||
memory_dynamic_max: 4,
|
||||
memory_static_max: 8,
|
||||
},
|
||||
expectedUpdates: [],
|
||||
},
|
||||
]
|
||||
|
||||
describe('updateMemoryFields() should update in the right order', () => {
|
||||
for (const test of tests) {
|
||||
it(test.label, async () => {
|
||||
const mock = mockXapiVm(test.targetVm)
|
||||
test.targetVm.$ref = MOCK_REF
|
||||
await updateMemoryFields(mock, test.targetVm, test.vmRecord)
|
||||
|
||||
assert.equal(mock.updates.length, test.expectedUpdates.length)
|
||||
for (let i = 0; i < mock.updates.length; i++) {
|
||||
assert.equal(mock.updates[i].value, test.expectedUpdates[i].value)
|
||||
assert.equal(mock.updates[i].field, test.expectedUpdates[i].field)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -9,9 +9,7 @@ import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
||||
import { IncrementalXapi } from './_vmRunners/IncrementalXapi.mjs'
|
||||
import { FullXapi } from './_vmRunners/FullXapi.mjs'
|
||||
import { Throttle } from '@vates/generator-toolbox'
|
||||
import { asyncEach } from '@vates/async-each'
|
||||
import createStreamThrottle from './_createStreamThrottle.mjs'
|
||||
import { selectSynchronizedSnapshotVms } from './_selectSynchronizedSnapshotVms.mjs'
|
||||
|
||||
const noop = Function.prototype
|
||||
|
||||
@@ -33,9 +31,7 @@ const DEFAULT_XAPI_VM_SETTINGS = {
|
||||
nRetriesVmBackupFailures: 0,
|
||||
offlineBackup: false,
|
||||
offlineSnapshot: false,
|
||||
snapshotConcurrency: 2,
|
||||
snapshotRetention: 0,
|
||||
synchronizedSnapshot: false,
|
||||
timeout: 0,
|
||||
useNbd: false,
|
||||
unconditionalSnapshot: false,
|
||||
@@ -51,16 +47,6 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
||||
return baseSettings
|
||||
}
|
||||
|
||||
_getVmBackup(jobMode, opts) {
|
||||
if (jobMode === 'delta') {
|
||||
return new IncrementalXapi(opts)
|
||||
} else if (jobMode === 'full') {
|
||||
return new FullXapi(opts)
|
||||
}
|
||||
|
||||
throw new Error(`Job mode ${jobMode} not implemented`)
|
||||
}
|
||||
|
||||
async run() {
|
||||
const job = this._job
|
||||
|
||||
@@ -109,81 +95,7 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
||||
const allSettings = this._job.settings
|
||||
const baseSettings = this._baseSettings
|
||||
|
||||
const preTakenTimestampByVmId = {}
|
||||
const failedSnapshotByVmId = {}
|
||||
if (settings.synchronizedSnapshot) {
|
||||
await Task.run({ properties: { name: 'snapshot VMs' } }, async () => {
|
||||
await Disposable.use(
|
||||
Disposable.all(vmIds.map(vmId => this._getRecord('VM', vmId).catch(noop))),
|
||||
async vms => {
|
||||
// remove vms that failed (already handled)
|
||||
vms = vms.filter(_ => _ !== undefined)
|
||||
|
||||
const batchIds = selectSynchronizedSnapshotVms(settings.synchronizedSnapshot, vms)
|
||||
|
||||
await asyncEach(
|
||||
[...vms].filter(vm => batchIds.has(vm.uuid)),
|
||||
async vm => {
|
||||
const vmSettings = { ...settings, ...allSettings[vm.uuid] }
|
||||
const opts = {
|
||||
baseSettings,
|
||||
config,
|
||||
getSnapshotNameLabel,
|
||||
healthCheckSr,
|
||||
job,
|
||||
remoteAdapters,
|
||||
schedule,
|
||||
settings: vmSettings,
|
||||
srs,
|
||||
throttleGenerator,
|
||||
throttleStream,
|
||||
vm,
|
||||
}
|
||||
|
||||
let vmBackup
|
||||
try {
|
||||
vmBackup = this._getVmBackup(job.mode, opts)
|
||||
if (
|
||||
!vmBackup._settings.offlineBackup &&
|
||||
!vmBackup._settings.offlineSnapshot &&
|
||||
(await vmBackup._mustDoSnapshot())
|
||||
) {
|
||||
await vmBackup._prepareAndSnapshot()
|
||||
preTakenTimestampByVmId[vm.uuid] = vmBackup.timestamp
|
||||
}
|
||||
} catch (error) {
|
||||
failedSnapshotByVmId[vm.uuid] = error
|
||||
if (vmBackup !== undefined) {
|
||||
try {
|
||||
await vmBackup._fetchJobSnapshots()
|
||||
await vmBackup._removeUnusedSnapshots()
|
||||
await vmBackup._cleanMetadata()
|
||||
} catch (cleanupError) {
|
||||
// Best effort cleanup
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrency: settings.snapshotConcurrency,
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const snapshotedVmIds = new Set(vmIds.filter(id => !(id in failedSnapshotByVmId)))
|
||||
Object.entries(failedSnapshotByVmId).forEach(([vmId, error]) => {
|
||||
Task.run(
|
||||
{
|
||||
properties: { id: vmId, name: 'backup VM', type: 'VM' },
|
||||
},
|
||||
() => Promise.reject(error)
|
||||
).catch(noop)
|
||||
})
|
||||
|
||||
const queue = new Set(snapshotedVmIds)
|
||||
const queue = new Set(vmIds)
|
||||
const taskByVmId = {}
|
||||
const nTriesByVmId = {}
|
||||
|
||||
@@ -243,16 +155,21 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
||||
schedule,
|
||||
settings: vmSettings,
|
||||
srs,
|
||||
// when set, the batch phase already snapshotted this VM; the
|
||||
// runner re-finds that snapshot by its metadata (see _snapshot)
|
||||
synchronizedSnapshotTimestamp: preTakenTimestampByVmId[vmUuid],
|
||||
throttleGenerator,
|
||||
throttleStream,
|
||||
vm,
|
||||
}
|
||||
|
||||
const vmBackup = this._getVmBackup(job.mode, opts)
|
||||
|
||||
let vmBackup
|
||||
if (job.mode === 'delta') {
|
||||
vmBackup = new IncrementalXapi(opts)
|
||||
} else {
|
||||
if (job.mode === 'full') {
|
||||
vmBackup = new FullXapi(opts)
|
||||
} else {
|
||||
throw new Error(`Job mode ${job.mode} not implemented`)
|
||||
}
|
||||
}
|
||||
return vmBackup.run().catch(error => {
|
||||
taskError = error
|
||||
})
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Task } from '@vates/task'
|
||||
|
||||
export function selectSynchronizedSnapshotVms(synchronizedSnapshot, vms) {
|
||||
if (synchronizedSnapshot === false) {
|
||||
return new Set()
|
||||
}
|
||||
|
||||
let matches
|
||||
if (typeof synchronizedSnapshot === 'string') {
|
||||
matches = vms.filter(vm => vm.tags.includes(synchronizedSnapshot))
|
||||
} else if (synchronizedSnapshot === true) {
|
||||
matches = vms
|
||||
} else {
|
||||
Task.warning('unsupported synchronizedSnapshot option, expected a boolean or a tag name', { synchronizedSnapshot })
|
||||
return new Set()
|
||||
}
|
||||
|
||||
return new Set(matches.map(vm => vm.uuid))
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { selectSynchronizedSnapshotVms } from './_selectSynchronizedSnapshotVms.mjs'
|
||||
|
||||
// Helper mirroring the minimal VM record shape the selector needs.
|
||||
const vm = (uuid, tags = []) => ({ uuid, tags })
|
||||
|
||||
// `selectSynchronizedSnapshotVms(synchronizedSnapshot, vms)` must return a Set
|
||||
// of the UUIDs that should be snapshotted together in the batch phase.
|
||||
// - false -> feature off, no VM is batched
|
||||
// - true -> every VM is batched, regardless of tags
|
||||
// - '<tagName>' -> only VMs carrying that exact tag are batched
|
||||
const tests = [
|
||||
{
|
||||
label: 'false disables batching',
|
||||
setting: false,
|
||||
vms: [vm('a', ['prod']), vm('b')],
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
label: 'true batches every VM regardless of tags',
|
||||
setting: true,
|
||||
vms: [vm('a', ['prod']), vm('b')],
|
||||
expected: ['a', 'b'],
|
||||
},
|
||||
{
|
||||
label: 'tag batches only the VMs carrying it',
|
||||
setting: 'prod',
|
||||
vms: [vm('a', ['prod']), vm('b', ['dev']), vm('c', ['prod', 'other'])],
|
||||
expected: ['a', 'c'],
|
||||
},
|
||||
{
|
||||
label: 'tag carried by no VM yields an empty batch',
|
||||
setting: 'prod',
|
||||
vms: [vm('a', ['dev']), vm('b')],
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
label: 'tag carried by every VM batches all of them',
|
||||
setting: 'prod',
|
||||
vms: [vm('a', ['prod']), vm('b', ['prod'])],
|
||||
expected: ['a', 'b'],
|
||||
},
|
||||
{
|
||||
label: 'empty VM list yields an empty batch',
|
||||
setting: true,
|
||||
vms: [],
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
label: 'empty-string tag matches no VM when none carries an empty tag',
|
||||
setting: '',
|
||||
vms: [vm('a', ['prod'])],
|
||||
expected: [],
|
||||
},
|
||||
{
|
||||
label: 'non boolean or string yiels an empty batch',
|
||||
setting: 1,
|
||||
vms: [vm('a', ['prod'])],
|
||||
expected: [],
|
||||
},
|
||||
]
|
||||
|
||||
describe('selectSynchronizedSnapshotVms()', () => {
|
||||
for (const { label, setting, vms, expected } of tests) {
|
||||
it(label, () => {
|
||||
const result = selectSynchronizedSnapshotVms(setting, vms)
|
||||
assert.ok(result instanceof Set, 'result must be a Set')
|
||||
assert.deepEqual([...result].sort(), [...expected].sort())
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -80,14 +80,14 @@ export const FullXapi = class FullXapiVmBackupRunner extends AbstractXapi {
|
||||
|
||||
const sizeContainer = watchStreamSize(stream)
|
||||
|
||||
const transferStart = Date.now()
|
||||
const timestamp = Date.now()
|
||||
await this._callWriters(
|
||||
writer =>
|
||||
writer.run({
|
||||
maxStreamLength,
|
||||
sizeContainer,
|
||||
stream: forkStreamUnpipe(stream),
|
||||
timestamp: this.timestamp,
|
||||
timestamp,
|
||||
vm,
|
||||
vmSnapshot: exportedVm,
|
||||
}),
|
||||
@@ -95,7 +95,8 @@ export const FullXapi = class FullXapiVmBackupRunner extends AbstractXapi {
|
||||
)
|
||||
|
||||
const { size } = sizeContainer
|
||||
const duration = Date.now() - transferStart
|
||||
const end = Date.now()
|
||||
const duration = end - timestamp
|
||||
debug('transfer complete', {
|
||||
duration,
|
||||
speed: duration !== 0 ? (size * 1e3) / 1024 / 1024 / duration : 0,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
DELTA_CHAIN_LENGTH,
|
||||
EXPORTED_SUCCESSFULLY,
|
||||
setVmDeltaChainLength,
|
||||
markExportSuccessfull,
|
||||
} from '../../_otherConfig.mjs'
|
||||
import { ThrottledDisk, SynchronizedDisk } from '@xen-orchestra/disk-transform'
|
||||
import { AggregatedIncrementalRemoteWriter } from '../_writers/AggregatedIncrementalRemoteWriter.mjs'
|
||||
@@ -67,6 +68,7 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
||||
|
||||
// @todo : reimplement throttle
|
||||
|
||||
const timestamp = Date.now()
|
||||
await this._callWriters(
|
||||
writer =>
|
||||
writer.transfer({
|
||||
@@ -76,7 +78,7 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
||||
// clean; the tip's flag lets the next run skip re-probing
|
||||
includeNonNbdQcow2Fix: true,
|
||||
isVhdDifferencing,
|
||||
timestamp: this.timestamp,
|
||||
timestamp,
|
||||
vm,
|
||||
vmSnapshot: exportedVm,
|
||||
}),
|
||||
@@ -89,6 +91,11 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
||||
await setVmDeltaChainLength(this._xapi, exportedVm.$ref, (this._deltaChainLength ?? 0) + 1)
|
||||
}
|
||||
|
||||
// not the case if offlineBackup
|
||||
if (exportedVm.is_a_snapshot) {
|
||||
await markExportSuccessfull(this._xapi, exportedVm.$ref)
|
||||
}
|
||||
|
||||
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import { asyncEach } from '@vates/async-each'
|
||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||
import { defer } from 'golike-defer'
|
||||
import { Task } from '@vates/task'
|
||||
import { formatDateTime } from '@xen-orchestra/xapi'
|
||||
|
||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||
import { Abstract } from './_Abstract.mjs'
|
||||
@@ -17,11 +16,9 @@ import {
|
||||
JOB_ID,
|
||||
SCHEDULE_ID,
|
||||
VM_UUID,
|
||||
EXPORTED_SUCCESSFULLY,
|
||||
resetVmOtherConfig,
|
||||
setVmOtherConfig,
|
||||
setVmSnapshotContentKeys,
|
||||
markExportSuccessfull,
|
||||
} from '../../_otherConfig.mjs'
|
||||
|
||||
const { warn, info } = createLogger('xo:backups:AbstractXapi')
|
||||
@@ -39,7 +36,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
schedule,
|
||||
settings,
|
||||
srs,
|
||||
synchronizedSnapshotTimestamp,
|
||||
throttleGenerator,
|
||||
throttleStream,
|
||||
vm,
|
||||
@@ -67,9 +63,9 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
|
||||
// VM (snapshot) that is really exported
|
||||
this._exportedVm = undefined
|
||||
this._synchronizedSnapshotTimestamp = synchronizedSnapshotTimestamp
|
||||
this._vm = vm
|
||||
|
||||
this._baseVdis = undefined
|
||||
this._getSnapshotNameLabel = getSnapshotNameLabel
|
||||
this._isIncremental = job.mode === 'delta'
|
||||
this._healthCheckSr = healthCheckSr
|
||||
@@ -184,27 +180,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
}
|
||||
|
||||
async _snapshot() {
|
||||
if (this._synchronizedSnapshotTimestamp !== undefined) {
|
||||
const datetime = formatDateTime(this._synchronizedSnapshotTimestamp)
|
||||
const candidates = this._vm.$snapshots.filter(
|
||||
snapshot =>
|
||||
snapshot?.other_config[JOB_ID] === this._jobId &&
|
||||
snapshot?.other_config[DATETIME] === datetime &&
|
||||
!snapshot.other_config[EXPORTED_SUCCESSFULLY]
|
||||
)
|
||||
if (candidates.length === 1) {
|
||||
this._exportedVm = candidates[0]
|
||||
this.timestamp = this._synchronizedSnapshotTimestamp
|
||||
return
|
||||
}
|
||||
|
||||
warn('expected exactly one synchronized snapshot to reuse, taking a fresh one', {
|
||||
vm: this._vm.uuid,
|
||||
datetime,
|
||||
count: candidates.length,
|
||||
})
|
||||
}
|
||||
|
||||
const vm = this._vm
|
||||
const xapi = this._xapi
|
||||
|
||||
@@ -421,20 +396,7 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
await xapi.barrier()
|
||||
// ensure cached object are up to date
|
||||
this._jobSnapshotVdis = this._jobSnapshotVdis.map(vdi => xapi.getObject(vdi.$ref))
|
||||
let disklessVmSnapshots = this._disklessJobSnapshotVms.map(vm => xapi.getObject(vm.$ref))
|
||||
|
||||
// The synchronized snapshot for this run is taken up-front by the batch
|
||||
// phase but transferred later. Until it has been exported, hide it from
|
||||
// retention so it is neither reclaimed nor allowed to steal the delta
|
||||
// base's "most recent" protection. This makes the pre-transfer pass behave
|
||||
// like a normal run, where the snapshot does not exist yet.
|
||||
if (this._synchronizedSnapshotTimestamp !== undefined) {
|
||||
const datetime = formatDateTime(this._synchronizedSnapshotTimestamp)
|
||||
const isInFlightSyncSnapshot = ({ other_config }) =>
|
||||
other_config[DATETIME] === datetime && !other_config[EXPORTED_SUCCESSFULLY]
|
||||
this._jobSnapshotVdis = this._jobSnapshotVdis.filter(vdi => !isInFlightSyncSnapshot(vdi))
|
||||
disklessVmSnapshots = disklessVmSnapshots.filter(vm => !isInFlightSyncSnapshot(vm))
|
||||
}
|
||||
const disklessVmSnapshots = this._disklessJobSnapshotVms.map(vm => xapi.getObject(vm.$ref))
|
||||
|
||||
// get the datetime of the most recent snapshot across both VDI and diskless VM snapshots
|
||||
const lastSnapshotDateTime = [...this._jobSnapshotVdis, ...disklessVmSnapshots]
|
||||
@@ -502,7 +464,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
vm = vdiVm
|
||||
}
|
||||
}
|
||||
|
||||
if (vm?.$ref !== undefined) {
|
||||
return xapi.VM_destroy(vm.$ref)
|
||||
} else {
|
||||
@@ -532,7 +493,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
if (this.job.mode === 'delta' && datetime === lastSnapshotDateTime) {
|
||||
return
|
||||
}
|
||||
|
||||
await xapi.VM_destroy(snapshotPerDatetime[datetime])
|
||||
})
|
||||
})
|
||||
@@ -591,11 +551,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
async _prepareAndSnapshot() {
|
||||
await this._cleanMetadata()
|
||||
await this._snapshot()
|
||||
}
|
||||
|
||||
async run($defer) {
|
||||
const settings = this._settings
|
||||
assert(
|
||||
@@ -659,10 +614,6 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||
if (this._writers.size !== 0) {
|
||||
await this._copy()
|
||||
}
|
||||
// not the case if offlineBackup
|
||||
if (this._exportedVm.is_a_snapshot) {
|
||||
await markExportSuccessfull(this._xapi, this._exportedVm.$ref)
|
||||
}
|
||||
} finally {
|
||||
if (startAfter) {
|
||||
ignoreErrors.call(vm.$callAsync('start', false, false))
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { formatDateTime } from '@xen-orchestra/xapi'
|
||||
|
||||
import { AbstractXapi } from './_AbstractXapi.mjs'
|
||||
import { DATETIME, EXPORTED_SUCCESSFULLY, JOB_ID, SCHEDULE_ID } from '../../_otherConfig.mjs'
|
||||
|
||||
// Build an AbstractXapi instance without running its heavy constructor, then
|
||||
// assign only the fields the method under test reads.
|
||||
const makeRunner = props => Object.assign(Object.create(AbstractXapi.prototype), props)
|
||||
|
||||
describe('_snapshot() synchronized-snapshot reuse guard', () => {
|
||||
it('reuses the batch snapshot, found by metadata, without snapshotting again', async () => {
|
||||
let mustDoSnapshotCalls = 0
|
||||
const timestamp = 1717200000000
|
||||
// the snapshot taken by the batch phase, identified by its other_config
|
||||
const batchSnapshot = {
|
||||
$ref: 'batch-snapshot-ref',
|
||||
other_config: {
|
||||
[JOB_ID]: 'job-1',
|
||||
[SCHEDULE_ID]: 'schedule-1',
|
||||
[DATETIME]: formatDateTime(timestamp),
|
||||
},
|
||||
}
|
||||
const runner = makeRunner({
|
||||
_synchronizedSnapshotTimestamp: timestamp,
|
||||
_jobId: 'job-1',
|
||||
scheduleId: 'schedule-1',
|
||||
_vm: { uuid: 'vm-uuid', $snapshots: [batchSnapshot] },
|
||||
_xapi: { barrier: async () => {} },
|
||||
// if the metadata lookup fails, _snapshot() falls through to here
|
||||
_mustDoSnapshot: async () => {
|
||||
mustDoSnapshotCalls++
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
await runner._snapshot()
|
||||
|
||||
assert.equal(mustDoSnapshotCalls, 0, '_mustDoSnapshot() should not be called when the batch snapshot is found')
|
||||
assert.equal(runner._exportedVm, batchSnapshot, '_exportedVm should be the batch snapshot found by metadata')
|
||||
assert.equal(runner.timestamp, timestamp, 'timestamp should be the synchronized snapshot timestamp')
|
||||
})
|
||||
|
||||
it('takes a fresh snapshot when the batch snapshot can no longer be found', async () => {
|
||||
let mustDoSnapshotCalls = 0
|
||||
const vm = { uuid: 'vm-uuid', $snapshots: [] } // the pre-taken snapshot is gone
|
||||
const runner = makeRunner({
|
||||
_synchronizedSnapshotTimestamp: 1717200000000,
|
||||
_jobId: 'job-1',
|
||||
scheduleId: 'schedule-1',
|
||||
_vm: vm,
|
||||
_xapi: { barrier: async () => {} },
|
||||
_settings: {},
|
||||
_mustDoSnapshot: async () => {
|
||||
mustDoSnapshotCalls++
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
await runner._snapshot()
|
||||
|
||||
assert.equal(
|
||||
mustDoSnapshotCalls,
|
||||
1,
|
||||
'a missing batch snapshot should not be reused: _snapshot() should fall through and take a fresh snapshot'
|
||||
)
|
||||
assert.equal(
|
||||
runner._exportedVm,
|
||||
vm,
|
||||
'_exportedVm should fall back to the freshly-snapshotted VM, not stay on a stale/missing batch snapshot'
|
||||
)
|
||||
})
|
||||
|
||||
it('without a pre-taken snapshot and no snapshot needed, exports the live VM', async () => {
|
||||
let mustDoSnapshotCalls = 0
|
||||
const vm = { uuid: 'vm-uuid' }
|
||||
const runner = makeRunner({
|
||||
_exportedVm: undefined,
|
||||
_vm: vm,
|
||||
_xapi: {},
|
||||
_settings: {},
|
||||
_mustDoSnapshot: async () => {
|
||||
mustDoSnapshotCalls++
|
||||
return false
|
||||
},
|
||||
})
|
||||
|
||||
await runner._snapshot()
|
||||
|
||||
assert.equal(mustDoSnapshotCalls, 1, '_mustDoSnapshot() should be called once when no snapshot was pre-taken')
|
||||
assert.equal(runner._exportedVm, vm, '_exportedVm should be set to the live VM when no snapshot is needed')
|
||||
assert.equal(typeof runner.timestamp, 'number', 'timestamp should be set when exporting the live VM')
|
||||
})
|
||||
})
|
||||
|
||||
describe('_removeUnusedSnapshots() protects the pre-taken synchronized snapshot', () => {
|
||||
const OLD_DATETIME = '20240101T00:00:00Z'
|
||||
const SYNC_TIMESTAMP = 1717200000000
|
||||
const SYNC_DATETIME = formatDateTime(SYNC_TIMESTAMP)
|
||||
|
||||
// Full-mode job with snapshotRetention 0, so retention wants to remove every
|
||||
// snapshot. `vdi-fresh` is the snapshot taken up-front by the synchronized
|
||||
// batch phase (identified by SYNC_TIMESTAMP); until it is exported it must be
|
||||
// hidden from retention.
|
||||
const makeRemoveRunner = ({ exported }) => {
|
||||
const destroyed = []
|
||||
|
||||
const snapshotVm = ($ref, name_label) => ({
|
||||
$ref,
|
||||
name_label,
|
||||
is_control_domain: false,
|
||||
$snapshot_of: 'live-vm-ref',
|
||||
other_config: {},
|
||||
})
|
||||
const freshSnapshotVm = snapshotVm('vm-fresh', 'fresh')
|
||||
const oldSnapshotVm = snapshotVm('vm-old', 'old')
|
||||
|
||||
const vdi = ($ref, datetime, snapshotVmRecord, isExported = false) => ({
|
||||
$ref,
|
||||
other_config: {
|
||||
[DATETIME]: datetime,
|
||||
[SCHEDULE_ID]: 'schedule-1',
|
||||
...(isExported ? { [EXPORTED_SUCCESSFULLY]: 'true' } : {}),
|
||||
},
|
||||
$VBDs: [{ $VM: snapshotVmRecord }],
|
||||
})
|
||||
// the old snapshot was exported by a previous run
|
||||
const oldVdi = vdi('vdi-old', OLD_DATETIME, oldSnapshotVm, true)
|
||||
const freshVdi = vdi('vdi-fresh', SYNC_DATETIME, freshSnapshotVm, exported)
|
||||
|
||||
const registry = { 'vdi-old': oldVdi, 'vdi-fresh': freshVdi }
|
||||
|
||||
const runner = makeRunner({
|
||||
_synchronizedSnapshotTimestamp: SYNC_TIMESTAMP,
|
||||
_vm: { uuid: 'live-uuid', $snapshots: [] },
|
||||
_baseSettings: { snapshotRetention: 0 },
|
||||
_jobSnapshotVdis: [oldVdi, freshVdi],
|
||||
_disklessJobSnapshotVms: [],
|
||||
job: { mode: 'full', settings: {} },
|
||||
_xapi: {
|
||||
barrier: async () => {},
|
||||
getObject: ref => registry[ref],
|
||||
VM_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
VDI_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return { runner, destroyed }
|
||||
}
|
||||
|
||||
it('does not destroy the pre-taken snapshot before it has been transferred', async () => {
|
||||
const { runner, destroyed } = makeRemoveRunner({ exported: false })
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(destroyed, ['vm-old'], 'only the older snapshot should be removed')
|
||||
})
|
||||
|
||||
it('destroys the snapshot once it has been transferred (retention 0, no leak)', async () => {
|
||||
const { runner, destroyed } = makeRemoveRunner({ exported: true })
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(destroyed.sort(), ['vm-fresh', 'vm-old'], 'both snapshots should be removed after transfer')
|
||||
})
|
||||
})
|
||||
|
||||
describe('_removeUnusedSnapshots() in the synchronized batch pre-snapshot state', () => {
|
||||
it('delta mode: keeps the base snapshot when the fresh one has not been taken yet', async () => {
|
||||
const destroyed = []
|
||||
|
||||
const BASE_DATETIME = '2024-06-01T00:00:00Z'
|
||||
const baseSnapshotVm = {
|
||||
$ref: 'vm-base',
|
||||
name_label: 'base',
|
||||
is_control_domain: false,
|
||||
$snapshot_of: 'live-vm-ref',
|
||||
// exported successfully by the previous run
|
||||
other_config: { [EXPORTED_SUCCESSFULLY]: 'true' },
|
||||
}
|
||||
const baseVdi = {
|
||||
$ref: 'vdi-base',
|
||||
other_config: { [DATETIME]: BASE_DATETIME, [SCHEDULE_ID]: 'schedule-1' },
|
||||
$VBDs: [{ $VM: baseSnapshotVm }],
|
||||
}
|
||||
const registry = { 'vdi-base': baseVdi }
|
||||
|
||||
const runner = makeRunner({
|
||||
// batch pre-snapshot state: the synchronized snapshot has not been taken yet
|
||||
_exportedVm: undefined,
|
||||
_vm: { uuid: 'live-uuid', $snapshots: [] },
|
||||
_baseSettings: { snapshotRetention: 0 },
|
||||
_jobSnapshotVdis: [baseVdi],
|
||||
_disklessJobSnapshotVms: [],
|
||||
job: { mode: 'delta', settings: {} },
|
||||
_xapi: {
|
||||
barrier: async () => {},
|
||||
getObject: ref => registry[ref],
|
||||
VM_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
VDI_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(destroyed, [], 'the base snapshot must be kept as the delta base for the upcoming transfer')
|
||||
})
|
||||
})
|
||||
|
||||
describe('_removeUnusedSnapshots() reclaims orphan / CBT snapshot VDIs (no attached VM)', () => {
|
||||
// Guards the `else` branch: snapshot VDIs that are not attached to any user VM
|
||||
// (e.g. CBT metadata, orphans) must be reclaimed via VDI_destroy, not VM_destroy.
|
||||
it('destroys snapshot VDIs directly when they are not attached to any VM', async () => {
|
||||
const vmDestroyed = []
|
||||
const vdiDestroyed = []
|
||||
|
||||
const orphanVdi = {
|
||||
$ref: 'vdi-orphan',
|
||||
other_config: { [DATETIME]: '2024-01-01T00:00:00Z', [SCHEDULE_ID]: 'schedule-1' },
|
||||
$VBDs: [], // not attached to any VM
|
||||
}
|
||||
const registry = { 'vdi-orphan': orphanVdi }
|
||||
|
||||
const runner = makeRunner({
|
||||
_exportedVm: undefined,
|
||||
_vm: { uuid: 'live-uuid', $snapshots: [] },
|
||||
_baseSettings: { snapshotRetention: 0 },
|
||||
_jobSnapshotVdis: [orphanVdi],
|
||||
_disklessJobSnapshotVms: [],
|
||||
job: { mode: 'full', settings: {} },
|
||||
_xapi: {
|
||||
barrier: async () => {},
|
||||
getObject: ref => registry[ref],
|
||||
VM_destroy: async ref => {
|
||||
vmDestroyed.push(ref)
|
||||
},
|
||||
VDI_destroy: async ref => {
|
||||
vdiDestroyed.push(ref)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(vdiDestroyed, ['vdi-orphan'], 'the orphan VDI should be reclaimed via VDI_destroy')
|
||||
assert.deepEqual(vmDestroyed, [], 'no VM should be destroyed for an orphan VDI')
|
||||
})
|
||||
})
|
||||
|
||||
describe('_removeUnusedSnapshots() diskless VM snapshots', () => {
|
||||
const OLD_DATETIME = '20240101T00:00:00Z'
|
||||
const SYNC_TIMESTAMP = 1717200000000
|
||||
const SYNC_DATETIME = formatDateTime(SYNC_TIMESTAMP)
|
||||
|
||||
// A diskless VM's backup snapshots are tracked as VM snapshots (no VDIs to
|
||||
// anchor them). `dl-fresh` is the snapshot the synchronized batch pre-took,
|
||||
// identified by SYNC_TIMESTAMP.
|
||||
const makeDisklessRunner = ({ exported, mode = 'full' }) => {
|
||||
const destroyed = []
|
||||
|
||||
const oldSnap = { $ref: 'dl-old', other_config: { [DATETIME]: OLD_DATETIME, [SCHEDULE_ID]: 'schedule-1' } }
|
||||
const freshSnap = { $ref: 'dl-fresh', other_config: { [DATETIME]: SYNC_DATETIME, [SCHEDULE_ID]: 'schedule-1' } }
|
||||
if (exported) freshSnap.other_config[EXPORTED_SUCCESSFULLY] = 'true'
|
||||
const registry = { 'dl-old': oldSnap, 'dl-fresh': freshSnap }
|
||||
|
||||
const runner = makeRunner({
|
||||
_synchronizedSnapshotTimestamp: SYNC_TIMESTAMP,
|
||||
_vm: { uuid: 'live-uuid', $snapshots: [] },
|
||||
_baseSettings: { snapshotRetention: 0 },
|
||||
_jobSnapshotVdis: [],
|
||||
_disklessJobSnapshotVms: [oldSnap, freshSnap],
|
||||
job: { mode, settings: {} },
|
||||
_xapi: {
|
||||
barrier: async () => {},
|
||||
getObject: ref => registry[ref],
|
||||
VM_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
VDI_destroy: async ref => {
|
||||
destroyed.push(ref)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return { runner, destroyed }
|
||||
}
|
||||
|
||||
it('does not destroy the pre-taken diskless snapshot before it has been transferred', async () => {
|
||||
const { runner, destroyed } = makeDisklessRunner({ exported: false })
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(destroyed, ['dl-old'], 'only the older diskless snapshot should be removed')
|
||||
})
|
||||
|
||||
it('destroys the diskless snapshot once it has been transferred (retention 0, no leak)', async () => {
|
||||
const { runner, destroyed } = makeDisklessRunner({ exported: true })
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(
|
||||
destroyed.sort(),
|
||||
['dl-fresh', 'dl-old'],
|
||||
'both diskless snapshots should be removed after transfer'
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps the most recent diskless snapshot in delta mode (base for next delta)', async () => {
|
||||
// Even after transfer (exported), delta mode must retain the latest
|
||||
// snapshot so the next run can compute its delta against it.
|
||||
const { runner, destroyed } = makeDisklessRunner({ exported: true, mode: 'delta' })
|
||||
|
||||
await runner._removeUnusedSnapshots()
|
||||
|
||||
assert.deepEqual(destroyed, ['dl-old'], 'the most recent diskless snapshot should be kept in delta mode')
|
||||
})
|
||||
})
|
||||
@@ -263,7 +263,6 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
||||
vdiRef: activeVdi.$ref,
|
||||
baseRef: snapshot.$ref,
|
||||
onlyListChangedBlocks: true,
|
||||
preferNbd: this._settings.preferNbd,
|
||||
})
|
||||
await diffDisk.init()
|
||||
if (diffDisk.getBlockIndexes().length === 0) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"version": "0.74.2",
|
||||
"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.5.1",
|
||||
"@vates/nbd-client": "^3.5.0",
|
||||
"@vates/parse-duration": "^0.1.1",
|
||||
"@vates/task": "^0.7.0",
|
||||
"@vates/types": "^2.0.1",
|
||||
"@xen-orchestra/async-map": "^0.1.4",
|
||||
"@vates/types": "^1.30.1",
|
||||
"@xen-orchestra/async-map": "^0.1.3",
|
||||
"@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.1.2",
|
||||
"@xen-orchestra/backup-archive": "^1.1.1",
|
||||
"app-conf": "^3.0.0",
|
||||
"compare-versions": "^6.0.0",
|
||||
"d3-time-format": "^4.1.0",
|
||||
@@ -52,11 +52,11 @@
|
||||
"parse-pairs": "^2.0.0",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"proper-lockfile": "^4.1.2",
|
||||
"tar": "^7.5.19",
|
||||
"tar": "^7.5.3",
|
||||
"uuid": "^9.0.0",
|
||||
"value-matcher": "^0.2.0",
|
||||
"vhd-lib": "^4.16.1",
|
||||
"xen-api": "^4.9.0",
|
||||
"xen-api": "^4.8.0",
|
||||
"yazl": "^2.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -67,7 +67,7 @@
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@xen-orchestra/xapi": "^8.10.5"
|
||||
"@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.9.0"
|
||||
"xen-api": "^4.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@xen-orchestra/disk-cli",
|
||||
"version": "2.2.1",
|
||||
"version": "2.2.0",
|
||||
"description": "CLI tool to inspect and manage disks in backup repositories",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
@@ -20,8 +20,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/backups": "^0.74.2",
|
||||
"@xen-orchestra/backup-archive": "^1.1.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",
|
||||
|
||||
@@ -59,7 +59,7 @@ export async function transformCommand(handlerUrl: string, diskPath: string, ext
|
||||
} else if (format === 'vhd') {
|
||||
stream = await toVhdStream(disk)
|
||||
} else {
|
||||
stream = await toQcow2Stream(disk)
|
||||
stream = toQcow2Stream(disk)
|
||||
}
|
||||
|
||||
await pipeline(stream, process.stdout, { end: false })
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
"xo-immutable-remote": "./dist/protectRemotes.mjs"
|
||||
},
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.4",
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/async-each": "^1.0.3",
|
||||
"@xen-orchestra/backups": "^0.74.2",
|
||||
"@xen-orchestra/backups": "^0.73.10",
|
||||
"@xen-orchestra/log": "^0.7.2",
|
||||
"app-conf": "^3.0.0",
|
||||
"execa": "^5.0.0",
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
# ChangeLog
|
||||
|
||||
## **next**
|
||||
|
||||
- [Host] Add possibility to reboot a host (PR [#10250](https://github.com/vatesfr/xen-orchestra/pull/10250))
|
||||
- [Web-Core/TabItem] Update the component to remove uppercase for better readability (PR [#10338](https://github.com/vatesfr/xen-orchestra/pull/10338))
|
||||
|
||||
## **0.25.0** (2026-08-31)
|
||||
|
||||
- [Treeview] Add VM tree actions (PR [#10304](https://github.com/vatesfr/xen-orchestra/pull/10304))
|
||||
- [Pool/networks] Add the possibility to create new network or bonded network (PR [#10145](https://github.com/vatesfr/xen-orchestra/pull/10145))
|
||||
- [VM] Add VDIs page with table and side panel (PR [#10269](https://github.com/vatesfr/xen-orchestra/pull/10269))
|
||||
- [Host/Network] Add ability to rescan physical network interfaces (PIFs) (PR [#10147](https://github.com/vatesfr/xen-orchestra/pull/10147))
|
||||
- Fix inconsistent spacing in side panel cards (PR [#10279](https://github.com/vatesfr/xen-orchestra/pull/10279))
|
||||
- Fix missing collapse buttons on pools and hosts in the tree sidebar (added `hasChildren` prop) (PR [#10244](https://github.com/vatesfr/xen-orchestra/pull/10244))
|
||||
- [Pool/networks] Add the possibility to create new internal network (PR [#10235](https://github.com/vatesfr/xen-orchestra/pull/10235))
|
||||
|
||||
## **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))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xen-orchestra/lite",
|
||||
"version": "0.25.0",
|
||||
"version": "0.24.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
|
||||
@@ -23,21 +23,18 @@
|
||||
"@fortawesome/vue-fontawesome": "^3.0.8",
|
||||
"@intlify/unplugin-vue-i18n": "^6.0.3",
|
||||
"@novnc/novnc": "~1.5.0",
|
||||
"@regle/core": "^1.26.0",
|
||||
"@regle/rules": "^1.26.0",
|
||||
"@regle/schemas": "^1.20.2",
|
||||
"@tsconfig/node18": "^18.2.4",
|
||||
"@types/d3-time-format": "^4.0.3",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^18.19.80",
|
||||
"@vates/types": "^2.0.1",
|
||||
"@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.60.0",
|
||||
"@xen-orchestra/web-core": "^0.58.0",
|
||||
"complex-matcher": "^1.1.1",
|
||||
"d3-time-format": "^4.1.0",
|
||||
"decorator-synchronized": "^0.6.0",
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
import AppHeader from '@/components/AppHeader.vue'
|
||||
import AppLogin from '@/components/AppLogin.vue'
|
||||
import AppNavigation from '@/components/AppNavigation.vue'
|
||||
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
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.ts'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { useChartTheme } from '@core/composables/chart-theme.composable'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import { useActiveElement, useMagicKeys, whenever } from '@vueuse/core'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
import AccountMenu from '@/components/account-menu/AccountMenu.vue'
|
||||
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
|
||||
import XoaButton from '@/components/XoaButton.vue'
|
||||
import { useNavigationStore } from '@/stores/navigation.store.ts'
|
||||
import { useNavigationStore } from '@/stores/navigation.store'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import UiLogoText from '@core/components/ui/logo-text/UiLogoText.vue'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -42,9 +42,9 @@
|
||||
import FormInput from '@/components/form/FormInput.vue'
|
||||
import LoginError from '@/components/LoginError.vue'
|
||||
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
|
||||
import type { XenApiError } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { usePageTitleStore } from '@/stores/page-title.store.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import type { XenApiError } from '@/libs/xen-api/xen-api.types'
|
||||
import { usePageTitleStore } from '@/stores/page-title.store'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import markdown from '@/libs/markdown.ts'
|
||||
import markdown from '@/libs/markdown'
|
||||
import { useEventListener } from '@vueuse/core'
|
||||
import { computed, type Ref, ref } from 'vue'
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<script lang="ts" setup>
|
||||
import StoryMenu from '@/components/component-story/StoryMenu.vue'
|
||||
import InfraPoolList from '@/components/infra/InfraPoolList.vue'
|
||||
import { useNavigationStore } from '@/stores/navigation.store.ts'
|
||||
import { useNavigationStore } from '@/stores/navigation.store'
|
||||
import { onClickOutside, tryOnMounted, useTimeoutFn, watchImmediate } from '@vueuse/core'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { type AcceptedLanguage, highlight } from '@/libs/highlight.ts'
|
||||
import { type AcceptedLanguage, highlight } from '@/libs/highlight'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
|
||||
@@ -19,7 +19,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.ts'
|
||||
import type { Filters } from '@/types/filter'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiActionButton from '@/components/ui/UiActionButton.vue'
|
||||
import { buildComplexMatcherNode } from '@/libs/complex-matcher.utils.ts'
|
||||
import type { Filter, FilterComparisons, FilterComparisonType, Filters, FilterType, NewFilter } from '@/types/filter.ts'
|
||||
import { buildComplexMatcherNode } from '@/libs/complex-matcher.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'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import UiActionButton from '@/components/ui/UiActionButton.vue'
|
||||
import UiFilter from '@/components/ui/UiFilter.vue'
|
||||
import UiFilterGroup from '@/components/ui/UiFilterGroup.vue'
|
||||
import type { ActiveSorts, Sorts } from '@/types/sort.ts'
|
||||
import type { ActiveSorts, Sorts } from '@/types/sort'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiPatchWithHostRefs } from '@/composables/host-patches.composable.ts'
|
||||
import type { XenApiPatchWithHostRefs } from '@/composables/host-patches.composable'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import { useTableState } from '@core/composables/table-state.composable.ts'
|
||||
import { useUiStore } from '@core/stores/ui.store.ts'
|
||||
import { usePatchColumns } from '@core/tables/column-sets/patch-columns.ts'
|
||||
import { useTableState } from '@core/composables/table-state.composable'
|
||||
import { useUiStore } from '@core/stores/ui.store'
|
||||
import { usePatchColumns } from '@core/tables/column-sets/patch-columns'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiError } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { XenApiError } from '@/libs/xen-api/xen-api.types'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
</template>
|
||||
|
||||
<script generic="T extends ObjectType" lang="ts" setup>
|
||||
import type { ObjectType, ObjectTypeToRecord } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { XapiContext } from '@/stores/xen-api/create-xapi-store-config.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import { useSrStore } from '@/stores/xen-api/sr.store.ts'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store.ts'
|
||||
import type { ObjectType, ObjectTypeToRecord } from '@/libs/xen-api/xen-api.types'
|
||||
import type { XapiContext } from '@/stores/xen-api/create-xapi-store-config'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import { useSrStore } from '@/stores/xen-api/sr.store'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import { computed, watch } from 'vue'
|
||||
import { type RouteLocationTyped, type RouteRecordName } from 'vue-router'
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</template>
|
||||
|
||||
<script generic="T extends XenApiRecord<ObjectType>, I extends T['uuid']" lang="ts" setup>
|
||||
import type { ObjectType, XenApiRecord } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { ObjectType, XenApiRecord } from '@/libs/xen-api/xen-api.types'
|
||||
import ObjectNotFoundView from '@/pages/object-not-found.vue'
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useSessionStorage } from '@vueuse/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums.ts'
|
||||
import { VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums'
|
||||
import type { IconName } from '@core/icons'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
<template>
|
||||
<RouterLink v-slot="{ isActive, href }" :to custom>
|
||||
<UiTabItem
|
||||
<TabItem
|
||||
:active="isActive"
|
||||
:disabled="isDisabled"
|
||||
:href="isDisabled ? undefined : href"
|
||||
:tag="isDisabled ? undefined : 'a'"
|
||||
>
|
||||
<slot />
|
||||
</UiTabItem>
|
||||
</TabItem>
|
||||
</RouterLink>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiTabItem from '@core/components/ui/tab-item/UiTabItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable.ts'
|
||||
import TabItem from '@core/components/tab/TabItem.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
|
||||
const props = defineProps<{
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PRIMARY_ADDRESS_TYPE } from '@/libs/xen-api/xen-api.enums.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import type { PRIMARY_ADDRESS_TYPE } from '@/libs/xen-api/xen-api.enums'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useXenApiStore } from '@/stores/xen-api.store.ts'
|
||||
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import UiAccountMenuButton from '@core/components/ui/account-menu-button/UiAccountMenuButton.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { nextTick } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<TabList>
|
||||
<UiTabItem v-bind="tab(TAB.PROPS, propParams)">Props</UiTabItem>
|
||||
<UiTabItem class="event-tab" v-bind="tab(TAB.EVENTS, eventParams)">
|
||||
<TabItem v-bind="tab(TAB.PROPS, propParams)">Props</TabItem>
|
||||
<TabItem class="event-tab" v-bind="tab(TAB.EVENTS, eventParams)">
|
||||
Events
|
||||
<UiCounter
|
||||
v-if="unreadEventsCount > 0"
|
||||
@@ -10,15 +10,15 @@
|
||||
variant="primary"
|
||||
size="small"
|
||||
/>
|
||||
</UiTabItem>
|
||||
<UiTabItem v-bind="tab(TAB.SLOTS, slotParams)">Slots</UiTabItem>
|
||||
<UiTabItem v-bind="tab(TAB.SETTINGS, settingParams)">Settings</UiTabItem>
|
||||
</TabItem>
|
||||
<TabItem v-bind="tab(TAB.SLOTS, slotParams)">Slots</TabItem>
|
||||
<TabItem v-bind="tab(TAB.SETTINGS, settingParams)">Settings</TabItem>
|
||||
<MenuList placement="bottom">
|
||||
<template #trigger="{ open, isOpen }">
|
||||
<UiTabItem :active="isOpen" :disabled="presets === undefined" class="preset-tab" @click="open">
|
||||
<TabItem :active="isOpen" :disabled="presets === undefined" class="preset-tab" @click="open">
|
||||
<VtsIcon name="fa:sliders" size="medium" />
|
||||
Presets
|
||||
</UiTabItem>
|
||||
</TabItem>
|
||||
</template>
|
||||
<MenuItem v-for="(preset, label) in presets" :key="label" @click="applyPreset(preset)">
|
||||
{{ label }}
|
||||
@@ -87,16 +87,16 @@ import {
|
||||
isSlotParam,
|
||||
ModelParam,
|
||||
type Param,
|
||||
} from '@/libs/story/story-param.ts'
|
||||
} from '@/libs/story/story-param'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import MenuItem from '@core/components/menu/MenuItem.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import TabList from '@core/components/tab-list/TabList.vue'
|
||||
import TabItem from '@core/components/tab/TabItem.vue'
|
||||
import TabList from '@core/components/tab/TabList.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiCardTitle from '@core/components/ui/card-title/UiCardTitle.vue'
|
||||
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
|
||||
import UiTabItem from '@core/components/ui/tab-item/UiTabItem.vue'
|
||||
import 'highlight.js/styles/github-dark.css'
|
||||
import { uniqueId, upperFirst } from 'lodash-es'
|
||||
import { computed, onBeforeMount, reactive, ref, watch, watchEffect } from 'vue'
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<script lang="ts" setup>
|
||||
import CodeHighlight from '@/components/CodeHighlight.vue'
|
||||
import StoryParamsTable from '@/components/component-story/StoryParamsTable.vue'
|
||||
import type { EventParam } from '@/libs/story/story-param.ts'
|
||||
import type { EventParam } from '@/libs/story/story-param'
|
||||
|
||||
defineProps<{
|
||||
params: EventParam[]
|
||||
|
||||
@@ -83,10 +83,10 @@
|
||||
import CodeHighlight from '@/components/CodeHighlight.vue'
|
||||
import StoryParamsTable from '@/components/component-story/StoryParamsTable.vue'
|
||||
import StoryWidget from '@/components/component-story/StoryWidget.vue'
|
||||
import useSortedCollection from '@/composables/sorted-collection.composable.ts'
|
||||
import type { PropParam } from '@/libs/story/story-param.ts'
|
||||
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.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useOverlay } from '@core/packages/overlay/use-overlay.ts'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { toRef } from 'vue'
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<script lang="ts" setup>
|
||||
import StoryParamsTable from '@/components/component-story/StoryParamsTable.vue'
|
||||
import StoryWidget from '@/components/component-story/StoryWidget.vue'
|
||||
import type { SettingParam } from '@/libs/story/story-param.ts'
|
||||
import type { SettingParam } from '@/libs/story/story-param'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
|
||||
const props = defineProps<{
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<script lang="ts" setup>
|
||||
import CodeHighlight from '@/components/CodeHighlight.vue'
|
||||
import StoryParamsTable from '@/components/component-story/StoryParamsTable.vue'
|
||||
import type { SlotParam } from '@/libs/story/story-param.ts'
|
||||
import type { SlotParam } from '@/libs/story/story-param'
|
||||
|
||||
defineProps<{
|
||||
params: SlotParam[]
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
isSelectWidget,
|
||||
isTextWidget,
|
||||
type Widget,
|
||||
} from '@/libs/story/story-widget.ts'
|
||||
} from '@/libs/story/story-widget'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { computed, defineAsyncComponent } from 'vue'
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useContext } from '@/composables/context.composable.ts'
|
||||
import { ColorContext } from '@/context.ts'
|
||||
import type { Color } from '@/types/index.ts'
|
||||
import { IK_INPUT_ID, IK_INPUT_TYPE } from '@/types/injection-keys.ts'
|
||||
import { useContext } from '@/composables/context.composable'
|
||||
import { ColorContext } from '@/context'
|
||||
import type { Color } from '@/types'
|
||||
import { IK_INPUT_ID, IK_INPUT_TYPE } from '@/types/injection-keys'
|
||||
import type { IconName } from '@core/icons'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import { useDisabled } from '@core/composables/disabled.composable.ts'
|
||||
import { useDisabled } from '@core/composables/disabled.composable'
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import { computed, type HTMLAttributes, inject, ref, useAttrs } from 'vue'
|
||||
|
||||
|
||||
@@ -1,41 +1,23 @@
|
||||
<template>
|
||||
<UiHeadBar>
|
||||
<template #icon>
|
||||
<VtsObjectIcon
|
||||
size="medium"
|
||||
type="host"
|
||||
:state="powerState"
|
||||
:busy="isChangingState"
|
||||
:busy-tooltip="currentOperation"
|
||||
/>
|
||||
<VtsObjectIcon size="medium" type="host" :state="powerState" />
|
||||
</template>
|
||||
{{ host.name_label }}
|
||||
<template v-if="isMaster" #status>
|
||||
<VtsIcon v-tooltip="t('master')" name="status:primary-circle" size="medium" />
|
||||
</template>
|
||||
<template #actions>
|
||||
<MenuList placement="bottom-end">
|
||||
<template #trigger="{ open }">
|
||||
<UiDropdownButton @click="open($event)">{{ t('action:change-state') }}</UiDropdownButton>
|
||||
</template>
|
||||
<HostPowerStateActions :host />
|
||||
</MenuList>
|
||||
</template>
|
||||
</UiHeadBar>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import HostPowerStateActions from '@/modules/host/components/actions/HostPowerStateActions.vue'
|
||||
import { useHostUtils } from '@/modules/host/composables/host-utils.composable.ts'
|
||||
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
|
||||
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import VtsObjectIcon from '@core/components/object-icon/VtsObjectIcon.vue'
|
||||
import UiDropdownButton from '@core/components/ui/dropdown-button/UiDropdownButton.vue'
|
||||
import UiHeadBar from '@core/components/ui/head-bar/UiHeadBar.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -51,6 +33,4 @@ const powerState = computed(() => (isHostRunning(host) ? 'running' : 'halted'))
|
||||
|
||||
const { isMasterHost } = usePoolStore().subscribe()
|
||||
const isMaster = computed(() => isMasterHost(host.$ref))
|
||||
|
||||
const { isChangingState, currentOperation } = useHostUtils(() => host)
|
||||
</script>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import RouterTab from '@/components/RouterTab.vue'
|
||||
import TabList from '@core/components/tab-list/TabList.vue'
|
||||
import TabList from '@core/components/tab/TabList.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{
|
||||
|
||||
@@ -65,10 +65,10 @@ import VtsQuickInfoCard from '@core/components/quick-info-card/VtsQuickInfoCard.
|
||||
import VtsTag from '@core/components/tag/VtsTag.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiTagsList from '@core/components/ui/tag/UiTagsList.vue'
|
||||
import useRelativeTime from '@core/composables/relative-time.composable.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { formatSizeRaw } from '@core/utils/size.util.ts'
|
||||
import { parseDateTime } from '@core/utils/time.util.ts'
|
||||
import useRelativeTime from '@core/composables/relative-time.composable'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { formatSizeRaw } from '@core/utils/size.util'
|
||||
import { parseDateTime } from '@core/utils/time.util'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -36,7 +36,7 @@ import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiCardNumbers from '@core/components/ui/card-numbers/UiCardNumbers.vue'
|
||||
import UiCardTitle from '@core/components/ui/card-title/UiCardTitle.vue'
|
||||
import { formatSizeRaw } from '@core/utils/size.util.ts'
|
||||
import { formatSizeRaw } from '@core/utils/size.util'
|
||||
import { logicAnd } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -20,7 +20,7 @@ import VtsStateHero from '@core/components/state-hero/VtsStateHero.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiCardNumbers from '@core/components/ui/card-numbers/UiCardNumbers.vue'
|
||||
import UiCardTitle from '@core/components/ui/card-title/UiCardTitle.vue'
|
||||
import { useItemCounter } from '@core/composables/item-counter.composable.ts'
|
||||
import { useItemCounter } from '@core/composables/item-counter.composable'
|
||||
import { VM_POWER_STATE } from '@vates/types'
|
||||
import { logicAnd, useSum } from '@vueuse/math'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<VtsSidePanel :has-selection="!!pif" class="host-pif-side-panel" @close="emit('close')">
|
||||
<VtsSidePanel :has-selection="!!pif" @close="emit('close')">
|
||||
<template v-if="pif" #default>
|
||||
<!-- PIF -->
|
||||
<UiPanelCard>
|
||||
<UiCard class="card">
|
||||
<VtsCardObjectTitle :id="pif.uuid" :label="isBond ? t('bond') : t('pif')" />
|
||||
<div class="content">
|
||||
<!-- NETWORK -->
|
||||
@@ -75,9 +75,9 @@
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
</UiPanelCard>
|
||||
</UiCard>
|
||||
<!-- NETWORK INFORMATION -->
|
||||
<UiPanelCard>
|
||||
<UiCard class="card">
|
||||
<UiCardTitle>{{ t('network-information') }}</UiCardTitle>
|
||||
<div class="content">
|
||||
<!-- IP ADDRESSES -->
|
||||
@@ -180,9 +180,9 @@
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
</div>
|
||||
</UiPanelCard>
|
||||
</UiCard>
|
||||
<!-- PROPERTIES -->
|
||||
<UiPanelCard>
|
||||
<UiCard class="card">
|
||||
<UiCardTitle>{{ t('properties') }}</UiCardTitle>
|
||||
<div class="content">
|
||||
<!-- MTU -->
|
||||
@@ -219,16 +219,16 @@
|
||||
</template>
|
||||
</VtsCardRowKeyValue>
|
||||
</div>
|
||||
</UiPanelCard>
|
||||
</UiCard>
|
||||
</template>
|
||||
</VtsSidePanel>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiPif } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useNetworkStore } from '@/stores/xen-api/network.store.ts'
|
||||
import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store.ts'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store.ts'
|
||||
import type { XenApiPif } from '@/libs/xen-api/xen-api.types'
|
||||
import { useNetworkStore } from '@/stores/xen-api/network.store'
|
||||
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'
|
||||
@@ -237,10 +237,10 @@ import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import VtsSidePanel from '@core/components/panel/VtsSidePanel.vue'
|
||||
import VtsStatus from '@core/components/status/VtsStatus.vue'
|
||||
import VtsTag from '@core/components/tag/VtsTag.vue'
|
||||
import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiCardTitle from '@core/components/ui/card-title/UiCardTitle.vue'
|
||||
import UiPanelCard from '@core/components/ui/panel-card/UiPanelCard.vue'
|
||||
import UiTagsList from '@core/components/ui/tag/UiTagsList.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import humanFormat from 'human-format'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -317,7 +317,9 @@ const speed = computed(() => {
|
||||
</script>
|
||||
|
||||
<style scoped lang="postcss">
|
||||
.host-pif-side-panel {
|
||||
.card {
|
||||
gap: 1.6rem;
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
<div class="host-pif-table">
|
||||
<UiTitle>
|
||||
{{ t('pifs') }}
|
||||
<template #action>
|
||||
<slot name="title-actions" />
|
||||
</template>
|
||||
</UiTitle>
|
||||
<div class="container">
|
||||
<UiQuerySearchBar @search="(value: string) => (searchQuery = value)" />
|
||||
@@ -25,18 +22,18 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiNetwork, XenApiPif } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useNetworkStore } from '@/stores/xen-api/network.store.ts'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store.ts'
|
||||
import type { XenApiNetwork, XenApiPif } from '@/libs/xen-api/xen-api.types'
|
||||
import { useNetworkStore } from '@/stores/xen-api/network.store'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import UiQuerySearchBar from '@core/components/ui/query-search-bar/UiQuerySearchBar.vue'
|
||||
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 { usePagination } from '@core/composables/pagination.composable'
|
||||
import { useRouteQuery } from '@core/composables/route-query.composable'
|
||||
import { useTableState } from '@core/composables/table-state.composable'
|
||||
import { icon } from '@core/icons'
|
||||
import { usePifColumns } from '@core/tables/column-sets/pif-columns.ts'
|
||||
import { usePifColumns } from '@core/tables/column-sets/pif-columns'
|
||||
import { logicNot } from '@vueuse/math'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -45,10 +42,6 @@ const { pifs } = defineProps<{
|
||||
pifs: XenApiPif[]
|
||||
}>()
|
||||
|
||||
defineSlots<{
|
||||
'title-actions'(): any
|
||||
}>()
|
||||
|
||||
const { isReady, hasError } = usePifStore().subscribe()
|
||||
const { getByOpaqueRef } = useNetworkStore().subscribe()
|
||||
const { getPifStatus } = usePifStore().subscribe()
|
||||
@@ -111,7 +104,6 @@ function getManagementIcon(pif: XenApiPif) {
|
||||
}
|
||||
|
||||
const { HeadCells, BodyCells } = usePifColumns({
|
||||
exclude: ['actions'],
|
||||
body: (pif: XenApiPif) => {
|
||||
const name = computed(() => getNetworkName(pif.network))
|
||||
const status = computed(() => getPifStatus(pif))
|
||||
|
||||
@@ -70,7 +70,7 @@ import UiCard from '@core/components/ui/card/UiCard.vue'
|
||||
import UiLink from '@core/components/ui/link/UiLink.vue'
|
||||
import UiTagsList from '@core/components/ui/tag/UiTagsList.vue'
|
||||
import UiTitle from '@core/components/ui/title/UiTitle.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<template>
|
||||
<VtsTreeItem
|
||||
v-if="host !== undefined"
|
||||
:expanded="isExpanded"
|
||||
has-children
|
||||
class="infra-host-item"
|
||||
:node-id="`host:${host.uuid}`"
|
||||
>
|
||||
<VtsTreeItem v-if="host !== undefined" :expanded="isExpanded" class="infra-host-item" :node-id="`host:${host.uuid}`">
|
||||
<UiTreeItemLabel
|
||||
:route="{ name: '/host/[uuid]', params: { uuid: host.uuid } }"
|
||||
icon="object:host"
|
||||
@@ -13,7 +7,6 @@
|
||||
>
|
||||
{{ host.name_label || '(Host)' }}
|
||||
<template #addons>
|
||||
<UiLoader v-if="isChangingState" v-tooltip="currentOperation" />
|
||||
<VtsIcon v-if="isPoolMaster" v-tooltip="t('master')" name="status:primary-circle" size="medium" />
|
||||
<UiCounter
|
||||
v-if="isReady"
|
||||
@@ -33,7 +26,7 @@
|
||||
@click="open($event)"
|
||||
/>
|
||||
</template>
|
||||
<HostTreeActions :host />
|
||||
<HostTreeActions :host-opaque-ref="hostOpaqueRef" />
|
||||
</MenuList>
|
||||
</template>
|
||||
</UiTreeItemLabel>
|
||||
@@ -47,21 +40,19 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import InfraVmItems from '@/components/infra/InfraVmItems.vue'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
|
||||
import HostTreeActions from '@/modules/host/components/actions/HostTreeActions.vue'
|
||||
import { useHostUtils } from '@/modules/host/composables/host-utils.composable.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsIcon from '@core/components/icon/VtsIcon.vue'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import VtsTreeItem from '@core/components/tree/VtsTreeItem.vue'
|
||||
import VtsTreeList from '@core/components/tree/VtsTreeList.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import UiCounter from '@core/components/ui/counter/UiCounter.vue'
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import UiTreeItemLabel from '@core/components/ui/tree-item-label/UiTreeItemLabel.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { useToggle } from '@vueuse/shared'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -78,8 +69,6 @@ const host = computed(() => getByOpaqueRef(hostOpaqueRef))
|
||||
const { pool } = usePoolStore().subscribe()
|
||||
const isPoolMaster = computed(() => pool.value?.master === hostOpaqueRef)
|
||||
|
||||
const { isChangingState, currentOperation } = useHostUtils(host)
|
||||
|
||||
const { runningVms, isReady } = useVmStore().subscribe()
|
||||
|
||||
const vmCount = computed(() => runningVms.value.filter(vm => vm.resident_on === hostOpaqueRef)?.length ?? 0)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import InfraHostItem from '@/components/infra/InfraHostItem.vue'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import VtsTreeItemError from '@core/components/tree/VtsTreeItemError.vue'
|
||||
import VtsTreeLoadingItem from '@core/components/tree/VtsTreeLoadingItem.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<VtsTreeList class="infra-pool-list">
|
||||
<VtsTreeItem :expanded="isExpanded" has-children :node-id="`pool:${pool?.uuid}`">
|
||||
<VtsTreeItem :expanded="isExpanded" :node-id="`pool:${pool?.uuid}`">
|
||||
<VtsTreeItemError v-if="hasError">
|
||||
{{ t('error-no-data') }}
|
||||
</VtsTreeItemError>
|
||||
@@ -41,7 +41,7 @@
|
||||
import InfraHostItems from '@/components/infra/InfraHostItems.vue'
|
||||
import InfraVmItems from '@/components/infra/InfraVmItems.vue'
|
||||
import PoolTreeActions from '@/modules/pool/components/actions/PoolTreeActions.vue'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store.ts'
|
||||
import { usePoolStore } from '@/stores/xen-api/pool.store'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import VtsTreeItem from '@core/components/tree/VtsTreeItem.vue'
|
||||
import VtsTreeItemError from '@core/components/tree/VtsTreeItemError.vue'
|
||||
|
||||
@@ -5,51 +5,24 @@
|
||||
<template #icon>
|
||||
<VtsObjectIcon size="medium" :state="vmPowerState!" type="vm" />
|
||||
</template>
|
||||
<template #addons>
|
||||
<UiLoader v-if="isChangingState" v-tooltip="{ placement: 'top', content: currentOperation }" />
|
||||
<MenuList placement="bottom-start">
|
||||
<template #trigger="{ open }">
|
||||
<UiButtonIcon
|
||||
v-tooltip="{
|
||||
placement: 'top',
|
||||
content: t('quick-actions'),
|
||||
}"
|
||||
icon="action:more-actions"
|
||||
accent="brand"
|
||||
size="small"
|
||||
@click="open($event)"
|
||||
/>
|
||||
</template>
|
||||
<VmTreeActions :vm-opaque-ref />
|
||||
</MenuList>
|
||||
</template>
|
||||
</UiTreeItemLabel>
|
||||
</VtsTreeItem>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { VM_POWER_STATE } from '@/libs/xen-api/xen-api.enums.ts'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import VmTreeActions from '@/modules/vm/components/actions/VmTreeActions.vue'
|
||||
import { useVmOperation } from '@/modules/vm/composables/vm-operation.composable.ts'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store.ts'
|
||||
import MenuList from '@core/components/menu/MenuList.vue'
|
||||
import type { VM_POWER_STATE } 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 VtsObjectIcon from '@core/components/object-icon/VtsObjectIcon.vue'
|
||||
import VtsTreeItem from '@core/components/tree/VtsTreeItem.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import UiLoader from '@core/components/ui/loader/UiLoader.vue'
|
||||
import UiTreeItemLabel from '@core/components/ui/tree-item-label/UiTreeItemLabel.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { useIntersectionObserver } from '@vueuse/core'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { vmOpaqueRef } = defineProps<{
|
||||
vmOpaqueRef: XenApiVm['$ref']
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { getByOpaqueRef } = useVmStore().subscribe()
|
||||
const vm = computed(() => getByOpaqueRef(vmOpaqueRef))
|
||||
const rootElement = ref()
|
||||
@@ -63,6 +36,4 @@ const { stop } = useIntersectionObserver(rootElement, ([entry]) => {
|
||||
})
|
||||
|
||||
const vmPowerState = computed(() => vm.value?.power_state.toLowerCase() as Lowercase<VM_POWER_STATE> | undefined)
|
||||
|
||||
const { isChangingState, currentOperation } = useVmOperation(vm)
|
||||
</script>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import InfraVmItem from '@/components/infra/InfraVmItem.vue'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store.ts'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsTreeItemError from '@core/components/tree/VtsTreeItemError.vue'
|
||||
import VtsTreeLoadingItem from '@core/components/tree/VtsTreeLoadingItem.vue'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
<script lang="ts" setup>
|
||||
import CollectionFilterRow from '@/components/CollectionFilterRow.vue'
|
||||
import UiBadge from '@/components/ui/UiBadge.vue'
|
||||
import { getFilterIcon } from '@/libs/utils.ts'
|
||||
import type { Filters, NewFilter } from '@/types/filter.ts'
|
||||
import { getFilterIcon } from '@/libs/utils'
|
||||
import type { Filters, NewFilter } from '@/types/filter'
|
||||
import VtsOverlayButton from '@core/components/overlay/VtsOverlayButton.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { NewSort, Sorts } from '@/types/sort.ts'
|
||||
import type { NewSort, Sorts } from '@/types/sort'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import VtsSelect from '@core/components/select/VtsSelect.vue'
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store.ts'
|
||||
import type { XenApiVm } from '@/libs/xen-api/xen-api.types'
|
||||
import { useVmStore } from '@/stores/xen-api/vm.store'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
import UiModal from '@core/components/ui/modal/UiModal.vue'
|
||||
import { computed } from 'vue'
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums.ts'
|
||||
import { VM_COMPRESSION_TYPE } from '@/libs/xen-api/xen-api.enums'
|
||||
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { XenApiHost } from '@/libs/xen-api/xen-api.types'
|
||||
import VtsInputWrapper from '@core/components/input-wrapper/VtsInputWrapper.vue'
|
||||
import VtsOverlayCancelButton from '@core/components/overlay/VtsOverlayCancelButton.vue'
|
||||
import VtsOverlayConfirmButton from '@core/components/overlay/VtsOverlayConfirmButton.vue'
|
||||
|
||||
@@ -21,14 +21,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { NetworkInterface, VmState } from '@/types/new-vm.ts'
|
||||
import type { XenApiNetwork } from '@/libs/xen-api/xen-api.types'
|
||||
import type { NetworkInterface, VmState } from '@/types/new-vm'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiTableCell from '@core/components/ui/table-cell/UiTableCell.vue'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { useNewVmNetworkColumns } from '@core/tables/column-sets/new-vm-network-columns.ts'
|
||||
import { useNewVmNetworkColumns } from '@core/tables/column-sets/new-vm-network-columns'
|
||||
import { toRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import type { Vdi, VmState } from '@/types/new-vm.ts'
|
||||
import type { XenApiSr } from '@/libs/xen-api/xen-api.types'
|
||||
import type { Vdi, VmState } from '@/types/new-vm'
|
||||
import VtsRow from '@core/components/table/VtsRow.vue'
|
||||
import VtsTable from '@core/components/table/VtsTable.vue'
|
||||
import UiButton from '@core/components/ui/button/UiButton.vue'
|
||||
import UiTableCell from '@core/components/ui/table-cell/UiTableCell.vue'
|
||||
import { useFormSelect } from '@core/packages/form-select'
|
||||
import { useNewVmSrColumns } from '@core/tables/column-sets/new-vm-sr-columns.ts'
|
||||
import { renderBodyCell } from '@core/tables/helpers/render-body-cell.ts'
|
||||
import { useNewVmSrColumns } from '@core/tables/column-sets/new-vm-sr-columns'
|
||||
import { renderBodyCell } from '@core/tables/helpers/render-body-cell'
|
||||
import { toRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { XenApiPif } from '@/libs/xen-api/xen-api.types.ts'
|
||||
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store.ts'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store.ts'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store.ts'
|
||||
import type { XenApiPif } from '@/libs/xen-api/xen-api.types'
|
||||
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store'
|
||||
import { useHostStore } from '@/stores/xen-api/host.store'
|
||||
import { usePifStore } from '@/stores/xen-api/pif.store'
|
||||
import VtsObjectIcon from '@core/components/object-icon/VtsObjectIcon.vue'
|
||||
import VtsStatus from '@core/components/status/VtsStatus.vue'
|
||||
import UiButtonIcon from '@core/components/ui/button-icon/UiButtonIcon.vue'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive.ts'
|
||||
import { vTooltip } from '@core/directives/tooltip.directive'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user