Compare commits
164 Commits
use-vates-
...
pool-autop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b214b57e0f | ||
|
|
aefcce45ff | ||
|
|
367fb4d8a6 | ||
|
|
e54a0bfc80 | ||
|
|
9e5541703b | ||
|
|
039d5687c0 | ||
|
|
b89195eb80 | ||
|
|
822cdc3fb8 | ||
|
|
c7b5b715a3 | ||
|
|
56b427c09c | ||
|
|
0e45c52bbc | ||
|
|
4fd2b91fc4 | ||
|
|
7890320a7d | ||
|
|
1718649e0c | ||
|
|
7fc5d62ca9 | ||
|
|
eedaca0195 | ||
|
|
9ffa52cc01 | ||
|
|
e9a23755b6 | ||
|
|
5712f29a58 | ||
|
|
509ebf900e | ||
|
|
757a8915d9 | ||
|
|
35c660dbf6 | ||
|
|
f23fd69e7e | ||
|
|
39c10a7197 | ||
|
|
7a1bc16468 | ||
|
|
93dd1a63da | ||
|
|
b4e1064914 | ||
|
|
810cdc1a77 | ||
|
|
1023131828 | ||
|
|
e2d83324ac | ||
|
|
7cea445c21 | ||
|
|
b5d9d9a9e1 | ||
|
|
3a4e9b8f8e | ||
|
|
92efd28b33 | ||
|
|
a2c36c0832 | ||
|
|
2eb49cfdf1 | ||
|
|
ba9d4d4bb5 | ||
|
|
18dea2f2fe | ||
|
|
70c51227bf | ||
|
|
e162fd835b | ||
|
|
bcdcfbf20b | ||
|
|
a6e93c895c | ||
|
|
5c4f907358 | ||
|
|
e19dbc06fe | ||
|
|
287378f9c6 | ||
|
|
83a94eefd6 | ||
|
|
92fc19e2e3 | ||
|
|
521d31ac84 | ||
|
|
2b3ccb4b0e | ||
|
|
2498a4f47c | ||
|
|
dd61feeaf3 | ||
|
|
7851f8c196 | ||
|
|
404a764821 | ||
|
|
59cc418973 | ||
|
|
bc00551cb3 | ||
|
|
4d24248ea2 | ||
|
|
5c731fd56e | ||
|
|
79abb97b1f | ||
|
|
3314ba6e08 | ||
|
|
0fe8f8cac3 | ||
|
|
aaffe8c872 | ||
|
|
cf0e820632 | ||
|
|
82fdfbd18b | ||
|
|
116f2ec47a | ||
|
|
5d4723ec06 | ||
|
|
092475d57f | ||
|
|
e7a97fd175 | ||
|
|
2262ce8814 | ||
|
|
7ec64476a4 | ||
|
|
bbb43808dd | ||
|
|
02d7f0f20b | ||
|
|
e226db708a | ||
|
|
b7af74e27e | ||
|
|
70f2e50274 | ||
|
|
619b3f3c78 | ||
|
|
ac182374d6 | ||
|
|
8461d68d40 | ||
|
|
838f9a42d1 | ||
|
|
a9dbc01b84 | ||
|
|
5daf269ab3 | ||
|
|
383677f4dd | ||
|
|
28ad2af9b0 | ||
|
|
53b25508af | ||
|
|
54836ec576 | ||
|
|
c9897166e0 | ||
|
|
1b35fddf3d | ||
|
|
fc2ca1f4d4 | ||
|
|
ed7046c1ab | ||
|
|
215579ff4d | ||
|
|
4c79a78a05 | ||
|
|
7864c05ee1 | ||
|
|
1026d18e4b | ||
|
|
d62acd3fe7 | ||
|
|
cc1b4bc06c | ||
|
|
d45f843308 | ||
|
|
3c7fa05c43 | ||
|
|
05df055552 | ||
|
|
755b206901 | ||
|
|
3360399b2a | ||
|
|
091bc04ace | ||
|
|
3ab2a8354b | ||
|
|
2d047c4fef | ||
|
|
0f1dcda7db | ||
|
|
44760668a3 | ||
|
|
a4023dbc54 | ||
|
|
3cad7e2467 | ||
|
|
ad5f37436a | ||
|
|
8c05eab720 | ||
|
|
4db605f14a | ||
|
|
06d411543a | ||
|
|
6084db22a9 | ||
|
|
2e6f7d35ef | ||
|
|
0f1f45953c | ||
|
|
89a4de5b21 | ||
|
|
32dd16114e | ||
|
|
f5a3cc0cdb | ||
|
|
5cabf9916a | ||
|
|
8e65ef7dbc | ||
|
|
0c0251082d | ||
|
|
c250cd9b89 | ||
|
|
d6abdb246b | ||
|
|
5769da3ebc | ||
|
|
4f383635ef | ||
|
|
8a7abc2e54 | ||
|
|
af1650bd14 | ||
|
|
c6fdef33c4 | ||
|
|
5f73f09f59 | ||
|
|
1b0fc62e2e | ||
|
|
aa2dc9206d | ||
|
|
2b1562da81 | ||
|
|
25e270edb4 | ||
|
|
51c11c15a8 | ||
|
|
47922dee56 | ||
|
|
3dda4dbaad | ||
|
|
901f7b3fe2 | ||
|
|
774d66512e | ||
|
|
ec1669a32e | ||
|
|
bbcd4184b0 | ||
|
|
85ec26194b | ||
|
|
f0242380ca | ||
|
|
a624330818 | ||
|
|
3892efcca2 | ||
|
|
c1c122d92c | ||
|
|
b7a66e9f73 | ||
|
|
d92d2efc78 | ||
|
|
c2cb51a470 | ||
|
|
5242affdc1 | ||
|
|
71f3be288b | ||
|
|
58769815b0 | ||
|
|
c81c23c0d0 | ||
|
|
f06f89b5b4 | ||
|
|
fa748ed9de | ||
|
|
cd753acff7 | ||
|
|
8ff861e2be | ||
|
|
95ccb2e0ae | ||
|
|
b0e5846ad1 | ||
|
|
19fd456ccf | ||
|
|
7946a7db68 | ||
|
|
6127e30574 | ||
|
|
4aad9d8e32 | ||
|
|
78d15ddf96 | ||
|
|
302f7fb85e | ||
|
|
ea19b0851f | ||
|
|
b0c37df8d7 |
55
.eslintrc.js
55
.eslintrc.js
@@ -15,9 +15,10 @@ module.exports = {
|
|||||||
|
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: ['cli.{,c,m}js', '*-cli.{,c,m}js', '**/*cli*/**/*.{,c,m}js'],
|
files: ['cli.{,c,m}js', '*-cli.{,c,m}js', '**/*cli*/**/*.{,c,m}js', '**/scripts/**.{,c,m}js'],
|
||||||
rules: {
|
rules: {
|
||||||
'n/no-process-exit': 'off',
|
'n/no-process-exit': 'off',
|
||||||
|
'n/shebang': 'off',
|
||||||
'no-console': 'off',
|
'no-console': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -46,6 +47,58 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
files: ['@xen-orchestra/{web-core,lite,web}/**/*.{vue,ts}'],
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
plugins: ['import'],
|
||||||
|
extends: [
|
||||||
|
'plugin:import/recommended',
|
||||||
|
'plugin:import/typescript',
|
||||||
|
'plugin:vue/vue3-recommended',
|
||||||
|
'@vue/eslint-config-typescript/recommended',
|
||||||
|
'@vue/eslint-config-prettier',
|
||||||
|
],
|
||||||
|
settings: {
|
||||||
|
'import/resolver': {
|
||||||
|
typescript: true,
|
||||||
|
'eslint-import-resolver-custom-alias': {
|
||||||
|
alias: {
|
||||||
|
'@core': '../web-core/lib',
|
||||||
|
'@': './src',
|
||||||
|
},
|
||||||
|
extensions: ['.ts'],
|
||||||
|
packages: ['@xen-orchestra/lite', '@xen-orchestra/web'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'no-void': 'off',
|
||||||
|
'n/no-missing-import': 'off', // using 'import' plugin instead to support TS aliases
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
'vue/require-default-prop': 'off', // https://github.com/vuejs/eslint-plugin-vue/issues/2051
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['@xen-orchestra/{web-core,lite,web}/src/pages/**/*.vue'],
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'vue/multi-word-component-names': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['@xen-orchestra/{web-core,lite,web}/typed-router.d.ts'],
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'eslint-comments/disable-enable-pair': 'off',
|
||||||
|
'eslint-comments/no-unlimited-disable': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -64,7 +64,7 @@ body:
|
|||||||
id: error-message
|
id: error-message
|
||||||
attributes:
|
attributes:
|
||||||
label: Error message
|
label: Error message
|
||||||
render: Markdown
|
render: Text
|
||||||
validations:
|
validations:
|
||||||
required: false
|
required: false
|
||||||
- type: textarea
|
- type: textarea
|
||||||
|
|||||||
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -24,8 +24,12 @@ jobs:
|
|||||||
cache: 'yarn'
|
cache: 'yarn'
|
||||||
- name: Install project dependencies
|
- name: Install project dependencies
|
||||||
run: yarn
|
run: yarn
|
||||||
|
- name: Ensure yarn.lock is up-to-date
|
||||||
|
run: git diff --exit-code yarn.lock
|
||||||
- name: Build the project
|
- name: Build the project
|
||||||
run: yarn build
|
run: yarn build
|
||||||
|
- name: Unit tests
|
||||||
|
run: yarn test-unit
|
||||||
- name: Lint tests
|
- name: Lint tests
|
||||||
run: yarn test-lint
|
run: yarn test-lint
|
||||||
- name: Integration tests
|
- name: Integration tests
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -30,8 +30,12 @@ pnpm-debug.log.*
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
yarn-error.log.*
|
yarn-error.log.*
|
||||||
.env
|
.env
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
# code coverage
|
# code coverage
|
||||||
.nyc_output/
|
.nyc_output/
|
||||||
coverage/
|
coverage/
|
||||||
.turbo/
|
.turbo/
|
||||||
|
|
||||||
|
# https://node-tap.org/dot-tap-folder/
|
||||||
|
.tap/
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sinon": "^17.0.1",
|
"sinon": "^17.0.1",
|
||||||
"tap": "^16.3.0",
|
|
||||||
"test": "^3.2.1"
|
"test": "^3.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,42 @@ decorateClass(Foo, {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `decorateObject(object, map)`
|
||||||
|
|
||||||
|
Decorates an object the same way `decorateClass()` decorates a class:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { decorateObject } from '@vates/decorate-with'
|
||||||
|
|
||||||
|
const object = {
|
||||||
|
get bar() {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
|
||||||
|
set bar(value) {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
|
||||||
|
baz() {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
decorateObject(object, {
|
||||||
|
// getter and/or setter
|
||||||
|
bar: {
|
||||||
|
// without arguments
|
||||||
|
get: lodash.memoize,
|
||||||
|
|
||||||
|
// with arguments
|
||||||
|
set: [lodash.debounce, 150],
|
||||||
|
},
|
||||||
|
|
||||||
|
// method (with or without arguments)
|
||||||
|
baz: lodash.curry,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### `perInstance(fn, ...args)`
|
### `perInstance(fn, ...args)`
|
||||||
|
|
||||||
Helper to decorate the method by instance instead of for the whole class.
|
Helper to decorate the method by instance instead of for the whole class.
|
||||||
|
|||||||
@@ -80,6 +80,42 @@ decorateClass(Foo, {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `decorateObject(object, map)`
|
||||||
|
|
||||||
|
Decorates an object the same way `decorateClass()` decorates a class:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { decorateObject } from '@vates/decorate-with'
|
||||||
|
|
||||||
|
const object = {
|
||||||
|
get bar() {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
|
||||||
|
set bar(value) {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
|
||||||
|
baz() {
|
||||||
|
// body
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
decorateObject(object, {
|
||||||
|
// getter and/or setter
|
||||||
|
bar: {
|
||||||
|
// without arguments
|
||||||
|
get: lodash.memoize,
|
||||||
|
|
||||||
|
// with arguments
|
||||||
|
set: [lodash.debounce, 150],
|
||||||
|
},
|
||||||
|
|
||||||
|
// method (with or without arguments)
|
||||||
|
baz: lodash.curry,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### `perInstance(fn, ...args)`
|
### `perInstance(fn, ...args)`
|
||||||
|
|
||||||
Helper to decorate the method by instance instead of for the whole class.
|
Helper to decorate the method by instance instead of for the whole class.
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ function applyDecorator(decorator, value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.decorateClass = exports.decorateMethodsWith = function decorateClass(klass, map) {
|
exports.decorateClass = exports.decorateMethodsWith = function decorateClass(klass, map) {
|
||||||
const { prototype } = klass
|
return decorateObject(klass.prototype, map)
|
||||||
|
}
|
||||||
|
|
||||||
|
function decorateObject(object, map) {
|
||||||
for (const name of Object.keys(map)) {
|
for (const name of Object.keys(map)) {
|
||||||
const decorator = map[name]
|
const decorator = map[name]
|
||||||
const descriptor = getOwnPropertyDescriptor(prototype, name)
|
const descriptor = getOwnPropertyDescriptor(object, name)
|
||||||
if (typeof decorator === 'function' || Array.isArray(decorator)) {
|
if (typeof decorator === 'function' || Array.isArray(decorator)) {
|
||||||
descriptor.value = applyDecorator(decorator, descriptor.value)
|
descriptor.value = applyDecorator(decorator, descriptor.value)
|
||||||
} else {
|
} else {
|
||||||
@@ -30,10 +33,11 @@ exports.decorateClass = exports.decorateMethodsWith = function decorateClass(kla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProperty(prototype, name, descriptor)
|
defineProperty(object, name, descriptor)
|
||||||
}
|
}
|
||||||
return klass
|
return object
|
||||||
}
|
}
|
||||||
|
exports.decorateObject = decorateObject
|
||||||
|
|
||||||
exports.perInstance = function perInstance(fn, decorator, ...args) {
|
exports.perInstance = function perInstance(fn, decorator, ...args) {
|
||||||
const map = new WeakMap()
|
const map = new WeakMap()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"url": "https://vates.fr"
|
"url": "https://vates.fr"
|
||||||
},
|
},
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.10"
|
"node": ">=8.10"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ function assertListeners(t, event, listeners) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.beforeEach(function (t) {
|
t.beforeEach(function (t) {
|
||||||
|
// work around https://github.com/tapjs/tapjs/issues/998
|
||||||
|
t.context = {}
|
||||||
|
|
||||||
t.context.ee = new EventEmitter()
|
t.context.ee = new EventEmitter()
|
||||||
t.context.em = new EventListenersManager(t.context.ee)
|
t.context.em = new EventListenersManager(t.context.ee)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -38,9 +38,9 @@
|
|||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public",
|
"postversion": "npm publish --access public",
|
||||||
"test": "tap --branches=72"
|
"test": "tap --allow-incomplete-coverage"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^16.2.0"
|
"tap": "^18.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
@vates/fuse-vhd/.USAGE.md
Normal file
28
@vates/fuse-vhd/.USAGE.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
Mount a vhd generated by xen-orchestra to filesystem
|
||||||
|
|
||||||
|
### Library
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { mount } from 'fuse-vhd'
|
||||||
|
|
||||||
|
// return a disposable, see promise-toolbox/Disposable
|
||||||
|
// unmount automatically when disposable is disposed
|
||||||
|
// in case of differencing VHD, it mounts the full chain
|
||||||
|
await mount(handler, diskId, mountPoint)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cli
|
||||||
|
|
||||||
|
From the install folder :
|
||||||
|
|
||||||
|
```
|
||||||
|
cli.mjs <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||||
|
```
|
||||||
|
|
||||||
|
After installing the package
|
||||||
|
|
||||||
|
```
|
||||||
|
xo-fuse-vhd <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||||
|
```
|
||||||
|
|
||||||
|
remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root`
|
||||||
59
@vates/fuse-vhd/README.md
Normal file
59
@vates/fuse-vhd/README.md
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||||
|
|
||||||
|
# @vates/fuse-vhd
|
||||||
|
|
||||||
|
[](https://npmjs.org/package/@vates/fuse-vhd)  [](https://bundlephobia.com/result?p=@vates/fuse-vhd) [](https://npmjs.org/package/@vates/fuse-vhd)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Installation of the [npm package](https://npmjs.org/package/@vates/fuse-vhd):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save @vates/fuse-vhd
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Mount a vhd generated by xen-orchestra to filesystem
|
||||||
|
|
||||||
|
### Library
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { mount } from 'fuse-vhd'
|
||||||
|
|
||||||
|
// return a disposable, see promise-toolbox/Disposable
|
||||||
|
// unmount automatically when disposable is disposed
|
||||||
|
// in case of differencing VHD, it mounts the full chain
|
||||||
|
await mount(handler, diskId, mountPoint)
|
||||||
|
```
|
||||||
|
|
||||||
|
### cli
|
||||||
|
|
||||||
|
From the install folder :
|
||||||
|
|
||||||
|
```
|
||||||
|
cli.mjs <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||||
|
```
|
||||||
|
|
||||||
|
After installing the package
|
||||||
|
|
||||||
|
```
|
||||||
|
xo-fuse-vhd <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||||
|
```
|
||||||
|
|
||||||
|
remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root`
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
Contributions are _very_ welcomed, either on the documentation or on
|
||||||
|
the code.
|
||||||
|
|
||||||
|
You may:
|
||||||
|
|
||||||
|
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||||
|
you've encountered;
|
||||||
|
- fork and create a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||||
26
@vates/fuse-vhd/cli.mjs
Executable file
26
@vates/fuse-vhd/cli.mjs
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import Disposable from 'promise-toolbox/Disposable'
|
||||||
|
import { getSyncedHandler } from '@xen-orchestra/fs'
|
||||||
|
|
||||||
|
import { mount } from './index.mjs'
|
||||||
|
|
||||||
|
async function* main([remoteUrl, vhdPathInRemote, mountPoint]) {
|
||||||
|
if (mountPoint === undefined) {
|
||||||
|
throw new TypeError('missing arg: cli <remoteUrl> <vhdPathInRemote> <mountPoint>')
|
||||||
|
}
|
||||||
|
const handler = yield getSyncedHandler({ url: remoteUrl })
|
||||||
|
const mounted = await mount(handler, vhdPathInRemote, mountPoint)
|
||||||
|
|
||||||
|
let disposePromise
|
||||||
|
process.on('SIGINT', async () => {
|
||||||
|
// ensure single dispose
|
||||||
|
if (!disposePromise) {
|
||||||
|
disposePromise = mounted.dispose()
|
||||||
|
}
|
||||||
|
await disposePromise
|
||||||
|
process.exit()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Disposable.wrap(main)(process.argv.slice(2))
|
||||||
@@ -58,7 +58,7 @@ export const mount = Disposable.factory(async function* mount(handler, diskPath,
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
return new Disposable(
|
return new Disposable(
|
||||||
() => fromCallback(() => fuse.unmount()),
|
() => fromCallback(cb => fuse.unmount(cb)),
|
||||||
fromCallback(() => fuse.mount())
|
fromCallback(cb => fuse.mount(cb))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vates/fuse-vhd",
|
"name": "@vates/fuse-vhd",
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"private": false,
|
"private": false,
|
||||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/fuse-vhd",
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/fuse-vhd",
|
||||||
@@ -19,11 +19,15 @@
|
|||||||
},
|
},
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@xen-orchestra/fs": "^4.1.4",
|
||||||
"fuse-native": "^2.2.6",
|
"fuse-native": "^2.2.6",
|
||||||
"lru-cache": "^7.14.0",
|
"lru-cache": "^7.14.0",
|
||||||
"promise-toolbox": "^0.21.0",
|
"promise-toolbox": "^0.21.0",
|
||||||
"vhd-lib": "^4.9.0"
|
"vhd-lib": "^4.9.0"
|
||||||
},
|
},
|
||||||
|
"bin": {
|
||||||
|
"xo-fuse-vhd": "./cli.mjs"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public"
|
"postversion": "npm publish --access public"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,14 @@
|
|||||||
"@xen-orchestra/async-map": "^0.1.2",
|
"@xen-orchestra/async-map": "^0.1.2",
|
||||||
"@xen-orchestra/log": "^0.6.0",
|
"@xen-orchestra/log": "^0.6.0",
|
||||||
"promise-toolbox": "^0.21.0",
|
"promise-toolbox": "^0.21.0",
|
||||||
"xen-api": "^2.0.0"
|
"xen-api": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^16.3.0",
|
"tap": "^18.7.0",
|
||||||
"tmp": "^0.2.1"
|
"tmp": "^0.2.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public",
|
"postversion": "npm publish --access public",
|
||||||
"test-integration": "tap --lines 97 --functions 95 --branches 74 --statements 97 tests/*.integ.mjs"
|
"test-integration": "tap --allow-incomplete-coverage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { strict as assert } from 'node:assert'
|
import { strict as assert } from 'node:assert'
|
||||||
import { describe, it } from 'tap/mocha'
|
import test from 'test'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
generateHotp,
|
generateHotp,
|
||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
verifyTotp,
|
verifyTotp,
|
||||||
} from './index.mjs'
|
} from './index.mjs'
|
||||||
|
|
||||||
|
const { describe, it } = test
|
||||||
|
|
||||||
describe('generateSecret', function () {
|
describe('generateSecret', function () {
|
||||||
it('generates a string of 32 chars', async function () {
|
it('generates a string of 32 chars', async function () {
|
||||||
const secret = generateSecret()
|
const secret = generateSecret()
|
||||||
@@ -31,9 +31,9 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public",
|
"postversion": "npm publish --access public",
|
||||||
"test": "tap"
|
"test": "node--test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^16.3.0"
|
"test": "^3.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const assert = require('assert/strict')
|
const assert = require('assert/strict')
|
||||||
const { describe, it } = require('tap').mocha
|
const { describe, it } = require('test')
|
||||||
|
|
||||||
const { every, not, some } = require('./')
|
const { every, not, some } = require('./')
|
||||||
|
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public",
|
"postversion": "npm publish --access public",
|
||||||
"test": "tap"
|
"test": "node--test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^16.0.1"
|
"test": "^3.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const assert = require('assert/strict')
|
const assert = require('assert/strict')
|
||||||
const { afterEach, describe, it } = require('tap').mocha
|
const { afterEach, describe, it } = require('test')
|
||||||
|
|
||||||
const { AlteredRecordError, AuditCore, MissingRecordError, NULL_ID, Storage } = require('.')
|
const { AlteredRecordError, AuditCore, MissingRecordError, NULL_ID, Storage } = require('.')
|
||||||
|
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish --access public",
|
"postversion": "npm publish --access public",
|
||||||
"test": "tap --lines 67 --functions 92 --branches 52 --statements 67"
|
"test": "node--test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vates/decorate-with": "^2.0.0",
|
"@vates/decorate-with": "^2.1.0",
|
||||||
"@xen-orchestra/log": "^0.6.0",
|
"@xen-orchestra/log": "^0.6.0",
|
||||||
"golike-defer": "^0.5.1",
|
"golike-defer": "^0.5.1",
|
||||||
"object-hash": "^2.0.1"
|
"object-hash": "^2.0.1"
|
||||||
@@ -28,6 +28,6 @@
|
|||||||
"url": "https://vates.fr"
|
"url": "https://vates.fr"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "^16.0.1"
|
"test": "^3.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xen-orchestra/async-map": "^0.1.2",
|
"@xen-orchestra/async-map": "^0.1.2",
|
||||||
"@xen-orchestra/backups": "^0.44.3",
|
"@xen-orchestra/backups": "^0.44.6",
|
||||||
"@xen-orchestra/fs": "^4.1.3",
|
"@xen-orchestra/fs": "^4.1.4",
|
||||||
"filenamify": "^6.0.0",
|
"filenamify": "^6.0.0",
|
||||||
"getopts": "^2.2.5",
|
"getopts": "^2.2.5",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Task } from '@vates/task'
|
import { Task } from './Task.mjs'
|
||||||
|
|
||||||
export class HealthCheckVmBackup {
|
export class HealthCheckVmBackup {
|
||||||
#restoredVm
|
#restoredVm
|
||||||
@@ -14,7 +14,7 @@ export class HealthCheckVmBackup {
|
|||||||
async run() {
|
async run() {
|
||||||
return Task.run(
|
return Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'vmstart' },
|
name: 'vmstart',
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
let restoredVm = this.#restoredVm
|
let restoredVm = this.#restoredVm
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import assert from 'node:assert'
|
import assert from 'node:assert'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { formatFilenameDate } from './_filenameDate.mjs'
|
import { formatFilenameDate } from './_filenameDate.mjs'
|
||||||
import { importIncrementalVm } from './_incrementalVm.mjs'
|
import { importIncrementalVm } from './_incrementalVm.mjs'
|
||||||
|
import { Task } from './Task.mjs'
|
||||||
import { watchStreamSize } from './_watchStreamSize.mjs'
|
import { watchStreamSize } from './_watchStreamSize.mjs'
|
||||||
import { VhdNegative, VhdSynthetic } from 'vhd-lib'
|
import { VhdNegative, VhdSynthetic } from 'vhd-lib'
|
||||||
import { decorateClass } from '@vates/decorate-with'
|
import { decorateClass } from '@vates/decorate-with'
|
||||||
@@ -160,10 +160,10 @@ export class ImportVmBackup {
|
|||||||
// update the stream with the negative vhd stream
|
// update the stream with the negative vhd stream
|
||||||
stream = await negativeVhd.stream()
|
stream = await negativeVhd.stream()
|
||||||
vdis[vdiRef].baseVdi = snapshotCandidate
|
vdis[vdiRef].baseVdi = snapshotCandidate
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
// can be a broken VHD chain, a vhd chain with a key backup, ....
|
// can be a broken VHD chain, a vhd chain with a key backup, ....
|
||||||
// not an irrecuperable error, don't dispose parentVhd, and fallback to full restore
|
// not an irrecuperable error, don't dispose parentVhd, and fallback to full restore
|
||||||
warn(`can't use differential restore`, err)
|
warn(`can't use differential restore`, { error })
|
||||||
disposableDescendants?.dispose()
|
disposableDescendants?.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ export class ImportVmBackup {
|
|||||||
|
|
||||||
return Task.run(
|
return Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'transfer' },
|
name: 'transfer',
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
const xapi = this._xapi
|
const xapi = this._xapi
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ export const DIR_XO_CONFIG_BACKUPS = 'xo-config-backups'
|
|||||||
|
|
||||||
export const DIR_XO_POOL_METADATA_BACKUPS = 'xo-pool-metadata-backups'
|
export const DIR_XO_POOL_METADATA_BACKUPS = 'xo-pool-metadata-backups'
|
||||||
|
|
||||||
|
const IMMUTABILTY_METADATA_FILENAME = '/immutability.json'
|
||||||
|
|
||||||
const { debug, warn } = createLogger('xo:backups:RemoteAdapter')
|
const { debug, warn } = createLogger('xo:backups:RemoteAdapter')
|
||||||
|
|
||||||
const compareTimestamp = (a, b) => a.timestamp - b.timestamp
|
const compareTimestamp = (a, b) => a.timestamp - b.timestamp
|
||||||
@@ -189,13 +191,14 @@ export class RemoteAdapter {
|
|||||||
// check if we will be allowed to merge a a vhd created in this adapter
|
// check if we will be allowed to merge a a vhd created in this adapter
|
||||||
// with the vhd at path `path`
|
// with the vhd at path `path`
|
||||||
async isMergeableParent(packedParentUid, path) {
|
async isMergeableParent(packedParentUid, path) {
|
||||||
return await Disposable.use(openVhd(this.handler, path), vhd => {
|
return await Disposable.use(VhdSynthetic.fromVhdChain(this.handler, path), vhd => {
|
||||||
// this baseUuid is not linked with this vhd
|
// this baseUuid is not linked with this vhd
|
||||||
if (!vhd.footer.uuid.equals(packedParentUid)) {
|
if (!vhd.footer.uuid.equals(packedParentUid)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const isVhdDirectory = vhd instanceof VhdDirectory
|
// check if all the chain is composed of vhd directory
|
||||||
|
const isVhdDirectory = vhd.checkVhdsClass(VhdDirectory)
|
||||||
return isVhdDirectory
|
return isVhdDirectory
|
||||||
? this.useVhdDirectory() && this.#getCompressionType() === vhd.compressionType
|
? this.useVhdDirectory() && this.#getCompressionType() === vhd.compressionType
|
||||||
: !this.useVhdDirectory()
|
: !this.useVhdDirectory()
|
||||||
@@ -749,10 +752,37 @@ export class RemoteAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async readVmBackupMetadata(path) {
|
async readVmBackupMetadata(path) {
|
||||||
|
let json
|
||||||
|
let isImmutable = false
|
||||||
|
let remoteIsImmutable = false
|
||||||
|
// if the remote is immutable, check if this metadatas are also immutables
|
||||||
|
try {
|
||||||
|
// this file is not encrypted
|
||||||
|
await this._handler._readFile(IMMUTABILTY_METADATA_FILENAME)
|
||||||
|
remoteIsImmutable = true
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'ENOENT') {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// this will trigger an EPERM error if the file is immutable
|
||||||
|
json = await this.handler.readFile(path, { flag: 'r+' })
|
||||||
|
// s3 handler don't respect flags
|
||||||
|
} catch (err) {
|
||||||
|
// retry without triggerring immutbaility check ,only on immutable remote
|
||||||
|
if (err.code === 'EPERM' && remoteIsImmutable) {
|
||||||
|
isImmutable = true
|
||||||
|
json = await this._handler.readFile(path, { flag: 'r' })
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
// _filename is a private field used to compute the backup id
|
// _filename is a private field used to compute the backup id
|
||||||
//
|
//
|
||||||
// it's enumerable to make it cacheable
|
// it's enumerable to make it cacheable
|
||||||
const metadata = { ...JSON.parse(await this._handler.readFile(path)), _filename: path }
|
const metadata = { ...JSON.parse(json), _filename: path, isImmutable }
|
||||||
|
|
||||||
// backups created on XenServer < 7.1 via JSON in XML-RPC transports have boolean values encoded as integers, which make them unusable with more recent XAPIs
|
// backups created on XenServer < 7.1 via JSON in XML-RPC transports have boolean values encoded as integers, which make them unusable with more recent XAPIs
|
||||||
if (typeof metadata.vm.is_a_template === 'number') {
|
if (typeof metadata.vm.is_a_template === 'number') {
|
||||||
|
|||||||
155
@xen-orchestra/backups/Task.mjs
Normal file
155
@xen-orchestra/backups/Task.mjs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import CancelToken from 'promise-toolbox/CancelToken'
|
||||||
|
import Zone from 'node-zone'
|
||||||
|
|
||||||
|
const logAfterEnd = log => {
|
||||||
|
const error = new Error('task has already ended')
|
||||||
|
error.log = log
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
const noop = Function.prototype
|
||||||
|
|
||||||
|
const serializeErrors = errors => (Array.isArray(errors) ? errors.map(serializeError) : errors)
|
||||||
|
|
||||||
|
// Create a serializable object from an error.
|
||||||
|
//
|
||||||
|
// Otherwise some fields might be non-enumerable and missing from logs.
|
||||||
|
const serializeError = error =>
|
||||||
|
error instanceof Error
|
||||||
|
? {
|
||||||
|
...error, // Copy enumerable properties.
|
||||||
|
code: error.code,
|
||||||
|
errors: serializeErrors(error.errors), // supports AggregateError
|
||||||
|
message: error.message,
|
||||||
|
name: error.name,
|
||||||
|
stack: error.stack,
|
||||||
|
}
|
||||||
|
: error
|
||||||
|
|
||||||
|
const $$task = Symbol('@xen-orchestra/backups/Task')
|
||||||
|
|
||||||
|
export class Task {
|
||||||
|
static get cancelToken() {
|
||||||
|
const task = Zone.current.data[$$task]
|
||||||
|
return task !== undefined ? task.#cancelToken : CancelToken.none
|
||||||
|
}
|
||||||
|
|
||||||
|
static run(opts, fn) {
|
||||||
|
return new this(opts).run(fn, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
static wrapFn(opts, fn) {
|
||||||
|
// compatibility with @decorateWith
|
||||||
|
if (typeof fn !== 'function') {
|
||||||
|
;[fn, opts] = [opts, fn]
|
||||||
|
}
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
return Task.run(typeof opts === 'function' ? opts.apply(this, arguments) : opts, () => fn.apply(this, arguments))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#cancelToken
|
||||||
|
#id = Math.random().toString(36).slice(2)
|
||||||
|
#onLog
|
||||||
|
#zone
|
||||||
|
|
||||||
|
constructor({ name, data, onLog }) {
|
||||||
|
let parentCancelToken, parentId
|
||||||
|
if (onLog === undefined) {
|
||||||
|
const parent = Zone.current.data[$$task]
|
||||||
|
if (parent === undefined) {
|
||||||
|
onLog = noop
|
||||||
|
} else {
|
||||||
|
onLog = log => parent.#onLog(log)
|
||||||
|
parentCancelToken = parent.#cancelToken
|
||||||
|
parentId = parent.#id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const zone = Zone.current.fork('@xen-orchestra/backups/Task')
|
||||||
|
zone.data[$$task] = this
|
||||||
|
this.#zone = zone
|
||||||
|
|
||||||
|
const { cancel, token } = CancelToken.source(parentCancelToken && [parentCancelToken])
|
||||||
|
this.#cancelToken = token
|
||||||
|
this.cancel = cancel
|
||||||
|
|
||||||
|
this.#onLog = onLog
|
||||||
|
|
||||||
|
this.#log('start', {
|
||||||
|
data,
|
||||||
|
message: name,
|
||||||
|
parentId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
failure(error) {
|
||||||
|
this.#end('failure', serializeError(error))
|
||||||
|
}
|
||||||
|
|
||||||
|
info(message, data) {
|
||||||
|
this.#log('info', { data, message })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a function in the context of this task
|
||||||
|
*
|
||||||
|
* In case of error, the task will be failed.
|
||||||
|
*
|
||||||
|
* @typedef Result
|
||||||
|
* @param {() => Result} fn
|
||||||
|
* @param {boolean} last - Whether the task should succeed if there is no error
|
||||||
|
* @returns Result
|
||||||
|
*/
|
||||||
|
run(fn, last = false) {
|
||||||
|
return this.#zone.run(() => {
|
||||||
|
try {
|
||||||
|
const result = fn()
|
||||||
|
let then
|
||||||
|
if (result != null && typeof (then = result.then) === 'function') {
|
||||||
|
then.call(result, last && (value => this.success(value)), error => this.failure(error))
|
||||||
|
} else if (last) {
|
||||||
|
this.success(result)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} catch (error) {
|
||||||
|
this.failure(error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
success(value) {
|
||||||
|
this.#end('success', value)
|
||||||
|
}
|
||||||
|
|
||||||
|
warning(message, data) {
|
||||||
|
this.#log('warning', { data, message })
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapFn(fn, last) {
|
||||||
|
const task = this
|
||||||
|
return function () {
|
||||||
|
return task.run(() => fn.apply(this, arguments), last)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#end(status, result) {
|
||||||
|
this.#log('end', { result, status })
|
||||||
|
this.#onLog = logAfterEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
#log(event, props) {
|
||||||
|
this.#onLog({
|
||||||
|
...props,
|
||||||
|
event,
|
||||||
|
taskId: this.#id,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const method of ['info', 'warning']) {
|
||||||
|
Task[method] = (...args) => Zone.current.data[$$task]?.[method](...args)
|
||||||
|
}
|
||||||
@@ -11,10 +11,10 @@ import { decorateMethodsWith } from '@vates/decorate-with'
|
|||||||
import { deduped } from '@vates/disposable/deduped.js'
|
import { deduped } from '@vates/disposable/deduped.js'
|
||||||
import { getHandler } from '@xen-orchestra/fs'
|
import { getHandler } from '@xen-orchestra/fs'
|
||||||
import { parseDuration } from '@vates/parse-duration'
|
import { parseDuration } from '@vates/parse-duration'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import { Xapi } from '@xen-orchestra/xapi'
|
import { Xapi } from '@xen-orchestra/xapi'
|
||||||
|
|
||||||
import { RemoteAdapter } from './RemoteAdapter.mjs'
|
import { RemoteAdapter } from './RemoteAdapter.mjs'
|
||||||
|
import { Task } from './Task.mjs'
|
||||||
|
|
||||||
createCachedLookup().patchGlobal()
|
createCachedLookup().patchGlobal()
|
||||||
|
|
||||||
@@ -154,8 +154,8 @@ process.on('message', async message => {
|
|||||||
const result = message.runWithLogs
|
const result = message.runWithLogs
|
||||||
? await Task.run(
|
? await Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'backup run' },
|
name: 'backup run',
|
||||||
onProgress: data =>
|
onLog: data =>
|
||||||
emitMessage({
|
emitMessage({
|
||||||
data,
|
data,
|
||||||
type: 'log',
|
type: 'log',
|
||||||
|
|||||||
@@ -36,34 +36,32 @@ const computeVhdsSize = (handler, vhdPaths) =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
// chain is [ ancestor, child_1, ..., child_n ]
|
// chain is [ ancestor, child_1, ..., child_n ]
|
||||||
async function _mergeVhdChain(handler, chain, { logInfo, remove, merge, mergeBlockConcurrency }) {
|
async function _mergeVhdChain(handler, chain, { logInfo, remove, mergeBlockConcurrency }) {
|
||||||
if (merge) {
|
logInfo(`merging VHD chain`, { chain })
|
||||||
logInfo(`merging VHD chain`, { chain })
|
|
||||||
|
|
||||||
let done, total
|
let done, total
|
||||||
const handle = setInterval(() => {
|
const handle = setInterval(() => {
|
||||||
if (done !== undefined) {
|
if (done !== undefined) {
|
||||||
logInfo('merge in progress', {
|
logInfo('merge in progress', {
|
||||||
done,
|
done,
|
||||||
parent: chain[0],
|
parent: chain[0],
|
||||||
progress: Math.round((100 * done) / total),
|
progress: Math.round((100 * done) / total),
|
||||||
total,
|
total,
|
||||||
})
|
|
||||||
}
|
|
||||||
}, 10e3)
|
|
||||||
try {
|
|
||||||
return await mergeVhdChain(handler, chain, {
|
|
||||||
logInfo,
|
|
||||||
mergeBlockConcurrency,
|
|
||||||
onProgress({ done: d, total: t }) {
|
|
||||||
done = d
|
|
||||||
total = t
|
|
||||||
},
|
|
||||||
removeUnused: remove,
|
|
||||||
})
|
})
|
||||||
} finally {
|
|
||||||
clearInterval(handle)
|
|
||||||
}
|
}
|
||||||
|
}, 10e3)
|
||||||
|
try {
|
||||||
|
return await mergeVhdChain(handler, chain, {
|
||||||
|
logInfo,
|
||||||
|
mergeBlockConcurrency,
|
||||||
|
onProgress({ done: d, total: t }) {
|
||||||
|
done = d
|
||||||
|
total = t
|
||||||
|
},
|
||||||
|
removeUnused: remove,
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
clearInterval(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,23 +469,20 @@ export async function cleanVm(
|
|||||||
const metadataWithMergedVhd = {}
|
const metadataWithMergedVhd = {}
|
||||||
const doMerge = async () => {
|
const doMerge = async () => {
|
||||||
await asyncMap(toMerge, async chain => {
|
await asyncMap(toMerge, async chain => {
|
||||||
const merged = await limitedMergeVhdChain(handler, chain, {
|
const { finalVhdSize } = await limitedMergeVhdChain(handler, chain, {
|
||||||
logInfo,
|
logInfo,
|
||||||
logWarn,
|
logWarn,
|
||||||
remove,
|
remove,
|
||||||
merge,
|
|
||||||
mergeBlockConcurrency,
|
mergeBlockConcurrency,
|
||||||
})
|
})
|
||||||
if (merged !== undefined) {
|
const metadataPath = vhdsToJSons[chain[chain.length - 1]] // all the chain should have the same metada file
|
||||||
const metadataPath = vhdsToJSons[chain[chain.length - 1]] // all the chain should have the same metada file
|
metadataWithMergedVhd[metadataPath] = (metadataWithMergedVhd[metadataPath] ?? 0) + finalVhdSize
|
||||||
metadataWithMergedVhd[metadataPath] = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
...unusedVhdsDeletion,
|
...unusedVhdsDeletion,
|
||||||
toMerge.length !== 0 && (merge ? Task.run({ properties: { name: 'merge' } }, doMerge) : () => Promise.resolve()),
|
toMerge.length !== 0 && (merge ? Task.run({ name: 'merge' }, doMerge) : () => Promise.resolve()),
|
||||||
asyncMap(unusedXvas, path => {
|
asyncMap(unusedXvas, path => {
|
||||||
logWarn('unused XVA', { path })
|
logWarn('unused XVA', { path })
|
||||||
if (remove) {
|
if (remove) {
|
||||||
@@ -509,12 +504,11 @@ export async function cleanVm(
|
|||||||
|
|
||||||
// update size for delta metadata with merged VHD
|
// update size for delta metadata with merged VHD
|
||||||
// check for the other that the size is the same as the real file size
|
// check for the other that the size is the same as the real file size
|
||||||
|
|
||||||
await asyncMap(jsons, async metadataPath => {
|
await asyncMap(jsons, async metadataPath => {
|
||||||
const metadata = backups.get(metadataPath)
|
const metadata = backups.get(metadataPath)
|
||||||
|
|
||||||
let fileSystemSize
|
let fileSystemSize
|
||||||
const merged = metadataWithMergedVhd[metadataPath] !== undefined
|
const mergedSize = metadataWithMergedVhd[metadataPath]
|
||||||
|
|
||||||
const { mode, size, vhds, xva } = metadata
|
const { mode, size, vhds, xva } = metadata
|
||||||
|
|
||||||
@@ -524,26 +518,29 @@ export async function cleanVm(
|
|||||||
const linkedXva = resolve('/', vmDir, xva)
|
const linkedXva = resolve('/', vmDir, xva)
|
||||||
try {
|
try {
|
||||||
fileSystemSize = await handler.getSize(linkedXva)
|
fileSystemSize = await handler.getSize(linkedXva)
|
||||||
|
if (fileSystemSize !== size && fileSystemSize !== undefined) {
|
||||||
|
logWarn('cleanVm: incorrect backup size in metadata', {
|
||||||
|
path: metadataPath,
|
||||||
|
actual: size ?? 'none',
|
||||||
|
expected: fileSystemSize,
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// can fail with encrypted remote
|
// can fail with encrypted remote
|
||||||
}
|
}
|
||||||
} else if (mode === 'delta') {
|
} else if (mode === 'delta') {
|
||||||
const linkedVhds = Object.keys(vhds).map(key => resolve('/', vmDir, vhds[key]))
|
|
||||||
fileSystemSize = await computeVhdsSize(handler, linkedVhds)
|
|
||||||
|
|
||||||
// the size is not computed in some cases (e.g. VhdDirectory)
|
|
||||||
if (fileSystemSize === undefined) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't warn if the size has changed after a merge
|
// don't warn if the size has changed after a merge
|
||||||
if (!merged && fileSystemSize !== size) {
|
if (mergedSize === undefined) {
|
||||||
// FIXME: figure out why it occurs so often and, once fixed, log the real problems with `logWarn`
|
const linkedVhds = Object.keys(vhds).map(key => resolve('/', vmDir, vhds[key]))
|
||||||
console.warn('cleanVm: incorrect backup size in metadata', {
|
fileSystemSize = await computeVhdsSize(handler, linkedVhds)
|
||||||
path: metadataPath,
|
// the size is not computed in some cases (e.g. VhdDirectory)
|
||||||
actual: size ?? 'none',
|
if (fileSystemSize !== undefined && fileSystemSize !== size) {
|
||||||
expected: fileSystemSize,
|
logWarn('cleanVm: incorrect backup size in metadata', {
|
||||||
})
|
path: metadataPath,
|
||||||
|
actual: size ?? 'none',
|
||||||
|
expected: fileSystemSize,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -551,9 +548,19 @@ export async function cleanVm(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// systematically update size after a merge
|
// systematically update size and differentials after a merge
|
||||||
if ((merged || fixMetadata) && size !== fileSystemSize) {
|
|
||||||
metadata.size = fileSystemSize
|
// @todo : after 2024-04-01 remove the fixmetadata options since the size computation is fixed
|
||||||
|
if (mergedSize || (fixMetadata && fileSystemSize !== size)) {
|
||||||
|
metadata.size = mergedSize ?? fileSystemSize ?? size
|
||||||
|
|
||||||
|
if (mergedSize) {
|
||||||
|
// all disks are now key disk
|
||||||
|
metadata.isVhdDifferencing = {}
|
||||||
|
for (const id of Object.values(metadata.vdis ?? {})) {
|
||||||
|
metadata.isVhdDifferencing[`${id}.vhd`] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
mustRegenerateCache = true
|
mustRegenerateCache = true
|
||||||
try {
|
try {
|
||||||
await handler.writeFile(metadataPath, JSON.stringify(metadata), { flags: 'w' })
|
await handler.writeFile(metadataPath, JSON.stringify(metadata), { flags: 'w' })
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { CancelToken } from 'promise-toolbox'
|
|||||||
import { compareVersions } from 'compare-versions'
|
import { compareVersions } from 'compare-versions'
|
||||||
import { createVhdStreamWithLength } from 'vhd-lib'
|
import { createVhdStreamWithLength } from 'vhd-lib'
|
||||||
import { defer } from 'golike-defer'
|
import { defer } from 'golike-defer'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { cancelableMap } from './_cancelableMap.mjs'
|
import { cancelableMap } from './_cancelableMap.mjs'
|
||||||
|
import { Task } from './Task.mjs'
|
||||||
import pick from 'lodash/pick.js'
|
import pick from 'lodash/pick.js'
|
||||||
|
|
||||||
// in `other_config` of an incrementally replicated VM, contains the UUID of the source VM
|
// in `other_config` of an incrementally replicated VM, contains the UUID of the source VM
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import Disposable from 'promise-toolbox/Disposable'
|
import Disposable from 'promise-toolbox/Disposable'
|
||||||
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
||||||
|
|
||||||
@@ -7,6 +6,7 @@ import { extractIdsFromSimplePattern } from '../extractIdsFromSimplePattern.mjs'
|
|||||||
import { PoolMetadataBackup } from './_PoolMetadataBackup.mjs'
|
import { PoolMetadataBackup } from './_PoolMetadataBackup.mjs'
|
||||||
import { XoMetadataBackup } from './_XoMetadataBackup.mjs'
|
import { XoMetadataBackup } from './_XoMetadataBackup.mjs'
|
||||||
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
||||||
|
import { runTask } from './_runTask.mjs'
|
||||||
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
||||||
|
|
||||||
const DEFAULT_METADATA_SETTINGS = {
|
const DEFAULT_METADATA_SETTINGS = {
|
||||||
@@ -14,8 +14,6 @@ const DEFAULT_METADATA_SETTINGS = {
|
|||||||
retentionXoMetadata: 0,
|
retentionXoMetadata: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
const noop = Function.prototype
|
|
||||||
|
|
||||||
export const Metadata = class MetadataBackupRunner extends Abstract {
|
export const Metadata = class MetadataBackupRunner extends Abstract {
|
||||||
_computeBaseSettings(config, job) {
|
_computeBaseSettings(config, job) {
|
||||||
const baseSettings = { ...DEFAULT_SETTINGS }
|
const baseSettings = { ...DEFAULT_SETTINGS }
|
||||||
@@ -57,16 +55,13 @@ export const Metadata = class MetadataBackupRunner extends Abstract {
|
|||||||
poolIds.map(id =>
|
poolIds.map(id =>
|
||||||
this._getRecord('pool', id).catch(error => {
|
this._getRecord('pool', id).catch(error => {
|
||||||
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
|
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
|
||||||
new Task(
|
runTask(
|
||||||
{
|
{
|
||||||
properties: {
|
name: 'get pool record',
|
||||||
id,
|
data: { type: 'pool', id },
|
||||||
name: 'get pool record',
|
|
||||||
type: 'pool',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
() => Promise.reject(error)
|
() => Promise.reject(error)
|
||||||
).catch(noop)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -86,11 +81,11 @@ export const Metadata = class MetadataBackupRunner extends Abstract {
|
|||||||
if (pools.length !== 0 && settings.retentionPoolMetadata !== 0) {
|
if (pools.length !== 0 && settings.retentionPoolMetadata !== 0) {
|
||||||
promises.push(
|
promises.push(
|
||||||
asyncMap(pools, async pool =>
|
asyncMap(pools, async pool =>
|
||||||
new Task(
|
runTask(
|
||||||
{
|
{
|
||||||
properties: {
|
name: `Starting metadata backup for the pool (${pool.$id}). (${job.id})`,
|
||||||
|
data: {
|
||||||
id: pool.$id,
|
id: pool.$id,
|
||||||
name: `Starting metadata backup for the pool (${pool.$id}). (${job.id})`,
|
|
||||||
pool,
|
pool,
|
||||||
poolMaster: await ignoreErrors.call(pool.$xapi.getRecord('host', pool.master)),
|
poolMaster: await ignoreErrors.call(pool.$xapi.getRecord('host', pool.master)),
|
||||||
type: 'pool',
|
type: 'pool',
|
||||||
@@ -105,17 +100,17 @@ export const Metadata = class MetadataBackupRunner extends Abstract {
|
|||||||
schedule,
|
schedule,
|
||||||
settings,
|
settings,
|
||||||
}).run()
|
}).run()
|
||||||
).catch(noop)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job.xoMetadata !== undefined && settings.retentionXoMetadata !== 0) {
|
if (job.xoMetadata !== undefined && settings.retentionXoMetadata !== 0) {
|
||||||
promises.push(
|
promises.push(
|
||||||
new Task(
|
runTask(
|
||||||
{
|
{
|
||||||
properties: {
|
name: `Starting XO metadata backup. (${job.id})`,
|
||||||
name: `Starting XO metadata backup. (${job.id})`,
|
data: {
|
||||||
type: 'xo',
|
type: 'xo',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -127,7 +122,7 @@ export const Metadata = class MetadataBackupRunner extends Abstract {
|
|||||||
schedule,
|
schedule,
|
||||||
settings,
|
settings,
|
||||||
}).run()
|
}).run()
|
||||||
).catch(noop)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { asyncMapSettled } from '@xen-orchestra/async-map'
|
import { asyncMapSettled } from '@xen-orchestra/async-map'
|
||||||
import Disposable from 'promise-toolbox/Disposable'
|
import Disposable from 'promise-toolbox/Disposable'
|
||||||
import { limitConcurrency } from 'limit-concurrency-decorator'
|
import { limitConcurrency } from 'limit-concurrency-decorator'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { extractIdsFromSimplePattern } from '../extractIdsFromSimplePattern.mjs'
|
import { extractIdsFromSimplePattern } from '../extractIdsFromSimplePattern.mjs'
|
||||||
|
import { Task } from '../Task.mjs'
|
||||||
import createStreamThrottle from './_createStreamThrottle.mjs'
|
import createStreamThrottle from './_createStreamThrottle.mjs'
|
||||||
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
||||||
|
import { runTask } from './_runTask.mjs'
|
||||||
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
||||||
import { FullRemote } from './_vmRunners/FullRemote.mjs'
|
import { FullRemote } from './_vmRunners/FullRemote.mjs'
|
||||||
import { IncrementalRemote } from './_vmRunners/IncrementalRemote.mjs'
|
import { IncrementalRemote } from './_vmRunners/IncrementalRemote.mjs'
|
||||||
@@ -24,8 +25,6 @@ const DEFAULT_REMOTE_VM_SETTINGS = {
|
|||||||
vmTimeout: 0,
|
vmTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
const noop = Function.prototype
|
|
||||||
|
|
||||||
export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
|
export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
|
||||||
_computeBaseSettings(config, job) {
|
_computeBaseSettings(config, job) {
|
||||||
const baseSettings = { ...DEFAULT_SETTINGS }
|
const baseSettings = { ...DEFAULT_SETTINGS }
|
||||||
@@ -64,13 +63,7 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
|
|||||||
const baseSettings = this._baseSettings
|
const baseSettings = this._baseSettings
|
||||||
|
|
||||||
const handleVm = vmUuid => {
|
const handleVm = vmUuid => {
|
||||||
const taskStart = {
|
const taskStart = { name: 'backup VM', data: { type: 'VM', id: vmUuid } }
|
||||||
properties: {
|
|
||||||
id: vmUuid,
|
|
||||||
name: 'backup VM',
|
|
||||||
type: 'VM',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
baseSettings,
|
baseSettings,
|
||||||
@@ -93,7 +86,7 @@ export const VmsRemote = class RemoteVmsBackupRunner extends Abstract {
|
|||||||
throw new Error(`Job mode ${job.mode} not implemented for mirror backup`)
|
throw new Error(`Job mode ${job.mode} not implemented for mirror backup`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Task(taskStart, () => vmBackup.run()).catch(noop)
|
return runTask(taskStart, () => vmBackup.run())
|
||||||
}
|
}
|
||||||
const { concurrency } = settings
|
const { concurrency } = settings
|
||||||
await asyncMapSettled(vmsUuids, !concurrency ? handleVm : limitConcurrency(concurrency)(handleVm))
|
await asyncMapSettled(vmsUuids, !concurrency ? handleVm : limitConcurrency(concurrency)(handleVm))
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { asyncMapSettled } from '@xen-orchestra/async-map'
|
import { asyncMapSettled } from '@xen-orchestra/async-map'
|
||||||
import Disposable from 'promise-toolbox/Disposable'
|
import Disposable from 'promise-toolbox/Disposable'
|
||||||
import { limitConcurrency } from 'limit-concurrency-decorator'
|
import { limitConcurrency } from 'limit-concurrency-decorator'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { extractIdsFromSimplePattern } from '../extractIdsFromSimplePattern.mjs'
|
import { extractIdsFromSimplePattern } from '../extractIdsFromSimplePattern.mjs'
|
||||||
|
import { Task } from '../Task.mjs'
|
||||||
import createStreamThrottle from './_createStreamThrottle.mjs'
|
import createStreamThrottle from './_createStreamThrottle.mjs'
|
||||||
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
import { DEFAULT_SETTINGS, Abstract } from './_Abstract.mjs'
|
||||||
|
import { runTask } from './_runTask.mjs'
|
||||||
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
import { getAdaptersByRemote } from './_getAdaptersByRemote.mjs'
|
||||||
import { IncrementalXapi } from './_vmRunners/IncrementalXapi.mjs'
|
import { IncrementalXapi } from './_vmRunners/IncrementalXapi.mjs'
|
||||||
import { FullXapi } from './_vmRunners/FullXapi.mjs'
|
import { FullXapi } from './_vmRunners/FullXapi.mjs'
|
||||||
@@ -33,8 +34,6 @@ const DEFAULT_XAPI_VM_SETTINGS = {
|
|||||||
vmTimeout: 0,
|
vmTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
const noop = Function.prototype
|
|
||||||
|
|
||||||
export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
||||||
_computeBaseSettings(config, job) {
|
_computeBaseSettings(config, job) {
|
||||||
const baseSettings = { ...DEFAULT_SETTINGS }
|
const baseSettings = { ...DEFAULT_SETTINGS }
|
||||||
@@ -58,16 +57,13 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
|||||||
Disposable.all(
|
Disposable.all(
|
||||||
extractIdsFromSimplePattern(job.srs).map(id =>
|
extractIdsFromSimplePattern(job.srs).map(id =>
|
||||||
this._getRecord('SR', id).catch(error => {
|
this._getRecord('SR', id).catch(error => {
|
||||||
new Task(
|
runTask(
|
||||||
{
|
{
|
||||||
properties: {
|
name: 'get SR record',
|
||||||
id,
|
data: { type: 'SR', id },
|
||||||
name: 'get SR record',
|
|
||||||
type: 'SR',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
() => Promise.reject(error)
|
() => Promise.reject(error)
|
||||||
).catch(noop)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -94,19 +90,13 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
|||||||
const baseSettings = this._baseSettings
|
const baseSettings = this._baseSettings
|
||||||
|
|
||||||
const handleVm = vmUuid => {
|
const handleVm = vmUuid => {
|
||||||
const taskStart = {
|
const taskStart = { name: 'backup VM', data: { type: 'VM', id: vmUuid } }
|
||||||
properties: {
|
|
||||||
id: vmUuid,
|
|
||||||
name: 'backup VM',
|
|
||||||
type: 'VM',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._getRecord('VM', vmUuid).then(
|
return this._getRecord('VM', vmUuid).then(
|
||||||
disposableVm =>
|
disposableVm =>
|
||||||
Disposable.use(disposableVm, vm => {
|
Disposable.use(disposableVm, vm => {
|
||||||
taskStart.data.name_label = vm.name_label
|
taskStart.data.name_label = vm.name_label
|
||||||
return new Task()(taskStart, () => {
|
return runTask(taskStart, () => {
|
||||||
const opts = {
|
const opts = {
|
||||||
baseSettings,
|
baseSettings,
|
||||||
config,
|
config,
|
||||||
@@ -131,12 +121,12 @@ export const VmsXapi = class VmsXapiBackupRunner extends Abstract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vmBackup.run()
|
return vmBackup.run()
|
||||||
}).catch(noop)
|
})
|
||||||
}),
|
}),
|
||||||
error =>
|
error =>
|
||||||
new Task(taskStart, () => {
|
runTask(taskStart, () => {
|
||||||
throw error
|
throw error
|
||||||
}).catch(noop)
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const { concurrency } = settings
|
const { concurrency } = settings
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import Disposable from 'promise-toolbox/Disposable'
|
import Disposable from 'promise-toolbox/Disposable'
|
||||||
import pTimeout from 'promise-toolbox/timeout'
|
import pTimeout from 'promise-toolbox/timeout'
|
||||||
import { compileTemplate } from '@xen-orchestra/template'
|
import { compileTemplate } from '@xen-orchestra/template'
|
||||||
import { Task } from '@vates/task'
|
import { runTask } from './_runTask.mjs'
|
||||||
|
|
||||||
import { RemoteTimeoutError } from './_RemoteTimeoutError.mjs'
|
import { RemoteTimeoutError } from './_RemoteTimeoutError.mjs'
|
||||||
|
|
||||||
const noop = Function.prototype
|
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS = {
|
export const DEFAULT_SETTINGS = {
|
||||||
getRemoteTimeout: 300e3,
|
getRemoteTimeout: 300e3,
|
||||||
reportWhen: 'failure',
|
reportWhen: 'failure',
|
||||||
@@ -39,16 +36,13 @@ export const Abstract = class AbstractRunner {
|
|||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
|
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
|
||||||
Task.run(
|
runTask(
|
||||||
{
|
{
|
||||||
properties: {
|
name: 'get remote adapter',
|
||||||
id: remoteId,
|
data: { type: 'remote', id: remoteId },
|
||||||
name: 'get remote adapter',
|
|
||||||
type: 'remote',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
() => Promise.reject(error)
|
() => Promise.reject(error)
|
||||||
).catch(noop)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { DIR_XO_POOL_METADATA_BACKUPS } from '../RemoteAdapter.mjs'
|
import { DIR_XO_POOL_METADATA_BACKUPS } from '../RemoteAdapter.mjs'
|
||||||
import { forkStreamUnpipe } from './_forkStreamUnpipe.mjs'
|
import { forkStreamUnpipe } from './_forkStreamUnpipe.mjs'
|
||||||
import { formatFilenameDate } from '../_filenameDate.mjs'
|
import { formatFilenameDate } from '../_filenameDate.mjs'
|
||||||
|
import { Task } from '../Task.mjs'
|
||||||
|
|
||||||
export const PATH_DB_DUMP = '/pool/xmldbdump'
|
export const PATH_DB_DUMP = '/pool/xmldbdump'
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ export class PoolMetadataBackup {
|
|||||||
([remoteId, adapter]) =>
|
([remoteId, adapter]) =>
|
||||||
Task.run(
|
Task.run(
|
||||||
{
|
{
|
||||||
properties: {
|
name: `Starting metadata backup for the pool (${pool.$id}) for the remote (${remoteId}). (${job.id})`,
|
||||||
name: `Starting metadata backup for the pool (${pool.$id}) for the remote (${remoteId}). (${job.id})`,
|
data: {
|
||||||
id: remoteId,
|
id: remoteId,
|
||||||
type: 'remote',
|
type: 'remote',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { join } from '@xen-orchestra/fs/path'
|
import { join } from '@xen-orchestra/fs/path'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { DIR_XO_CONFIG_BACKUPS } from '../RemoteAdapter.mjs'
|
import { DIR_XO_CONFIG_BACKUPS } from '../RemoteAdapter.mjs'
|
||||||
import { formatFilenameDate } from '../_filenameDate.mjs'
|
import { formatFilenameDate } from '../_filenameDate.mjs'
|
||||||
|
import { Task } from '../Task.mjs'
|
||||||
|
|
||||||
export class XoMetadataBackup {
|
export class XoMetadataBackup {
|
||||||
constructor({ config, job, remoteAdapters, schedule, settings }) {
|
constructor({ config, job, remoteAdapters, schedule, settings }) {
|
||||||
@@ -51,8 +51,8 @@ export class XoMetadataBackup {
|
|||||||
([remoteId, adapter]) =>
|
([remoteId, adapter]) =>
|
||||||
Task.run(
|
Task.run(
|
||||||
{
|
{
|
||||||
properties: {
|
name: `Starting XO metadata backup for the remote (${remoteId}). (${job.id})`,
|
||||||
name: `Starting XO metadata backup for the remote (${remoteId}). (${job.id})`,
|
data: {
|
||||||
id: remoteId,
|
id: remoteId,
|
||||||
type: 'remote',
|
type: 'remote',
|
||||||
},
|
},
|
||||||
|
|||||||
5
@xen-orchestra/backups/_runners/_runTask.mjs
Normal file
5
@xen-orchestra/backups/_runners/_runTask.mjs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { Task } from '../Task.mjs'
|
||||||
|
|
||||||
|
const noop = Function.prototype
|
||||||
|
|
||||||
|
export const runTask = (...args) => Task.run(...args).catch(noop) // errors are handled by logs
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||||
import { defer } from 'golike-defer'
|
import { defer } from 'golike-defer'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { AbstractRemote } from './_AbstractRemote.mjs'
|
import { AbstractRemote } from './_AbstractRemote.mjs'
|
||||||
import { FullRemoteWriter } from '../_writers/FullRemoteWriter.mjs'
|
import { FullRemoteWriter } from '../_writers/FullRemoteWriter.mjs'
|
||||||
import { forkStreamUnpipe } from '../_forkStreamUnpipe.mjs'
|
import { forkStreamUnpipe } from '../_forkStreamUnpipe.mjs'
|
||||||
import { watchStreamSize } from '../../_watchStreamSize.mjs'
|
import { watchStreamSize } from '../../_watchStreamSize.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
export const FullRemote = class FullRemoteVmBackupRunner extends AbstractRemote {
|
export const FullRemote = class FullRemoteVmBackupRunner extends AbstractRemote {
|
||||||
_getRemoteWriter() {
|
_getRemoteWriter() {
|
||||||
|
|||||||
@@ -1,19 +1,57 @@
|
|||||||
import { asyncEach } from '@vates/async-each'
|
import { asyncEach } from '@vates/async-each'
|
||||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||||
import { defer } from 'golike-defer'
|
import { defer } from 'golike-defer'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import assert from 'node:assert'
|
import assert from 'node:assert'
|
||||||
|
import * as UUID from 'uuid'
|
||||||
import isVhdDifferencingDisk from 'vhd-lib/isVhdDifferencingDisk.js'
|
import isVhdDifferencingDisk from 'vhd-lib/isVhdDifferencingDisk.js'
|
||||||
import mapValues from 'lodash/mapValues.js'
|
import mapValues from 'lodash/mapValues.js'
|
||||||
|
|
||||||
import { AbstractRemote } from './_AbstractRemote.mjs'
|
import { AbstractRemote } from './_AbstractRemote.mjs'
|
||||||
import { forkDeltaExport } from './_forkDeltaExport.mjs'
|
import { forkDeltaExport } from './_forkDeltaExport.mjs'
|
||||||
import { IncrementalRemoteWriter } from '../_writers/IncrementalRemoteWriter.mjs'
|
import { IncrementalRemoteWriter } from '../_writers/IncrementalRemoteWriter.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
import { Disposable } from 'promise-toolbox'
|
||||||
|
import { openVhd } from 'vhd-lib'
|
||||||
|
import { getVmBackupDir } from '../../_getVmBackupDir.mjs'
|
||||||
|
|
||||||
class IncrementalRemoteVmBackupRunner extends AbstractRemote {
|
class IncrementalRemoteVmBackupRunner extends AbstractRemote {
|
||||||
_getRemoteWriter() {
|
_getRemoteWriter() {
|
||||||
return IncrementalRemoteWriter
|
return IncrementalRemoteWriter
|
||||||
}
|
}
|
||||||
|
async _selectBaseVm(metadata) {
|
||||||
|
// for each disk , get the parent
|
||||||
|
const baseUuidToSrcVdi = new Map()
|
||||||
|
|
||||||
|
// no previous backup for a base( =key) backup
|
||||||
|
if (metadata.isBase) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await asyncEach(Object.entries(metadata.vdis), async ([id, vdi]) => {
|
||||||
|
const isDifferencing = metadata.isVhdDifferencing[`${id}.vhd`]
|
||||||
|
if (isDifferencing) {
|
||||||
|
const vmDir = getVmBackupDir(metadata.vm.uuid)
|
||||||
|
const path = `${vmDir}/${metadata.vhds[id]}`
|
||||||
|
// don't catch error : we can't recover if the source vhd are missing
|
||||||
|
await Disposable.use(openVhd(this._sourceRemoteAdapter._handler, path), vhd => {
|
||||||
|
baseUuidToSrcVdi.set(UUID.stringify(vhd.header.parentUuid), vdi.$snapshot_of$uuid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const presentBaseVdis = new Map(baseUuidToSrcVdi)
|
||||||
|
await this._callWriters(
|
||||||
|
writer => presentBaseVdis.size !== 0 && writer.checkBaseVdis(presentBaseVdis),
|
||||||
|
'writer.checkBaseVdis()',
|
||||||
|
false
|
||||||
|
)
|
||||||
|
// check if the parent vdi are present in all the remotes
|
||||||
|
baseUuidToSrcVdi.forEach((srcVdiUuid, baseUuid) => {
|
||||||
|
if (!presentBaseVdis.has(baseUuid)) {
|
||||||
|
throw new Error(`Missing vdi ${baseUuid} which is a base for a delta`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// yeah , let's go
|
||||||
|
}
|
||||||
async _run($defer) {
|
async _run($defer) {
|
||||||
const transferList = await this._computeTransferList(({ mode }) => mode === 'delta')
|
const transferList = await this._computeTransferList(({ mode }) => mode === 'delta')
|
||||||
await this._callWriters(async writer => {
|
await this._callWriters(async writer => {
|
||||||
@@ -26,7 +64,7 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
|
|||||||
if (transferList.length > 0) {
|
if (transferList.length > 0) {
|
||||||
for (const metadata of transferList) {
|
for (const metadata of transferList) {
|
||||||
assert.strictEqual(metadata.mode, 'delta')
|
assert.strictEqual(metadata.mode, 'delta')
|
||||||
|
await this._selectBaseVm(metadata)
|
||||||
await this._callWriters(writer => writer.prepare({ isBase: metadata.isBase }), 'writer.prepare()')
|
await this._callWriters(writer => writer.prepare({ isBase: metadata.isBase }), 'writer.prepare()')
|
||||||
const incrementalExport = await this._sourceRemoteAdapter.readIncrementalVmBackup(metadata, undefined, {
|
const incrementalExport = await this._sourceRemoteAdapter.readIncrementalVmBackup(metadata, undefined, {
|
||||||
useChain: false,
|
useChain: false,
|
||||||
@@ -50,6 +88,17 @@ class IncrementalRemoteVmBackupRunner extends AbstractRemote {
|
|||||||
}),
|
}),
|
||||||
'writer.transfer()'
|
'writer.transfer()'
|
||||||
)
|
)
|
||||||
|
// this will update parent name with the needed alias
|
||||||
|
await this._callWriters(
|
||||||
|
writer =>
|
||||||
|
writer.updateUuidAndChain({
|
||||||
|
isVhdDifferencing,
|
||||||
|
timestamp: metadata.timestamp,
|
||||||
|
vdis: incrementalExport.vdis,
|
||||||
|
}),
|
||||||
|
'writer.updateUuidAndChain()'
|
||||||
|
)
|
||||||
|
|
||||||
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
|
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
|
||||||
// for healthcheck
|
// for healthcheck
|
||||||
this._tags = metadata.vm.tags
|
this._tags = metadata.vm.tags
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { asyncEach } from '@vates/async-each'
|
|||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { createLogger } from '@xen-orchestra/log'
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { pipeline } from 'node:stream'
|
import { pipeline } from 'node:stream'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import findLast from 'lodash/findLast.js'
|
import findLast from 'lodash/findLast.js'
|
||||||
import isVhdDifferencingDisk from 'vhd-lib/isVhdDifferencingDisk.js'
|
import isVhdDifferencingDisk from 'vhd-lib/isVhdDifferencingDisk.js'
|
||||||
import keyBy from 'lodash/keyBy.js'
|
import keyBy from 'lodash/keyBy.js'
|
||||||
@@ -14,6 +13,7 @@ import { exportIncrementalVm } from '../../_incrementalVm.mjs'
|
|||||||
import { forkDeltaExport } from './_forkDeltaExport.mjs'
|
import { forkDeltaExport } from './_forkDeltaExport.mjs'
|
||||||
import { IncrementalRemoteWriter } from '../_writers/IncrementalRemoteWriter.mjs'
|
import { IncrementalRemoteWriter } from '../_writers/IncrementalRemoteWriter.mjs'
|
||||||
import { IncrementalXapiWriter } from '../_writers/IncrementalXapiWriter.mjs'
|
import { IncrementalXapiWriter } from '../_writers/IncrementalXapiWriter.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
import { watchStreamSize } from '../../_watchStreamSize.mjs'
|
import { watchStreamSize } from '../../_watchStreamSize.mjs'
|
||||||
|
|
||||||
const { debug } = createLogger('xo:backups:IncrementalXapiVmBackup')
|
const { debug } = createLogger('xo:backups:IncrementalXapiVmBackup')
|
||||||
@@ -78,6 +78,18 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
|||||||
'writer.transfer()'
|
'writer.transfer()'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// we want to control the uuid of the vhd in the chain
|
||||||
|
// and ensure they are correctly chained
|
||||||
|
await this._callWriters(
|
||||||
|
writer =>
|
||||||
|
writer.updateUuidAndChain({
|
||||||
|
isVhdDifferencing,
|
||||||
|
timestamp,
|
||||||
|
vdis: deltaExport.vdis,
|
||||||
|
}),
|
||||||
|
'writer.updateUuidAndChain()'
|
||||||
|
)
|
||||||
|
|
||||||
this._baseVm = exportedVm
|
this._baseVm = exportedVm
|
||||||
|
|
||||||
if (baseVm !== undefined) {
|
if (baseVm !== undefined) {
|
||||||
@@ -133,7 +145,7 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
|||||||
])
|
])
|
||||||
const srcVdi = srcVdis[snapshotOf]
|
const srcVdi = srcVdis[snapshotOf]
|
||||||
if (srcVdi !== undefined) {
|
if (srcVdi !== undefined) {
|
||||||
baseUuidToSrcVdi.set(baseUuid, srcVdi)
|
baseUuidToSrcVdi.set(baseUuid, srcVdi.uuid)
|
||||||
} else {
|
} else {
|
||||||
debug('ignore snapshot VDI because no longer present on VM', {
|
debug('ignore snapshot VDI because no longer present on VM', {
|
||||||
vdi: baseUuid,
|
vdi: baseUuid,
|
||||||
@@ -154,18 +166,18 @@ export const IncrementalXapi = class IncrementalXapiVmBackupRunner extends Abstr
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fullVdisRequired = new Set()
|
const fullVdisRequired = new Set()
|
||||||
baseUuidToSrcVdi.forEach((srcVdi, baseUuid) => {
|
baseUuidToSrcVdi.forEach((srcVdiUuid, baseUuid) => {
|
||||||
if (presentBaseVdis.has(baseUuid)) {
|
if (presentBaseVdis.has(baseUuid)) {
|
||||||
debug('found base VDI', {
|
debug('found base VDI', {
|
||||||
base: baseUuid,
|
base: baseUuid,
|
||||||
vdi: srcVdi.uuid,
|
vdi: srcVdiUuid,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
debug('missing base VDI', {
|
debug('missing base VDI', {
|
||||||
base: baseUuid,
|
base: baseUuid,
|
||||||
vdi: srcVdi.uuid,
|
vdi: srcVdiUuid,
|
||||||
})
|
})
|
||||||
fullVdisRequired.add(srcVdi.uuid)
|
fullVdisRequired.add(srcVdiUuid)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { createLogger } from '@xen-orchestra/log'
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { Task } from '@vates/task'
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
const { debug, warn } = createLogger('xo:backups:AbstractVmRunner')
|
const { debug, warn } = createLogger('xo:backups:AbstractVmRunner')
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ export const Abstract = class AbstractVmBackupRunner {
|
|||||||
// create a task to have an info in the logs and reports
|
// create a task to have an info in the logs and reports
|
||||||
return Task.run(
|
return Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'health check' },
|
name: 'health check',
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
Task.info(`This VM doesn't match the health check's tags for this schedule`)
|
Task.info(`This VM doesn't match the health check's tags for this schedule`)
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import { asyncMap } from '@xen-orchestra/async-map'
|
|||||||
import { decorateMethodsWith } from '@vates/decorate-with'
|
import { decorateMethodsWith } from '@vates/decorate-with'
|
||||||
import { defer } from 'golike-defer'
|
import { defer } from 'golike-defer'
|
||||||
import { formatDateTime } from '@xen-orchestra/xapi'
|
import { formatDateTime } from '@xen-orchestra/xapi'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
import { Abstract } from './_Abstract.mjs'
|
import { Abstract } from './_Abstract.mjs'
|
||||||
|
|
||||||
export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
||||||
@@ -142,7 +142,7 @@ export const AbstractXapi = class AbstractXapiVmBackupRunner extends Abstract {
|
|||||||
const settings = this._settings
|
const settings = this._settings
|
||||||
|
|
||||||
if (this._mustDoSnapshot()) {
|
if (this._mustDoSnapshot()) {
|
||||||
await Task.run({ properties: { name: 'snapshot' } }, async () => {
|
await Task.run({ name: 'snapshot' }, async () => {
|
||||||
if (!settings.bypassVdiChainsCheck) {
|
if (!settings.bypassVdiChainsCheck) {
|
||||||
await vm.$assertHealthyVdiChains()
|
await vm.$assertHealthyVdiChains()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
|
import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
|
||||||
import { AbstractFullWriter } from './_AbstractFullWriter.mjs'
|
import { AbstractFullWriter } from './_AbstractFullWriter.mjs'
|
||||||
@@ -10,10 +9,10 @@ export class FullRemoteWriter extends MixinRemoteWriter(AbstractFullWriter) {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.run = Task.wrap(
|
this.run = Task.wrapFn(
|
||||||
{
|
{
|
||||||
properties: {
|
name: 'export',
|
||||||
name: 'export',
|
data: {
|
||||||
id: props.remoteId,
|
id: props.remoteId,
|
||||||
type: 'remote',
|
type: 'remote',
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ export class FullRemoteWriter extends MixinRemoteWriter(AbstractFullWriter) {
|
|||||||
await deleteOldBackups()
|
await deleteOldBackups()
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.run({ properties: { name: 'transfer' } }, async () => {
|
await Task.run({ name: 'transfer' }, async () => {
|
||||||
await adapter.outputStream(dataFilename, stream, {
|
await adapter.outputStream(dataFilename, stream, {
|
||||||
maxStreamLength,
|
maxStreamLength,
|
||||||
streamLength,
|
streamLength,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
||||||
import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
|
import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
|
||||||
import { formatDateTime } from '@xen-orchestra/xapi'
|
import { formatDateTime } from '@xen-orchestra/xapi'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
import { AbstractFullWriter } from './_AbstractFullWriter.mjs'
|
import { AbstractFullWriter } from './_AbstractFullWriter.mjs'
|
||||||
import { MixinXapiWriter } from './_MixinXapiWriter.mjs'
|
import { MixinXapiWriter } from './_MixinXapiWriter.mjs'
|
||||||
@@ -14,10 +14,10 @@ export class FullXapiWriter extends MixinXapiWriter(AbstractFullWriter) {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.run = Task.wrap(
|
this.run = Task.wrapFn(
|
||||||
{
|
{
|
||||||
properties: {
|
name: 'export',
|
||||||
name: 'export',
|
data: {
|
||||||
id: props.sr.uuid,
|
id: props.sr.uuid,
|
||||||
name_label: this._sr.name_label,
|
name_label: this._sr.name_label,
|
||||||
type: 'SR',
|
type: 'SR',
|
||||||
@@ -52,7 +52,7 @@ export class FullXapiWriter extends MixinXapiWriter(AbstractFullWriter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let targetVmRef
|
let targetVmRef
|
||||||
await Task.run({ properties: { name: 'transfer' } }, async () => {
|
await Task.run({ name: 'transfer' }, async () => {
|
||||||
targetVmRef = await xapi.VM_import(stream, sr.$ref, vm =>
|
targetVmRef = await xapi.VM_import(stream, sr.$ref, vm =>
|
||||||
Promise.all([
|
Promise.all([
|
||||||
!_warmMigration && vm.add_tags('Disaster Recovery'),
|
!_warmMigration && vm.add_tags('Disaster Recovery'),
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import assert from 'node:assert'
|
import assert from 'node:assert'
|
||||||
import mapValues from 'lodash/mapValues.js'
|
import mapValues from 'lodash/mapValues.js'
|
||||||
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
|
||||||
import { asyncEach } from '@vates/async-each'
|
import { asyncEach } from '@vates/async-each'
|
||||||
import { asyncMap } from '@xen-orchestra/async-map'
|
import { asyncMap } from '@xen-orchestra/async-map'
|
||||||
import { chainVhd, checkVhdChain, openVhd, VhdAbstract } from 'vhd-lib'
|
import { chainVhd, openVhd } from 'vhd-lib'
|
||||||
import { createLogger } from '@xen-orchestra/log'
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { decorateClass } from '@vates/decorate-with'
|
import { decorateClass } from '@vates/decorate-with'
|
||||||
import { defer } from 'golike-defer'
|
import { defer } from 'golike-defer'
|
||||||
import { dirname } from 'node:path'
|
import { dirname, basename } from 'node:path'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||||
import { TAG_BASE_DELTA } from '../../_incrementalVm.mjs'
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
|
import { MixinRemoteWriter } from './_MixinRemoteWriter.mjs'
|
||||||
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
|
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
|
||||||
@@ -23,42 +21,45 @@ import { Disposable } from 'promise-toolbox'
|
|||||||
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
|
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
|
||||||
|
|
||||||
export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrementalWriter) {
|
export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrementalWriter) {
|
||||||
|
#parentVdiPaths
|
||||||
|
#vhds
|
||||||
async checkBaseVdis(baseUuidToSrcVdi) {
|
async checkBaseVdis(baseUuidToSrcVdi) {
|
||||||
|
this.#parentVdiPaths = {}
|
||||||
const { handler } = this._adapter
|
const { handler } = this._adapter
|
||||||
const adapter = this._adapter
|
const adapter = this._adapter
|
||||||
|
|
||||||
const vdisDir = `${this._vmBackupDir}/vdis/${this._job.id}`
|
const vdisDir = `${this._vmBackupDir}/vdis/${this._job.id}`
|
||||||
|
|
||||||
await asyncMap(baseUuidToSrcVdi, async ([baseUuid, srcVdi]) => {
|
await asyncMap(baseUuidToSrcVdi, async ([baseUuid, srcVdiUuid]) => {
|
||||||
let found = false
|
let parentDestPath
|
||||||
|
const vhdDir = `${vdisDir}/${srcVdiUuid}`
|
||||||
try {
|
try {
|
||||||
const vhds = await handler.list(`${vdisDir}/${srcVdi.uuid}`, {
|
const vhds = await handler.list(vhdDir, {
|
||||||
filter: _ => _[0] !== '.' && _.endsWith('.vhd'),
|
filter: _ => _[0] !== '.' && _.endsWith('.vhd'),
|
||||||
ignoreMissing: true,
|
ignoreMissing: true,
|
||||||
prependDir: true,
|
prependDir: true,
|
||||||
})
|
})
|
||||||
const packedBaseUuid = packUuid(baseUuid)
|
const packedBaseUuid = packUuid(baseUuid)
|
||||||
await asyncMap(vhds, async path => {
|
// the last one is probably the right one
|
||||||
try {
|
|
||||||
await checkVhdChain(handler, path)
|
|
||||||
// Warning, this should not be written as found = found || await adapter.isMergeableParent(packedBaseUuid, path)
|
|
||||||
//
|
|
||||||
// since all the checks of a path are done in parallel, found would be containing
|
|
||||||
// only the last answer of isMergeableParent which is probably not the right one
|
|
||||||
// this led to the support tickets https://help.vates.fr/#ticket/zoom/4751 , 4729, 4665 and 4300
|
|
||||||
|
|
||||||
const isMergeable = await adapter.isMergeableParent(packedBaseUuid, path)
|
for (let i = vhds.length - 1; i >= 0 && parentDestPath === undefined; i--) {
|
||||||
found = found || isMergeable
|
const path = vhds[i]
|
||||||
|
try {
|
||||||
|
if (await adapter.isMergeableParent(packedBaseUuid, path)) {
|
||||||
|
parentDestPath = path
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
warn('checkBaseVdis', { error })
|
warn('checkBaseVdis', { error })
|
||||||
await ignoreErrors.call(VhdAbstract.unlink(handler, path))
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
warn('checkBaseVdis', { error })
|
warn('checkBaseVdis', { error })
|
||||||
}
|
}
|
||||||
if (!found) {
|
// no usable parent => the runner will have to decide to fall back to a full or stop backup
|
||||||
|
if (parentDestPath === undefined) {
|
||||||
baseUuidToSrcVdi.delete(baseUuid)
|
baseUuidToSrcVdi.delete(baseUuid)
|
||||||
|
} else {
|
||||||
|
this.#parentVdiPaths[vhdDir] = parentDestPath
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -71,17 +72,17 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
prepare({ isFull }) {
|
prepare({ isFull }) {
|
||||||
// create the task related to this export and ensure all methods are called in this context
|
// create the task related to this export and ensure all methods are called in this context
|
||||||
const task = new Task({
|
const task = new Task({
|
||||||
properties: {
|
name: 'export',
|
||||||
name: 'export',
|
data: {
|
||||||
id: this._remoteId,
|
id: this._remoteId,
|
||||||
isFull,
|
isFull,
|
||||||
type: 'remote',
|
type: 'remote',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
this.transfer = task.wrapInside(this.transfer)
|
this.transfer = task.wrapFn(this.transfer)
|
||||||
this.healthCheck = task.wrapInside(this.healthCheck)
|
this.healthCheck = task.wrapFn(this.healthCheck)
|
||||||
this.cleanup = task.wrapInside(this.cleanup)
|
this.cleanup = task.wrapFn(this.cleanup)
|
||||||
this.afterBackup = task.wrap(this.afterBackup)
|
this.afterBackup = task.wrapFn(this.afterBackup, true)
|
||||||
|
|
||||||
return task.run(() => this._prepare())
|
return task.run(() => this._prepare())
|
||||||
}
|
}
|
||||||
@@ -123,6 +124,44 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateUuidAndChain({ isVhdDifferencing, vdis }) {
|
||||||
|
assert.notStrictEqual(
|
||||||
|
this.#vhds,
|
||||||
|
undefined,
|
||||||
|
'_transfer must be called before updateUuidAndChain for incremental backups'
|
||||||
|
)
|
||||||
|
|
||||||
|
const parentVdiPaths = this.#parentVdiPaths
|
||||||
|
const { handler } = this._adapter
|
||||||
|
const vhds = this.#vhds
|
||||||
|
await asyncEach(Object.entries(vdis), async ([id, vdi]) => {
|
||||||
|
const isDifferencing = isVhdDifferencing[`${id}.vhd`]
|
||||||
|
const path = `${this._vmBackupDir}/${vhds[id]}`
|
||||||
|
if (isDifferencing) {
|
||||||
|
assert.notStrictEqual(
|
||||||
|
parentVdiPaths,
|
||||||
|
'checkbasevdi must be called before updateUuidAndChain for incremental backups'
|
||||||
|
)
|
||||||
|
const parentPath = parentVdiPaths[dirname(path)]
|
||||||
|
// we are in a incremental backup
|
||||||
|
// we already computed the chain in checkBaseVdis
|
||||||
|
assert.notStrictEqual(parentPath, undefined, 'A differential VHD must have a parent')
|
||||||
|
// forbid any kind of loop
|
||||||
|
assert.ok(basename(parentPath) < basename(path), `vhd must be sorted to be chained`)
|
||||||
|
await chainVhd(handler, parentPath, handler, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the correct UUID in the VHD if needed
|
||||||
|
await Disposable.use(openVhd(handler, path), async vhd => {
|
||||||
|
if (!vhd.footer.uuid.equals(packUuid(vdi.uuid))) {
|
||||||
|
vhd.footer.uuid = packUuid(vdi.uuid)
|
||||||
|
await vhd.readBlockAllocationTable() // required by writeFooter()
|
||||||
|
await vhd.writeFooter()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async _deleteOldEntries() {
|
async _deleteOldEntries() {
|
||||||
const adapter = this._adapter
|
const adapter = this._adapter
|
||||||
const oldEntries = this._oldEntries
|
const oldEntries = this._oldEntries
|
||||||
@@ -141,14 +180,10 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
const jobId = job.id
|
const jobId = job.id
|
||||||
const handler = adapter.handler
|
const handler = adapter.handler
|
||||||
|
|
||||||
let metadataContent = await this._isAlreadyTransferred(timestamp)
|
|
||||||
if (metadataContent !== undefined) {
|
|
||||||
// @todo : should skip backup while being vigilant to not stuck the forked stream
|
|
||||||
Task.info('This backup has already been transfered')
|
|
||||||
}
|
|
||||||
|
|
||||||
const basename = formatFilenameDate(timestamp)
|
const basename = formatFilenameDate(timestamp)
|
||||||
const vhds = mapValues(
|
// update this.#vhds before eventually skipping transfer, so that
|
||||||
|
// updateUuidAndChain has all the mandatory data
|
||||||
|
const vhds = (this.#vhds = mapValues(
|
||||||
deltaExport.vdis,
|
deltaExport.vdis,
|
||||||
vdi =>
|
vdi =>
|
||||||
`vdis/${jobId}/${
|
`vdis/${jobId}/${
|
||||||
@@ -158,7 +193,15 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
vdi.uuid
|
vdi.uuid
|
||||||
: vdi.$snapshot_of$uuid
|
: vdi.$snapshot_of$uuid
|
||||||
}/${adapter.getVhdFileName(basename)}`
|
}/${adapter.getVhdFileName(basename)}`
|
||||||
)
|
))
|
||||||
|
|
||||||
|
let metadataContent = await this._isAlreadyTransferred(timestamp)
|
||||||
|
if (metadataContent !== undefined) {
|
||||||
|
// skip backup while being vigilant to not stuck the forked stream
|
||||||
|
Task.info('This backup has already been transfered')
|
||||||
|
Object.values(deltaExport.streams).forEach(stream => stream.destroy())
|
||||||
|
return { size: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
metadataContent = {
|
metadataContent = {
|
||||||
isVhdDifferencing,
|
isVhdDifferencing,
|
||||||
@@ -174,38 +217,13 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
vm,
|
vm,
|
||||||
vmSnapshot,
|
vmSnapshot,
|
||||||
}
|
}
|
||||||
const { size } = await Task.run({ properties: { name: 'transfer' } }, async () => {
|
|
||||||
|
const { size } = await Task.run({ name: 'transfer' }, async () => {
|
||||||
let transferSize = 0
|
let transferSize = 0
|
||||||
await asyncEach(
|
await asyncEach(
|
||||||
Object.entries(deltaExport.vdis),
|
Object.keys(deltaExport.vdis),
|
||||||
async ([id, vdi]) => {
|
async id => {
|
||||||
const path = `${this._vmBackupDir}/${vhds[id]}`
|
const path = `${this._vmBackupDir}/${vhds[id]}`
|
||||||
|
|
||||||
const isDifferencing = isVhdDifferencing[`${id}.vhd`]
|
|
||||||
let parentPath
|
|
||||||
if (isDifferencing) {
|
|
||||||
const vdiDir = dirname(path)
|
|
||||||
parentPath = (
|
|
||||||
await handler.list(vdiDir, {
|
|
||||||
filter: filename => filename[0] !== '.' && filename.endsWith('.vhd'),
|
|
||||||
prependDir: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.sort()
|
|
||||||
.pop()
|
|
||||||
|
|
||||||
assert.notStrictEqual(
|
|
||||||
parentPath,
|
|
||||||
undefined,
|
|
||||||
`missing parent of ${id} in ${dirname(path)}, looking for ${vdi.other_config[TAG_BASE_DELTA]}`
|
|
||||||
)
|
|
||||||
|
|
||||||
parentPath = parentPath.slice(1) // remove leading slash
|
|
||||||
|
|
||||||
// TODO remove when this has been done before the export
|
|
||||||
await checkVhd(handler, parentPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't write it as transferSize += await async function
|
// don't write it as transferSize += await async function
|
||||||
// since i += await asyncFun lead to race condition
|
// since i += await asyncFun lead to race condition
|
||||||
// as explained : https://eslint.org/docs/latest/rules/require-atomic-updates
|
// as explained : https://eslint.org/docs/latest/rules/require-atomic-updates
|
||||||
@@ -217,17 +235,6 @@ export class IncrementalRemoteWriter extends MixinRemoteWriter(AbstractIncrement
|
|||||||
writeBlockConcurrency: this._config.writeBlockConcurrency,
|
writeBlockConcurrency: this._config.writeBlockConcurrency,
|
||||||
})
|
})
|
||||||
transferSize += transferSizeOneDisk
|
transferSize += transferSizeOneDisk
|
||||||
|
|
||||||
if (isDifferencing) {
|
|
||||||
await chainVhd(handler, parentPath, handler, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the correct UUID in the VHD
|
|
||||||
await Disposable.use(openVhd(handler, path), async vhd => {
|
|
||||||
vhd.footer.uuid = packUuid(vdi.uuid)
|
|
||||||
await vhd.readBlockAllocationTable() // required by writeFooter()
|
|
||||||
await vhd.writeFooter()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
concurrency: settings.diskPerVmConcurrency,
|
concurrency: settings.diskPerVmConcurrency,
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
|
import assert from 'node:assert'
|
||||||
import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
|
import { asyncMap, asyncMapSettled } from '@xen-orchestra/async-map'
|
||||||
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
||||||
import { formatDateTime } from '@xen-orchestra/xapi'
|
import { formatDateTime } from '@xen-orchestra/xapi'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
|
|
||||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||||
import { getOldEntries } from '../../_getOldEntries.mjs'
|
import { getOldEntries } from '../../_getOldEntries.mjs'
|
||||||
import { importIncrementalVm, TAG_BACKUP_SR, TAG_BASE_DELTA, TAG_COPY_SRC } from '../../_incrementalVm.mjs'
|
import { importIncrementalVm, TAG_BACKUP_SR, TAG_BASE_DELTA, TAG_COPY_SRC } from '../../_incrementalVm.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
|
import { AbstractIncrementalWriter } from './_AbstractIncrementalWriter.mjs'
|
||||||
import { MixinXapiWriter } from './_MixinXapiWriter.mjs'
|
import { MixinXapiWriter } from './_MixinXapiWriter.mjs'
|
||||||
@@ -14,6 +15,7 @@ import find from 'lodash/find.js'
|
|||||||
|
|
||||||
export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWriter) {
|
export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWriter) {
|
||||||
async checkBaseVdis(baseUuidToSrcVdi, baseVm) {
|
async checkBaseVdis(baseUuidToSrcVdi, baseVm) {
|
||||||
|
assert.notStrictEqual(baseVm, undefined)
|
||||||
const sr = this._sr
|
const sr = this._sr
|
||||||
const replicatedVm = listReplicatedVms(sr.$xapi, this._job.id, sr.uuid, this._vmUuid).find(
|
const replicatedVm = listReplicatedVms(sr.$xapi, this._job.id, sr.uuid, this._vmUuid).find(
|
||||||
vm => vm.other_config[TAG_COPY_SRC] === baseVm.uuid
|
vm => vm.other_config[TAG_COPY_SRC] === baseVm.uuid
|
||||||
@@ -36,25 +38,24 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateUuidAndChain() {
|
||||||
|
// nothing to do, the chaining is not modified in this case
|
||||||
|
}
|
||||||
prepare({ isFull }) {
|
prepare({ isFull }) {
|
||||||
// create the task related to this export and ensure all methods are called in this context
|
// create the task related to this export and ensure all methods are called in this context
|
||||||
const task = new Task({
|
const task = new Task({
|
||||||
properties: {
|
name: 'export',
|
||||||
name: 'export',
|
data: {
|
||||||
id: this._sr.uuid,
|
id: this._sr.uuid,
|
||||||
isFull,
|
isFull,
|
||||||
name_label: this._sr.name_label,
|
name_label: this._sr.name_label,
|
||||||
type: 'SR',
|
type: 'SR',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
this.transfer = task.wrapInside(this.transfer)
|
const hasHealthCheckSr = this._healthCheckSr !== undefined
|
||||||
if (this._healthCheckSr !== undefined) {
|
this.transfer = task.wrapFn(this.transfer)
|
||||||
this.cleanup = task.wrapInside(this.cleanup)
|
this.cleanup = task.wrapFn(this.cleanup, !hasHealthCheckSr)
|
||||||
this.healthCheck = task.wrap(this.healthCheck)
|
this.healthCheck = task.wrapFn(this.healthCheck, hasHealthCheckSr)
|
||||||
} else {
|
|
||||||
this.cleanup = task.wrap(this.cleanup)
|
|
||||||
}
|
|
||||||
|
|
||||||
return task.run(() => this._prepare())
|
return task.run(() => this._prepare())
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ export class IncrementalXapiWriter extends MixinXapiWriter(AbstractIncrementalWr
|
|||||||
const { uuid: srUuid, $xapi: xapi } = sr
|
const { uuid: srUuid, $xapi: xapi } = sr
|
||||||
|
|
||||||
let targetVmRef
|
let targetVmRef
|
||||||
await Task.run({ properties: { name: 'transfer' } }, async () => {
|
await Task.run({ name: 'transfer' }, async () => {
|
||||||
targetVmRef = await importIncrementalVm(this.#decorateVmMetadata(deltaExport), sr)
|
targetVmRef = await importIncrementalVm(this.#decorateVmMetadata(deltaExport), sr)
|
||||||
return {
|
return {
|
||||||
size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0),
|
size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0),
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ export class AbstractIncrementalWriter extends AbstractWriter {
|
|||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateUuidAndChain() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
throw new Error('Not implemented')
|
throw new Error('Not implemented')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { createLogger } from '@xen-orchestra/log'
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
import { join } from 'node:path'
|
import { join } from 'node:path'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import assert from 'node:assert'
|
import assert from 'node:assert'
|
||||||
|
|
||||||
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
import { formatFilenameDate } from '../../_filenameDate.mjs'
|
||||||
import { getVmBackupDir } from '../../_getVmBackupDir.mjs'
|
import { getVmBackupDir } from '../../_getVmBackupDir.mjs'
|
||||||
import { HealthCheckVmBackup } from '../../HealthCheckVmBackup.mjs'
|
import { HealthCheckVmBackup } from '../../HealthCheckVmBackup.mjs'
|
||||||
import { ImportVmBackup } from '../../ImportVmBackup.mjs'
|
import { ImportVmBackup } from '../../ImportVmBackup.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
import * as MergeWorker from '../../merge-worker/index.mjs'
|
import * as MergeWorker from '../../merge-worker/index.mjs'
|
||||||
|
|
||||||
const { info, warn } = createLogger('xo:backups:MixinBackupWriter')
|
const { info, warn } = createLogger('xo:backups:MixinBackupWriter')
|
||||||
@@ -26,7 +26,7 @@ export const MixinRemoteWriter = (BaseClass = Object) =>
|
|||||||
|
|
||||||
async _cleanVm(options) {
|
async _cleanVm(options) {
|
||||||
try {
|
try {
|
||||||
return await Task.run({ properties: { name: 'clean-vm' } }, () => {
|
return await Task.run({ name: 'clean-vm' }, () => {
|
||||||
return this._adapter.cleanVm(this._vmBackupDir, {
|
return this._adapter.cleanVm(this._vmBackupDir, {
|
||||||
...options,
|
...options,
|
||||||
fixMetadata: true,
|
fixMetadata: true,
|
||||||
@@ -84,7 +84,7 @@ export const MixinRemoteWriter = (BaseClass = Object) =>
|
|||||||
)
|
)
|
||||||
return Task.run(
|
return Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'health check' },
|
name: 'health check',
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
const xapi = sr.$xapi
|
const xapi = sr.$xapi
|
||||||
@@ -113,13 +113,13 @@ export const MixinRemoteWriter = (BaseClass = Object) =>
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_isAlreadyTransferred(timestamp) {
|
async _isAlreadyTransferred(timestamp) {
|
||||||
const vmUuid = this._vmUuid
|
const vmUuid = this._vmUuid
|
||||||
const adapter = this._adapter
|
const adapter = this._adapter
|
||||||
const backupDir = getVmBackupDir(vmUuid)
|
const backupDir = getVmBackupDir(vmUuid)
|
||||||
try {
|
try {
|
||||||
const actualMetadata = JSON.parse(
|
const actualMetadata = JSON.parse(
|
||||||
adapter._handler.readFile(`${backupDir}/${formatFilenameDate(timestamp)}.json`)
|
await adapter._handler.readFile(`${backupDir}/${formatFilenameDate(timestamp)}.json`)
|
||||||
)
|
)
|
||||||
return actualMetadata
|
return actualMetadata
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { extractOpaqueRef } from '@xen-orchestra/xapi'
|
import { extractOpaqueRef } from '@xen-orchestra/xapi'
|
||||||
import { Task } from '@vates/task'
|
|
||||||
import assert from 'node:assert/strict'
|
import assert from 'node:assert/strict'
|
||||||
|
|
||||||
import { HealthCheckVmBackup } from '../../HealthCheckVmBackup.mjs'
|
import { HealthCheckVmBackup } from '../../HealthCheckVmBackup.mjs'
|
||||||
|
import { Task } from '../../Task.mjs'
|
||||||
|
|
||||||
export const MixinXapiWriter = (BaseClass = Object) =>
|
export const MixinXapiWriter = (BaseClass = Object) =>
|
||||||
class MixinXapiWriter extends BaseClass {
|
class MixinXapiWriter extends BaseClass {
|
||||||
@@ -32,7 +32,7 @@ export const MixinXapiWriter = (BaseClass = Object) =>
|
|||||||
// copy VM
|
// copy VM
|
||||||
return Task.run(
|
return Task.run(
|
||||||
{
|
{
|
||||||
properties: { name: 'health check' },
|
name: 'health check',
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
const { $xapi: xapi } = sr
|
const { $xapi: xapi } = sr
|
||||||
@@ -42,7 +42,7 @@ export const MixinXapiWriter = (BaseClass = Object) =>
|
|||||||
|
|
||||||
if (await this.#isAlreadyOnHealthCheckSr(baseVm)) {
|
if (await this.#isAlreadyOnHealthCheckSr(baseVm)) {
|
||||||
healthCheckVmRef = await Task.run(
|
healthCheckVmRef = await Task.run(
|
||||||
{ properties: { name: 'cloning-vm' } },
|
{ name: 'cloning-vm' },
|
||||||
async () =>
|
async () =>
|
||||||
await xapi
|
await xapi
|
||||||
.callAsync('VM.clone', this._targetVmRef, `Health Check - ${baseVm.name_label}`)
|
.callAsync('VM.clone', this._targetVmRef, `Health Check - ${baseVm.name_label}`)
|
||||||
@@ -50,7 +50,7 @@ export const MixinXapiWriter = (BaseClass = Object) =>
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
healthCheckVmRef = await Task.run(
|
healthCheckVmRef = await Task.run(
|
||||||
{ properties: { name: 'copying-vm' } },
|
{ name: 'copying-vm' },
|
||||||
async () =>
|
async () =>
|
||||||
await xapi
|
await xapi
|
||||||
.callAsync('VM.copy', this._targetVmRef, `Health Check - ${baseVm.name_label}`, sr.$ref)
|
.callAsync('VM.copy', this._targetVmRef, `Health Check - ${baseVm.name_label}`, sr.$ref)
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ Settings are described in [`@xen-orchestra/backups/\_runners/VmsXapi.mjs``](http
|
|||||||
- `checkBaseVdis(baseUuidToSrcVdi, baseVm)`
|
- `checkBaseVdis(baseUuidToSrcVdi, baseVm)`
|
||||||
- `prepare({ isFull })`
|
- `prepare({ isFull })`
|
||||||
- `transfer({ timestamp, deltaExport, sizeContainers })`
|
- `transfer({ timestamp, deltaExport, sizeContainers })`
|
||||||
|
- `updateUuidAndChain({ isVhdDifferencing, vdis })`
|
||||||
- `cleanup()`
|
- `cleanup()`
|
||||||
- `healthCheck()` // is not executed if no health check sr or tag doesn't match
|
- `healthCheck()` // is not executed if no health check sr or tag doesn't match
|
||||||
- **Full**
|
- **Full**
|
||||||
|
|||||||
@@ -2,8 +2,21 @@ import mapValues from 'lodash/mapValues.js'
|
|||||||
import { dirname } from 'node:path'
|
import { dirname } from 'node:path'
|
||||||
|
|
||||||
function formatVmBackup(backup) {
|
function formatVmBackup(backup) {
|
||||||
const { isVhdDifferencing } = backup
|
const { isVhdDifferencing, vmSnapshot } = backup
|
||||||
|
|
||||||
|
let differencingVhds
|
||||||
|
let dynamicVhds
|
||||||
|
// some backups don't use snapshots, therefore cannot be with memory
|
||||||
|
const withMemory = vmSnapshot !== undefined && vmSnapshot.suspend_VDI !== 'OpaqueRef:NULL'
|
||||||
|
// isVhdDifferencing is either undefined or an object
|
||||||
|
if (isVhdDifferencing !== undefined) {
|
||||||
|
differencingVhds = Object.values(isVhdDifferencing).filter(t => t).length
|
||||||
|
dynamicVhds = Object.values(isVhdDifferencing).filter(t => !t).length
|
||||||
|
if (withMemory) {
|
||||||
|
// the suspend VDI (memory) is always a dynamic
|
||||||
|
dynamicVhds -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
disks:
|
disks:
|
||||||
backup.vhds === undefined
|
backup.vhds === undefined
|
||||||
@@ -18,6 +31,7 @@ function formatVmBackup(backup) {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
id: backup.id,
|
id: backup.id,
|
||||||
|
isImmutable: backup.isImmutable,
|
||||||
jobId: backup.jobId,
|
jobId: backup.jobId,
|
||||||
mode: backup.mode,
|
mode: backup.mode,
|
||||||
scheduleId: backup.scheduleId,
|
scheduleId: backup.scheduleId,
|
||||||
@@ -28,9 +42,9 @@ function formatVmBackup(backup) {
|
|||||||
name_label: backup.vm.name_label,
|
name_label: backup.vm.name_label,
|
||||||
},
|
},
|
||||||
|
|
||||||
// isVhdDifferencing is either undefined or an object
|
differencingVhds,
|
||||||
differencingVhds: isVhdDifferencing && Object.values(isVhdDifferencing).filter(t => t).length,
|
dynamicVhds,
|
||||||
dynamicVhds: isVhdDifferencing && Object.values(isVhdDifferencing).filter(t => !t).length,
|
withMemory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||||
},
|
},
|
||||||
"version": "0.44.3",
|
"version": "0.44.6",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.18"
|
"node": ">=14.18"
|
||||||
},
|
},
|
||||||
@@ -22,14 +22,13 @@
|
|||||||
"@vates/async-each": "^1.0.0",
|
"@vates/async-each": "^1.0.0",
|
||||||
"@vates/cached-dns.lookup": "^1.0.0",
|
"@vates/cached-dns.lookup": "^1.0.0",
|
||||||
"@vates/compose": "^2.1.0",
|
"@vates/compose": "^2.1.0",
|
||||||
"@vates/decorate-with": "^2.0.0",
|
"@vates/decorate-with": "^2.1.0",
|
||||||
"@vates/disposable": "^0.1.5",
|
"@vates/disposable": "^0.1.5",
|
||||||
"@vates/fuse-vhd": "^2.0.0",
|
"@vates/fuse-vhd": "^2.1.0",
|
||||||
"@vates/nbd-client": "^3.0.0",
|
"@vates/nbd-client": "^3.0.0",
|
||||||
"@vates/parse-duration": "^0.1.1",
|
"@vates/parse-duration": "^0.1.1",
|
||||||
"@vates/task": "^0.2.0",
|
|
||||||
"@xen-orchestra/async-map": "^0.1.2",
|
"@xen-orchestra/async-map": "^0.1.2",
|
||||||
"@xen-orchestra/fs": "^4.1.3",
|
"@xen-orchestra/fs": "^4.1.4",
|
||||||
"@xen-orchestra/log": "^0.6.0",
|
"@xen-orchestra/log": "^0.6.0",
|
||||||
"@xen-orchestra/template": "^0.1.0",
|
"@xen-orchestra/template": "^0.1.0",
|
||||||
"app-conf": "^2.3.0",
|
"app-conf": "^2.3.0",
|
||||||
@@ -46,7 +45,7 @@
|
|||||||
"tar": "^6.1.15",
|
"tar": "^6.1.15",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^9.0.0",
|
||||||
"vhd-lib": "^4.9.0",
|
"vhd-lib": "^4.9.0",
|
||||||
"xen-api": "^2.0.0",
|
"xen-api": "^2.0.1",
|
||||||
"yazl": "^2.5.1"
|
"yazl": "^2.5.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -57,7 +56,7 @@
|
|||||||
"tmp": "^0.2.1"
|
"tmp": "^0.2.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@xen-orchestra/xapi": "^4.1.0"
|
"@xen-orchestra/xapi": "^4.2.0"
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"golike-defer": "^0.5.1",
|
"golike-defer": "^0.5.1",
|
||||||
"xen-api": "^2.0.0"
|
"xen-api": "^2.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postversion": "npm publish"
|
"postversion": "npm publish"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": false,
|
"private": false,
|
||||||
"name": "@xen-orchestra/fs",
|
"name": "@xen-orchestra/fs",
|
||||||
"version": "4.1.3",
|
"version": "4.1.4",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"description": "The File System for Xen Orchestra backups.",
|
"description": "The File System for Xen Orchestra backups.",
|
||||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/fs",
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/fs",
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"@sindresorhus/df": "^3.1.1",
|
"@sindresorhus/df": "^3.1.1",
|
||||||
"@vates/async-each": "^1.0.0",
|
"@vates/async-each": "^1.0.0",
|
||||||
"@vates/coalesce-calls": "^0.1.0",
|
"@vates/coalesce-calls": "^0.1.0",
|
||||||
"@vates/decorate-with": "^2.0.0",
|
"@vates/decorate-with": "^2.1.0",
|
||||||
"@vates/read-chunk": "^1.2.0",
|
"@vates/read-chunk": "^1.2.0",
|
||||||
"@xen-orchestra/log": "^0.6.0",
|
"@xen-orchestra/log": "^0.6.0",
|
||||||
"bind-property-descriptor": "^2.0.0",
|
"bind-property-descriptor": "^2.0.0",
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ export default class RemoteHandlerAbstract {
|
|||||||
let data
|
let data
|
||||||
try {
|
try {
|
||||||
// this file is not encrypted
|
// this file is not encrypted
|
||||||
data = await this._readFile(normalizePath(ENCRYPTION_DESC_FILENAME), 'utf-8')
|
data = await this._readFile(normalizePath(ENCRYPTION_DESC_FILENAME))
|
||||||
const json = JSON.parse(data)
|
const json = JSON.parse(data)
|
||||||
encryptionAlgorithm = json.algorithm
|
encryptionAlgorithm = json.algorithm
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -377,7 +377,7 @@ export default class RemoteHandlerAbstract {
|
|||||||
try {
|
try {
|
||||||
this.#rawEncryptor = _getEncryptor(encryptionAlgorithm, this._remote.encryptionKey)
|
this.#rawEncryptor = _getEncryptor(encryptionAlgorithm, this._remote.encryptionKey)
|
||||||
// this file is encrypted
|
// this file is encrypted
|
||||||
const data = await this.__readFile(ENCRYPTION_METADATA_FILENAME, 'utf-8')
|
const data = await this.__readFile(ENCRYPTION_METADATA_FILENAME)
|
||||||
JSON.parse(data)
|
JSON.parse(data)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// can be enoent, bad algorithm, or broeken json ( bad key or algorithm)
|
// can be enoent, bad algorithm, or broeken json ( bad key or algorithm)
|
||||||
|
|||||||
@@ -171,7 +171,12 @@ export default class LocalHandler extends RemoteHandlerAbstract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _readFile(file, options) {
|
async _readFile(file, { flags, ...options } = {}) {
|
||||||
|
// contrary to createReadStream, readFile expect singular `flag`
|
||||||
|
if (flags !== undefined) {
|
||||||
|
options.flag = flags
|
||||||
|
}
|
||||||
|
|
||||||
const filePath = this.getFilePath(file)
|
const filePath = this.getFilePath(file)
|
||||||
return await this.#addSyncStackTrace(retry, () => fs.readFile(filePath, options), this.#retriesOnEagain)
|
return await this.#addSyncStackTrace(retry, () => fs.readFile(filePath, options), this.#retriesOnEagain)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,7 @@ export function split(path) {
|
|||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
export const relativeFromFile = (file, path) => relative(dirname(file), path)
|
// paths are made absolute otherwise fs.relative() would resolve them against working directory
|
||||||
|
export const relativeFromFile = (file, path) => relative(dirname(normalize(file)), normalize(path))
|
||||||
|
|
||||||
export const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)
|
export const resolveFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)
|
||||||
|
|||||||
17
@xen-orchestra/fs/src/path.test.js
Normal file
17
@xen-orchestra/fs/src/path.test.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { describe, it } from 'test'
|
||||||
|
import { strict as assert } from 'assert'
|
||||||
|
|
||||||
|
import { relativeFromFile } from './path.js'
|
||||||
|
|
||||||
|
describe('relativeFromFile()', function () {
|
||||||
|
for (const [title, args] of Object.entries({
|
||||||
|
'file absolute and path absolute': ['/foo/bar/file.vhd', '/foo/baz/path.vhd'],
|
||||||
|
'file relative and path absolute': ['foo/bar/file.vhd', '/foo/baz/path.vhd'],
|
||||||
|
'file absolute and path relative': ['/foo/bar/file.vhd', 'foo/baz/path.vhd'],
|
||||||
|
'file relative and path relative': ['foo/bar/file.vhd', 'foo/baz/path.vhd'],
|
||||||
|
})) {
|
||||||
|
it('works with ' + title, function () {
|
||||||
|
assert.equal(relativeFromFile(...args), '../baz/path.vhd')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
10
@xen-orchestra/immutable-backups/.USAGE.md
Normal file
10
@xen-orchestra/immutable-backups/.USAGE.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
### make a remote immutable
|
||||||
|
|
||||||
|
launch the `xo-immutable-remote` command. The configuration is stored in the config file.
|
||||||
|
This script must be kept running to make file immutable reliably.
|
||||||
|
|
||||||
|
### make file mutable
|
||||||
|
|
||||||
|
launch the `xo-lift-remote-immutability` cli. The configuration is stored in the config file .
|
||||||
|
|
||||||
|
If the config file have a `liftEvery`, this script will contiue to run and check regularly if there are files to update.
|
||||||
1
@xen-orchestra/immutable-backups/.npmignore
Symbolic link
1
@xen-orchestra/immutable-backups/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../scripts/npmignore
|
||||||
41
@xen-orchestra/immutable-backups/README.md
Normal file
41
@xen-orchestra/immutable-backups/README.md
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||||
|
|
||||||
|
# @xen-orchestra/immutable-backups
|
||||||
|
|
||||||
|
[](https://npmjs.org/package/@xen-orchestra/immutable-backups)  [](https://bundlephobia.com/result?p=@xen-orchestra/immutable-backups) [](https://npmjs.org/package/@xen-orchestra/immutable-backups)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Installation of the [npm package](https://npmjs.org/package/@xen-orchestra/immutable-backups):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save @xen-orchestra/immutable-backups
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### make a remote immutable
|
||||||
|
|
||||||
|
launch the `xo-immutable-remote` command. The configuration is stored in the config file.
|
||||||
|
This script must be kept running to make file immutable reliably.
|
||||||
|
|
||||||
|
### make file mutable
|
||||||
|
|
||||||
|
launch the `xo-lift-remote-immutability` cli. The configuration is stored in the config file .
|
||||||
|
|
||||||
|
If the config file have a `liftEvery`, this script will contiue to run and check regularly if there are files to update.
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
|
||||||
|
Contributions are _very_ welcomed, either on the documentation or on
|
||||||
|
the code.
|
||||||
|
|
||||||
|
You may:
|
||||||
|
|
||||||
|
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||||
|
you've encountered;
|
||||||
|
- fork and create a pull request.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[AGPL-3.0-or-later](https://spdx.org/licenses/AGPL-3.0-or-later) © [Vates SAS](https://vates.fr)
|
||||||
10
@xen-orchestra/immutable-backups/_cleanXoCache.mjs
Normal file
10
@xen-orchestra/immutable-backups/_cleanXoCache.mjs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import isBackupMetadata from './isBackupMetadata.mjs'
|
||||||
|
|
||||||
|
export default async path => {
|
||||||
|
if (isBackupMetadata(path)) {
|
||||||
|
// snipe vm metadata cache to force XO to update it
|
||||||
|
await fs.unlink(join(dirname(path), 'cache.json.gz'))
|
||||||
|
}
|
||||||
|
}
|
||||||
4
@xen-orchestra/immutable-backups/_isInVhdDirectory.mjs
Normal file
4
@xen-orchestra/immutable-backups/_isInVhdDirectory.mjs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { dirname } from 'node:path'
|
||||||
|
|
||||||
|
// check if we are handling file directly under a vhd directory ( bat, headr, footer,..)
|
||||||
|
export default path => dirname(path).endsWith('.vhd')
|
||||||
46
@xen-orchestra/immutable-backups/_loadConfig.mjs
Normal file
46
@xen-orchestra/immutable-backups/_loadConfig.mjs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { load } from 'app-conf'
|
||||||
|
import { homedir } from 'os'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import ms from 'ms'
|
||||||
|
|
||||||
|
const APP_NAME = 'xo-immutable-backups'
|
||||||
|
const APP_DIR = new URL('.', import.meta.url).pathname
|
||||||
|
|
||||||
|
export default async function loadConfig() {
|
||||||
|
const config = await load(APP_NAME, {
|
||||||
|
appDir: APP_DIR,
|
||||||
|
ignoreUnknownFormats: true,
|
||||||
|
})
|
||||||
|
if (config.remotes === undefined || config.remotes?.length < 1) {
|
||||||
|
throw new Error(
|
||||||
|
'No remotes are configured in the config file, please add at least one [remotes.<remoteid>] with a root property pointing to the absolute path of the remote to watch'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (config.liftEvery) {
|
||||||
|
config.liftEvery = ms(config.liftEvery)
|
||||||
|
}
|
||||||
|
for (const [remoteId, { indexPath, immutabilityDuration, root }] of Object.entries(config.remotes)) {
|
||||||
|
if (!root) {
|
||||||
|
throw new Error(
|
||||||
|
`Remote ${remoteId} don't have a root property,containing the absolute path to the root of a backup repository `
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!immutabilityDuration) {
|
||||||
|
throw new Error(
|
||||||
|
`Remote ${remoteId} don't have a immutabilityDuration property to indicate the minimal duration the backups should be protected by immutability `
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (ms(immutabilityDuration) < ms('1d')) {
|
||||||
|
throw new Error(
|
||||||
|
`Remote ${remoteId} immutability duration is smaller than the minimum allowed (1d), current : ${immutabilityDuration}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!indexPath) {
|
||||||
|
const basePath = indexPath ?? process.env.XDG_DATA_HOME ?? join(homedir(), '.local', 'share')
|
||||||
|
const immutabilityIndexPath = join(basePath, APP_NAME, remoteId)
|
||||||
|
config.remotes[remoteId].indexPath = immutabilityIndexPath
|
||||||
|
}
|
||||||
|
config.remotes[remoteId].immutabilityDuration = ms(immutabilityDuration)
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
14
@xen-orchestra/immutable-backups/config.toml
Normal file
14
@xen-orchestra/immutable-backups/config.toml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
# how often does the lift immutability script will run to check if
|
||||||
|
# some files need to be made mutable
|
||||||
|
liftEvery = 1h
|
||||||
|
|
||||||
|
# you can add as many remote as you want, if you change the id ( here : remote1)
|
||||||
|
#[remotes.remote1]
|
||||||
|
#root = "/mnt/ssd/vhdblock/" # the absolute path of the root of the backup repository
|
||||||
|
#immutabilityDuration = 7d # mandatory
|
||||||
|
# optional, default value is false will scan and update the index on start, can be expensive
|
||||||
|
#rebuildIndexOnStart = true
|
||||||
|
|
||||||
|
# the index path is optional, default in XDG_DATA_HOME, or if this is not set, in ~/.local/share
|
||||||
|
#indexPath = "/var/lib/" # will add automatically the application name immutable-backup
|
||||||
33
@xen-orchestra/immutable-backups/directory.integ.mjs
Normal file
33
@xen-orchestra/immutable-backups/directory.integ.mjs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, it } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import * as Directory from './directory.mjs'
|
||||||
|
import { rimraf } from 'rimraf'
|
||||||
|
|
||||||
|
describe('immutable-backups/file', async () => {
|
||||||
|
it('really lock a directory', async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(tmpdir(), 'immutable-backups-tests'))
|
||||||
|
const dataDir = path.join(dir, 'data')
|
||||||
|
await fs.mkdir(dataDir)
|
||||||
|
const immutDir = path.join(dir, '.immutable')
|
||||||
|
const filePath = path.join(dataDir, 'test')
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
await Directory.makeImmutable(dataDir, immutDir)
|
||||||
|
assert.strictEqual(await Directory.isImmutable(dataDir), true)
|
||||||
|
await assert.rejects(() => fs.writeFile(filePath, 'data'))
|
||||||
|
await assert.rejects(() => fs.appendFile(filePath, 'data'))
|
||||||
|
await assert.rejects(() => fs.unlink(filePath))
|
||||||
|
await assert.rejects(() => fs.rename(filePath, filePath + 'copy'))
|
||||||
|
await assert.rejects(() => fs.writeFile(path.join(dataDir, 'test2'), 'data'))
|
||||||
|
await assert.rejects(() => fs.rename(dataDir, dataDir + 'copy'))
|
||||||
|
await Directory.liftImmutability(dataDir, immutDir)
|
||||||
|
assert.strictEqual(await Directory.isImmutable(dataDir), false)
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
await fs.appendFile(filePath, 'data')
|
||||||
|
await fs.unlink(filePath)
|
||||||
|
await fs.rename(dataDir, dataDir + 'copy')
|
||||||
|
await rimraf(dir)
|
||||||
|
})
|
||||||
|
})
|
||||||
21
@xen-orchestra/immutable-backups/directory.mjs
Normal file
21
@xen-orchestra/immutable-backups/directory.mjs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import execa from 'execa'
|
||||||
|
import { unindexFile, indexFile } from './fileIndex.mjs'
|
||||||
|
|
||||||
|
export async function makeImmutable(dirPath, immutabilityCachePath) {
|
||||||
|
if (immutabilityCachePath) {
|
||||||
|
await indexFile(dirPath, immutabilityCachePath)
|
||||||
|
}
|
||||||
|
await execa('chattr', ['+i', '-R', dirPath])
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function liftImmutability(dirPath, immutabilityCachePath) {
|
||||||
|
if (immutabilityCachePath) {
|
||||||
|
await unindexFile(dirPath, immutabilityCachePath)
|
||||||
|
}
|
||||||
|
await execa('chattr', ['-i', '-R', dirPath])
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function isImmutable(path) {
|
||||||
|
const { stdout } = await execa('lsattr', ['-d', path])
|
||||||
|
return stdout[4] === 'i'
|
||||||
|
}
|
||||||
114
@xen-orchestra/immutable-backups/doc.md
Normal file
114
@xen-orchestra/immutable-backups/doc.md
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
# Imutability
|
||||||
|
|
||||||
|
the goal is to make a remote that XO can write, but not modify during the immutability duration set on the remote. That way, it's not possible for XO to delete or encrypt any backup during this period. It protects your backup agains ransomware, at least as long as the attacker does not have a root access to the remote server.
|
||||||
|
|
||||||
|
We target `governance` type of immutability, **the local root account of the remote server will be able to lift immutability**.
|
||||||
|
|
||||||
|
We use the file system capabilities, they are tested on the protection process start.
|
||||||
|
|
||||||
|
It is compatible with encryption at rest made by XO.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
The commands must be run as root on the remote, or by a user with the `CAP_LINUX_IMMUTABLE` capability . On start, the protect process writes into the remote `imutability.json` file its status and the immutability duration.
|
||||||
|
|
||||||
|
the `chattr` and `lsattr` should be installed on the system
|
||||||
|
|
||||||
|
## Configuring
|
||||||
|
|
||||||
|
this package uses app-conf to store its config. The application name is `xo-immutable-backup`. A sample config file is provided in this package.
|
||||||
|
|
||||||
|
## Making a file immutable
|
||||||
|
|
||||||
|
when marking a file or a folder immutable, it create an alias file in the `<indexPath>/<DayOfFileCreation>/<sha256(fullpath)>`.
|
||||||
|
|
||||||
|
`indexPath` can be defined in the config file, otherwise `XDG_HOME` is used. If not available it goes to `~/.local/share`
|
||||||
|
|
||||||
|
This index is used when lifting the immutability of the remote, it will only look at the old enough `<indexPath>/<DayOfFileCreation>/` folders.
|
||||||
|
|
||||||
|
## Real time protecting
|
||||||
|
|
||||||
|
On start, the watcher will create the index if it does not exists.
|
||||||
|
It will also do a checkup to ensure immutability could work on this remote and handle the easiest issues.
|
||||||
|
|
||||||
|
The watching process depends on the backup type, since we don't want to make temporary files and cache immutable.
|
||||||
|
|
||||||
|
It won't protect files during upload, only when the files have been completly written on disk. Real time, in this case, means "protecting critical files as soon as possible after they are uploaded"
|
||||||
|
|
||||||
|
This can be alleviated by :
|
||||||
|
|
||||||
|
- Coupling immutability with encryption to ensure the file is not modified
|
||||||
|
- Making health check to ensure the data are exactly as the snapshot data
|
||||||
|
|
||||||
|
List of protected files :
|
||||||
|
|
||||||
|
```js
|
||||||
|
const PATHS = [
|
||||||
|
// xo configuration backupq
|
||||||
|
'xo-config-backups/*/*/data',
|
||||||
|
'xo-config-backups/*/*/data.json',
|
||||||
|
'xo-config-backups/*/*/metadata.json',
|
||||||
|
// pool backupq
|
||||||
|
'xo-pool-metadata-backups/*/metadata.json',
|
||||||
|
'xo-pool-metadata-backups/*/data',
|
||||||
|
// vm backups , xo-vm-backups/<vmuuid>/
|
||||||
|
'xo-vm-backups/*/*.json',
|
||||||
|
'xo-vm-backups/*/*.xva',
|
||||||
|
'xo-vm-backups/*/*.xva.checksum',
|
||||||
|
// xo-vm-backups/<vmuuid>/vdis/<jobid>/<vdiUuid>
|
||||||
|
'xo-vm-backups/*/vdis/*/*/*.vhd', // can be an alias or a vhd file
|
||||||
|
// for vhd directory :
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/bat',
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/header',
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/footer',
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Releasing protection on old enough files on a remote
|
||||||
|
|
||||||
|
the watcher will periodically check if some file must by unlocked
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### some files are still locked
|
||||||
|
|
||||||
|
add the `rebuildIndexOnStart` option to the config file
|
||||||
|
|
||||||
|
### make remote fully mutable again
|
||||||
|
|
||||||
|
- Update the immutability setting with a 0 duration
|
||||||
|
- launch the `liftProtection` cli.
|
||||||
|
- remove the `protectRemotes` service
|
||||||
|
|
||||||
|
### increasing the immutability duration
|
||||||
|
|
||||||
|
this will prolong immutable file, but won't protect files that are already out of immutability
|
||||||
|
|
||||||
|
### reducing the immutability duration
|
||||||
|
|
||||||
|
change the setting, and launch the `liftProtection` cli , or wait for next planed execution
|
||||||
|
|
||||||
|
### why are my incremental backups not marked as protected in XO ?
|
||||||
|
|
||||||
|
are not marked as protected in XO ?
|
||||||
|
|
||||||
|
For incremental backups to be marked as protected in XO, the entire chain must be under protection. To ensure at least 7 days of backups are protected, you need to set the immutability duration and retention at 14 days, the full backup interval at 7 days
|
||||||
|
|
||||||
|
That means that if the last backup chain is complete ( 7 backup ) it is completely under protection, and if not, the precedent chain is also under protection. K are key backups, and are delta
|
||||||
|
|
||||||
|
```
|
||||||
|
Kd Kdddddd Kdddddd K # 8 backups protected, 2 chains
|
||||||
|
K Kdddddd Kdddddd Kd # 9 backups protected, 2 chains
|
||||||
|
Kdddddd Kdddddd Kdd # 10 backups protected, 2 chains
|
||||||
|
Kddddd Kdddddd Kddd # 11 backups protected, 2 chains
|
||||||
|
Kdddd Kdddddd Kdddd # 12 backups protected, 2 chains
|
||||||
|
Kddd Kdddddd Kddddd # 13 backups protected, 2 chains
|
||||||
|
Kdd Kdddddd Kdddddd # 7 backups protected, 1 chain since precedent full is now mutable
|
||||||
|
Kd Kdddddd Kdddddd K # 8 backups protected, 2 chains
|
||||||
|
```
|
||||||
|
|
||||||
|
### Why doesn't the protect process start ?
|
||||||
|
|
||||||
|
- it should be run as root or by a user with the `CAP_LINUX_IMMUTABLE` capability
|
||||||
|
- the underlying file system should support immutability, especially the `chattr` and `lsattr` command
|
||||||
|
- logs are in journalctl
|
||||||
29
@xen-orchestra/immutable-backups/file.integ.mjs
Normal file
29
@xen-orchestra/immutable-backups/file.integ.mjs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { describe, it } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
import * as File from './file.mjs'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import { rimraf } from 'rimraf'
|
||||||
|
|
||||||
|
describe('immutable-backups/file', async () => {
|
||||||
|
it('really lock a file', async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(tmpdir(), 'immutable-backups-tests'))
|
||||||
|
const immutDir = path.join(dir, '.immutable')
|
||||||
|
const filePath = path.join(dir, 'test.ext')
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
assert.strictEqual(await File.isImmutable(filePath), false)
|
||||||
|
await File.makeImmutable(filePath, immutDir)
|
||||||
|
assert.strictEqual(await File.isImmutable(filePath), true)
|
||||||
|
await assert.rejects(() => fs.writeFile(filePath, 'data'))
|
||||||
|
await assert.rejects(() => fs.appendFile(filePath, 'data'))
|
||||||
|
await assert.rejects(() => fs.unlink(filePath))
|
||||||
|
await assert.rejects(() => fs.rename(filePath, filePath + 'copy'))
|
||||||
|
await File.liftImmutability(filePath, immutDir)
|
||||||
|
assert.strictEqual(await File.isImmutable(filePath), false)
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
await fs.appendFile(filePath, 'data')
|
||||||
|
await fs.unlink(filePath)
|
||||||
|
await rimraf(dir)
|
||||||
|
})
|
||||||
|
})
|
||||||
24
@xen-orchestra/immutable-backups/file.mjs
Normal file
24
@xen-orchestra/immutable-backups/file.mjs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import execa from 'execa'
|
||||||
|
import { unindexFile, indexFile } from './fileIndex.mjs'
|
||||||
|
|
||||||
|
// this work only on linux like systems
|
||||||
|
// this could work on windows : https://4sysops.com/archives/set-and-remove-the-read-only-file-attribute-with-powershell/
|
||||||
|
|
||||||
|
export async function makeImmutable(path, immutabilityCachePath) {
|
||||||
|
if (immutabilityCachePath) {
|
||||||
|
await indexFile(path, immutabilityCachePath)
|
||||||
|
}
|
||||||
|
await execa('chattr', ['+i', path])
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function liftImmutability(filePath, immutabilityCachePath) {
|
||||||
|
if (immutabilityCachePath) {
|
||||||
|
await unindexFile(filePath, immutabilityCachePath)
|
||||||
|
}
|
||||||
|
await execa('chattr', ['-i', filePath])
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function isImmutable(path) {
|
||||||
|
const { stdout } = await execa('lsattr', ['-d', path])
|
||||||
|
return stdout[4] === 'i'
|
||||||
|
}
|
||||||
81
@xen-orchestra/immutable-backups/fileIndex.integ.mjs
Normal file
81
@xen-orchestra/immutable-backups/fileIndex.integ.mjs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { describe, it } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import path from 'node:path'
|
||||||
|
import * as FileIndex from './fileIndex.mjs'
|
||||||
|
import * as Directory from './directory.mjs'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import { rimraf } from 'rimraf'
|
||||||
|
|
||||||
|
describe('immutable-backups/fileIndex', async () => {
|
||||||
|
it('index File changes', async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(tmpdir(), 'immutable-backups-tests'))
|
||||||
|
const immutDir = path.join(dir, '.immutable')
|
||||||
|
const filePath = path.join(dir, 'test.ext')
|
||||||
|
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
await FileIndex.indexFile(filePath, immutDir)
|
||||||
|
await fs.mkdir(path.join(immutDir, 'NOTADATE'))
|
||||||
|
await fs.writeFile(path.join(immutDir, 'NOTADATE.file'), 'content')
|
||||||
|
let nb = 0
|
||||||
|
let index, target
|
||||||
|
for await ({ index, target } of FileIndex.listOlderTargets(immutDir, 0)) {
|
||||||
|
assert.strictEqual(true, false, 'Nothing should be eligible for deletion')
|
||||||
|
}
|
||||||
|
nb = 0
|
||||||
|
for await ({ index, target } of FileIndex.listOlderTargets(immutDir, -24 * 60 * 60 * 1000)) {
|
||||||
|
assert.strictEqual(target, filePath)
|
||||||
|
await fs.unlink(index)
|
||||||
|
nb++
|
||||||
|
}
|
||||||
|
assert.strictEqual(nb, 1)
|
||||||
|
await fs.rmdir(path.join(immutDir, 'NOTADATE'))
|
||||||
|
await fs.rm(path.join(immutDir, 'NOTADATE.file'))
|
||||||
|
for await ({ index, target } of FileIndex.listOlderTargets(immutDir, -24 * 60 * 60 * 1000)) {
|
||||||
|
// should remove the empty dir
|
||||||
|
assert.strictEqual(true, false, 'Nothing should have stayed here')
|
||||||
|
}
|
||||||
|
assert.strictEqual((await fs.readdir(immutDir)).length, 0)
|
||||||
|
await rimraf(dir)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('fails correctly', async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(tmpdir(), 'immutable-backups-tests'))
|
||||||
|
const immutDir = path.join(dir, '.immutable')
|
||||||
|
await fs.mkdir(immutDir)
|
||||||
|
const placeholderFile = path.join(dir, 'test.ext')
|
||||||
|
await fs.writeFile(placeholderFile, 'data')
|
||||||
|
await FileIndex.indexFile(placeholderFile, immutDir)
|
||||||
|
|
||||||
|
const filePath = path.join(dir, 'test2.ext')
|
||||||
|
await fs.writeFile(filePath, 'data')
|
||||||
|
await FileIndex.indexFile(filePath, immutDir)
|
||||||
|
await assert.rejects(() => FileIndex.indexFile(filePath, immutDir), { code: 'EEXIST' })
|
||||||
|
|
||||||
|
await Directory.makeImmutable(immutDir)
|
||||||
|
await assert.rejects(() => FileIndex.unindexFile(filePath, immutDir), { code: 'EPERM' })
|
||||||
|
await Directory.liftImmutability(immutDir)
|
||||||
|
await rimraf(dir)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('handles bomb index files', async () => {
|
||||||
|
const dir = await fs.mkdtemp(path.join(tmpdir(), 'immutable-backups-tests'))
|
||||||
|
const immutDir = path.join(dir, '.immutable')
|
||||||
|
await fs.mkdir(immutDir)
|
||||||
|
const placeholderFile = path.join(dir, 'test.ext')
|
||||||
|
await fs.writeFile(placeholderFile, 'data')
|
||||||
|
await FileIndex.indexFile(placeholderFile, immutDir)
|
||||||
|
|
||||||
|
const indexDayDir = path.join(immutDir, '1980,11-28')
|
||||||
|
await fs.mkdir(indexDayDir)
|
||||||
|
await fs.writeFile(path.join(indexDayDir, 'big'), Buffer.alloc(2 * 1024 * 1024))
|
||||||
|
assert.rejects(async () => {
|
||||||
|
let index, target
|
||||||
|
for await ({ index, target } of FileIndex.listOlderTargets(immutDir, 0)) {
|
||||||
|
// should remove the empty dir
|
||||||
|
assert.strictEqual(true, false, `Nothing should have stayed here, got ${index} ${target}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await rimraf(dir)
|
||||||
|
})
|
||||||
|
})
|
||||||
88
@xen-orchestra/immutable-backups/fileIndex.mjs
Normal file
88
@xen-orchestra/immutable-backups/fileIndex.mjs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import { join } from 'node:path'
|
||||||
|
import { createHash } from 'node:crypto'
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import { dirname } from 'path'
|
||||||
|
const MAX_INDEX_FILE_SIZE = 1024 * 1024
|
||||||
|
function sha256(content) {
|
||||||
|
return createHash('sha256').update(content).digest('hex')
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(date) {
|
||||||
|
return date.toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function computeIndexFilePath(path, immutabilityIndexPath) {
|
||||||
|
const stat = await fs.stat(path)
|
||||||
|
const date = new Date(stat.birthtimeMs)
|
||||||
|
const day = formatDate(date)
|
||||||
|
const hash = sha256(path)
|
||||||
|
return join(immutabilityIndexPath, day, hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function indexFile(path, immutabilityIndexPath) {
|
||||||
|
const indexFilePath = await computeIndexFilePath(path, immutabilityIndexPath)
|
||||||
|
try {
|
||||||
|
await fs.writeFile(indexFilePath, path, { flag: 'wx' })
|
||||||
|
} catch (err) {
|
||||||
|
// missing dir: make it
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
await fs.mkdir(dirname(indexFilePath), { recursive: true })
|
||||||
|
await fs.writeFile(indexFilePath, path)
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return indexFilePath
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function unindexFile(path, immutabilityIndexPath) {
|
||||||
|
try {
|
||||||
|
const cacheFileName = await computeIndexFilePath(path, immutabilityIndexPath)
|
||||||
|
await fs.unlink(cacheFileName)
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code !== 'ENOENT') {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function* listOlderTargets(immutabilityCachePath, immutabilityDuration) {
|
||||||
|
// walk all dir by day until the limit day
|
||||||
|
const limitDate = new Date(Date.now() - immutabilityDuration)
|
||||||
|
|
||||||
|
const limitDay = formatDate(limitDate)
|
||||||
|
const dir = await fs.opendir(immutabilityCachePath)
|
||||||
|
for await (const dirent of dir) {
|
||||||
|
if (dirent.isFile()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// ensure we have a valid date
|
||||||
|
if (isNaN(new Date(dirent.name))) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// recent enough to be kept
|
||||||
|
if (dirent.name >= limitDay) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const subDirPath = join(immutabilityCachePath, dirent.name)
|
||||||
|
const subdir = await fs.opendir(subDirPath)
|
||||||
|
let nb = 0
|
||||||
|
for await (const hashFileEntry of subdir) {
|
||||||
|
const entryFullPath = join(subDirPath, hashFileEntry.name)
|
||||||
|
const { size } = await fs.stat(entryFullPath)
|
||||||
|
if (size > MAX_INDEX_FILE_SIZE) {
|
||||||
|
throw new Error(`Index file at ${entryFullPath} is too big, ${size} bytes `)
|
||||||
|
}
|
||||||
|
const targetPath = await fs.readFile(entryFullPath, { encoding: 'utf8' })
|
||||||
|
yield {
|
||||||
|
index: entryFullPath,
|
||||||
|
target: targetPath,
|
||||||
|
}
|
||||||
|
nb++
|
||||||
|
}
|
||||||
|
// cleanup older folder
|
||||||
|
if (nb === 0) {
|
||||||
|
await fs.rmdir(subDirPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
@xen-orchestra/immutable-backups/isBackupMetadata.mjs
Normal file
1
@xen-orchestra/immutable-backups/isBackupMetadata.mjs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default path => path.match(/xo-vm-backups\/[^/]+\/[^/]+\.json$/)
|
||||||
37
@xen-orchestra/immutable-backups/liftProtection.mjs
Executable file
37
@xen-orchestra/immutable-backups/liftProtection.mjs
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import * as Directory from './directory.mjs'
|
||||||
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
|
import { listOlderTargets } from './fileIndex.mjs'
|
||||||
|
import cleanXoCache from './_cleanXoCache.mjs'
|
||||||
|
import loadConfig from './_loadConfig.mjs'
|
||||||
|
|
||||||
|
const { info, warn } = createLogger('xen-orchestra:immutable-backups:liftProtection')
|
||||||
|
|
||||||
|
async function liftRemoteImmutability(immutabilityCachePath, immutabilityDuration) {
|
||||||
|
for await (const { index, target } of listOlderTargets(immutabilityCachePath, immutabilityDuration)) {
|
||||||
|
await Directory.liftImmutability(target, immutabilityCachePath)
|
||||||
|
await fs.unlink(index)
|
||||||
|
await cleanXoCache(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function liftImmutability(remotes) {
|
||||||
|
for (const [remoteId, { indexPath, immutabilityDuration }] of Object.entries(remotes)) {
|
||||||
|
liftRemoteImmutability(indexPath, immutabilityDuration).catch(err =>
|
||||||
|
warn('error during watchRemote', { err, remoteId, indexPath, immutabilityDuration })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { liftEvery, remotes } = await loadConfig()
|
||||||
|
|
||||||
|
if (liftEvery > 0) {
|
||||||
|
info('setup watcher for immutability lifting')
|
||||||
|
setInterval(async () => {
|
||||||
|
liftImmutability(remotes)
|
||||||
|
}, liftEvery)
|
||||||
|
} else {
|
||||||
|
liftImmutability(remotes)
|
||||||
|
}
|
||||||
42
@xen-orchestra/immutable-backups/package.json
Normal file
42
@xen-orchestra/immutable-backups/package.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"private": false,
|
||||||
|
"name": "@xen-orchestra/immutable-backups",
|
||||||
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/immutable-backups",
|
||||||
|
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||||
|
"repository": {
|
||||||
|
"directory": "@xen-orchestra/immutable-backups",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "Vates SAS",
|
||||||
|
"url": "https://vates.fr"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"xo-immutable-remote": "./protectRemotes.mjs",
|
||||||
|
"xo-lift-remote-immutability": "./liftProtection.mjs"
|
||||||
|
},
|
||||||
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@vates/async-each": "^1.0.0",
|
||||||
|
"@xen-orchestra/backups": "^0.44.6",
|
||||||
|
"@xen-orchestra/log": "^0.6.0",
|
||||||
|
"app-conf": "^2.3.0",
|
||||||
|
"chokidar": "^3.5.3",
|
||||||
|
"execa": "^5.0.0",
|
||||||
|
"ms": "^2.1.3",
|
||||||
|
"vhd-lib": "^4.7.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"rimraf": "^5.0.5",
|
||||||
|
"tap": "^18.6.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"postversion": "npm publish --access public",
|
||||||
|
"test-integration": "tap *.integ.mjs"
|
||||||
|
}
|
||||||
|
}
|
||||||
191
@xen-orchestra/immutable-backups/protectRemotes.mjs
Executable file
191
@xen-orchestra/immutable-backups/protectRemotes.mjs
Executable file
@@ -0,0 +1,191 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import fs from 'node:fs/promises'
|
||||||
|
import * as File from './file.mjs'
|
||||||
|
import * as Directory from './directory.mjs'
|
||||||
|
import assert from 'node:assert'
|
||||||
|
import { dirname, join, sep } from 'node:path'
|
||||||
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
|
import chokidar from 'chokidar'
|
||||||
|
import { indexFile } from './fileIndex.mjs'
|
||||||
|
import cleanXoCache from './_cleanXoCache.mjs'
|
||||||
|
import loadConfig from './_loadConfig.mjs'
|
||||||
|
import isInVhdDirectory from './_isInVhdDirectory.mjs'
|
||||||
|
const { debug, info, warn } = createLogger('xen-orchestra:immutable-backups:remote')
|
||||||
|
|
||||||
|
async function test(remotePath, indexPath) {
|
||||||
|
await fs.readdir(remotePath)
|
||||||
|
|
||||||
|
const testPath = join(remotePath, '.test-immut')
|
||||||
|
// cleanup
|
||||||
|
try {
|
||||||
|
await File.liftImmutability(testPath, indexPath)
|
||||||
|
await fs.unlink(testPath)
|
||||||
|
} catch (err) {}
|
||||||
|
// can create , modify and delete a file
|
||||||
|
await fs.writeFile(testPath, `test immut ${new Date()}`)
|
||||||
|
await fs.writeFile(testPath, `test immut change 1 ${new Date()}`)
|
||||||
|
await fs.unlink(testPath)
|
||||||
|
|
||||||
|
// cannot modify or delete an immutable file
|
||||||
|
await fs.writeFile(testPath, `test immut ${new Date()}`)
|
||||||
|
await File.makeImmutable(testPath, indexPath)
|
||||||
|
await assert.rejects(fs.writeFile(testPath, `test immut change 2 ${new Date()}`), { code: 'EPERM' })
|
||||||
|
await assert.rejects(fs.unlink(testPath), { code: 'EPERM' })
|
||||||
|
// can modify and delete a file after lifting immutability
|
||||||
|
await File.liftImmutability(testPath, indexPath)
|
||||||
|
|
||||||
|
await fs.writeFile(testPath, `test immut change 3 ${new Date()}`)
|
||||||
|
await fs.unlink(testPath)
|
||||||
|
}
|
||||||
|
async function handleExistingFile(root, indexPath, path) {
|
||||||
|
try {
|
||||||
|
// a vhd block directory is completly immutable
|
||||||
|
if (isInVhdDirectory(path)) {
|
||||||
|
// this will trigger 3 times per vhd blocks
|
||||||
|
const dir = join(root, dirname(path))
|
||||||
|
if (Directory.isImmutable(dir)) {
|
||||||
|
await indexFile(dir, indexPath)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// other files are immutable a file basis
|
||||||
|
const fullPath = join(root, path)
|
||||||
|
if (File.isImmutable(fullPath)) {
|
||||||
|
await indexFile(fullPath, indexPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code !== 'EEXIST') {
|
||||||
|
// there can be a symbolic link in the tree
|
||||||
|
warn('handleExistingFile', { error })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleNewFile(root, indexPath, pendingVhds, path) {
|
||||||
|
// with awaitWriteFinish we have complete files here
|
||||||
|
// we can make them immutable
|
||||||
|
|
||||||
|
if (isInVhdDirectory(path)) {
|
||||||
|
// watching a vhd block
|
||||||
|
// wait for header/footer and BAT before making this immutable recursively
|
||||||
|
const splitted = path.split(sep)
|
||||||
|
const vmUuid = splitted[1]
|
||||||
|
const vdiUuid = splitted[4]
|
||||||
|
const uniqPath = `${vmUuid}/${vdiUuid}`
|
||||||
|
const { existing } = pendingVhds.get(uniqPath) ?? {}
|
||||||
|
if (existing === undefined) {
|
||||||
|
pendingVhds.set(uniqPath, { existing: 1, lastModified: Date.now() })
|
||||||
|
} else {
|
||||||
|
// already two of the key files,and we got the last one
|
||||||
|
if (existing === 2) {
|
||||||
|
await Directory.makeImmutable(join(root, dirname(path)), indexPath)
|
||||||
|
pendingVhds.delete(uniqPath)
|
||||||
|
} else {
|
||||||
|
// wait for the other
|
||||||
|
pendingVhds.set(uniqPath, { existing: existing + 1, lastModified: Date.now() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const fullFilePath = join(root, path)
|
||||||
|
await File.makeImmutable(fullFilePath, indexPath)
|
||||||
|
await cleanXoCache(fullFilePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export async function watchRemote(remoteId, { root, immutabilityDuration, rebuildIndexOnStart = false, indexPath }) {
|
||||||
|
// create index directory
|
||||||
|
await fs.mkdir(indexPath, { recursive: true })
|
||||||
|
|
||||||
|
// test if fs and index directories are well configured
|
||||||
|
await test(root, indexPath)
|
||||||
|
|
||||||
|
// add duration and watch status in the metadata.json of the remote
|
||||||
|
const settingPath = join(root, 'immutability.json')
|
||||||
|
try {
|
||||||
|
// this file won't be made mutable by liftimmutability
|
||||||
|
await File.liftImmutability(settingPath)
|
||||||
|
} catch (error) {
|
||||||
|
// file may not exists, and it's not really a problem
|
||||||
|
info('lifting immutability on current settings', { error })
|
||||||
|
}
|
||||||
|
await fs.writeFile(
|
||||||
|
settingPath,
|
||||||
|
JSON.stringify({
|
||||||
|
since: Date.now(),
|
||||||
|
immutable: true,
|
||||||
|
duration: immutabilityDuration,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
// no index path in makeImmutable(): the immutability won't be lifted
|
||||||
|
File.makeImmutable(settingPath)
|
||||||
|
|
||||||
|
// we wait for footer/header AND BAT to be written before locking a vhd directory
|
||||||
|
// this map allow us to track the vhd with partial metadata
|
||||||
|
const pendingVhds = new Map()
|
||||||
|
// cleanup pending vhd map periodically
|
||||||
|
setInterval(
|
||||||
|
() => {
|
||||||
|
pendingVhds.forEach(({ lastModified, existing }, path) => {
|
||||||
|
if (Date.now() - lastModified > 60 * 60 * 1000) {
|
||||||
|
pendingVhds.delete(path)
|
||||||
|
warn(`vhd at ${path} is incomplete since ${lastModified}`, { existing, lastModified, path })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
60 * 60 * 1000
|
||||||
|
)
|
||||||
|
|
||||||
|
// watch the remote for any new VM metadata json file
|
||||||
|
const PATHS = [
|
||||||
|
'xo-config-backups/*/*/data',
|
||||||
|
'xo-config-backups/*/*/data.json',
|
||||||
|
'xo-config-backups/*/*/metadata.json',
|
||||||
|
'xo-pool-metadata-backups/*/metadata.json',
|
||||||
|
'xo-pool-metadata-backups/*/data',
|
||||||
|
// xo-vm-backups/<vmuuid>/
|
||||||
|
'xo-vm-backups/*/*.json',
|
||||||
|
'xo-vm-backups/*/*.xva',
|
||||||
|
'xo-vm-backups/*/*.xva.checksum',
|
||||||
|
// xo-vm-backups/<vmuuid>/vdis/<jobid>/<vdiUuid>
|
||||||
|
'xo-vm-backups/*/vdis/*/*/*.vhd', // can be an alias or a vhd file
|
||||||
|
// for vhd directory :
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/bat',
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/header',
|
||||||
|
'xo-vm-backups/*/vdis/*/*/data/*.vhd/footer',
|
||||||
|
]
|
||||||
|
|
||||||
|
let ready = false
|
||||||
|
const watcher = chokidar.watch(PATHS, {
|
||||||
|
ignored: [
|
||||||
|
/(^|[/\\])\../, // ignore dotfiles
|
||||||
|
/\.lock$/,
|
||||||
|
],
|
||||||
|
cwd: root,
|
||||||
|
recursive: false, // vhd directory can generate a lot of folder, don't let chokidar choke on this
|
||||||
|
ignoreInitial: !rebuildIndexOnStart,
|
||||||
|
depth: 7,
|
||||||
|
awaitWriteFinish: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Add event listeners.
|
||||||
|
watcher
|
||||||
|
.on('add', async path => {
|
||||||
|
debug(`File ${path} has been added ${path.split('/').length}`)
|
||||||
|
if (ready) {
|
||||||
|
await handleNewFile(root, indexPath, pendingVhds, path)
|
||||||
|
} else {
|
||||||
|
await handleExistingFile(root, indexPath, path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on('error', error => warn(`Watcher error: ${error}`))
|
||||||
|
.on('ready', () => {
|
||||||
|
ready = true
|
||||||
|
info('Ready for changes')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const { remotes } = await loadConfig()
|
||||||
|
|
||||||
|
for (const [remoteId, remote] of Object.entries(remotes)) {
|
||||||
|
watchRemote(remoteId, remote).catch(err => warn('error during watchRemote', { err, remoteId, remote }))
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
/* eslint-env node */
|
|
||||||
require("@rushstack/eslint-patch/modern-module-resolution");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
globals: {
|
|
||||||
XO_LITE_GIT_HEAD: true,
|
|
||||||
XO_LITE_VERSION: true,
|
|
||||||
},
|
|
||||||
root: true,
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
"plugin:vue/vue3-essential",
|
|
||||||
"eslint:recommended",
|
|
||||||
"@vue/eslint-config-typescript/recommended",
|
|
||||||
"@vue/eslint-config-prettier",
|
|
||||||
],
|
|
||||||
plugins: ["@limegrass/import-alias"],
|
|
||||||
ignorePatterns: ["scripts/*.mjs"],
|
|
||||||
rules: {
|
|
||||||
"@typescript-eslint/no-non-null-assertion": "off",
|
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
|
||||||
"@limegrass/import-alias/import-alias": [
|
|
||||||
"error",
|
|
||||||
{ aliasConfigPath: require("path").join(__dirname, "tsconfig.json") },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// Keeping this file to prevent applying the global monorepo config for now
|
|
||||||
module.exports = {
|
|
||||||
trailingComma: "es5",
|
|
||||||
};
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
## **next**
|
## **next**
|
||||||
|
|
||||||
- Fix Typescript typings errors when running `yarn type-check` command (PR [#7278](https://github.com/vatesfr/xen-orchestra/pull/7278))
|
- Fix Typescript typings errors when running `yarn type-check` command (PR [#7278](https://github.com/vatesfr/xen-orchestra/pull/7278))
|
||||||
|
- Introduce PWA Json Manifest (PR [#7291](https://github.com/vatesfr/xen-orchestra/pull/7291))
|
||||||
|
|
||||||
## **0.1.7** (2023-12-28)
|
## **0.1.7** (2023-12-28)
|
||||||
|
|
||||||
|
|||||||
@@ -48,18 +48,16 @@ Note: When reading Vue official doc, don't forget to set "API Preference" toggle
|
|||||||
|
|
||||||
```vue
|
```vue
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
greetings: string;
|
greetings: string
|
||||||
}>();
|
}>()
|
||||||
|
|
||||||
const firstName = ref("");
|
const firstName = ref('')
|
||||||
const lastName = ref("");
|
const lastName = ref('')
|
||||||
|
|
||||||
const fullName = computed(
|
const fullName = computed(() => `${props.greetings} ${firstName.value} ${lastName.value}`)
|
||||||
() => `${props.greetings} ${firstName.value} ${lastName.value}`
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -73,9 +71,9 @@ Vue variables can be interpolated with `v-bind`.
|
|||||||
|
|
||||||
```vue
|
```vue
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from "vue";
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const fontSize = ref("2rem");
|
const fontSize = ref('2rem')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -105,8 +103,8 @@ Use the `busy` prop to display a loader icon.
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||||
import { faDisplay } from "@fortawesome/free-solid-svg-icons";
|
import { faDisplay } from '@fortawesome/free-solid-svg-icons'
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -140,21 +138,21 @@ For a `foobar` store, create a `store/foobar.store.ts` then use `defineStore('fo
|
|||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
export const useFoobarStore = defineStore("foobar", () => {
|
export const useFoobarStore = defineStore('foobar', () => {
|
||||||
const aStateVar = ref(0);
|
const aStateVar = ref(0)
|
||||||
const otherStateVar = ref(0);
|
const otherStateVar = ref(0)
|
||||||
const aGetter = computed(() => aStateVar.value * 2);
|
const aGetter = computed(() => aStateVar.value * 2)
|
||||||
const anAction = () => (otherStateVar.value += 10);
|
const anAction = () => (otherStateVar.value += 10)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
aStateVar,
|
aStateVar,
|
||||||
otherStateVar,
|
otherStateVar,
|
||||||
aGetter,
|
aGetter,
|
||||||
anAction,
|
anAction,
|
||||||
};
|
}
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### I18n
|
### I18n
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ In your `.story.vue` file, import and use the `ComponentStory` component.
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import MyComponent from "@/components/MyComponent.vue";
|
import MyComponent from '@/components/MyComponent.vue'
|
||||||
import ComponentStory from "@/components/component-story/ComponentStory.vue";
|
import ComponentStory from '@/components/component-story/ComponentStory.vue'
|
||||||
import { prop, event, model, slot, setting } from "@/libs/story/story-param";
|
import { prop, event, model, slot, setting } from '@/libs/story/story-param'
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -119,27 +119,27 @@ Let's take this Vue component:
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
imString: string;
|
imString: string
|
||||||
imNumber: number;
|
imNumber: number
|
||||||
imOptional?: string;
|
imOptional?: string
|
||||||
imOptionalWithDefault?: string;
|
imOptionalWithDefault?: string
|
||||||
modelValue?: string;
|
modelValue?: string
|
||||||
customModel?: number;
|
customModel?: number
|
||||||
}>(),
|
}>(),
|
||||||
{ imOptionalWithDefault: "Hi World" }
|
{ imOptionalWithDefault: 'Hi World' }
|
||||||
);
|
)
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(event: "click"): void;
|
(event: 'click'): void
|
||||||
(event: "clickWithArg", id: string): void;
|
(event: 'clickWithArg', id: string): void
|
||||||
(event: "update:modelValue", value: string): void;
|
(event: 'update:modelValue', value: string): void
|
||||||
(event: "update:customModel", value: number): void;
|
(event: 'update:customModel', value: number): void
|
||||||
}>();
|
}>()
|
||||||
|
|
||||||
const moonDistance = 384400;
|
const moonDistance = 384400
|
||||||
|
|
||||||
const handleClick = () => emit("click");
|
const handleClick = () => emit('click')
|
||||||
const handleClickWithArg = (id: string) => emit("clickWithArg", id);
|
const handleClickWithArg = (id: string) => emit('clickWithArg', id)
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -150,53 +150,33 @@ Here is how to document it with a Component Story:
|
|||||||
<ComponentStory
|
<ComponentStory
|
||||||
v-slot="{ properties, settings }"
|
v-slot="{ properties, settings }"
|
||||||
:params="[
|
:params="[
|
||||||
prop('imString')
|
prop('imString').str().required().preset('Example').widget().help('This is a required string prop'),
|
||||||
.str()
|
prop('imNumber').num().required().preset(42).widget().help('This is a required number prop'),
|
||||||
.required()
|
|
||||||
.preset('Example')
|
|
||||||
.widget()
|
|
||||||
.help('This is a required string prop'),
|
|
||||||
prop('imNumber')
|
|
||||||
.num()
|
|
||||||
.required()
|
|
||||||
.preset(42)
|
|
||||||
.widget()
|
|
||||||
.help('This is a required number prop'),
|
|
||||||
prop('imOptional').str().widget().help('This is an optional string prop'),
|
prop('imOptional').str().widget().help('This is an optional string prop'),
|
||||||
prop('imOptionalWithDefault')
|
prop('imOptionalWithDefault').str().default('Hi World').widget().default('My default value'),
|
||||||
.str()
|
model().prop(p => p.str()),
|
||||||
.default('Hi World')
|
model('customModel').prop(p => p.num()),
|
||||||
.widget()
|
|
||||||
.default('My default value'),
|
|
||||||
model().prop((p) => p.str()),
|
|
||||||
model('customModel').prop((p) => p.num()),
|
|
||||||
event('click').help('Emitted when the user clicks the first button'),
|
event('click').help('Emitted when the user clicks the first button'),
|
||||||
event('clickWithArg')
|
event('clickWithArg').args({ id: 'string' }).help('Emitted when the user clicks the second button'),
|
||||||
.args({ id: 'string' })
|
|
||||||
.help('Emitted when the user clicks the second button'),
|
|
||||||
slot().help('This is the default slot'),
|
slot().help('This is the default slot'),
|
||||||
slot('namedSlot').help('This is a named slot'),
|
slot('namedSlot').help('This is a named slot'),
|
||||||
slot('namedScopedSlot')
|
slot('namedScopedSlot').prop('moon-distance', 'number').help('This is a named slot'),
|
||||||
.prop('moon-distance', 'number')
|
|
||||||
.help('This is a named slot'),
|
|
||||||
setting('contentExample').widget(text()).preset('Some content'),
|
setting('contentExample').widget(text()).preset('Some content'),
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<MyComponent v-bind="properties">
|
<MyComponent v-bind="properties">
|
||||||
{{ settings.contentExample }}
|
{{ settings.contentExample }}
|
||||||
<template #named-slot>Named slot content</template>
|
<template #named-slot>Named slot content</template>
|
||||||
<template #named-scoped-slot="{ moonDistance }">
|
<template #named-scoped-slot="{ moonDistance }"> Moon distance is {{ moonDistance }} meters. </template>
|
||||||
Moon distance is {{ moonDistance }} meters.
|
|
||||||
</template>
|
|
||||||
</MyComponent>
|
</MyComponent>
|
||||||
</ComponentStory>
|
</ComponentStory>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import ComponentStory from "@/components/component-story/ComponentStory.vue";
|
import ComponentStory from '@/components/component-story/ComponentStory.vue'
|
||||||
import MyComponent from "@/components/MyComponent.vue";
|
import MyComponent from '@/components/MyComponent.vue'
|
||||||
import { event, model, prop, setting, slot } from "@/libs/story/story-param";
|
import { event, model, prop, setting, slot } from '@/libs/story/story-param'
|
||||||
import { text } from "@/libs/story/story-widget";
|
import { text } from '@/libs/story/story-widget'
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -20,45 +20,45 @@ This will return an object with the following methods:
|
|||||||
### Static modal
|
### Static modal
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
useModal(MyModal);
|
useModal(MyModal)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Modal with props
|
### Modal with props
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
useModal(MyModal, { message: "Hello world!" });
|
useModal(MyModal, { message: 'Hello world!' })
|
||||||
```
|
```
|
||||||
|
|
||||||
### Handle modal approval
|
### Handle modal approval
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const { onApprove } = useModal(MyModal, { message: "Hello world!" });
|
const { onApprove } = useModal(MyModal, { message: 'Hello world!' })
|
||||||
|
|
||||||
onApprove(() => console.log("Modal approved"));
|
onApprove(() => console.log('Modal approved'))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Handle modal approval with payload
|
### Handle modal approval with payload
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const { onApprove } = useModal(MyModal, { message: "Hello world!" });
|
const { onApprove } = useModal(MyModal, { message: 'Hello world!' })
|
||||||
|
|
||||||
onApprove((payload) => console.log("Modal approved with payload", payload));
|
onApprove(payload => console.log('Modal approved with payload', payload))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Handle modal decline
|
### Handle modal decline
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const { onDecline } = useModal(MyModal, { message: "Hello world!" });
|
const { onDecline } = useModal(MyModal, { message: 'Hello world!' })
|
||||||
|
|
||||||
onDecline(() => console.log("Modal declined"));
|
onDecline(() => console.log('Modal declined'))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Handle modal close
|
### Handle modal close
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const { onClose } = useModal(MyModal, { message: "Hello world!" });
|
const { onClose } = useModal(MyModal, { message: 'Hello world!' })
|
||||||
|
|
||||||
onClose(() => console.log("Modal closed"));
|
onClose(() => console.log('Modal closed'))
|
||||||
```
|
```
|
||||||
|
|
||||||
## Modal controller
|
## Modal controller
|
||||||
@@ -66,7 +66,7 @@ onClose(() => console.log("Modal closed"));
|
|||||||
Inside the modal component, you can inject the modal controller with `inject(IK_MODAL)!`.
|
Inside the modal component, you can inject the modal controller with `inject(IK_MODAL)!`.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const modal = inject(IK_MODAL)!;
|
const modal = inject(IK_MODAL)!
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then use the following properties and methods on the `modal` object:
|
You can then use the following properties and methods on the `modal` object:
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ They are stored in `src/composables/xen-api-collection/*-collection.composable.t
|
|||||||
```typescript
|
```typescript
|
||||||
// src/composables/xen-api-collection/console-collection.composable.ts
|
// src/composables/xen-api-collection/console-collection.composable.ts
|
||||||
|
|
||||||
export const useConsoleCollection = () => useXenApiCollection("console");
|
export const useConsoleCollection = () => useXenApiCollection('console')
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to allow the user to defer the subscription, you can propagate the options to `useXenApiCollection`.
|
If you want to allow the user to defer the subscription, you can propagate the options to `useXenApiCollection`.
|
||||||
@@ -44,19 +44,16 @@ If you want to allow the user to defer the subscription, you can propagate the o
|
|||||||
```typescript
|
```typescript
|
||||||
// console-collection.composable.ts
|
// console-collection.composable.ts
|
||||||
|
|
||||||
export const useConsoleCollection = <
|
export const useConsoleCollection = <Immediate extends boolean = true>(options?: { immediate?: Immediate }) =>
|
||||||
Immediate extends boolean = true,
|
useXenApiCollection('console', options)
|
||||||
>(options?: {
|
|
||||||
immediate?: Immediate;
|
|
||||||
}) => useXenApiCollection("console", options);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// MyComponent.vue
|
// MyComponent.vue
|
||||||
|
|
||||||
const collection = useConsoleCollection({ immediate: false });
|
const collection = useConsoleCollection({ immediate: false })
|
||||||
|
|
||||||
setTimeout(() => collection.start(), 10000);
|
setTimeout(() => collection.start(), 10000)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alter the collection
|
## Alter the collection
|
||||||
@@ -68,10 +65,10 @@ You can alter the collection by overriding parts of it.
|
|||||||
```typescript
|
```typescript
|
||||||
// xen-api.ts
|
// xen-api.ts
|
||||||
|
|
||||||
export interface XenApiConsole extends XenApiRecord<"console"> {
|
export interface XenApiConsole extends XenApiRecord<'console'> {
|
||||||
// ... existing props
|
// ... existing props
|
||||||
someProp: string;
|
someProp: string
|
||||||
someOtherProp: number;
|
someOtherProp: number
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -79,27 +76,27 @@ export interface XenApiConsole extends XenApiRecord<"console"> {
|
|||||||
// console-collection.composable.ts
|
// console-collection.composable.ts
|
||||||
|
|
||||||
export const useConsoleCollection = () => {
|
export const useConsoleCollection = () => {
|
||||||
const collection = useXenApiCollection("console");
|
const collection = useXenApiCollection('console')
|
||||||
|
|
||||||
const records = computed(() => {
|
const records = computed(() => {
|
||||||
return collection.records.value.map((console) => ({
|
return collection.records.value.map(console => ({
|
||||||
...console,
|
...console,
|
||||||
someProp: "Some value",
|
someProp: 'Some value',
|
||||||
someOtherProp: 42,
|
someOtherProp: 42,
|
||||||
}));
|
}))
|
||||||
});
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...collection,
|
...collection,
|
||||||
records,
|
records,
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const consoleCollection = useConsoleCollection();
|
const consoleCollection = useConsoleCollection()
|
||||||
|
|
||||||
consoleCollection.getByUuid("...").someProp; // "Some value"
|
consoleCollection.getByUuid('...').someProp // "Some value"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example 2: Adding props to the collection
|
### Example 2: Adding props to the collection
|
||||||
@@ -108,17 +105,13 @@ consoleCollection.getByUuid("...").someProp; // "Some value"
|
|||||||
// vm-collection.composable.ts
|
// vm-collection.composable.ts
|
||||||
|
|
||||||
export const useVmCollection = () => {
|
export const useVmCollection = () => {
|
||||||
const collection = useXenApiCollection("VM");
|
const collection = useXenApiCollection('VM')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...collection,
|
...collection,
|
||||||
runningVms: computed(() =>
|
runningVms: computed(() => collection.records.value.filter(vm => vm.power_state === POWER_STATE.RUNNING)),
|
||||||
collection.records.value.filter(
|
}
|
||||||
(vm) => vm.power_state === POWER_STATE.RUNNING
|
}
|
||||||
)
|
|
||||||
),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example 3, filtering and sorting the collection
|
### Example 3, filtering and sorting the collection
|
||||||
@@ -127,18 +120,15 @@ export const useVmCollection = () => {
|
|||||||
// vm-collection.composable.ts
|
// vm-collection.composable.ts
|
||||||
|
|
||||||
export const useVmCollection = () => {
|
export const useVmCollection = () => {
|
||||||
const collection = useXenApiCollection("VM");
|
const collection = useXenApiCollection('VM')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...collection,
|
...collection,
|
||||||
records: computed(() =>
|
records: computed(() =>
|
||||||
collection.records.value
|
collection.records.value
|
||||||
.filter(
|
.filter(vm => !vm.is_a_snapshot && !vm.is_a_template && !vm.is_control_domain)
|
||||||
(vm) =>
|
|
||||||
!vm.is_a_snapshot && !vm.is_a_template && !vm.is_control_domain
|
|
||||||
)
|
|
||||||
.sort((vm1, vm2) => vm1.name_label.localeCompare(vm2.name_label))
|
.sort((vm1, vm2) => vm1.name_label.localeCompare(vm2.name_label))
|
||||||
),
|
),
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
4
@xen-orchestra/lite/env.d.ts
vendored
4
@xen-orchestra/lite/env.d.ts
vendored
@@ -2,5 +2,5 @@
|
|||||||
/// <reference types="json-rpc-2.0/dist" />
|
/// <reference types="json-rpc-2.0/dist" />
|
||||||
/// <reference types="vite-plugin-pages/client" />
|
/// <reference types="vite-plugin-pages/client" />
|
||||||
|
|
||||||
declare const XO_LITE_VERSION: string;
|
declare const XO_LITE_VERSION: string
|
||||||
declare const XO_LITE_GIT_HEAD: string;
|
declare const XO_LITE_GIT_HEAD: string
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||||
|
<link rel="manifest" href="/manifest.webmanifest" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>XO Lite</title>
|
<title>XO Lite</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -1,43 +1,42 @@
|
|||||||
{
|
{
|
||||||
"name": "@xen-orchestra/lite",
|
"name": "@xen-orchestra/lite",
|
||||||
"version": "0.1.7",
|
"version": "0.1.7",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
|
"dev": "GIT_HEAD=$(git rev-parse HEAD) vite",
|
||||||
"build": "run-p type-check build-only",
|
"build": "run-p type-check build-only",
|
||||||
"preview": "vite preview --port 4173",
|
"preview": "vite preview --port 4173",
|
||||||
"release": "zx ./scripts/release.mjs",
|
"release": "./scripts/release.mjs",
|
||||||
"build-only": "yarn release --build",
|
"build-only": "yarn release --build",
|
||||||
"deploy": "yarn release --build --deploy",
|
"deploy": "yarn release --build --deploy",
|
||||||
"gh-release": "yarn release --build --tarball --gh-release",
|
"gh-release": "yarn release --build --tarball --gh-release",
|
||||||
"test": "yarn run type-check",
|
"test": "yarn run type-check",
|
||||||
"type-check": "vue-tsc --noEmit"
|
"type-check": "vue-tsc --build --force tsconfig.type-check.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@csstools/postcss-global-data": "^2.1.1",
|
||||||
"@fontsource/poppins": "^5.0.8",
|
"@fontsource/poppins": "^5.0.8",
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.4.2",
|
"@fortawesome/fontawesome-svg-core": "^6.5.1",
|
||||||
"@fortawesome/free-regular-svg-icons": "^6.4.2",
|
"@fortawesome/free-regular-svg-icons": "^6.5.1",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
"@fortawesome/free-solid-svg-icons": "^6.5.1",
|
||||||
"@fortawesome/vue-fontawesome": "^3.0.5",
|
"@fortawesome/vue-fontawesome": "^3.0.5",
|
||||||
"@intlify/unplugin-vue-i18n": "^1.5.0",
|
"@intlify/unplugin-vue-i18n": "^2.0.0",
|
||||||
"@limegrass/eslint-plugin-import-alias": "^1.1.0",
|
|
||||||
"@novnc/novnc": "^1.4.0",
|
"@novnc/novnc": "^1.4.0",
|
||||||
"@rushstack/eslint-patch": "^1.5.1",
|
|
||||||
"@tsconfig/node18": "^18.2.2",
|
"@tsconfig/node18": "^18.2.2",
|
||||||
"@types/d3-time-format": "^4.0.3",
|
"@types/d3-time-format": "^4.0.3",
|
||||||
"@types/file-saver": "^2.0.7",
|
"@types/file-saver": "^2.0.7",
|
||||||
"@types/lodash-es": "^4.17.11",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^18.18.9",
|
"@types/node": "^18.19.7",
|
||||||
"@vitejs/plugin-vue": "^4.4.0",
|
"@vitejs/plugin-vue": "^5.0.3",
|
||||||
"@vue/eslint-config-prettier": "^8.0.0",
|
"@vue/tsconfig": "^0.5.1",
|
||||||
"@vue/eslint-config-typescript": "^12.0.0",
|
"@vueuse/core": "^10.7.1",
|
||||||
"@vue/tsconfig": "^0.4.0",
|
"@vueuse/math": "^10.7.1",
|
||||||
"@vueuse/core": "^10.5.0",
|
"@vueuse/shared": "^10.7.1",
|
||||||
"@vueuse/math": "^10.5.0",
|
"@xen-orchestra/web-core": "*",
|
||||||
"complex-matcher": "^0.7.1",
|
"complex-matcher": "^0.7.1",
|
||||||
"d3-time-format": "^4.1.0",
|
"d3-time-format": "^4.1.0",
|
||||||
"decorator-synchronized": "^0.6.0",
|
"decorator-synchronized": "^0.6.0",
|
||||||
"echarts": "^5.4.3",
|
"echarts": "^5.4.3",
|
||||||
"eslint-plugin-vue": "^9.18.1",
|
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"human-format": "^1.2.0",
|
"human-format": "^1.2.0",
|
||||||
@@ -48,19 +47,21 @@
|
|||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"make-error": "^1.3.6",
|
"make-error": "^1.3.6",
|
||||||
"marked": "^9.1.5",
|
"marked": "^9.1.5",
|
||||||
|
"minimist": "^1.2.8",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"placement.js": "^1.0.0-beta.5",
|
"placement.js": "^1.0.0-beta.5",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.33",
|
||||||
|
"postcss-color-function": "^4.1.0",
|
||||||
"postcss-custom-media": "^10.0.2",
|
"postcss-custom-media": "^10.0.2",
|
||||||
"postcss-nested": "^6.0.1",
|
"postcss-nested": "^6.0.1",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "~5.3.3",
|
||||||
"vite": "^4.5.0",
|
"vite": "^5.0.11",
|
||||||
"vue": "^3.3.8",
|
"vue": "^3.4.13",
|
||||||
"vue-echarts": "^6.6.1",
|
"vue-echarts": "^6.6.8",
|
||||||
"vue-i18n": "^9.6.5",
|
"vue-i18n": "^9.9.0",
|
||||||
"vue-router": "^4.2.5",
|
"vue-router": "^4.2.5",
|
||||||
"vue-tsc": "^1.8.22",
|
"vue-tsc": "^1.8.27",
|
||||||
"zx": "^7.2.3"
|
"zx": "^7.2.3"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: {
|
|
||||||
"postcss-nested": {},
|
|
||||||
"postcss-custom-media": {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
10
@xen-orchestra/lite/postcss.config.mjs
Normal file
10
@xen-orchestra/lite/postcss.config.mjs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
'@csstools/postcss-global-data': {
|
||||||
|
files: ['../web-core/lib/assets/css/.globals.pcss'],
|
||||||
|
},
|
||||||
|
'postcss-nested': {},
|
||||||
|
'postcss-custom-media': {},
|
||||||
|
'postcss-color-function': {},
|
||||||
|
},
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
14
@xen-orchestra/lite/public/manifest.webmanifest
Normal file
14
@xen-orchestra/lite/public/manifest.webmanifest
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "XO Lite",
|
||||||
|
"short_name": "XOLite",
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"description": "Integrated local and lightweight solution to manage a local XCP-ng pool.",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.svg",
|
||||||
|
"sizes": "any",
|
||||||
|
"type": "image/svg+xml"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
281
@xen-orchestra/lite/scripts/release.mjs
Normal file → Executable file
281
@xen-orchestra/lite/scripts/release.mjs
Normal file → Executable file
@@ -1,53 +1,34 @@
|
|||||||
#!/usr/bin/env zx
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import argv from "minimist";
|
import argv from 'minimist'
|
||||||
import { tmpdir } from "os";
|
import { tmpdir } from 'os'
|
||||||
|
import { fileURLToPath, URL } from 'url'
|
||||||
|
import { $, cd, chalk, fs, path, question, within } from 'zx'
|
||||||
|
|
||||||
$.verbose = false;
|
$.verbose = false
|
||||||
|
|
||||||
const DEPLOY_SERVER = "www-xo.gpn.vates.fr";
|
const DEPLOY_SERVER = 'www-xo.gpn.vates.fr'
|
||||||
|
|
||||||
const { version: pkgVersion } = await fs.readJson("./package.json");
|
const { version: pkgVersion } = await fs.readJson('./package.json')
|
||||||
|
|
||||||
const opts = argv(process.argv, {
|
const opts = argv(process.argv, {
|
||||||
boolean: ["help", "build", "deploy", "ghRelease", "tarball"],
|
boolean: ['help', 'build', 'deploy', 'ghRelease', 'tarball'],
|
||||||
string: [
|
string: ['base', 'dist', 'ghToken', 'tarballDest', 'tarballName', 'username', 'version'],
|
||||||
"base",
|
|
||||||
"dist",
|
|
||||||
"ghToken",
|
|
||||||
"tarballDest",
|
|
||||||
"tarballName",
|
|
||||||
"username",
|
|
||||||
"version",
|
|
||||||
],
|
|
||||||
alias: {
|
alias: {
|
||||||
u: "username",
|
u: 'username',
|
||||||
h: "help",
|
h: 'help',
|
||||||
"gh-release": "ghRelease",
|
'gh-release': 'ghRelease',
|
||||||
"gh-token": "ghToken",
|
'gh-token': 'ghToken',
|
||||||
"tarball-dest": "tarballDest",
|
'tarball-dest': 'tarballDest',
|
||||||
"tarball-name": "tarballName",
|
'tarball-name': 'tarballName',
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
dist: "dist",
|
dist: 'dist',
|
||||||
version: pkgVersion,
|
version: pkgVersion,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
let {
|
let { base, build, deploy, dist, ghRelease, ghToken, help, tarball, tarballDest, tarballName, username, version } = opts
|
||||||
base,
|
|
||||||
build,
|
|
||||||
deploy,
|
|
||||||
dist,
|
|
||||||
ghRelease,
|
|
||||||
ghToken,
|
|
||||||
help,
|
|
||||||
tarball,
|
|
||||||
tarballDest,
|
|
||||||
tarballName,
|
|
||||||
username,
|
|
||||||
version,
|
|
||||||
} = opts;
|
|
||||||
|
|
||||||
const usage = () => {
|
const usage = () => {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -78,172 +59,164 @@ const usage = () => {
|
|||||||
--username|-u <LDAP username>
|
--username|-u <LDAP username>
|
||||||
]
|
]
|
||||||
`
|
`
|
||||||
);
|
)
|
||||||
};
|
|
||||||
|
|
||||||
if (help) {
|
|
||||||
usage();
|
|
||||||
process.exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const yes = async (q) =>
|
if (help) {
|
||||||
["y", "yes"].includes((await question(q + " [y/N] ")).toLowerCase());
|
usage()
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
const no = async (q) => !(await yes(q));
|
const yes = async q => ['y', 'yes'].includes((await question(q + ' [y/N] ')).toLowerCase())
|
||||||
|
|
||||||
const step = (s) => console.log(chalk.green.bold(`\n${s}\n`));
|
const no = async q => !(await yes(q))
|
||||||
|
|
||||||
|
const step = s => console.log(chalk.green.bold(`\n${s}\n`))
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
console.log(chalk.yellow("Stopping"));
|
console.log(chalk.yellow('Stopping'))
|
||||||
process.exit(0);
|
process.exit(0)
|
||||||
};
|
}
|
||||||
|
|
||||||
const ghApiCall = async (path, method = "GET", data) => {
|
const ghApiCall = async (path, method = 'GET', data) => {
|
||||||
const opts = {
|
const opts = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/vnd.github+json",
|
Accept: 'application/vnd.github+json',
|
||||||
Authorization: `Bearer ${ghToken}`,
|
Authorization: `Bearer ${ghToken}`,
|
||||||
"X-GitHub-Api-Version": "2022-11-28",
|
'X-GitHub-Api-Version': '2022-11-28',
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
if (data !== undefined) {
|
|
||||||
opts.body = typeof data === "object" ? JSON.stringify(data) : data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(
|
if (data !== undefined) {
|
||||||
"https://api.github.com/repos/vatesfr/xen-orchestra" + path,
|
opts.body = typeof data === 'object' ? JSON.stringify(data) : data
|
||||||
opts
|
}
|
||||||
);
|
|
||||||
|
const res = await fetch('https://api.github.com/repos/vatesfr/xen-orchestra' + path, opts)
|
||||||
|
|
||||||
if (res.status === 404 || res.status === 422) {
|
if (res.status === 404 || res.status === 422) {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.log(chalk.red(await res.text()));
|
console.log(chalk.red(await res.text()))
|
||||||
throw new Error(`GitHub API error: ${res.statusText}`);
|
throw new Error(`GitHub API error: ${res.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Return undefined if response is not JSON
|
// Return undefined if response is not JSON
|
||||||
return JSON.parse(await res.text());
|
return JSON.parse(await res.text())
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
}
|
||||||
|
|
||||||
const ghApiUploadReleaseAsset = async (releaseId, assetName, file) => {
|
const ghApiUploadReleaseAsset = async (releaseId, assetName, file) => {
|
||||||
const opts = {
|
const opts = {
|
||||||
method: "POST",
|
method: 'POST',
|
||||||
body: fs.createReadStream(file),
|
body: fs.createReadStream(file),
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/vnd.github+json",
|
Accept: 'application/vnd.github+json',
|
||||||
Authorization: `Bearer ${ghToken}`,
|
Authorization: `Bearer ${ghToken}`,
|
||||||
"Content-Length": (await fs.stat(file)).size,
|
'Content-Length': (await fs.stat(file)).size,
|
||||||
"Content-Type": "application/vnd.cncf.helm.chart.content.v1.tar+gzip",
|
'Content-Type': 'application/vnd.cncf.helm.chart.content.v1.tar+gzip',
|
||||||
"X-GitHub-Api-Version": "2022-11-28",
|
'X-GitHub-Api-Version': '2022-11-28',
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`https://uploads.github.com/repos/vatesfr/xen-orchestra/releases/${releaseId}/assets?name=${encodeURIComponent(
|
`https://uploads.github.com/repos/vatesfr/xen-orchestra/releases/${releaseId}/assets?name=${encodeURIComponent(
|
||||||
assetName
|
assetName
|
||||||
)}`,
|
)}`,
|
||||||
opts
|
opts
|
||||||
);
|
)
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.log(chalk.red(await res.text()));
|
console.log(chalk.red(await res.text()))
|
||||||
throw new Error(`GitHub API error: ${res.statusText}`);
|
throw new Error(`GitHub API error: ${res.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.parse(await res.text());
|
return JSON.parse(await res.text())
|
||||||
};
|
}
|
||||||
|
|
||||||
// Validate args and assign defaults -------------------------------------------
|
// Validate args and assign defaults -------------------------------------------
|
||||||
|
|
||||||
const headSha = (await $`git rev-parse HEAD`).stdout.trim();
|
const headSha = (await $`git rev-parse HEAD`).stdout.trim()
|
||||||
|
|
||||||
if (!build && !deploy && !tarball && !ghRelease) {
|
if (!build && !deploy && !tarball && !ghRelease) {
|
||||||
console.log(
|
console.log(chalk.yellow('Nothing to do! Use --build, --deploy, --tarball and/or --gh-release'))
|
||||||
chalk.yellow(
|
process.exit(0)
|
||||||
"Nothing to do! Use --build, --deploy, --tarball and/or --gh-release"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deploy && ghRelease) {
|
if (deploy && ghRelease) {
|
||||||
throw new Error("--deploy and --gh-release cannot be used together");
|
throw new Error('--deploy and --gh-release cannot be used together')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deploy && username === undefined) {
|
if (deploy && username === undefined) {
|
||||||
throw new Error("--username is required when --deploy is used");
|
throw new Error('--username is required when --deploy is used')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ghRelease && ghToken === undefined) {
|
if (ghRelease && ghToken === undefined) {
|
||||||
throw new Error("--gh-token is required to upload a release to GitHub");
|
throw new Error('--gh-token is required to upload a release to GitHub')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base === undefined) {
|
if (base === undefined) {
|
||||||
base = deploy ? "https://lite.xen-orchestra.com/dist/" : "/";
|
base = deploy ? 'https://lite.xen-orchestra.com/dist/' : '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tarball) {
|
if (tarball) {
|
||||||
if (tarballDest === undefined) {
|
if (tarballDest === undefined) {
|
||||||
tarballDest = path.join(tmpdir(), `xo-lite-${new Date().toISOString()}`);
|
tarballDest = path.join(tmpdir(), `xo-lite-${new Date().toISOString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tarballName === undefined) {
|
if (tarballName === undefined) {
|
||||||
tarballName = `xo-lite-${version}.tar.gz`;
|
tarballName = `xo-lite-${version}.tar.gz`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tarballDest !== undefined) {
|
if (tarballDest !== undefined) {
|
||||||
tarballDest = path.resolve(tarballDest);
|
tarballDest = path.resolve(tarballDest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ghRelease && (tarballDest === undefined || tarballName === undefined)) {
|
if (ghRelease && (tarballDest === undefined || tarballName === undefined)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"In order to release to GitHub, either use --tarball to generate the tarball or provide the tarball with --tarball-dest and --tarball-name"
|
'In order to release to GitHub, either use --tarball to generate the tarball or provide the tarball with --tarball-dest and --tarball-name'
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let tarballPath;
|
let tarballPath
|
||||||
let tarballExists = false;
|
let tarballExists = false
|
||||||
if (tarballDest !== undefined && tarballName !== undefined) {
|
if (tarballDest !== undefined && tarballName !== undefined) {
|
||||||
tarballPath = path.join(tarballDest, tarballName);
|
tarballPath = path.join(tarballDest, tarballName)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((await fs.stat(tarballPath)).isFile()) {
|
if ((await fs.stat(tarballPath)).isFile()) {
|
||||||
tarballExists = true;
|
tarballExists = true
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== 'ENOENT') {
|
||||||
throw err;
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ghRelease && !tarball && !tarballExists) {
|
if (ghRelease && !tarball && !tarballExists) {
|
||||||
throw new Error(`No such file ${tarballPath}`);
|
throw new Error(`No such file ${tarballPath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tarball && tarballExists) {
|
if (tarball && tarballExists) {
|
||||||
if (await no(`Tarball ${tarballPath} already exists. Overwrite?`)) {
|
if (await no(`Tarball ${tarballPath} already exists. Overwrite?`)) {
|
||||||
stop();
|
stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tag = `xo-lite-v${version}`;
|
const tag = `xo-lite-v${version}`
|
||||||
if (ghRelease) {
|
if (ghRelease) {
|
||||||
const remoteTag = await ghApiCall(`/git/ref/tags/${encodeURIComponent(tag)}`);
|
const remoteTag = await ghApiCall(`/git/ref/tags/${encodeURIComponent(tag)}`)
|
||||||
|
|
||||||
if (remoteTag === undefined) {
|
if (remoteTag === undefined) {
|
||||||
if ((await ghApiCall(`/commits/${headSha}`)) === undefined) {
|
if ((await ghApiCall(`/commits/${headSha}`)) === undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Tag ${tag} and commit ${headSha} not found on GitHub. At least one needs to exist to use it as a release target.`
|
`Tag ${tag} and commit ${headSha} not found on GitHub. At least one needs to exist to use it as a release target.`
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -251,7 +224,7 @@ if (ghRelease) {
|
|||||||
`Tag ${tag} not found on GitHub. The GitHub release will be attached to the current commit and the tag will be created automatically when the release is published. Continue?`
|
`Tag ${tag} not found on GitHub. The GitHub release will be attached to the current commit and the tag will be created automatically when the release is published. Continue?`
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
stop();
|
stop()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
@@ -260,17 +233,14 @@ if (ghRelease) {
|
|||||||
`Commit SHA of tag ${tag} on GitHub (${remoteTag.object.sha}) is different from current commit SHA (${headSha}). Continue?`
|
`Commit SHA of tag ${tag} on GitHub (${remoteTag.object.sha}) is different from current commit SHA (${headSha}). Continue?`
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
stop();
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(await $`git tag --points-at HEAD`).stdout
|
!(await $`git tag --points-at HEAD`).stdout.trim().split('\n').includes(tag) &&
|
||||||
.trim()
|
|
||||||
.split("\n")
|
|
||||||
.includes(tag) &&
|
|
||||||
(await no(`Tag ${tag} not found on current commit. Continue?`))
|
(await no(`Tag ${tag} not found on current commit. Continue?`))
|
||||||
) {
|
) {
|
||||||
stop();
|
stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,67 +248,62 @@ if (ghRelease) {
|
|||||||
// Build -----------------------------------------------------------------------
|
// Build -----------------------------------------------------------------------
|
||||||
|
|
||||||
if (build) {
|
if (build) {
|
||||||
step("Build");
|
step('Build')
|
||||||
|
|
||||||
console.log(`Building XO Lite ${version} into ${dist}`);
|
console.log(`Building XO Lite ${version} into ${dist}`)
|
||||||
|
|
||||||
$.verbose = true;
|
$.verbose = true
|
||||||
await within(async () => {
|
await within(async () => {
|
||||||
cd("../..");
|
cd('../..')
|
||||||
await $`yarn`;
|
await $`yarn`
|
||||||
});
|
})
|
||||||
await $`GIT_HEAD=${headSha} vite build --base=${base}`;
|
await $`GIT_HEAD=${headSha} vite build --base=${base}`
|
||||||
$.verbose = false;
|
$.verbose = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// License and index.js --------------------------------------------------------
|
// License and index.js --------------------------------------------------------
|
||||||
|
|
||||||
if (ghRelease || deploy) {
|
if (ghRelease || deploy) {
|
||||||
step("Prepare dist");
|
step('Prepare dist')
|
||||||
|
|
||||||
if (ghRelease) {
|
if (ghRelease) {
|
||||||
console.log(`Adding LICENSE file to ${dist}`);
|
console.log(`Adding LICENSE file to ${dist}`)
|
||||||
|
await fs.copy(fileURLToPath(new URL('agpl-3.0.txt', import.meta.url)), path.join(dist, 'LICENSE'))
|
||||||
await fs.copy(
|
|
||||||
path.join(__dirname, "agpl-3.0.txt"),
|
|
||||||
path.join(dist, "LICENSE")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deploy) {
|
if (deploy) {
|
||||||
console.log(`Adding index.js file to ${dist}`);
|
console.log(`Adding index.js file to ${dist}`)
|
||||||
|
|
||||||
// Concatenate a URL (absolute or relative) and paths
|
// Concatenate a URL (absolute or relative) and paths
|
||||||
// e.g.: joinUrl('http://example.com/', 'foo/bar') => 'http://example.com/foo/bar
|
// e.g.: joinUrl('http://example.com/', 'foo/bar') => 'http://example.com/foo/bar
|
||||||
// `path.join` isn't made for URLs and deduplicates the slashes in URL
|
// `path.join` isn't made for URLs and deduplicates the slashes in URL
|
||||||
// schemes (http:// becomes http:/). `.replace()` reverts this.
|
// schemes (http:// becomes http:/). `.replace()` reverts this.
|
||||||
const joinUrl = (...parts) =>
|
const joinUrl = (...parts) => path.join(...parts).replace(/^(https?:\/)/, '$1/')
|
||||||
path.join(...parts).replace(/^(https?:\/)/, "$1/");
|
|
||||||
|
|
||||||
// Use of document.write is discouraged but seems to work consistently.
|
// Use of document.write is discouraged but seems to work consistently.
|
||||||
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document.write()
|
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#document.write()
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.join(dist, "index.js"),
|
path.join(dist, 'index.js'),
|
||||||
`(async () => {
|
`(async () => {
|
||||||
document.open();
|
document.open();
|
||||||
document.write(
|
document.write(
|
||||||
await (await fetch("${joinUrl(base, "index.html")}")).text()
|
await (await fetch("${joinUrl(base, 'index.html')}")).text()
|
||||||
);
|
);
|
||||||
document.close();
|
document.close();
|
||||||
})();
|
})();
|
||||||
`
|
`
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarball ---------------------------------------------------------------------
|
// Tarball ---------------------------------------------------------------------
|
||||||
|
|
||||||
if (tarball) {
|
if (tarball) {
|
||||||
step("Tarball");
|
step('Tarball')
|
||||||
|
|
||||||
console.log(`Generating tarball ${tarballPath}`);
|
console.log(`Generating tarball ${tarballPath}`)
|
||||||
|
|
||||||
await fs.mkdirp(tarballDest);
|
await fs.mkdirp(tarballDest)
|
||||||
|
|
||||||
// The file is called xo-lite-X.Y.Z.tar.gz by default
|
// The file is called xo-lite-X.Y.Z.tar.gz by default
|
||||||
// The archive contains the following tree:
|
// The archive contains the following tree:
|
||||||
@@ -348,17 +313,15 @@ if (tarball) {
|
|||||||
// ├ index.html
|
// ├ index.html
|
||||||
// ├ assets/
|
// ├ assets/
|
||||||
// └ ...
|
// └ ...
|
||||||
await $`tar -c -z -f ${tarballPath} --transform='s|^${dist}|xo-lite-${version}|' ${dist}`;
|
await $`tar -c -z -f ${tarballPath} --transform='s|^${dist}|xo-lite-${version}|' ${dist}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GitHub release -------------------------------------------------------
|
// Create GitHub release -------------------------------------------------------
|
||||||
|
|
||||||
if (ghRelease) {
|
if (ghRelease) {
|
||||||
step("GitHub release");
|
step('GitHub release')
|
||||||
|
|
||||||
let release = (await ghApiCall("/releases")).find(
|
let release = (await ghApiCall('/releases')).find(release => release.tag_name === tag)
|
||||||
(release) => release.tag_name === tag
|
|
||||||
);
|
|
||||||
|
|
||||||
if (release !== undefined) {
|
if (release !== undefined) {
|
||||||
if (
|
if (
|
||||||
@@ -368,37 +331,33 @@ if (ghRelease) {
|
|||||||
)}). Skip and proceed with upload?`
|
)}). Skip and proceed with upload?`
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
stop();
|
stop()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
release = await ghApiCall("/releases", "POST", {
|
release = await ghApiCall('/releases', 'POST', {
|
||||||
tag_name: tag,
|
tag_name: tag,
|
||||||
target_commitish: headSha,
|
target_commitish: headSha,
|
||||||
name: tag,
|
name: tag,
|
||||||
draft: true,
|
draft: true,
|
||||||
});
|
})
|
||||||
|
|
||||||
console.log(
|
console.log(`Created GitHub release ${tag}: ${chalk.blue(release.html_url)}`)
|
||||||
`Created GitHub release ${tag}: ${chalk.blue(release.html_url)}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Uploading tarball ${tarballPath} to GitHub`);
|
console.log(`Uploading tarball ${tarballPath} to GitHub`)
|
||||||
|
|
||||||
let asset = release.assets.find((asset) => asset.name === tarballName);
|
let asset = release.assets.find(asset => asset.name === tarballName)
|
||||||
if (
|
if (
|
||||||
asset !== undefined &&
|
asset !== undefined &&
|
||||||
(await yes(
|
(await yes(`An asset called ${tarballName} already exists on that release. Replace it?`))
|
||||||
`An asset called ${tarballName} already exists on that release. Replace it?`
|
|
||||||
))
|
|
||||||
) {
|
) {
|
||||||
await ghApiCall(`/releases/assets/${asset.id}`, "DELETE");
|
await ghApiCall(`/releases/assets/${asset.id}`, 'DELETE')
|
||||||
asset = undefined;
|
asset = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asset === undefined) {
|
if (asset === undefined) {
|
||||||
console.log("Uploading…");
|
console.log('Uploading…')
|
||||||
asset = await ghApiUploadReleaseAsset(release.id, tarballName, tarballPath);
|
asset = await ghApiUploadReleaseAsset(release.id, tarballName, tarballPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (release.draft) {
|
if (release.draft) {
|
||||||
@@ -406,18 +365,18 @@ if (ghRelease) {
|
|||||||
chalk.yellow(
|
chalk.yellow(
|
||||||
'The release is in DRAFT. To make it public, visit the release URL above, edit the release and click on "Publish release".'
|
'The release is in DRAFT. To make it public, visit the release URL above, edit the release and click on "Publish release".'
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deploy ----------------------------------------------------------------------
|
// Deploy ----------------------------------------------------------------------
|
||||||
|
|
||||||
if (deploy) {
|
if (deploy) {
|
||||||
step("Deploy");
|
step('Deploy')
|
||||||
|
|
||||||
console.log(`Deploying XO Lite from ${dist} to ${DEPLOY_SERVER}`);
|
console.log(`Deploying XO Lite from ${dist} to ${DEPLOY_SERVER}`)
|
||||||
|
|
||||||
await $`rsync -r --delete ${dist}/ ${username}@${DEPLOY_SERVER}:xo-lite`;
|
await $`rsync -r --delete ${dist}/ ${username}@${DEPLOY_SERVER}:xo-lite`
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
XO Lite files sent to server
|
XO Lite files sent to server
|
||||||
@@ -430,5 +389,5 @@ if (deploy) {
|
|||||||
|
|
||||||
→ Then run the following command to move the files to the \`latest\` folder:
|
→ Then run the following command to move the files to the \`latest\` folder:
|
||||||
\trsync -r --delete /home/${username}/xo-lite/ /home/xo-lite/public/latest
|
\trsync -r --delete /home/${username}/xo-lite/ /home/xo-lite/public/latest
|
||||||
`);
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,77 +16,56 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import favicon from "@/assets/favicon.svg";
|
import AppHeader from '@/components/AppHeader.vue'
|
||||||
import AppHeader from "@/components/AppHeader.vue";
|
import AppLogin from '@/components/AppLogin.vue'
|
||||||
import AppLogin from "@/components/AppLogin.vue";
|
import AppNavigation from '@/components/AppNavigation.vue'
|
||||||
import AppNavigation from "@/components/AppNavigation.vue";
|
import AppTooltips from '@/components/AppTooltips.vue'
|
||||||
import AppTooltips from "@/components/AppTooltips.vue";
|
import ModalList from '@/components/ui/modals/ModalList.vue'
|
||||||
import ModalList from "@/components/ui/modals/ModalList.vue";
|
import { useChartTheme } from '@/composables/chart-theme.composable'
|
||||||
import { useChartTheme } from "@/composables/chart-theme.composable";
|
import { useUnreachableHosts } from '@/composables/unreachable-hosts.composable'
|
||||||
import { useUnreachableHosts } from "@/composables/unreachable-hosts.composable";
|
import { useUiStore } from '@/stores/ui.store'
|
||||||
import { useUiStore } from "@/stores/ui.store";
|
import { usePoolCollection } from '@/stores/xen-api/pool.store'
|
||||||
import { usePoolCollection } from "@/stores/xen-api/pool.store";
|
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||||
import { useXenApiStore } from "@/stores/xen-api.store";
|
import { useActiveElement, useMagicKeys, whenever } from '@vueuse/core'
|
||||||
import { useActiveElement, useMagicKeys, whenever } from "@vueuse/core";
|
import { logicAnd } from '@vueuse/math'
|
||||||
import { logicAnd } from "@vueuse/math";
|
import { computed } from 'vue'
|
||||||
import { computed } from "vue";
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useI18n } from "vue-i18n";
|
|
||||||
|
|
||||||
let link = document.querySelector(
|
const xenApiStore = useXenApiStore()
|
||||||
"link[rel~='icon']"
|
|
||||||
) as HTMLLinkElement | null;
|
|
||||||
if (link == null) {
|
|
||||||
link = document.createElement("link");
|
|
||||||
link.rel = "icon";
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(link);
|
|
||||||
}
|
|
||||||
link.href = favicon;
|
|
||||||
|
|
||||||
const xenApiStore = useXenApiStore();
|
const { pool } = usePoolCollection()
|
||||||
|
|
||||||
const { pool } = usePoolCollection();
|
useChartTheme()
|
||||||
|
const uiStore = useUiStore()
|
||||||
useChartTheme();
|
|
||||||
const uiStore = useUiStore();
|
|
||||||
|
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n()
|
||||||
const activeElement = useActiveElement();
|
const activeElement = useActiveElement()
|
||||||
const { D, L } = useMagicKeys();
|
const { D, L } = useMagicKeys()
|
||||||
|
|
||||||
const canToggle = computed(() => {
|
const canToggle = computed(() => {
|
||||||
if (activeElement.value == null) {
|
if (activeElement.value == null) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return !["INPUT", "TEXTAREA"].includes(activeElement.value.tagName);
|
return !['INPUT', 'TEXTAREA'].includes(activeElement.value.tagName)
|
||||||
});
|
})
|
||||||
|
|
||||||
whenever(
|
whenever(logicAnd(D, canToggle), () => (uiStore.colorMode = uiStore.colorMode === 'dark' ? 'light' : 'dark'))
|
||||||
logicAnd(D, canToggle),
|
|
||||||
() => (uiStore.colorMode = uiStore.colorMode === "dark" ? "light" : "dark")
|
|
||||||
);
|
|
||||||
|
|
||||||
whenever(
|
whenever(logicAnd(L, canToggle), () => (locale.value = locale.value === 'en' ? 'fr' : 'en'))
|
||||||
logicAnd(L, canToggle),
|
|
||||||
() => (locale.value = locale.value === "en" ? "fr" : "en")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
whenever(
|
whenever(
|
||||||
() => pool.value?.$ref,
|
() => pool.value?.$ref,
|
||||||
(poolRef) => {
|
poolRef => {
|
||||||
xenApiStore.getXapi().startWatching(poolRef);
|
xenApiStore.getXapi().startWatching(poolRef)
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
|
||||||
useUnreachableHosts();
|
useUnreachableHosts()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="postcss">
|
|
||||||
@import "@/assets/base.css";
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<style lang="postcss" scoped>
|
<style lang="postcss" scoped>
|
||||||
.main {
|
.main {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
@custom-media --mobile (max-width: 1023px);
|
|
||||||
@custom-media --desktop (min-width: 1024px);
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
@import "reset.css";
|
|
||||||
@import "theme.css";
|
|
||||||
@import "@fontsource/poppins/400.css";
|
|
||||||
@import "@fontsource/poppins/500.css";
|
|
||||||
@import "@fontsource/poppins/600.css";
|
|
||||||
@import "@fontsource/poppins/700.css";
|
|
||||||
@import "@fontsource/poppins/900.css";
|
|
||||||
@import "@fontsource/poppins/400-italic.css";
|
|
||||||
|
|
||||||
body {
|
|
||||||
min-height: 100vh;
|
|
||||||
font-size: 1.3rem;
|
|
||||||
text-rendering: optimizeLegibility;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
color: var(--color-blue-scale-100);
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: var(--color-extra-blue-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
code,
|
|
||||||
code *,
|
|
||||||
pre {
|
|
||||||
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
|
|
||||||
"Courier New", monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-view {
|
|
||||||
padding: 1.2rem;
|
|
||||||
display: flex;
|
|
||||||
gap: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
text-decoration: underline;
|
|
||||||
color: var(--color-extra-blue-base);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link:hover {
|
|
||||||
color: var(--color-extra-blue-d20);
|
|
||||||
}
|
|
||||||
|
|
||||||
.link:active,
|
|
||||||
.link.router-link-active {
|
|
||||||
color: var(--color-extra-blue-d40);
|
|
||||||
}
|
|
||||||
|
|
||||||
.link.router-link-active {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-color-success {
|
|
||||||
color: var(--color-green-infra-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-color-error {
|
|
||||||
color: var(--color-red-vates-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-color-warning {
|
|
||||||
color: var(--color-orange-world-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-color-info {
|
|
||||||
color: var(--color-extra-blue-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-background-color-success {
|
|
||||||
background-color: var(--background-color-green-infra);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-background-color-error {
|
|
||||||
background-color: var(--background-color-red-vates);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-background-color-warning {
|
|
||||||
background-color: var(--background-color-orange-world);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-background-color-info {
|
|
||||||
background-color: var(--background-color-extra-blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-border-color-success {
|
|
||||||
border-color: var(--color-green-infra-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-border-color-error {
|
|
||||||
border-color: var(--color-red-vates-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-border-color-warning {
|
|
||||||
border-color: var(--color-orange-world-base);
|
|
||||||
}
|
|
||||||
|
|
||||||
.context-border-color-info {
|
|
||||||
border-color: var(--color-extra-blue-base);
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
:root {
|
|
||||||
--color-logo: #282467;
|
|
||||||
|
|
||||||
--color-blue-scale-000: #000000;
|
|
||||||
--color-blue-scale-100: #1a1b38;
|
|
||||||
--color-blue-scale-200: #595a6f;
|
|
||||||
--color-blue-scale-300: #9899a5;
|
|
||||||
--color-blue-scale-400: #e5e5e7;
|
|
||||||
--color-blue-scale-500: #ffffff;
|
|
||||||
|
|
||||||
--color-extra-blue-l60: #d1cefb;
|
|
||||||
--color-extra-blue-l40: #bbb5f9;
|
|
||||||
--color-extra-blue-l20: #a39df8;
|
|
||||||
--color-extra-blue-base: #8f84ff;
|
|
||||||
--color-extra-blue-d20: #716ac6;
|
|
||||||
--color-extra-blue-d40: #554f94;
|
|
||||||
--color-extra-blue-d60: #383563;
|
|
||||||
|
|
||||||
--color-green-infra-l60: #b5dbca;
|
|
||||||
--color-green-infra-l40: #91c9b0;
|
|
||||||
--color-green-infra-l20: #70b795;
|
|
||||||
--color-green-infra-base: #55a57b;
|
|
||||||
--color-green-infra-d20: #438463;
|
|
||||||
--color-green-infra-d40: #32634a;
|
|
||||||
--color-green-infra-d60: #214231;
|
|
||||||
|
|
||||||
--color-orange-world-l60: #f2cda8;
|
|
||||||
--color-orange-world-l40: #ebb57d;
|
|
||||||
--color-orange-world-l20: #e59d56;
|
|
||||||
--color-orange-world-base: #ef7f18;
|
|
||||||
--color-orange-world-d20: #bf6612;
|
|
||||||
--color-orange-world-d40: #864f1f;
|
|
||||||
--color-orange-world-d60: #5a3514;
|
|
||||||
|
|
||||||
--color-red-vates-l60: #dda5a7;
|
|
||||||
--color-red-vates-l40: #ce787c;
|
|
||||||
--color-red-vates-l20: #bf4f51;
|
|
||||||
--color-red-vates-base: #be1621;
|
|
||||||
--color-red-vates-d20: #8e2221;
|
|
||||||
--color-red-vates-d40: #6a1919;
|
|
||||||
--color-red-vates-d60: #471010;
|
|
||||||
|
|
||||||
--color-grayscale-200: #585757;
|
|
||||||
|
|
||||||
--background-color-primary: #ffffff;
|
|
||||||
--background-color-secondary: #f6f6f7;
|
|
||||||
--background-color-extra-blue: #f4f3fe;
|
|
||||||
--background-color-green-infra: #ecf5f2;
|
|
||||||
--background-color-orange-world: #fbf2e9;
|
|
||||||
--background-color-red-vates: #f5e8e9;
|
|
||||||
|
|
||||||
--shadow-100: 0 0.1rem 0.1rem rgba(20, 20, 30, 0.06);
|
|
||||||
--shadow-200: 0 0.1rem 0.3rem rgba(20, 20, 30, 0.1),
|
|
||||||
0 0.2rem 0.1rem rgba(20, 20, 30, 0.06),
|
|
||||||
0 0.1rem 0.1rem rgba(20, 20, 30, 0.08);
|
|
||||||
--shadow-300: 0 0.3rem 0.5rem rgba(20, 20, 30, 0.1),
|
|
||||||
0 0.1rem 1.8rem rgba(20, 20, 30, 0.06), 0 0.6rem 1rem rgba(20, 20, 30, 0.08);
|
|
||||||
--shadow-400: 0 1.1rem 1.5rem rgba(20, 20, 30, 0.1),
|
|
||||||
0 0.9rem 4.6rem rgba(20, 20, 30, 0.06),
|
|
||||||
0 2.4rem 3.8rem rgba(20, 20, 30, 0.04);
|
|
||||||
}
|
|
||||||
|
|
||||||
:root.dark {
|
|
||||||
color-scheme: dark;
|
|
||||||
|
|
||||||
--color-logo: #e5e5e7;
|
|
||||||
|
|
||||||
--color-blue-scale-000: #ffffff;
|
|
||||||
--color-blue-scale-100: #e5e5e7;
|
|
||||||
--color-blue-scale-200: #9899a5;
|
|
||||||
--color-blue-scale-300: #595a6f;
|
|
||||||
--color-blue-scale-400: #1a1b38;
|
|
||||||
--color-blue-scale-500: #000000;
|
|
||||||
|
|
||||||
--background-color-primary: #14141d;
|
|
||||||
--background-color-secondary: #17182a;
|
|
||||||
--background-color-extra-blue: #35335d;
|
|
||||||
--background-color-green-infra: #243b3d;
|
|
||||||
--background-color-orange-world: #493328;
|
|
||||||
--background-color-red-vates: #3c1a28;
|
|
||||||
|
|
||||||
--shadow-100: 0 0.1rem 0.1rem rgba(20, 20, 30, 0.12);
|
|
||||||
--shadow-200: 0 0.1rem 0.3rem rgba(20, 20, 30, 0.2),
|
|
||||||
0 0.2rem 0.1rem rgba(20, 20, 30, 0.12),
|
|
||||||
0 0.1rem 0.1rem rgba(20, 20, 30, 0.16);
|
|
||||||
--shadow-300: 0 0.3rem 0.5rem rgba(20, 20, 30, 0.2),
|
|
||||||
0 0.1rem 1.8rem rgba(20, 20, 30, 0.12), 0 0.6rem 1rem rgba(20, 20, 30, 0.16);
|
|
||||||
--shadow-400: 0 1.1rem 1.5rem rgba(20, 20, 30, 0.2),
|
|
||||||
0 0.9rem 4.6rem rgba(20, 20, 30, 0.12),
|
|
||||||
0 2.4rem 3.8rem rgba(20, 20, 30, 0.08);
|
|
||||||
}
|
|
||||||
@@ -6,54 +6,44 @@
|
|||||||
<UiIcon :icon="faAngleDown" class="dropdown-icon" />
|
<UiIcon :icon="faAngleDown" class="dropdown-icon" />
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
<MenuItem :icon="faGear" @click="openSettings">{{
|
<MenuItem :icon="faGear" @click="openSettings">{{ $t('settings') }}</MenuItem>
|
||||||
$t("settings")
|
|
||||||
}}</MenuItem>
|
|
||||||
<MenuItem :icon="faMessage" @click="openFeedbackUrl">
|
<MenuItem :icon="faMessage" @click="openFeedbackUrl">
|
||||||
{{ $t("send-us-feedback") }}
|
{{ $t('send-us-feedback') }}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem
|
<MenuItem :icon="faArrowRightFromBracket" class="menu-item-logout" @click="logout">
|
||||||
:icon="faArrowRightFromBracket"
|
{{ $t('log-out') }}
|
||||||
class="menu-item-logout"
|
|
||||||
@click="logout"
|
|
||||||
>
|
|
||||||
{{ $t("log-out") }}
|
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</AppMenu>
|
</AppMenu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { nextTick } from "vue";
|
import { nextTick } from 'vue'
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
faAngleDown,
|
faAngleDown,
|
||||||
faArrowRightFromBracket,
|
faArrowRightFromBracket,
|
||||||
faCircleUser,
|
faCircleUser,
|
||||||
faGear,
|
faGear,
|
||||||
faMessage,
|
faMessage,
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from '@fortawesome/free-solid-svg-icons'
|
||||||
import AppMenu from "@/components/menu/AppMenu.vue";
|
import AppMenu from '@/components/menu/AppMenu.vue'
|
||||||
import MenuItem from "@/components/menu/MenuItem.vue";
|
import MenuItem from '@/components/menu/MenuItem.vue'
|
||||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||||
import { useXenApiStore } from "@/stores/xen-api.store";
|
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter()
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
const xenApiStore = useXenApiStore();
|
const xenApiStore = useXenApiStore()
|
||||||
xenApiStore.disconnect();
|
xenApiStore.disconnect()
|
||||||
nextTick(() => router.push({ name: "home" }));
|
nextTick(() => router.push({ name: 'home' }))
|
||||||
};
|
}
|
||||||
|
|
||||||
const openFeedbackUrl = () => {
|
const openFeedbackUrl = () => {
|
||||||
window.open(
|
window.open('https://xcp-ng.org/forum/topic/4731/xen-orchestra-lite', '_blank', 'noopener')
|
||||||
"https://xcp-ng.org/forum/topic/4731/xen-orchestra-lite",
|
}
|
||||||
"_blank",
|
|
||||||
"noopener"
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const openSettings = () => router.push({ name: "settings" });
|
const openSettings = () => router.push({ name: 'settings' })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -61,14 +51,14 @@ const openSettings = () => router.push({ name: "settings" });
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
color: var(--color-blue-scale-100);
|
color: var(--color-grey-100);
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 0.8rem;
|
border-radius: 0.8rem;
|
||||||
background-color: var(--background-color-secondary);
|
background-color: var(--background-color-secondary);
|
||||||
gap: 0.8rem;
|
gap: 0.8rem;
|
||||||
|
|
||||||
&:disabled {
|
&:disabled {
|
||||||
color: var(--color-blue-scale-400);
|
color: var(--color-grey-500);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:not(:disabled) {
|
&:not(:disabled) {
|
||||||
@@ -82,7 +72,7 @@ const openSettings = () => router.push({ name: "settings" });
|
|||||||
|
|
||||||
&:active,
|
&:active,
|
||||||
&.active {
|
&.active {
|
||||||
color: var(--color-extra-blue-base);
|
color: var(--color-purple-base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,6 +86,6 @@ const openSettings = () => router.push({ name: "settings" });
|
|||||||
}
|
}
|
||||||
|
|
||||||
.menu-item-logout {
|
.menu-item-logout {
|
||||||
color: var(--color-red-vates-base);
|
color: var(--color-red-base);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<header class="app-header">
|
<header class="app-header">
|
||||||
<UiIcon
|
<UiIcon v-if="isMobile" ref="navigationTrigger" :icon="faBars" class="toggle-navigation" />
|
||||||
v-if="isMobile"
|
|
||||||
ref="navigationTrigger"
|
|
||||||
:icon="faBars"
|
|
||||||
class="toggle-navigation"
|
|
||||||
/>
|
|
||||||
<RouterLink :to="{ name: 'home' }">
|
<RouterLink :to="{ name: 'home' }">
|
||||||
<img v-if="isMobile" alt="XO Lite" src="../assets/logo.svg" />
|
<img v-if="isMobile" alt="XO Lite" src="../assets/logo.svg" />
|
||||||
<TextLogo v-else />
|
<TextLogo v-else />
|
||||||
@@ -14,7 +9,7 @@
|
|||||||
<div class="right">
|
<div class="right">
|
||||||
<PoolOverrideWarning as-tooltip />
|
<PoolOverrideWarning as-tooltip />
|
||||||
<UiButton v-if="isDesktop" :icon="faDownload" @click="openXoaDeploy">
|
<UiButton v-if="isDesktop" :icon="faDownload" @click="openXoaDeploy">
|
||||||
{{ $t("deploy-xoa") }}
|
{{ $t('deploy-xoa') }}
|
||||||
</UiButton>
|
</UiButton>
|
||||||
<AccountButton />
|
<AccountButton />
|
||||||
</div>
|
</div>
|
||||||
@@ -22,26 +17,26 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import AccountButton from "@/components/AccountButton.vue";
|
import AccountButton from '@/components/AccountButton.vue'
|
||||||
import PoolOverrideWarning from "@/components/PoolOverrideWarning.vue";
|
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
|
||||||
import TextLogo from "@/components/TextLogo.vue";
|
import TextLogo from '@/components/TextLogo.vue'
|
||||||
import UiButton from "@/components/ui/UiButton.vue";
|
import UiButton from '@/components/ui/UiButton.vue'
|
||||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||||
import { useNavigationStore } from "@/stores/navigation.store";
|
import { useNavigationStore } from '@/stores/navigation.store'
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from 'vue-router'
|
||||||
import { useUiStore } from "@/stores/ui.store";
|
import { useUiStore } from '@/stores/ui.store'
|
||||||
import { faBars, faDownload } from "@fortawesome/free-solid-svg-icons";
|
import { faBars, faDownload } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter()
|
||||||
|
|
||||||
const openXoaDeploy = () => router.push({ name: "xoa.deploy" });
|
const openXoaDeploy = () => router.push({ name: 'xoa.deploy' })
|
||||||
|
|
||||||
const uiStore = useUiStore();
|
const uiStore = useUiStore()
|
||||||
const { isMobile, isDesktop } = storeToRefs(uiStore);
|
const { isMobile, isDesktop } = storeToRefs(uiStore)
|
||||||
|
|
||||||
const navigationStore = useNavigationStore();
|
const navigationStore = useNavigationStore()
|
||||||
const { trigger: navigationTrigger } = storeToRefs(navigationStore);
|
const { trigger: navigationTrigger } = storeToRefs(navigationStore)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="postcss" scoped>
|
<style lang="postcss" scoped>
|
||||||
@@ -51,7 +46,7 @@ const { trigger: navigationTrigger } = storeToRefs(navigationStore);
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
height: 5.5rem;
|
height: 5.5rem;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
border-bottom: 0.1rem solid var(--color-blue-scale-400);
|
border-bottom: 0.1rem solid var(--color-grey-500);
|
||||||
background-color: var(--background-color-secondary);
|
background-color: var(--background-color-secondary);
|
||||||
|
|
||||||
img {
|
img {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<PoolOverrideWarning />
|
<PoolOverrideWarning />
|
||||||
<p v-if="isHostIsSlaveErr(error)" class="error">
|
<p v-if="isHostIsSlaveErr(error)" class="error">
|
||||||
<UiIcon :icon="faExclamationCircle" />
|
<UiIcon :icon="faExclamationCircle" />
|
||||||
{{ $t("login-only-on-master") }}
|
{{ $t('login-only-on-master') }}
|
||||||
<a :href="masterUrl.href">{{ masterUrl.hostname }}</a>
|
<a :href="masterUrl.href">{{ masterUrl.hostname }}</a>
|
||||||
</p>
|
</p>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
<FormInput v-model="login" name="login" readonly type="text" />
|
<FormInput v-model="login" name="login" readonly type="text" />
|
||||||
</FormInputWrapper>
|
</FormInputWrapper>
|
||||||
<FormInput
|
<FormInput
|
||||||
name="password"
|
|
||||||
ref="passwordRef"
|
ref="passwordRef"
|
||||||
type="password"
|
|
||||||
v-model="password"
|
v-model="password"
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
:class="{ error: isInvalidPassword }"
|
:class="{ error: isInvalidPassword }"
|
||||||
:placeholder="$t('password')"
|
:placeholder="$t('password')"
|
||||||
:readonly="isConnecting"
|
:readonly="isConnecting"
|
||||||
@@ -25,10 +25,10 @@
|
|||||||
<LoginError :error="error" />
|
<LoginError :error="error" />
|
||||||
<label class="remember-me-label">
|
<label class="remember-me-label">
|
||||||
<FormCheckbox v-model="rememberMe" />
|
<FormCheckbox v-model="rememberMe" />
|
||||||
{{ $t("keep-me-logged") }}
|
{{ $t('keep-me-logged') }}
|
||||||
</label>
|
</label>
|
||||||
<UiButton type="submit" :busy="isConnecting">
|
<UiButton type="submit" :busy="isConnecting">
|
||||||
{{ $t("login") }}
|
{{ $t('login') }}
|
||||||
</UiButton>
|
</UiButton>
|
||||||
</template>
|
</template>
|
||||||
</form>
|
</form>
|
||||||
@@ -36,69 +36,68 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { usePageTitleStore } from "@/stores/page-title.store";
|
import { usePageTitleStore } from '@/stores/page-title.store'
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from 'pinia'
|
||||||
import { onMounted, ref, watch } from "vue";
|
import { onMounted, ref, watch } from 'vue'
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useLocalStorage, whenever } from "@vueuse/core";
|
import { useLocalStorage, whenever } from '@vueuse/core'
|
||||||
|
|
||||||
import FormCheckbox from "@/components/form/FormCheckbox.vue";
|
import FormCheckbox from '@/components/form/FormCheckbox.vue'
|
||||||
import FormInput from "@/components/form/FormInput.vue";
|
import FormInput from '@/components/form/FormInput.vue'
|
||||||
import FormInputWrapper from "@/components/form/FormInputWrapper.vue";
|
import FormInputWrapper from '@/components/form/FormInputWrapper.vue'
|
||||||
import LoginError from "@/components/LoginError.vue";
|
import LoginError from '@/components/LoginError.vue'
|
||||||
import PoolOverrideWarning from "@/components/PoolOverrideWarning.vue";
|
import PoolOverrideWarning from '@/components/PoolOverrideWarning.vue'
|
||||||
import UiButton from "@/components/ui/UiButton.vue";
|
import UiButton from '@/components/ui/UiButton.vue'
|
||||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
import UiIcon from '@/components/ui/icon/UiIcon.vue'
|
||||||
import type { XenApiError } from "@/libs/xen-api/xen-api.types";
|
import type { XenApiError } from '@/libs/xen-api/xen-api.types'
|
||||||
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons";
|
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { useXenApiStore } from "@/stores/xen-api.store";
|
import { useXenApiStore } from '@/stores/xen-api.store'
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n()
|
||||||
usePageTitleStore().setTitle(t("login"));
|
usePageTitleStore().setTitle(t('login'))
|
||||||
const xenApiStore = useXenApiStore();
|
const xenApiStore = useXenApiStore()
|
||||||
const { isConnecting } = storeToRefs(xenApiStore);
|
const { isConnecting } = storeToRefs(xenApiStore)
|
||||||
const login = ref("root");
|
const login = ref('root')
|
||||||
const password = ref("");
|
const password = ref('')
|
||||||
const error = ref<XenApiError>();
|
const error = ref<XenApiError>()
|
||||||
const passwordRef = ref<InstanceType<typeof FormInput>>();
|
const passwordRef = ref<InstanceType<typeof FormInput>>()
|
||||||
const isInvalidPassword = ref(false);
|
const isInvalidPassword = ref(false)
|
||||||
const masterUrl = ref(new URL(window.origin));
|
const masterUrl = ref(new URL(window.origin))
|
||||||
const rememberMe = useLocalStorage("rememberMe", false);
|
const rememberMe = useLocalStorage('rememberMe', false)
|
||||||
|
|
||||||
const focusPasswordInput = () => passwordRef.value?.focus();
|
const focusPasswordInput = () => passwordRef.value?.focus()
|
||||||
const isHostIsSlaveErr = (err: XenApiError | undefined) =>
|
const isHostIsSlaveErr = (err: XenApiError | undefined) => err?.message === 'HOST_IS_SLAVE'
|
||||||
err?.message === "HOST_IS_SLAVE";
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (rememberMe.value) {
|
if (rememberMe.value) {
|
||||||
xenApiStore.reconnect();
|
xenApiStore.reconnect()
|
||||||
} else {
|
} else {
|
||||||
focusPasswordInput();
|
focusPasswordInput()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
watch(password, () => {
|
watch(password, () => {
|
||||||
isInvalidPassword.value = false;
|
isInvalidPassword.value = false
|
||||||
error.value = undefined;
|
error.value = undefined
|
||||||
});
|
})
|
||||||
|
|
||||||
whenever(
|
whenever(
|
||||||
() => isHostIsSlaveErr(error.value),
|
() => isHostIsSlaveErr(error.value),
|
||||||
() => (masterUrl.value.hostname = error.value!.data)
|
() => (masterUrl.value.hostname = error.value!.data)
|
||||||
);
|
)
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
try {
|
||||||
await xenApiStore.connect(login.value, password.value);
|
await xenApiStore.connect(login.value, password.value)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.message === "SESSION_AUTHENTICATION_FAILED") {
|
if (err.message === 'SESSION_AUTHENTICATION_FAILED') {
|
||||||
focusPasswordInput();
|
focusPasswordInput()
|
||||||
isInvalidPassword.value = true;
|
isInvalidPassword.value = true
|
||||||
} else {
|
} else {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
error.value = err;
|
error.value = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -136,7 +135,7 @@ form {
|
|||||||
background-color: var(--background-color-secondary);
|
background-color: var(--background-color-secondary);
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
color: var(--color-red-vates-base);
|
color: var(--color-red-base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +156,7 @@ input {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
padding: 1rem 1.5rem;
|
padding: 1rem 1.5rem;
|
||||||
border: 1px solid var(--color-blue-scale-400);
|
border: 1px solid var(--color-grey-500);
|
||||||
border-radius: 0.8rem;
|
border-radius: 0.8rem;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user