Compare commits

...

672 Commits

Author SHA1 Message Date
Nicolas Raynaud
f3c5efdd38 avoid parsing URL by hand 2021-07-06 15:06:54 +02:00
Nicolas Raynaud
e00270e916 remote S3 HTTP protocol from UI 2021-07-05 11:50:40 +02:00
Nicolas Raynaud
d17fd2dc11 try using minio for S3 backup 2021-06-30 16:03:53 +02:00
Nicolas Raynaud
a69d32de75 try using minio for S3 backup 2021-06-23 13:32:15 +02:00
Nicolas Raynaud
5040ce87e1 Merge branch 'master' into nr-fix-S3-upload 2021-05-21 11:43:50 +02:00
Julien Fontanet
3a52944f21 fix(docs): use correct bin with forever 2021-05-20 18:49:36 +02:00
Julien Fontanet
cc9d741275 fix(xo-server): fix plugins import
Fixes #5782 part 2

Introduced by 254558e9d
2021-05-20 12:07:00 +02:00
Julien Fontanet
f0096cf0e2 chore(xo-server): remove useless imports
Introduced by 254558e9d
2021-05-20 10:21:26 +02:00
Julien Fontanet
1d673bf6ff chore(xo-server): remove useless entry point
Introduced by 254558e9d

Due to ESM, it's no longer easy to alter `DEBUG` before all instances of `debug` are loaded, which makes it useless.
2021-05-20 10:16:23 +02:00
Julien Fontanet
d986f00b6a chore(xo-server): remove rimraf dev dep 2021-05-19 17:43:12 +02:00
Julien Fontanet
01c3ca4f37 chore(proxy): remove unused dev dep rimraf
Introduced by df9689854
2021-05-19 17:36:26 +02:00
Julien Fontanet
497bd7dad5 fix(xo-server): fix executables
Fixes #5782

Remove `bin` dir in favor of explicit listing, this allows to use ESM with executables without extensions.
2021-05-19 17:33:30 +02:00
Julien Fontanet
1d6a0ae8f1 chore(lint): apply overrides to .cjs and .mjs files 2021-05-19 17:29:09 +02:00
Julien Fontanet
c5e6b5ec7a chore(xo-server/recover-account): remove unused import
Introduced by 254558e9d
2021-05-19 17:28:41 +02:00
Julien Fontanet
ca26b4b30d chore(xo-server): remove unused run-vhd-test 2021-05-19 17:17:42 +02:00
Julien Fontanet
254558e9de chore(xo-server): convert to ESM 2021-05-19 15:53:21 +02:00
Julien Fontanet
da0cd0b99c chore: update to limit-concurrency-decorator@0.5.0 2021-05-19 15:08:53 +02:00
Julien Fontanet
2e49c685cc chore(emit-async): remove build step
It also helps with compatibility with Native ESM for default exports.
2021-05-19 15:00:59 +02:00
Julien Fontanet
a64af4da7c chore(defined): remove build step
It also helps with compatibility with Native ESM for default exports.
2021-05-19 12:07:18 +02:00
Julien Fontanet
68bb2fa7f0 feat(xo-collection): named instead of default exports
Behave better with Babel and native ESM.
2021-05-19 10:58:22 +02:00
Julien Fontanet
8bc2710380 chore(xo-collection/view.example): fix lint error 2021-05-19 10:51:57 +02:00
Julien Fontanet
1691e7ad83 chore(xo-collection): event-to-promise → promise-toolbox/fromEvent 2021-05-19 10:51:08 +02:00
Julien Fontanet
6c2cb31923 fix(proxy/api): fix JsonRpcWebSocketClient import
Introduced by 84b3162bc
2021-05-18 22:11:13 +02:00
Julien Fontanet
0c6d920682 chore(log): remove build step
It also helps with compatibility with native ESM for default exports.
2021-05-18 21:24:42 +02:00
Pierre Donias
a126b5b61b feat(xo-server-auth-saml): use registerUser2 (#5781) 2021-05-18 11:28:49 +02:00
Pierre Donias
dadb16bb04 feat(xen-api): ability to connect using a session ID (#5763) 2021-05-18 11:21:39 +02:00
Pierre Donias
f29473ef4c fix(xo-server/isHostServerTimeConsistent): change host permission from administrate to view (#5780) 2021-05-18 10:22:24 +02:00
Julien Fontanet
84b3162bcd fix(proxy/api): fix JsonRpcWebSocketClient import
Introduced by df9689854
2021-05-17 16:45:27 +02:00
Julien Fontanet
c7f1469e1f fix(proxy/backup.run): handle multiple self licenses
See xoa-support#3730

Previous code would fail if the first license returned was already expired.
2021-05-16 16:51:32 +02:00
Nicolas Raynaud
b7481f42cd remove AWS managed upload system for a simpler one 2021-05-14 16:11:42 +02:00
Nicolas Raynaud
2329705ad7 remove AWS managed upload system for a simpler one 2021-05-14 16:07:14 +02:00
Julien Fontanet
d1dfd93e15 feat(xen-api): 0.32.0 2021-05-12 17:57:06 +02:00
Julien Fontanet
4ef55b8d1f feat(xen-api): reverseHostIpAddresses option
See xoa-support#3727

When enabled, will attempt to get a FQDN from the host address returned by XAPI when using `getResource()` or `putResource()`.
2021-05-12 12:18:05 +02:00
Yannick Achy
7da22094f3 feat(docs/proxy): SSH connection and second nic (#5777) 2021-05-12 09:03:44 +02:00
Julien Fontanet
cf45cb56ad feat(npmignore): ignore /coverage/ 2021-05-11 09:04:35 +02:00
Julien Fontanet
df96898543 chore(proxy): convert to ESM 2021-05-10 23:23:37 +02:00
Julien Fontanet
a58bf66dea feat(scripts/travis-tests): handle .[cm]js files 2021-05-10 23:21:10 +02:00
Julien Fontanet
0f1fc0cc79 chore(proxy): remove rimraf dev dep 2021-05-10 18:17:40 +02:00
Julien Fontanet
dc41f60f52 feat(scripts/lint-staged): handle .[cm]js files 2021-05-10 14:50:19 +02:00
Julien Fontanet
3d21afb640 feat(package.json/scripts/prettify): handle cjs files 2021-05-10 14:48:32 +02:00
Julien Fontanet
79c3667fd4 fix(xo-server/api): never log pool.listMissingPatches or hosts.stats 2021-05-10 11:35:17 +02:00
Julien Fontanet
ab1549f60e feat(@xen-orchestra/backups-cli): 0.6.0 2021-05-08 10:44:49 +02:00
Julien Fontanet
5d32fa36ff feat(backups/_VmBackup#_callWriters): clearer error message
See xoa-support#3709
2021-05-08 10:43:39 +02:00
badrAZ
8ac17ab6e3 fix(xo-server): log missing pools (#5768)
Fixes #2844
2021-05-07 16:35:48 +02:00
badrAZ
2076141f47 feat(xo-web): add warning on restoring metadata backup (#5769)
See xoa-support#3691
2021-05-07 13:47:47 +02:00
badrAZ
6d0f479f81 fix(xo-server-backup-reports): don't take into account ignored tasks (#5770) 2021-05-07 11:09:38 +02:00
Julien Fontanet
f56a5a3de1 fix(xo-server/xapiObjectToXo/link): don't fail on array with missing objects
Fixes xoa-support#3691
2021-05-07 09:33:12 +02:00
Julien Fontanet
d0c34fd760 fix(CHANGELOG): update latest badge
Introduced by 9e7afd67b
2021-05-06 18:52:06 +02:00
Julien Fontanet
9e7afd67bc feat: release 5.58.1 2021-05-06 16:17:41 +02:00
Julien Fontanet
964810858b fix(fs/fs.spec): remove .only modifiers
Introduced by 48af5c7ed
2021-05-06 16:17:05 +02:00
Julien Fontanet
7a51361099 fix(CHANGELOG): typo
Introduced in e6f8fd923
2021-05-06 16:16:58 +02:00
Julien Fontanet
ec2e71a22f feat(CHANGELOG.unreleased): add better handling of remotes' errors
Introduced in 5b188f35b
2021-05-06 16:09:45 +02:00
Julien Fontanet
5b188f35b5 fix(backups/_VmBackup): better handling of writers' failures
- always wait for writers to finish their action
- log all writers' failures
- only interrupt process if all writers have failed
2021-05-05 14:32:39 +02:00
Julien Fontanet
5683571577 fix(xo-server): revert to schema-inspector@1
Fixes https://xcp-ng.org/forum/topic/4556/can-t-edit-xo-metatata-backup-config

See  schema-inspector/schema-inspector#119
2021-05-05 10:10:03 +02:00
badrAZ
db75568905 feat(backups/writers#beforeBackup): continue interrupted merges 2021-05-05 09:57:05 +02:00
badrAZ
5517305973 feat(backups/RemoteAdapter#cleanVm): optional lock 2021-05-05 09:57:05 +02:00
badrAZ
57ef531be0 feat(backups/cleanVm): detection of interrupted merges 2021-05-05 09:57:05 +02:00
Julien Fontanet
b590e29608 feat(@vates/parse-duration): 0.1.1 2021-05-05 09:51:44 +02:00
Julien Fontanet
569d575a96 fix(parse-duration): ISC license
Unrelated to XO code.
2021-05-05 09:49:50 +02:00
Julien Fontanet
dd8bf3776e fix(parse-duration): show original value in error message 2021-05-05 09:48:30 +02:00
Julien Fontanet
d4ea9c8892 fix(backups/_VmBackup#_selectBaseVm): typo
Fixes #5766

Introduced in 1d1bf504d
2021-05-04 16:39:32 +02:00
Julien Fontanet
793c6b4a5a chore(backups/_VmBackup#_copyDelta): remove useless check
All delta writers now have a `prepare()` method since e0d6b501c
2021-05-04 11:56:12 +02:00
Julien Fontanet
917c9dabc7 chore(backups/_VmBackup#copy{Delta,Full}): don't log writer errors
These errors are already logged in tasks.
2021-05-04 11:47:54 +02:00
Julien Fontanet
1d1bf504de chore(backups/VmBackup): make _writers a set
It will be easier to remove some writers in case of error.
2021-05-04 11:43:58 +02:00
Julien Fontanet
d0c07e1e97 chore: update promise-toolbox to 0.19.2 2021-05-03 15:41:53 +02:00
Julien Fontanet
dfff520259 fix(proxy/api): backup.{importVm,restoreMetadata}Backup
Fixes xoa-support#3688

Issue with `Disposable.use()` when returning an iterator like `runWithLogs()`.

Fixes by `promise-toolbox@0.19.2`.
2021-05-03 15:27:40 +02:00
Julien Fontanet
bb928bbd73 fix(backups/RemoteAdapter#cleanVm): don't fail if no vdis dir
Detected in #5756

Necessary to handle VMs with only full backups.
2021-05-02 11:22:01 +02:00
Julien Fontanet
f86ec98e05 fix(fs/list): ignoreMissing option
Introduced by 48af5c7ed

I messed up while renaming the option.
2021-05-02 11:22:01 +02:00
badrAZ
48af5c7ed6 feat(fs/abstract#list): ignore ENOENT error 2021-05-02 10:22:16 +02:00
Julien Fontanet
cfaf336597 feat(@xen-orchestra/proxy): 0.13.0 2021-04-30 23:11:25 +02:00
Julien Fontanet
b52345236d chore(fs): remove unused deps 2021-04-30 23:10:19 +02:00
Julien Fontanet
87ebaf62c1 fix(openflow): fix incorrect dev dep 2021-04-30 23:10:11 +02:00
Julien Fontanet
c7721d6100 feat(xo-server): 5.79.2 2021-04-30 22:53:05 +02:00
Julien Fontanet
40a722a7ff feat(@xen-orchestra/fs): 0.16.1 2021-04-30 22:52:25 +02:00
Julien Fontanet
d41fbb9216 fix(fs/_outputStream): validator should receive tmp path 2021-04-30 22:51:21 +02:00
Julien Fontanet
8bee0925d0 chore(fs/outputStream): remove incorrect await 2021-04-30 22:45:53 +02:00
Julien Fontanet
b8edca53cb feat: release 5.58.0 2021-04-30 22:28:17 +02:00
Julien Fontanet
34a13dd293 feat(xo-server): 5.79.1 2021-04-30 22:23:51 +02:00
Julien Fontanet
f72e582a80 feat(@xen-orchestra/backups): 0.10.1 2021-04-30 22:23:22 +02:00
Julien Fontanet
6da2865781 feat(@xen-orchestra/fs): 0.16.0 2021-04-30 22:22:19 +02:00
Julien Fontanet
a0ea12cf6c feat(CHANGELOG.unreleased): add S3 fix 2021-04-30 22:18:45 +02:00
Julien Fontanet
317bfde574 fix(fs/S3#_mkdir): throw ENOTDIR if file exists 2021-04-30 22:16:51 +02:00
Julien Fontanet
5f53ebdf12 chore(fs/S3#_rmdir): use _isNotEmptyDir 2021-04-30 22:16:51 +02:00
Julien Fontanet
cb835b7b6a fix(fs/S3#_unlink): throw EISDIR if dir
This fix `rmtree()`.
2021-04-30 22:16:51 +02:00
Julien Fontanet
bf76787e49 fix(fs/S3#_createReadStream): throw ENOENT if file doesn't exist 2021-04-30 22:16:51 +02:00
Julien Fontanet
15a4f7e273 fix(fs/S3): basic rmdir implementation 2021-04-30 22:16:51 +02:00
Julien Fontanet
dc3e5ffa4b chore(backups/RemoteAdapter#outputStream): use fs/outputStream
`createOutputStream` is deprecated and does not work with S3 remote.
2021-04-30 22:16:51 +02:00
Julien Fontanet
b84c7cc2bb feat(fs/outputStream): validator support 2021-04-30 22:16:51 +02:00
Julien Fontanet
049717260d chore(fs/outputStream): JsDoc 2021-04-30 19:50:00 +02:00
Julien Fontanet
a50a96de82 feat(fs/outputStream): remove support for promise input 2021-04-30 19:42:10 +02:00
Julien Fontanet
8ff8c0d176 chore(fs/outputStream): remove input.task handling
This should be handled at a higher level, not in this lib.
2021-04-30 19:38:31 +02:00
Julien Fontanet
a29b63c7d1 chore(fs/outputStream): move checksum handling to public wrapper 2021-04-30 19:31:56 +02:00
Julien Fontanet
a8400c77fb feat(fs/Abstract#outputStream): use stream.pipeline()
BREAKING CHANGE: requires Node >=14

- properly detect both input and output errors
- properly destroy streams in case of errors
2021-04-30 18:42:45 +02:00
Julien Fontanet
e1c40bd218 fix(fs/S3#mkdir): noop implementation 2021-04-30 18:26:50 +02:00
Julien Fontanet
757224683f chore(xo-server-audit): remove unused dep 2021-04-30 12:30:49 +02:00
Julien Fontanet
95d982f3f3 chore(xo-server-transport-icinga2): remove unused dep 2021-04-30 12:30:39 +02:00
Julien Fontanet
7bfdfe5e41 chore(xapi): remove unused dep 2021-04-30 12:10:14 +02:00
Julien Fontanet
8888b1a89a fix(proxy): add missing dep 2021-04-30 12:10:04 +02:00
Julien Fontanet
c6ba48be10 chore(proxy): remove unused deps 2021-04-30 12:09:51 +02:00
Julien Fontanet
f132c4b5d1 chore(log): remove unused dev dep 2021-04-30 12:08:03 +02:00
Julien Fontanet
87f5a8f6f2 chore(backups-cli): remove unused dep 2021-04-30 12:06:51 +02:00
Julien Fontanet
de500af30d fix(backups): add missing dep 2021-04-30 12:06:40 +02:00
Julien Fontanet
8b5607ac89 chore(audit-core): remove unused dep 2021-04-30 12:04:42 +02:00
Julien Fontanet
22727f68c1 fix(audit-core): fix incorrect dev dep 2021-04-30 12:04:30 +02:00
Julien Fontanet
ba64f8e5b5 fix(disposable): add missing dep 2021-04-30 12:02:39 +02:00
Julien Fontanet
b3bde5857e chore(xo-vmdk-to-vhd): remove unused dev dep 2021-04-30 12:01:29 +02:00
Julien Fontanet
6e36a21d18 chore(xo-server-web-hooks): remove unused deps 2021-04-30 12:01:07 +02:00
Julien Fontanet
968ebeb5a3 chore(xo-import-servers-csv): remove unused deps 2021-04-30 11:59:45 +02:00
Julien Fontanet
47e11652fb chore(vhd-lib): remove unused dev dep 2021-04-30 11:53:26 +02:00
Julien Fontanet
84019ed4e7 chore(vhd-cli): remove unused dep 2021-04-30 11:53:14 +02:00
Julien Fontanet
37befd89e7 chore(xo-server): remove unused deps 2021-04-30 11:48:28 +02:00
badrAZ
aa4f1b834a feat(vhd-lib/mergeVhd): continuable (#5749) 2021-04-30 09:18:21 +02:00
Rajaa.BARHTAOUI
e6f8fd9234 feat: technical release (#5761) 2021-04-29 10:40:55 +02:00
Rajaa.BARHTAOUI
86904892f2 fix(xo-server-perf-alert): fix 'Invalid parameters' error (#5755)
Introduced by 7c9850ada
2021-04-29 09:48:05 +02:00
badrAZ
d176dd6533 fix(xo-server-test/backupNg): remove obsolete snapshots (#5760) 2021-04-29 09:38:51 +02:00
badrAZ
283efe0eac fix(backups/cleanVm): pass handler to mergeVhdChain (#5758)
Introduced by 20f4c952fe
2021-04-28 18:21:23 +02:00
badrAZ
0e361cb105 fix(backups/cleanVm): correctly wait VHD deletions (#5757)
Introduced by c955da9bc6
2021-04-28 18:20:01 +02:00
Julien Fontanet
53aeb085ac fix(backups/MixinBackupWriter): ensure dir exist before locking 2021-04-28 17:52:46 +02:00
Rajaa.BARHTAOUI
cd8c618f08 feat(xo-server/pool.listPoolsMatchingCriteria): new API method (#5715)
See xoa-support#3489
2021-04-28 15:48:22 +02:00
Julien Fontanet
18b74d9797 fix(backups/RemoteAdapter#cleanVm): correctly rename/remove VHDs after merge 2021-04-28 15:06:22 +02:00
Ronan Abhamon
4008934bbb feat(load-balancer): improve migration (perf mode) regarding memory and cpu usage
- ensure we optimize CPU first instead of free memory
- use low threshold now to forbid bad migration based on cpu usage
- add a tolerance on the VM CPU usage to migrate VM with the most memory used
- do not migrate if we create an unbalanced configuration (only if high tresholds are not reached)
- change factors to take into account the new algorithm
2021-04-28 14:22:30 +02:00
Ronan Abhamon
8ae432554e fix(load-balancer): memory free limit must be expressed in B instead of KiB (bad calculations otherwise) 2021-04-28 14:22:30 +02:00
Ronan Abhamon
337b26176a fix(load-balancer): ensure anti-affinity tag array is always defined 2021-04-28 14:22:30 +02:00
Julien Fontanet
2e643fce28 fix(backups/MixinBackupWriter): clean VM dir after backup
Otherwise, it might trigger a chain reaction which will force all VDIs to be fully exported:

1. a single VDI chain is corrupted
2. it gets removed
3. the linked backups are removed
4. all other VDIs are now unused and are removed as well
5. all VDIs must now be fully exported
2021-04-28 13:20:56 +02:00
Julien Fontanet
5edd271975 fix(backups/RemoteAdapter#cleanVms): restore action logs
Introduced by 20f4c952fe

They are necessary because `cleanVms` can run in diagnostic or cleaning mode and the difference must be visible in logs.
2021-04-28 13:07:29 +02:00
Nicolas Raynaud
c219ea06bf feat(backup/s3): add http and region parameters to S3 (#5658) 2021-04-28 11:30:23 +02:00
badrAZ
ffacc0d8d0 fix(xo-server-test/backupNg): follow the new backup implementation (#5732) 2021-04-28 11:23:12 +02:00
Julien Fontanet
70fff77a28 fix(backups/_MixinBackupWriter): warn issues detected in cleanVm
`debug` is not good enough because not shown by default.
2021-04-28 10:43:48 +02:00
Rajaa.BARHTAOUI
bcc52d586e fix(xo-server-perf-alert): fix "required property uuids is not defined" warning (#5752)
See https://github.com/vatesfr/xen-orchestra/pull/5692#discussion_r611984364
2021-04-27 22:46:27 +02:00
Mathieu
521ded5079 feat(xo-web/host/network): identify management network (#5743)
Fixes #5731
2021-04-27 14:50:05 +02:00
Pierre Donias
73b6b59ec9 fix(xen-api/_sessionOpen): prevent deadlock (#5751)
Dead lock loop:
- `_sessionOpen`
- `getAllRecords`
- `_roCall`
- `_sessionCall` → `onRetry: _sessionOpen`

This triggers a dead lock because `_sessionOpen`'s calls are coalesced. Without `coalesceCalls`, this would be an infinite loop instead.
2021-04-27 14:00:00 +02:00
badrAZ
157c81b0e9 fix(@xen-orchestra/xapi#VM_import): ensure onVmCreation is called (#5747)
It was not called if the import task was not received (for instance because the import was very fast).
2021-04-26 17:29:14 +02:00
Rajaa.BARHTAOUI
233096354c feat(xo-web/xoa): notify user when proxies need to be upgraded (#5717)
See xoa-support#3597
2021-04-26 16:38:59 +02:00
Julien Fontanet
01ac23162f fix(xapi/watchObject): dont break potential promise chain 2021-04-26 16:12:30 +02:00
Julien Fontanet
4e3628c6fb fix(xapi/watchObject): correctly register generic watcher 2021-04-26 16:12:00 +02:00
Julien Fontanet
d6bea8aed8 feat(xapi/waitObject): simpler API
Align the API of `watchObject`, take a callback as param and return a function to stop waiting.
2021-04-26 15:30:45 +02:00
Julien Fontanet
a254097092 feat(xapi/watchObject): split from waitObject 2021-04-26 15:26:06 +02:00
Julien Fontanet
b2a3d224a5 feat(xapi/waitObject): make public 2021-04-26 14:29:52 +02:00
Julien Fontanet
b495c2b60b fix(xo-server/Xapi#importDeltaVm): remove transferSize in result
Not necessary and broken since bdb0ca836
2021-04-26 14:27:11 +02:00
Julien Fontanet
452f76cbef fix(xo-server/xapi): remove _waitObject
It was shadowing the parent implementation.
2021-04-26 14:23:43 +02:00
Julien Fontanet
3a0690bfee chore(proxy/api): dont access to stream private state 2021-04-26 11:44:55 +02:00
Julien Fontanet
29fd2ff5e9 feat(backups): lock VM dir during backup (#5746)
May fix xoa-support#3387
2021-04-26 09:23:20 +02:00
Julien Fontanet
a344b3b76d feat(xapi/_waitObject): cancelation support
Related to #5747
2021-04-25 16:01:32 +02:00
Julien Fontanet
14cf955cb9 chore(xapi): use extensions for file imports
Will be necessary for ESM.
2021-04-25 14:40:06 +02:00
badrAZ
31193d5b40 fix(xo-server/backup-ng#deleteVmBackupNg): pass remote obj to deleteVmBackup (#5744) 2021-04-23 16:34:23 +02:00
Julien Fontanet
d6dc63c491 chore(CHANGELOG.unreleased): format with Prettier 2021-04-23 16:04:38 +02:00
Julien Fontanet
263f693542 chore(xen-api): remove unused memory test 2021-04-23 14:59:02 +02:00
Julien Fontanet
3f42199f8f feat(normalize-packages): dont use files field
A centralized npmignore is easier to use and maintain.
2021-04-23 14:47:34 +02:00
Julien Fontanet
251ccd2e38 chore(npmignore): dont publish docs directories 2021-04-23 14:47:34 +02:00
Julien Fontanet
82ccf5886e chore(npmignore): dont publish hidden files 2021-04-23 14:47:34 +02:00
Julien Fontanet
6acb1e3853 chore(eslint): only use @babel/eslint-parser for pkgs using Babel 2021-04-23 14:47:34 +02:00
Mathieu
8c0238e98f feat(xo-server/pif.reconfigureIp): reconfigure on host if management (#5745)
Fixes #5730
2021-04-23 14:07:18 +02:00
Mathieu
e7779c3d55 feat(xo-server/template): ability to create a template from snapshot (#5736)
Fixes #4891
2021-04-23 10:52:35 +02:00
Julien Fontanet
bdb0ca836c feat(xo-server): remove legacy backups (#5735)
BREAKING: all `backup.*` API methods removed
2021-04-23 09:40:46 +02:00
Rajaa.BARHTAOUI
53038a0372 feat(xo-web): remove legacy backups (#5718) 2021-04-23 09:39:12 +02:00
Julien Fontanet
1b0eb91d58 chore(backups/writers): remove unnecessary index 2021-04-22 14:22:03 +02:00
Julien Fontanet
5814ba38ac chore(ackups,proxy,xo-server): use extensions for file imports
Follow-up on 7f570c074, 5171378be and b2ec0d288

Will be necessary for ESM.
2021-04-22 13:43:57 +02:00
Julien Fontanet
b2ec0d288b chore(xo-server): use extensions for file imports
Will be necessary for ESM.
2021-04-22 13:24:06 +02:00
Julien Fontanet
5171378bea chore(proxy): use extensions for file imports
Will be necessary for ESM.
2021-04-22 13:16:47 +02:00
Julien Fontanet
7f570c074b chore(backups): use extensions for file imports
Will be necessary for ESM.
2021-04-22 13:12:14 +02:00
Julien Fontanet
dac675143f chore(proxy): backups/index.js → backups.js 2021-04-22 13:10:30 +02:00
Julien Fontanet
72a5f0e220 chore: use decorateWith instead of defer decorator syntax
`golike-defer` built-in decorator syntax will be removed in future versions.
2021-04-21 17:47:40 +02:00
Julien Fontanet
375aaa8430 chore: dont use default export from golike-defer
- will be removed in future version
- not compatible with ESM implementation in Node
2021-04-21 17:20:16 +02:00
Julien Fontanet
4c704a8a3a chore(proxy/appliance): dont import log from dist/ 2021-04-21 16:59:50 +02:00
Julien Fontanet
78c0f2c7e9 chore: remove Flow
It was not used nor maintained by XO devs, and was causing issues with editors.

JSDoc or TypeScript should be used instead.
2021-04-21 16:55:03 +02:00
badrAZ
c262dd06e6 fix(@xen-orchestra/backups/isValidXva): move as RemoteAdapter method (#5741) 2021-04-21 16:27:13 +02:00
badrAZ
e0d6b501c7 feat(@xen-orchestra/backups): clean VM backups on run (#5727) 2021-04-21 13:27:33 +02:00
Julien Fontanet
efc3f45ef6 feat(babel-config): use top level targets option
See https://babeljs.io/blog/2021/02/22/7.13.0#top-level-targets-option-12189httpsgithubcombabelbabelpull12189-rfchttpsgithubcombabelrfcspull2
2021-04-20 16:24:44 +02:00
Julien Fontanet
24d8ef25bb feat(backups/VmBackup#run): assert offlineBackup not with snapshotRetention
See #5740
2021-04-20 15:03:17 +02:00
Julien Fontanet
2aca775907 fix(backups/VmBackup#_snapshot): dont fail on !offlineBackup && !snapshotRetention
Introduced by 7aa10ef4be
2021-04-20 14:59:18 +02:00
badrAZ
7aa10ef4be fix(backups): don't snapshot in case of offline backup (#5739)
Introduced by 0811da9014
2021-04-20 11:01:39 +02:00
Julien Fontanet
17ad622ce3 chore: update dev deps 2021-04-20 10:58:25 +02:00
Julien Fontanet
cc7431a092 chore(xo-server-test): update jest to 24.6.3 2021-04-20 10:51:57 +02:00
Julien Fontanet
4199d02d98 chore(xo-server-{auth-saml,transport-nagios}): remove unused dep babel-preset-env 2021-04-20 10:44:02 +02:00
badrAZ
8c434760fb fix(@xen-orchestra/backups/_cleanVm): don't resolve paths relatively to cwd (#5738) 2021-04-20 10:35:28 +02:00
Julien Fontanet
5f63b99dc8 feat(backups/_backupWorker): log global errors 2021-04-19 20:13:57 +02:00
Julien Fontanet
edd0ae4c59 fix(xapi/VM_snapshot): correctly delete broken snapshot
Introduced by 6b1c30157
2021-04-19 18:35:05 +02:00
Pierre Donias
3944e6450d feat(fs/nfs): remove vers=3 default option (#5725) 2021-04-19 15:29:17 +02:00
Julien Fontanet
a8e5ad42ba chore(xo-web): migrate to babel 7
Fix linting.
2021-04-19 15:18:09 +02:00
Julien Fontanet
d3bfb0b87b fix(xapi/VM_destroy): ensure all VDIs deletion errors are caught/logged
Related to 6b1c30157
2021-04-19 10:45:46 +02:00
Pierre Donias
75e3e36aa8 feat(xo-web/new VM): only send memory param so that it doesn't enable DMC (#5729)
Fixes xoa-support#3591
See 70d1537ecc

- If only "RAM" field is filled: only send `memory` param
- If any of the advanced memory fields are filled:
  - only send those
  - if "Dynamic memory max" field is empty, use the "RAM" field value for
  `memoryDynamicMax` param
2021-04-19 10:16:56 +02:00
Julien Fontanet
9102b4aa1b fix(fs): coalesce calls to sync/forget (#4770)
Might help with xoa-support#3637

It does not makes sense to call them multiple times and can create issues.
2021-04-17 14:55:21 +02:00
badrAZ
e744d90dbb fix(xo-server/backups-ng): continue execution when VM/SR is missing (#5733)
Introduced by 60ecfbfb8e
2021-04-16 23:33:20 +02:00
badrAZ
c38b957d7c fix(xo-{server,proxy}/config): add copyRetention default value (#5737)
Introduced in xo-server by 0811da901
2021-04-16 14:56:43 +02:00
Julien Fontanet
282bb26da9 chore(xapi/VM_{destroy,snapshot}): delete → destroy
Introduced by 6b1c30157
2021-04-16 10:35:48 +02:00
Julien Fontanet
6b1c30157f feat(xapi/VM_{destroy,snapshot}): warn instead of ignoring errors 2021-04-16 10:32:04 +02:00
Julien Fontanet
e433251420 fix(xo-server/recover-account): pass config as named param
Introduced by 7024c7d59
2021-04-15 15:52:56 +02:00
Julien Fontanet
49ed9c7f7f fix(xo-server/api): fix config name entry verboseApiLogsOnErrors 2021-04-15 13:34:05 +02:00
Julien Fontanet
5a5c0326b7 fix(xapi/VM_destroy): correctly check *other* VM is not control domain 2021-04-15 11:52:56 +02:00
Julien Fontanet
a25708be2b fix(xapi/VM_create): default actions_after_{crash,reboot} is restart
See https://xapi-project.github.io/xen-api/classes/vm.html

`reboot` is not valid.
2021-04-15 11:48:40 +02:00
Julien Fontanet
e8f2934534 feat(xo-server/getBackupNgLogs): expose proxyId
Follow up on b454b4dff
2021-04-15 11:43:34 +02:00
badrAZ
37f8ac9da9 fix(fs/LocalHandler#_lock): correctly resolve path (#5726) 2021-04-14 15:59:11 +02:00
badrAZ
0ded95ce48 fix(xo-server/backup-ng): add slash between backup and remote ids (#5723)
This is symmetric to the parsing: 052aafd7cb/packages/xo-server/src/xo-mixins/backups-ng/index.js (L88-L94)
2021-04-14 14:43:28 +02:00
Julien Fontanet
108e769833 fix(CHANGELOG.unreleased): @xen-orchestra/xapi
Introduced by 864946477
2021-04-14 11:46:12 +02:00
Julien Fontanet
5b2313ee56 feat(xapi): warn on retry 2021-04-14 11:10:20 +02:00
Julien Fontanet
368b84b7ff chore(xapi/VDI_destroy): move retry condition in constructor 2021-04-14 10:30:11 +02:00
Julien Fontanet
864946477b fix(xapi/VDI_destroy): respect vdiDestroyRetryWhenInUse option 2021-04-14 10:23:53 +02:00
Julien Fontanet
da67298b43 chore: update promise-toolbox to 0.19.0 2021-04-14 00:12:34 +02:00
Julien Fontanet
db5cb8b3a9 chore(disposables): using → Disposable.use 2021-04-13 23:35:10 +02:00
Julien Fontanet
9643292be6 fix(babel): dont ignore test files when linting 2021-04-13 18:09:40 +02:00
Julien Fontanet
a651e34206 fix(xo-server/math): fix ESLint directive 2021-04-13 18:09:40 +02:00
Julien Fontanet
a4e7fd3209 feat(xo-server): use @xen-orchestra/mixins/Config 2021-04-13 18:09:40 +02:00
Julien Fontanet
d1113d40aa chore(mixins): use PascalCase as they are classes 2021-04-13 18:09:40 +02:00
Julien Fontanet
dcd834d3e4 chore(xo-server/xo-mixins): xo → app
- already used in some mixins
- used in xo-proxy
2021-04-13 18:09:40 +02:00
badrAZ
c0be8a2c04 fix(@xen-orchestra/backups/_cleanVm): VHDs not correctly listed (#5720)
Introduced by 20f4c95
2021-04-13 16:09:42 +02:00
Julien Fontanet
09182172cf chore(xo-server): use @xen-orchestra/mixins/hooks 2021-04-13 13:41:22 +02:00
Julien Fontanet
56e903e359 feat(mixins): mixins shared between xo-proxy and xo-server 2021-04-13 13:17:50 +02:00
Julien Fontanet
9922d60e5b feat(@xen-orchestra/mixin): 0.1.0 2021-04-13 13:01:24 +02:00
Julien Fontanet
09ea42439e chore(mixin): remove build step 2021-04-13 12:31:11 +02:00
Julien Fontanet
ce1acf1adc feat(@xen-orchestra/proxy): 0.12.1 2021-04-13 10:46:44 +02:00
Julien Fontanet
fe00badb0f feat: release 5.57.1 2021-04-13 10:27:38 +02:00
Julien Fontanet
2146d67dc2 fix(CHANGELOG{,.unreleased}): move backup dev notes
Introduced by e7b846155
2021-04-13 10:26:26 +02:00
Julien Fontanet
6728768b3e feat(xo-server): 5.78.4 2021-04-12 23:43:33 +02:00
Julien Fontanet
48db3de08c feat(@xen-orchestra/backups): 0.9.3 2021-04-12 23:43:16 +02:00
Julien Fontanet
b944364d1e fix(backups/_copyDelta): dont pass extra params to watchStreamSize
Introduced by 9b1fbf0fb
2021-04-12 23:42:29 +02:00
Julien Fontanet
39c2fbe8c3 feat(xo-web): 5.80.1 2021-04-12 22:56:48 +02:00
Julien Fontanet
c7ba640ecb feat(xo-server): 5.78.3 2021-04-12 22:56:29 +02:00
Julien Fontanet
f749f6be72 feat(xo-server-load-balancer): 0.5.0 2021-04-12 22:56:09 +02:00
Julien Fontanet
ccdd384c6e feat(@xen-orchestra/backups): 0.9.2 2021-04-12 22:55:36 +02:00
Julien Fontanet
4061e2c149 feat(@xen-orchestra/xapi): 0.6.1 2021-04-12 22:55:19 +02:00
Julien Fontanet
e7b8461555 chore(CHANGELOG): update next 2021-04-12 22:54:51 +02:00
Julien Fontanet
70d1537ecc feat(xo-server/vm.set): dont switch to DMC when changing memory
Fixes #4983
2021-04-12 21:15:55 +02:00
Julien Fontanet
cb37f85d8e fix(xo-web/proxies): fix force ugprade
Introduced by a4d90e8aff

See xoa-support#3613

Forward options in `upgradeAppliance` effect.
2021-04-12 12:16:18 +02:00
Julien Fontanet
9becf565a4 fix(CHANGELOG.unreleased): add missing entriy
Introduced by 4bbe8488f
2021-04-12 11:12:54 +02:00
Julien Fontanet
b1a4e5467d feat(xo-server/xapi/startVm): move hostId into options 2021-04-12 11:01:42 +02:00
Julien Fontanet
4bbe8488fc fix(xo-server/xapi/startVm): dont destructure options without default value
See xoa-support#3613
2021-04-12 10:52:41 +02:00
Jon Sands
54a0d126b5 fix(xo-web/en): more grammar fixes (#5714) 2021-04-10 10:30:39 +02:00
Julien Fontanet
9b1fbf0fbf fix(backups/ImportVmBackup): use transfered size instead of backup size
Backup size is smaller in case of delta VHDs.
2021-04-09 15:33:50 +02:00
Julien Fontanet
6f626974ac chore(backups/readDeltaVmBackup): remove unused value 2021-04-09 15:02:26 +02:00
Julien Fontanet
5c47beb1c4 fix(CHANGELOG.unreleased): add missing entry
Related to 3cc9fd278
2021-04-09 11:35:49 +02:00
Julien Fontanet
b4fbe8df07 feat(xo-server/api): explicitely allow $type and enumNames in schemas 2021-04-09 11:16:17 +02:00
Julien Fontanet
3cc9fd2782 fix(xo-server/api): log instead of rejecting non-strict schemas
Fixes https://xcp-ng.org/forum/topic/4439/plugin-transport-email-v0-6-0-broken
2021-04-09 11:03:13 +02:00
Julien Fontanet
eaecba7ec8 fix(xo-server/api): dont log pool.listMissingPatches & host.stats errors
Introduced by 9226c6cac
2021-04-09 10:47:01 +02:00
Julien Fontanet
42a43be092 feat(backups/Task.wrapFn): opts can be a function 2021-04-09 01:27:54 +02:00
Julien Fontanet
052aafd7cb fix(backups/DeltaBackupWriter): merge should be subtask of export
Introduced by f5024f0e7
2021-04-09 01:25:01 +02:00
Julien Fontanet
4abae578f4 feat(backups/Task): new implementation
- no longer requires logging
- supports cancelation (`Task.cancelToken` and `Task#cancel()`)
- supports running multiple functions in the same task
2021-04-09 01:19:09 +02:00
Julien Fontanet
4132d96591 chore(backups): remove unused deps 2021-04-09 01:13:22 +02:00
Julien Fontanet
8e4c90129e fix(backups/DeltaBackupWriter): dont overwrite prepare/cleanup in constructor
Introduced in e69b6c4dc
2021-04-08 23:52:21 +02:00
Julien Fontanet
31406927e6 chore: disable unused Jest coverage 2021-04-08 22:25:10 +02:00
Julien Fontanet
303646efd3 chore: remove unnecessary Jest transform setting 2021-04-08 22:25:10 +02:00
Julien Fontanet
9efc4f9113 chore: remove unnecessary babel-core 2021-04-08 22:25:10 +02:00
Julien Fontanet
31a5a42ec7 chore: use @babel/eslint-parser instead of babel-eslint
babel-eslint is no longer maintained and has issues with some recent syntaxes like private methods.
2021-04-08 22:25:10 +02:00
Yannick Achy
2d0ed3ec8a feat(doc): Host update revision (#5716)
* Host update revision

Co-authored-by: yannick Achy <yannick.achy@vates.fr>
2021-04-08 16:54:06 +02:00
Julien Fontanet
de288a008d fix(proxy): upgrade to koa-compress@5
Fix a koa-compress@4 bug which compress the reply when no accept-encoding header has been passed.
2021-04-07 17:21:10 +02:00
Julien Fontanet
3c5d73224a feat(normalize-packages): delete empty dependencies, description and keywords fields 2021-04-07 15:14:48 +02:00
Julien Fontanet
05f9c07836 chore: add descriptions to all pkgs (but mixin) 2021-04-07 15:13:18 +02:00
Julien Fontanet
a7ba6add39 feat(read-chunk): ensure function is properly named 2021-04-07 14:02:50 +02:00
Julien Fontanet
479973bf06 fix(xapi): add missing cli.js
Introduced by be9b5332d9
2021-04-07 14:00:40 +02:00
Julien Fontanet
854c9fe794 fix(.gitignore): handle @vates/* pkgs 2021-04-07 13:59:07 +02:00
Julien Fontanet
5a17c75fe4 feat: unified .npmignore for all packages
Ensure sources, tests and USAGE.Md files will not be published.
2021-04-07 13:58:14 +02:00
Julien Fontanet
4dc5eff252 chore(normalize-packages): remove unused require 2021-04-07 13:39:12 +02:00
Julien Fontanet
7fe0d78154 fix(compose/USAGE): typo 2021-04-07 13:36:24 +02:00
Julien Fontanet
2c709dc205 fix(xo-server/proxies): readChunk import
Introduced by 538253cdc
2021-04-07 13:09:29 +02:00
Julien Fontanet
9353349a39 chore(vhd-lib): use @vates/read-chunk 2021-04-07 13:08:44 +02:00
Julien Fontanet
d3049b2bfa feat(@vates/read-chunk): 0.1.2 2021-04-07 13:07:57 +02:00
Julien Fontanet
61cb2529bd feat(read-chunk/package.json): only publish index.js 2021-04-07 13:05:49 +02:00
Julien Fontanet
e6c6e4395f chore(read-chunk): add tests 2021-04-07 13:03:56 +02:00
Julien Fontanet
959c955616 feat(read-chunk): handle 0 size 2021-04-07 12:51:27 +02:00
Julien Fontanet
538253cdc1 chore(xo-server/proxies): use @vates/read-chunk 2021-04-07 12:31:16 +02:00
Julien Fontanet
b4c6594333 chore(xo-server/utils): remove unused wrap 2021-04-07 12:25:47 +02:00
Julien Fontanet
a7f5f8889c chore(xo-server/http): use @xen-orchestra/defined 2021-04-07 12:15:33 +02:00
Julien Fontanet
1c9b4cf552 feat(xo-server/Xo): pass appDir, AppName and httpServer
As done in xo-proxy.

This may allow sharing mixins in the future.
2021-04-07 10:41:50 +02:00
Julien Fontanet
ce09f487bd feat(xo-server/XenServers): dont auto connect on safe mode 2021-04-07 10:41:50 +02:00
Julien Fontanet
a5d1decf40 feat(xo-server/Xo): safeMode param 2021-04-07 10:41:50 +02:00
Julien Fontanet
7024c7d598 chore(xo-server/Xo): pass config as named param
As done in xo-proxy.
2021-04-07 10:41:50 +02:00
Jon Sands
8109253eeb fix(xo-web/en): grammar fixes (#5713) 2021-04-06 10:31:52 +02:00
Julien Fontanet
b61f1e3803 fix(xapi/VM_snapshot): VM#refresh_snapshots does not exist
Fixes xoa-support#3587
2021-04-04 22:41:46 +02:00
Julien Fontanet
db40f80be7 chore(CHANGELOG.unreleased): formatting 2021-04-04 22:36:35 +02:00
Mathieu
26eaf97032 fix(xo-web/restore): generateNewMACAddresses disabled by default (#5707) 2021-04-04 18:41:37 +02:00
Ronan Abhamon
da349374bf feat(load-balancer): add option to disable migration (#5706) 2021-04-02 17:32:26 +02:00
Julien Fontanet
0ffa925fee chore(xo-server-load-balancer): format with Prettier 2021-04-02 15:34:38 +02:00
Julien Fontanet
082787c4cf chore: update dependencies 2021-04-02 15:34:19 +02:00
Julien Fontanet
be9b5332d9 feat(xapi): add xo-xapi CLI
Allows to easily test @xen-orchestra/xapi features.
2021-04-01 14:47:04 +02:00
Julien Fontanet
97ae3ba7d3 feat(@xen-orchestra/proxy): 0.12.0 2021-04-01 14:09:09 +02:00
Julien Fontanet
d047f401c2 fix(CHANGELOG): move Highlights title under badge
Introduced by 1e9e78223
2021-04-01 14:08:12 +02:00
Julien Fontanet
1e9e78223b fix(CHANGELOG): missing Highlights title 2021-04-01 13:44:21 +02:00
Julien Fontanet
6d5baebd08 feat: release 5.57.0 2021-04-01 13:29:58 +02:00
Pierre Donias
4e758dbb85 feat: technical release (#5705) 2021-04-01 11:28:09 +02:00
Julien Fontanet
40d943c620 feat(backups/CR writer): delete interrupted copies in prepare() 2021-04-01 10:52:06 +02:00
Julien Fontanet
e69b6c4dc8 fix(backups/delta writers): compute old entries before run 2021-04-01 10:48:39 +02:00
Julien Fontanet
23444f7083 fix(xo-server): Backup/getConnectedRecord receive XAPI not XO type 2021-03-31 16:48:20 +02:00
Julien Fontanet
8c077b96df chore(xo-server/getXapiObject): clarify that second param is an XO type 2021-03-31 16:31:56 +02:00
Pierre Donias
4b1a055a88 feat: technical release (#5704) 2021-03-31 11:15:41 +02:00
Rajaa.BARHTAOUI
b4ddcc1dec feat(xo-server,xo-web/startVm): avoid booting VM if there's an identical MAC address elsewhere (#5655)
Fixes #5601
2021-03-31 10:50:32 +02:00
badrAZ
271d2e3abc feat(fs): expose highWaterMark stream option (#5676) 2021-03-31 10:34:42 +02:00
Julien Fontanet
37b6399398 fix(backups/importDeltaVm): reverse newMacAddresses condition for VIF creation
Introduced by 4df8c9610
2021-03-30 21:26:08 +02:00
Julien Fontanet
ebf19b1506 fix(proxy/backup.importVmBackup): settings param is optional
Introduced by b475b265a
2021-03-30 21:26:08 +02:00
Julien Fontanet
e4dd773644 fix(proxy/api/ndJsonStream): dont fail if one message cannot be JSONified 2021-03-30 21:26:08 +02:00
Mathieu
f9b3a1f293 feat(xo-web/restore): support new mac addresses (#5697) 2021-03-30 17:48:45 +02:00
Rajaa.BARHTAOUI
7c9850ada8 feat(xo-server-perf-alert): ability to choose all hosts, VMs and SRs (#5692)
Fixes #2987
2021-03-30 17:26:48 +02:00
Ronan Abhamon
9ef05b8afe feat(load-balancer): add new anti-affinity mode (#5652)
Fixes #5600
2021-03-30 17:25:41 +02:00
Mathieu
efdd196441 feat(xo-web/proxies): move proxy actions to dropdown (#5688) 2021-03-30 16:56:10 +02:00
Julien Fontanet
6e780a3876 fix(xapi/call{,Async}): fix call to retry
Introduced by 3bb7d2c29
2021-03-30 15:42:05 +02:00
Julien Fontanet
b475b265ae feat(import VM backup): newMacAddresses setting
Related to #5697
2021-03-30 14:31:08 +02:00
Julien Fontanet
3bb7d2c294 feat(xapi/call{,Async}): retry if too many pending tasks
Logic from xo-server/xapi/call
2021-03-30 14:21:19 +02:00
Julien Fontanet
594a148a39 feat(xo-server): VDI_destroy instead of deleteVdi 2021-03-30 14:08:25 +02:00
Julien Fontanet
779591db36 feat(xapi/VDI_destroy): dont fail if VDI not found
Aligned with xo-server/xapi/deleteVdi.
2021-03-30 13:59:10 +02:00
Julien Fontanet
c002eeffb7 chore(proxy): remove unused Node test
The proxy now requires Node >=12
2021-03-30 09:23:15 +02:00
Julien Fontanet
1dac973d70 feat(backups/Task.wrapFn): compatibility with @decorateWith 2021-03-30 09:20:30 +02:00
Julien Fontanet
f5024f0e75 feat(backups/delta writers): split run method in prepare/transfer/cleanup
Fixes xoa-support#3523

This avoids starting the transfer before the writers are ready, which caused it to failed with `deleteFirst` when deletion was so long that the transfer stalled.
2021-03-30 09:20:30 +02:00
Pierre Donias
cf320c08c5 feat: technical release (#5702) 2021-03-29 16:45:00 +02:00
Rajaa.BARHTAOUI
8973c9550c fix(xo-web/vm/advanced): remove noop (#5700)
See https://github.com/vatesfr/xen-orchestra/pull/3774/files#r602860699
2021-03-29 15:10:48 +02:00
Julien Fontanet
bb671f0e93 feat(xapi): update to xo-common@0.7.0 2021-03-29 15:01:12 +02:00
Julien Fontanet
a8774b5011 chore(log/transport/console): remove unused code 2021-03-29 14:59:14 +02:00
Julien Fontanet
f092cd41bc chore: named import from @xen-orchestra/log 2021-03-29 14:06:29 +02:00
Julien Fontanet
b17ec9731a fix(xapi/task_create): dont use super
Introduced by 021810201b

It cannot be used due to our mixin architecture.
2021-03-28 23:29:17 +02:00
Julien Fontanet
021810201b fix(xapi/task_create): remove duplicate [XO] prefix
Found while investigating xoa-support#3553
2021-03-28 14:30:36 +02:00
Julien Fontanet
6038dc9c8a fix(xo-web/vm/advanced): RTL819 → RTL8139
Fixes #5698
2021-03-28 12:23:52 +02:00
Julien Fontanet
4df8c9610a fix(backups/importDeltaVm): new mac_seed when using newMacAddresses 2021-03-26 17:14:37 +01:00
Julien Fontanet
6c12dd4f16 feat(xapi/VM_create): generateMacSeed option 2021-03-26 17:14:37 +01:00
badrAZ
ad3b8fa59f feat(xo-server-usage-report): add VM IP addresses to the report (#5696) 2021-03-26 14:39:35 +01:00
Mathieu
cb52a8b51b feat(xo-server): VM_destroy instead of deleteVm (#5693)
Continuation of 5f1c127
2021-03-26 14:23:04 +01:00
badrAZ
22ba1302d2 fix(xo-server-backup-reports): support failed targets (#5694)
Introduced by d282d8dd5
2021-03-26 10:27:08 +01:00
Mathieu
7d04559921 fix(xo-web/disk import): an error has occurred (#5683)
Fixes #5663

undefined files in collection due to unhandled disk formats
2021-03-26 09:37:31 +01:00
Julien Fontanet
e40e35d30c fix(xo-server): dont provide mac_send when importing OVA VM
Fixes xoa-support#3544
2021-03-25 15:51:02 +01:00
Julien Fontanet
d1af9f236c feat(backup/importDeltaVm): restoreMacAddresses option 2021-03-24 16:39:08 +01:00
Julien Fontanet
45a0ff26c5 feat(xapi/VIF_create): MAC must be passed explicitely 2021-03-24 16:38:19 +01:00
Julien Fontanet
1fd330d7a4 fix(CHANGELOG.unreleased): @vates/disposable 2021-03-24 16:03:49 +01:00
Julien Fontanet
09833f31cf fix(xapi/VM_export): correctly destroy snapshot after export 2021-03-24 16:00:45 +01:00
Julien Fontanet
20e7a036cf feat(xapi): no longer use promise-toolbox/cancelable 2021-03-24 15:34:47 +01:00
Julien Fontanet
e6667c1782 fix(xapi/VM_destroy): only update blocked operations when bypassBlockedOperation 2021-03-24 15:13:09 +01:00
Julien Fontanet
657935eba5 feat(xapi/VM_destroy): split bypassBlockedOperation out of force 2021-03-24 15:12:25 +01:00
Julien Fontanet
67b905a757 feat(xapi/VM_destroy): forceDeleteDefaultTemplate default to force 2021-03-24 15:11:49 +01:00
Julien Fontanet
55cede0434 fix(xapi/VM_destroy): ignore missing VM.set_is_default_template
Introduced by 5f1c1278e
2021-03-24 15:09:09 +01:00
Julien Fontanet
c7677d6d1e fix(xapi/VM_destroy): only update default template when forceDeleteDefaultTemplate 2021-03-24 15:07:30 +01:00
Mathieu
d191ca54ad feat(xo-server/xapi-object-to-xo): display full driver version (#5691) 2021-03-24 13:38:49 +01:00
badrAZ
20f4c952fe feat(@xen-orchestra/backups#RemoteAdapter): ability to clean broken backups (#5684) 2021-03-24 10:00:47 +01:00
Julien Fontanet
0bd09896f3 feat(docs/xoa): network config for other interfaces 2021-03-24 09:49:59 +01:00
badrAZ
60ecfbfb8e feat(xo-server, proxy, @xen-orchestra/backups): execute backup jobs on different processes (#5660) 2021-03-24 09:25:52 +01:00
Julien Fontanet
8921d78610 fix(disposable/deduped): call dispose with disposable context 2021-03-24 00:27:25 +01:00
Julien Fontanet
b243ff94e9 feat(fs/lock): returns a disposable 2021-03-23 23:04:49 +01:00
Mathieu
5f1c1278e3 fix(xapi/VM_destroy): handle is_default_template (#5644) 2021-03-23 17:28:18 +01:00
badrAZ
fa56e594b1 feat(xo-server-transport-email): ability to customize transport settings (#5681)
See xoa-support#3327

This functionnality can help users to get more info about their SMTP issues
2021-03-23 15:47:31 +01:00
badrAZ
c9b64927be feat(@xen-orchestra/fs): ability to lock a path (#5689)
Related to #5684
2021-03-23 13:00:15 +01:00
Julien Fontanet
3689cb2a99 chore(fs/outputStream): dont normalize path twice 2021-03-23 12:53:17 +01:00
Julien Fontanet
3bb7541361 fix(fs/local): opts is optional 2021-03-23 12:53:17 +01:00
Julien Fontanet
7b15aa5f83 fix(package.json/jest.moduleNameMapper): dont map sub-modules
For instance `@xen-orchestra/async-map/legacy`.
2021-03-23 12:53:17 +01:00
Julien Fontanet
690d3036db chore(xo-server): use native Promise#finally() (#5687) 2021-03-22 17:25:40 +01:00
Julien Fontanet
416e8d02a1 chore(xo-server): usingDisposable.use (#5686)
`using` is deprecated.
2021-03-22 17:25:28 +01:00
Julien Fontanet
a968c2d2b7 chore(xo-server): remove promise-toolbox/all uses (#5685) 2021-03-22 15:58:13 +01:00
Julien Fontanet
b4787bf444 fix(xo-server/(re)deployProxy): works whith missing bound VM 2021-03-22 14:44:39 +01:00
Julien Fontanet
a4d90e8aff fix(xo-web/proxies): ignore running jobs on force upgrade
See #3527
2021-03-22 14:37:34 +01:00
Julien Fontanet
32d0606ee4 feat(@xen-orchestra/proxy): 0.11.6 2021-03-22 13:41:28 +01:00
Julien Fontanet
4541f7c758 chore(xo-server): remove pSettle (#5682) 2021-03-22 10:37:07 +01:00
Julien Fontanet
65428d629c feat: release 5.56.2 2021-03-22 10:36:24 +01:00
Julien Fontanet
bdfd9cc617 feat: technical release 2021-03-22 09:56:31 +01:00
Julien Fontanet
6d324921a0 fix(CHANGELOG.unreleased): add xapi to packages to release
Introduced by dcf0f5c5a
2021-03-19 14:53:29 +01:00
Julien Fontanet
dcf0f5c5a3 fix(xapi/VM_create): ignore missing VM.set_bios_strings
Fixes xoa-support#3516
2021-03-19 14:51:51 +01:00
Julien Fontanet
d98f851a2c fix(xo-web/restore): dont break if log is missing result
Found when investigating xoa-support#3516
2021-03-19 13:46:22 +01:00
Julien Fontanet
a95b102396 fix(backups/ImportVmBackup#run): dont swallow errors
Found when investigating xoa-support#3516
2021-03-19 13:38:17 +01:00
Julien Fontanet
7e2fbbaae6 fix(xo-server/createAuthenticationToken): parse expiresIn param
Introduced by 92cf6bb887
2021-03-19 13:02:19 +01:00
Julien Fontanet
070e8b0b54 fix(docs): restore full_backups.md
Introduced by 078f40281
2021-03-19 11:04:42 +01:00
Yannick Achy
7b49a1296c feat(doc): various changes (#5679) 2021-03-19 11:02:24 +01:00
Julien Fontanet
1e278bde92 feat(xo-common/Error.is): apply predicate only on data
See #5644
2021-03-19 10:30:35 +01:00
Yannick Achy
078f402819 feat(doc): check dead links and duplicate (#5664) 2021-03-18 09:35:07 +01:00
Mathieu
52af565f77 fix(fs/localHandler): resource temporarily unavailable (#5612)
Fixes xoa-support#3414
2021-03-17 15:28:04 +01:00
Julien Fontanet
853905e52f feat(xen-api): automatically retry ro calls on ECONNRESET (#5674)
See xoa-support#3266
2021-03-16 17:31:18 +01:00
Julien Fontanet
2e0e1d2aac fix(xo-server/xen-servers): fix autoconnection
Fixes #5675

Introduced by 2fbfc97cca
2021-03-16 13:59:01 +01:00
Julien Fontanet
7f33a62bb5 fix(async-map/asyncMap): fix typing of first param 2021-03-16 11:32:39 +01:00
Julien Fontanet
bdb59ea429 fix(Travis CI): use Node 14 2021-03-15 18:26:22 +01:00
Julien Fontanet
1c0ffe39f7 fix(xapi): merge vdiDestroyRetryWhenInUse after defaults 2021-03-15 13:22:41 +01:00
Julien Fontanet
2fbfc97cca fix(xo-server): connect servers after config import (#5672)
Fixes #5670
2021-03-15 11:49:41 +01:00
Pierre Donias
482299e765 fix(xo-web/pool): disconnectServer → disableServer (#5671)
Fixes #5669
Introduced c7aaeca530
2021-03-15 09:53:34 +01:00
Julien Fontanet
54f4734847 chore: remove babel-plugin-lodash where unnecessary 2021-03-13 20:47:20 +01:00
Julien Fontanet
0fb6cef577 chore(defined): remove Flow 2021-03-13 20:47:20 +01:00
badrAZ
7eec264961 chore(@xen-orchestra/backups): fix logger names (#5666) 2021-03-12 13:53:43 +01:00
Julien Fontanet
aff874c68a chore(xo-server,xo-server-load-balancer): phase out mapToArray (#5662)
Use native `Array#map` or `Object.values` where possible and import directly from `lodash`.

Reasons:
- less dependencies
- more idiomatic
- better example for new code
2021-03-11 15:17:28 +01:00
Julien Fontanet
27abee0850 chore(xo-server-load-balancer): typo ressource → resource 2021-03-11 14:17:02 +01:00
Julien Fontanet
bcfb19f7c5 feat(normalize-packages): delete empty bin field 2021-03-11 12:15:53 +01:00
Julien Fontanet
306a8ce0df feat(@xen-orchestra/proxy): 0.11.5 2021-03-10 13:48:15 +01:00
Julien Fontanet
d9ea8d2c9c feat: release 5.56.1 2021-03-10 13:04:11 +01:00
Julien Fontanet
b479956bb2 feat: technical release (#5657) 2021-03-10 11:11:27 +01:00
Julien Fontanet
b32dc0e450 fix(xen-api/call): allow *.get_all_records in read only 2021-03-10 09:41:49 +01:00
badrAZ
5cca5d69af fix(@xen-orchestra/backups/Backup.js): fix rolling snapshot not ran if alone (#5656) 2021-03-09 18:24:58 +01:00
badrAZ
e0e89213d3 chore(xo-server): delete unused workers mixin (#5654)
Due to 0811da9014
2021-03-09 15:26:21 +01:00
Julien Fontanet
e246c19eb3 feat(xen-api/Ref): introduce new utils to manipulate refs (#5650)
Fixes xoa-support#3463

See xapi-project/xen-api#4338
2021-03-09 14:59:32 +01:00
badrAZ
d282d8dd52 fix(@xen-orchestra/backups): missing targets no longer prevent runs (#5651)
Fixes #5353
2021-03-09 14:37:52 +01:00
badrAZ
9601ad13ee fix(xo-web/proxies): fix "invalid parameters" error on canceling proxy deploy (#5649)
Issue: fetchProxyUpgrades called with an undefined proxy in the proxies collection.

Solution: Interrupt the deployment process on cancel, in order to not fetch updates in this case.
2021-03-09 10:37:59 +01:00
badrAZ
b7603e109d feat(xo-web/backup/new): ability to force full backup per schedule in case of CR (#5648)
Fixes #5541
2021-03-09 09:38:56 +01:00
Julien Fontanet
066f54906b chore: format with Prettier 2021-03-08 17:41:10 +01:00
Julien Fontanet
ea0aa9df70 chore(xen-api): disable problematic ESLint rules on specific lines 2021-03-08 14:23:57 +01:00
badrAZ
0811da9014 feat(xo-server): use @xen-orchestra/backups lib to run VM backups (#5642) 2021-03-08 14:05:41 +01:00
Julien Fontanet
d601290c46 fix(destroy VM): try harder to destroy VDIs (#5645)
Should fix #4926

Work-around XCP-ng/XenServer unmount from control-domain delay, especially with iSCSI SRs.

This issue impacts a lot XO backups which create snapshots, export them and delete them.
2021-03-08 09:46:51 +01:00
badrAZ
64357aff55 fix(@xen-orchestra/xapi): fix full VM backup imported as a template (#5646) 2021-03-05 17:41:50 +01:00
badrAZ
a20a3311b5 fix(xo-server/backup-ng): fix "xapi._assertHealthyVdiChains is not a function" error (#5647)
Introduced by 4c27562650
2021-03-05 17:33:24 +01:00
Julien Fontanet
ffce5d4bb5 chore(@xen-orchestra/xapi): make xen-api a peer dep 2021-03-05 16:17:02 +01:00
badrAZ
cbfadc019a fix(@xen-orchestra/backups): fix "asyncMapSettled is not a function" error (#5643) 2021-03-05 12:23:25 +01:00
Julien Fontanet
bf5427f3e8 feat(@xen-orchestra/proxy): 0.11.4 2021-03-05 11:39:06 +01:00
badrAZ
4c27562650 fix(xo-server/xapi): dont override @xen-orchestra/xapi#_assertHealthyVdiChain (#5641) 2021-03-05 11:38:49 +01:00
badrAZ
e8d20532ba feat(xo-server): use @xen-orchestra/backups lib to run metadata backups (#5616) 2021-03-05 10:51:00 +01:00
Mathieu
d928157569 fix(xo-web/vm/tab-network): an error has occurred when trying to sort empty network (#5639)
This issue happens when you have an ACL role on one VM, but you don't have an ACL role on the network of this VM.
2021-03-05 09:37:40 +01:00
Mathieu
872b05a7de feat(xo-server/VIF): set MAC address requires Admin ACL on network (#5631)
Fixes #4700
2021-03-05 09:27:22 +01:00
Julien Fontanet
6ea71ec6a2 chore(xapi/VM_destroy): add new lines 2021-03-04 16:11:08 +01:00
Julien Fontanet
139cb72209 chore(xapi/VM_destroy): use VM_getDisks 2021-03-04 16:11:08 +01:00
Julien Fontanet
855a15e696 fix(xapi/VM_getDisks): sync iteration 2021-03-04 16:11:08 +01:00
Mathieu
eeebd3fc1b fix(xo-web/DropdownButton): add required id prop (#5628)
See https://react-bootstrap.netlify.app/components/dropdowns/#dropdown-button-props
2021-03-04 15:56:01 +01:00
Julien Fontanet
a4b209c654 fix(disposable/deduped): race condition when disposed during acquisition
Introduced in 43aad3d11
2021-03-04 10:46:03 +01:00
Julien Fontanet
43aad3d117 feat(disposable/deduped): works with sync factories 2021-03-03 17:43:39 +01:00
Mathieu
f2d4fdd4d2 fix(xo-web/editable/number): throw error if onChange fails (#5634) 2021-03-03 16:33:41 +01:00
Julien Fontanet
a630106d80 feat(@xen-orchestra/backups): 0.6.1 2021-03-03 12:05:33 +01:00
Julien Fontanet
c7acd455c5 feat(@xen-orchestra/async-map): 0.1.2 2021-03-03 12:05:05 +01:00
Julien Fontanet
555a9d4883 fix(async-map/asyncMapSettled): issue when latest promise rejects 2021-03-03 11:58:51 +01:00
Julien Fontanet
ec4ce0c70c fix(async-map/test): missing await 2021-03-03 11:57:51 +01:00
Julien Fontanet
edf275badc fix(backups/RemoteAdapter#readDeltaVmBackup): new asyncMapSettled does not support plain objects
Introduced by 20377e9c56
2021-03-03 11:49:21 +01:00
Julien Fontanet
2e91285f02 feat(xo-web/debug): similar display for success and result 2021-03-03 10:06:36 +01:00
Julien Fontanet
ec69ba7e0e feat(xo-web/debug): display API call result 2021-03-03 10:06:03 +01:00
Julien Fontanet
3804ca18cb feat(@xen-orchestra/proxy): 0.11.3 2021-03-03 09:19:14 +01:00
Julien Fontanet
9ea3222da8 feat(@xen-orchestra/xapi): 0.4.3 2021-03-03 09:18:58 +01:00
Julien Fontanet
df48524ca5 feat(@xen-orchestra/async-map): 0.1.1 2021-03-03 09:17:08 +01:00
Julien Fontanet
b3aff1162c feat(@xen-orchestra/proxy): 0.11.2 2021-03-03 08:58:42 +01:00
Julien Fontanet
891ca8a31b feat(@xen-orchestra/xapi): 0.4.2 2021-03-03 08:58:30 +01:00
Julien Fontanet
ba99ac8b17 fix(package.json): support non-transpiled @xen-orchestra/* and xo-* 2021-03-02 16:53:02 +01:00
badrAZ
1ff25943dc fix(xo-server): enable async_hooks support in Bluebird (#5635)
Necessary for `@xen-orchestra/backups`.
2021-03-02 13:22:47 +01:00
Julien Fontanet
deb58e40d5 chore(xo-server/bin): format with Prettier 2021-03-02 11:39:42 +01:00
Julien Fontanet
eab6eb8fab chore(xen-api): event-to-promise → promise-toolbox/fromEvent 2021-03-02 10:20:38 +01:00
Julien Fontanet
ff65367851 chore(async-map): add basic tests 2021-03-01 17:25:08 +01:00
Julien Fontanet
f16e29c63e fix(async-map/asyncMapSettled): fix hasError condition 2021-03-01 17:22:05 +01:00
Julien Fontanet
cdfeb094b3 chore(async-map/package.json): remove unused browserslist 2021-03-01 17:01:48 +01:00
Julien Fontanet
b63c5d2987 chore: dont import @xen-orchestra/log/dist 2021-03-01 17:00:42 +01:00
Julien Fontanet
015309c882 chore(backups-cli): use @xen-orchestra/async-map 2021-03-01 16:55:06 +01:00
Julien Fontanet
20377e9c56 feat(async-map): new implementations
These implementations are no longer compatible with plain objects but support iterables.

The previous implementation is still available as `@xen-orchestra/async-map/legacy`.
2021-03-01 16:55:06 +01:00
Mathieu
08857a6198 fix(xo-server): fix asyncMap is not defined (#5632)
Introduced by 57612ee
2021-03-01 16:54:53 +01:00
badrAZ
d9ce1b3a97 feat(xo-server#importVmBackupNg): use @xen-orchestra/backups lib (#5630) 2021-03-01 13:36:23 +01:00
Julien Fontanet
d166073b16 chore(xo-server/package.json): fix deps sorting
Introduced by 624f32826

Sorting values is different than sorting JSON text.
2021-03-01 09:48:13 +01:00
Julien Fontanet
f858c196f4 chore: rename asyncMap → asyncMapSettled
To express more clearly this function's behavior.
2021-03-01 09:45:56 +01:00
Julien Fontanet
57612eeced feat(async-map): remove build step 2021-02-28 23:32:23 +01:00
Julien Fontanet
be2257153c feat(proxy-cli): clearer call headers 2021-02-26 17:50:47 +01:00
Julien Fontanet
d920a97f4f feat(proxy-cli): supports nested sequences 2021-02-26 17:23:49 +01:00
Julien Fontanet
322f2a1728 chore(xo-server/runJob): group runningJobs logic 2021-02-26 16:52:43 +01:00
Julien Fontanet
cfe6b0d9ab fix(xo-server/runJob): emit job:terminated and forward error
Introduced in fd560c351
2021-02-26 16:52:43 +01:00
Pierre Donias
e229deb238 feat: release 5.56.0 (#5629) 2021-02-26 16:50:00 +01:00
Julien Fontanet
8cdde947bc feat(@xen-orchestra/proxy): 0.11.1 2021-02-26 16:07:47 +01:00
Julien Fontanet
c1b3ddf87a fix(proxy): add missing peerdep xen-api 2021-02-26 16:07:47 +01:00
Pierre Donias
27d97add1e feat: technical release (#5627) 2021-02-26 16:07:15 +01:00
Mathieu
3783724c40 fix(xo-web/task): items-per-page dropdown position (#5584) 2021-02-26 15:21:45 +01:00
Julien Fontanet
67bc4ffe68 feat(@xen-orchestra/proxy): 0.11.0 2021-02-26 15:15:05 +01:00
Julien Fontanet
453bbfbbde feat(@xen-orchestra/backups): 0.6.0 2021-02-26 15:11:35 +01:00
Julien Fontanet
ff463c4261 chore(proxy-cli): mutualize request options 2021-02-26 15:10:42 +01:00
Damien Thenot
748b77ae7a fix(docs/advanced): typo telemtry → telemetry (#5625) 2021-02-26 14:57:11 +01:00
Rajaa.BARHTAOUI
58c1005657 fix(xo-web/migrateVms): explicit main SR (#5615)
See #5577

So that when there's no default SR on the pool and the VM's snapshot has orphan
VDI-snapshots, xo-server knows where to migrate them
2021-02-26 14:01:48 +01:00
Rajaa.BARHTAOUI
9271eb61ac fix(xo-web/vm/advanced): fix 'an error has occurred' (#5604)
Fixes #5592
2021-02-26 13:39:34 +01:00
Rajaa.BARHTAOUI
c82cee25a5 fix(xo-web): fix 'mapVdisSrs is assigned a value but never used' error (#5617)
Introduced by 90cafa126f
2021-02-26 13:34:33 +01:00
badrAZ
2e5dfa5845 fix(xo-server#deleteVmBackupNg): pass remote record to getBackupsRemoteAdapter instead of ID (#5624)
Introduced by baa5847949
2021-02-26 12:07:04 +01:00
Julien Fontanet
693c07b927 chore: update app-conf to 0.9.0 2021-02-26 12:02:39 +01:00
Julien Fontanet
71a6f70f46 chore: update promise-toolbox to 0.17.0
Allow using `Disposable.use()`.
2021-02-26 12:02:39 +01:00
badrAZ
2952b5a7ec feat(xo-server#deleteVmBackupNg): use @xen-orchestra/backups lib (#5623) 2021-02-26 11:40:28 +01:00
badrAZ
baa5847949 feat(xo-server#_listVmBackupsOnRemote): use @xen-orchestra/backups lib (#5622) 2021-02-26 11:17:45 +01:00
Rajaa.BARHTAOUI
b9ce0bd99d fix(xo-web): fix 'mapValues is defined but never used' error (#5618)
Introduced by 062fb3ba30
2021-02-26 10:11:04 +01:00
Julien Fontanet
aac61d8120 chore: update golike-defer to 0.5.1 2021-02-25 18:41:11 +01:00
Julien Fontanet
1f6edfdbcc fix(xo-server/runJob): upgrade defer to fix import
Introduced by fd560c351
2021-02-25 18:40:55 +01:00
Mathieu
9d1ce7fadf fix(backups/importDeltaVm): restore the bios_strings (#5598)
Aligned with XAPI behavior for XVA exports/imports.
2021-02-25 17:26:43 +01:00
Julien Fontanet
fd560c351f fix(xo-server/runJob): register job as soon as job.start (#5620) 2021-02-25 17:00:07 +01:00
badrAZ
b45556062d fix(@xen-orchestra/backups): don't double JSON config (#5621)
Config returned by `Xo#exportConfig` is already a string, it must not be JSON encoded again.
2021-02-25 16:49:45 +01:00
badrAZ
5be45599ed fix(xo-server/metadata-backup): XO config not restored (#5619)
Introduced by 61c3057060

`log.taskId` cannot be compared with the `rootTaskId` because it's generated by the Task lib and the `rootTaskId` is generated by the `xo-server` logger.
2021-02-25 16:41:39 +01:00
Julien Fontanet
9b2533dbc9 chore(yarn.lock): update 2021-02-25 14:43:16 +01:00
Julien Fontanet
ec1a4b1974 fix(proxy/backup.run): bind getConnectedRecord
Introduced in 4eb9aa9cc
2021-02-25 11:19:20 +01:00
Julien Fontanet
bb9fde17c9 chore(xo-server/_backupVm): update todo list 2021-02-25 11:03:54 +01:00
Rajaa.BARHTAOUI
8cb524080c fix(xo-server#_migrateVmWithStorageMotion): don't migrate VM VDIs to default SR (#5577)
See xoa-support#3248
See xoa-support#3355
2021-02-25 10:35:14 +01:00
badrAZ
171ec54781 feat(xo-server#restoreMetadataBackup): use @xen-orchestra/backups lib (#5611) 2021-02-25 09:43:15 +01:00
Julien Fontanet
5d9503b78c feat(backups/Backup): getAdapter accepts ids instead of remotes
This should make it easier to interface with xo-server.
2021-02-24 17:33:26 +01:00
Julien Fontanet
f56cb69c2e chore(backups/Backup): remove unused property 2021-02-24 17:30:43 +01:00
Julien Fontanet
4eb9aa9ccb feat(backups/Backup): pass directly getConnectedRecord (#5614)
This should make it easier to interface with xo-server.
2021-02-24 17:25:46 +01:00
Pierre Donias
11801f306c feat: technical release (#5613) 2021-02-24 15:54:37 +01:00
badrAZ
95c2944f30 feat(xo-server#deleteMetadataBackup): use @xen-orchestra/backups lib (#5610) 2021-02-24 11:38:27 +01:00
badrAZ
5bd4c54ab6 feat(xo-server#_listXoMetadataBackups): use @xen-orchestra/backups lib (#5609) 2021-02-24 10:16:27 +01:00
Julien Fontanet
95d6d0a0fe chore(backups/formatVmBackup): ensure function is nammed 2021-02-24 10:08:59 +01:00
Julien Fontanet
7941be083a chore(backups): rename task.js → Task.js
To be in line with other modules in this lib.
2021-02-24 10:07:36 +01:00
badrAZ
e36efaec08 feat(xo-server#_listPoolMetadataBackups): use @xen-orchestra/backups lib (#5607) 2021-02-24 10:02:57 +01:00
Julien Fontanet
637afdb540 feat(@vates/toggle-scripts): 1.0.0 2021-02-24 08:55:38 +01:00
Julien Fontanet
dafdedef9a feat(toggle-scripts): supports npm < 7 2021-02-24 08:54:29 +01:00
Julien Fontanet
ce17ee2ae6 fix(toggle-scripts/package.json): fix files entry 2021-02-24 08:48:33 +01:00
Julien Fontanet
e74daa97d2 fix(toggle-scripts): fix usage 2021-02-23 21:54:31 +01:00
Julien Fontanet
44d64d1b80 fix(proxy): dont run systemd-service-installer in dev
See ronivay/XenOrchestraInstallerUpdater#62
2021-02-23 21:37:26 +01:00
Julien Fontanet
1a4731aa83 feat(@vates/toggle-scripts): 0.1.0 2021-02-23 21:32:58 +01:00
Julien Fontanet
a75e1c52b7 feat(toggle-scripts): CLI to enable/disable package.json scripts 2021-02-23 21:28:23 +01:00
Julien Fontanet
1b97cb263c feat(proxy/config): resourceDebouce → resourceCacheDelay
Similar to xo-server.
2021-02-23 19:54:20 +01:00
badrAZ
5c9a47b6b7 feat(xo-server#fetchBackupNgPartitionFiles): use @xen-orchestra/backups lib (#5606) 2021-02-23 17:48:11 +01:00
badrAZ
8a5fe86193 feat(xo-server#listBackupNgPartitionFiles): use @xen-orchestra/backups lib (#5605) 2021-02-23 17:40:02 +01:00
badrAZ
d9531e24a3 feat(xo-server/listBackupNgDiskPartitions): use @xen-orchestra/backups lib (#5599) 2021-02-23 17:34:55 +01:00
Julien Fontanet
624f328269 chore(xo-server/package.json): sort deps 2021-02-23 16:29:46 +01:00
badrAZ
a6f4e6771d fix(xo-server/package.json): missing dependency (#5603)
Introduced by a958fe86d7

Used in a506c21b80/%40xen-orchestra/backups/RemoteAdapter.js (L14)
2021-02-23 15:34:31 +01:00
Julien Fontanet
a506c21b80 feat(docs/installation): XO now requires Node >=14.5 2021-02-23 15:26:21 +01:00
Julien Fontanet
981193ed23 feat(docs/from the sources): XO now requires Node >=14.5 2021-02-23 15:12:42 +01:00
Julien Fontanet
85a6204db2 feat(@xen-orchestra/backups-cli): 0.4.0 2021-02-23 14:41:47 +01:00
Julien Fontanet
b82aba1181 chore(backups-cli): add usage to README 2021-02-23 14:40:15 +01:00
Julien Fontanet
0a6dea2c79 feat(backups-cli/clean-vms): better usage 2021-02-23 14:32:16 +01:00
Julien Fontanet
69b6d75927 feat(CHANGELOG.unreleased): release backups 2021-02-23 12:35:04 +01:00
Julien Fontanet
eff2d48cc5 feat(backups/RemoteAdapter#outputStream): make path first param
Similar to `fs/Abstract#outputStream()`.
2021-02-23 12:34:26 +01:00
Julien Fontanet
ca5af2505c fix(fs/outputStream): always make path first param
Introduced by 7a1377119
2021-02-23 11:47:19 +01:00
Julien Fontanet
a958fe86d7 feat(proxy): version 1 (#4495)
Co-authored-by: badrAZ <azizbibadr@gmail.com>
Co-authored-by: Mathieu <70369997+MathieuRA@users.noreply.github.com>
2021-02-23 08:58:10 +01:00
Julien Fontanet
3ed488e10f chore(compose): regenerate README 2021-02-22 15:09:23 +01:00
Julien Fontanet
dcc11f16b1 feat(@vates/compose): 2.0.0 2021-02-22 14:42:45 +01:00
Julien Fontanet
209706b70d feat(compose): forwards this to all functions 2021-02-22 14:42:18 +01:00
badrAZ
1bc80eb485 fix(package.json#moduleNameMapper): fix tests for non-transpiled @vates/ packages (#5593) 2021-02-19 16:34:14 +01:00
badrAZ
9ab9e3fe46 feat(vates/disposable): utilities for disposables (#5590) 2021-02-19 16:22:41 +01:00
Mathieu
d654c096ed feat(xo-web/menu): xoa.check sync between menu and support page (#5534) 2021-02-19 10:21:52 +01:00
Olivier Lambert
f5d5884988 feat(docs/advanced): add a section about terraform provider (#5589) 2021-02-19 09:22:05 +01:00
Julien Fontanet
2c016204bf feat(@vates/compose): 1.2.0 2021-02-18 17:03:17 +01:00
Julien Fontanet
04fd625bde feat(compose): this and args passed to first function 2021-02-18 17:03:17 +01:00
Mathieu
8455d4a49f fix(xo-web/select): wrapping text if label is too long (#5580)
See https://xcp-ng.org/forum/topic/4072/create-vm-network-names-too-large
2021-02-18 16:51:52 +01:00
Yannick Achy
a3960bb7c5 feat(docs/full backup): document offline backup (#5582)
Co-authored-by: yannick Achy <yannick.achy@vates.fr>
2021-02-18 15:15:21 +01:00
Mathieu
769262d60e fix(changelog): add # to PR reference (#5585) 2021-02-18 14:49:14 +01:00
Julien Fontanet
942567586f feat(@vates/compose): 1.1.1 2021-02-18 11:29:10 +01:00
Julien Fontanet
ba6baaec0a fix(compose): update README 2021-02-18 11:27:24 +01:00
Julien Fontanet
a8ac6fc738 fix(compose): require Node 7.6 2021-02-18 11:26:00 +01:00
Julien Fontanet
b027d3b1d6 feat(@vates/compose): 1.1.0 2021-02-18 11:25:33 +01:00
Julien Fontanet
71f9d268c9 feat(compose): async functions support 2021-02-18 11:25:14 +01:00
Julien Fontanet
2b91d4af99 feat(compose): right to left support 2021-02-18 11:25:14 +01:00
Julien Fontanet
0ec0e286ba feat(compose/README): document functions in an array 2021-02-18 11:25:14 +01:00
Rajaa.BARHTAOUI
258ae64568 fix(xo-web/home/vm): bulk intra pool migration: fix map VDI -> SR (#5578)
See xoa-support#3355
See xoa-support#3248
2021-02-18 11:04:47 +01:00
Rajaa.BARHTAOUI
90cafa126f feat(xo-web/migrateVm): show error when no main SR selected (#5568)
See xoa-support#3355
2021-02-18 10:57:00 +01:00
Julien Fontanet
43d31e285c feat(@vates/compose): 1.0.0 2021-02-18 10:40:27 +01:00
Julien Fontanet
57945e6751 feat(compose): new lib to compose functions 2021-02-18 10:39:57 +01:00
Rajaa.BARHTAOUI
fce56cbf4c fix(xo-server/utils/parseXml): keep all values as strings (#5581)
Fixes #5497

All values must be kept as strings because that's what the previous implementation used to do.

Introduced by 525369e0ce

See https://github.com/vatesfr/xen-orchestra/issues/5497#issuecomment-780314187

```
{
  'iscsi-target': {
    LUN: {
      vendor: 'TrueNAS',
      serial: '9eaa394581f3003',
      LUNid: 55,
      size: 10995116277760,
      SCSIid: '36589cfc000000581d40d6d5140d9b9da'
    }
  }
}
```
2021-02-18 09:46:17 +01:00
Julien Fontanet
7a13771198 fix(fs/outputStream): make path the first param
From #5373
2021-02-17 17:11:55 +01:00
Julien Fontanet
819c798e99 chore: format mardown files with Prettier 2021-02-17 16:04:22 +01:00
Julien Fontanet
8560ca0661 chore(vhd-lib/Vhd#_getBatEntry): name param blockId
Because it's not a full block but an identifier.
2021-02-17 14:39:02 +01:00
Julien Fontanet
82cdfe7014 chore(vhd-lib): fix a test
From #5481
2021-02-17 14:30:40 +01:00
Julien Fontanet
52642f5854 chore(vhd-lib): move tests into src
From #5481

Fix Jest module mapping.
2021-02-17 14:29:40 +01:00
Julien Fontanet
6c6f9f5a44 feat(backups-cli/clean-vms): rename force flag to remove 2021-02-17 14:01:14 +01:00
Julien Fontanet
039ce15253 chore(xo-server/backups-ng): use invalidParameter.is() 2021-02-17 14:01:14 +01:00
badrAZ
695a4c785c feat(xo-server/backups-ng): handle proxy VM restoration logs (#5576) 2021-02-17 11:03:52 +01:00
Rajaa.BARHTAOUI
7d7f160159 fix(xo-web/migrateVm): don't automatically select migration network (#5564)
See xoa-support#3355
2021-02-17 10:06:03 +01:00
Julien Fontanet
b454b4dff1 feat(xo-server/backups): add proxy id to logs 2021-02-17 09:53:00 +01:00
Nicolas Raynaud
e5d711dd28 fix(fs/S3Handler#_write): work when file doesn't exist (#5561) 2021-02-16 13:45:01 +01:00
badrAZ
10b127ca55 feat(xo-web/backup): ability to force full backup per schedule (#5546)
Fixes #5541
2021-02-16 11:31:17 +01:00
Julien Fontanet
fb4dff4fca chore(xo-cli/USAGE): clearer JSON param explanation 2021-02-16 10:52:22 +01:00
badrAZ
ef25b364ec fix(xo-server/metadata-backups): fix interrupted status on backup running (#5573)
Introduced by 8a3ae59f77
2021-02-15 14:31:01 +01:00
Nicolas Raynaud
9394db986d fix(import/disk): allow uppercase extensions (#5574)
See https://xcp-ng.org/forum/topic/4216/cannot-import-a-large-vhd-using-import-disk-option
2021-02-15 12:05:49 +01:00
Rajaa.BARHTAOUI
9226c6cac1 fix(xo-server/api): don't log host.stats errors (#5553)
See xoa-support#3323

This avoids flooding the logs with ECONNREFUSED errors when the host's toolstack
is restarted
2021-02-12 11:29:16 +01:00
Julien Fontanet
283193e992 feat(complex-matcher): 0.7.0 2021-02-11 13:54:29 +01:00
Julien Fontanet
72f8a6d220 chore(complex-matcher): add test for non-ASCII raw strings
Related to f5e4fb49c
2021-02-11 13:53:54 +01:00
Albin Hedman
f5e4fb49c3 feat(complex-matcher): allow most letters to be unquoted (#5555) 2021-02-11 11:14:44 +01:00
Olivier Lambert
3cd15c783c fix(docs): update the deploy script to fix an issue (#5565) 2021-02-11 10:17:42 +01:00
badrAZ
bf51ba860a fix(xo-server, xen-api): clear XO cache on event fetch failure (#5526)
Fixes #5475
2021-02-10 16:17:46 +01:00
Mathieu
6aa8515df4 feat(xo-web/restore): allow all licenses to restore backups (#5547)
See xcp-ng.org/forum/topic/4165/crashed-xoa-can-t-boot-a-clean-xoa-and-use-restore-because-of-registration/7
2021-02-10 15:53:29 +01:00
Julien Fontanet
3bf4ee35a1 fix(xo-server/Xapi#_disconnectVbd): dont swallow unhandled error
Detected while working on #5543
2021-02-09 14:47:55 +01:00
badrAZ
e08c600740 fix(xo-server/xapi): handle VM/VDI export stream close (#5538) 2021-02-09 14:24:35 +01:00
badrAZ
f823690b44 feat(xo-common,xo-server,xo-web/proxy upgrade): confirm before interrupting backup job (#5533) 2021-02-05 18:11:09 +01:00
Pierre Donias
350b0c1e3c feat: release 5.55.1 (#5551) 2021-02-05 16:13:32 +01:00
Pierre Donias
b01a6124a9 feat: technical release (#5550) 2021-02-05 15:46:04 +01:00
Rajaa.BARHTAOUI
b00652f9eb fix(xo-server#_migrateVmWithStorageMotion): fix VIF_NOT_IN_MAP error (#5544) 2021-02-04 17:17:24 +01:00
Mathieu
19159a203a feat(xo-web/task): display age and estimated duration (#5530)
See https://xcp-ng.org/forum/topic/4083/task-list-enhancement
2021-02-04 15:07:48 +01:00
Pierre Donias
be8c77af5a fix(xo-server-auth-ldap/synchronizeGroups): fix adding users to groups (#5545)
Fixes xoa-support#3333
Introduced by 8cfaabedeb

`synchronizeGroups` (called without a user) tries to find XO users that belong
to LDAP groups and add them to those groups. In order to find those users, it
was using the `userIdAttribute` attribute instead of the
`membersMapping.userAttribute` attribute from the configuration.
2021-02-04 11:45:59 +01:00
Mathieu
8bb7803d23 feat(docs): migration to new XOA (#5542)
Co-authored-by: Jon Sands <fohdeesha@gmail.com>
2021-02-04 09:41:17 +01:00
Julien Fontanet
54a85a8dd0 fix(xo-server/utils/parseXml): fix buffer support
Fixes #5539

Introduced by 525369e0c
2021-01-30 10:51:18 +01:00
Julien Fontanet
6fd40c0a7c chore(xo-server/utils/parseXml): add basic test 2021-01-30 10:50:59 +01:00
Rajaa.BARHTAOUI
97dd423486 feat: release 5.55.0 (#5537) 2021-01-29 15:05:21 +01:00
Rajaa.BARHTAOUI
281d60df4f feat: technical release (#5531) 2021-01-27 16:44:25 +01:00
badrAZ
43933f4089 fix(xo-server/metadata-backups): ensure cache reset at the end (#5529)
Introduced by 61c3057060
2021-01-27 14:41:15 +01:00
badrAZ
4f7e140737 feat(xo-web/proxies): better upgrade feedback (#5525)
- display up-to-date message instead of upgrade button
- add "force upgrade" button to the advanced actions
2021-01-27 11:05:33 +01:00
badrAZ
2b6945a382 feat(xo-server/metadata-backups): delete proxy backups (#5520) 2021-01-27 09:54:09 +01:00
badrAZ
8a3ae59f77 feat(xo-server/metadata-backups): restore proxy backup (#5519) 2021-01-27 08:57:02 +01:00
Mathieu
db253875cc feat(xo-server,xo-web/vm): expose VM UEFI secure boot option (#5527)
Fixes #5502
2021-01-26 17:08:21 +01:00
Jerome Charaoui
a8359dcb75 feat(docs/backups): modifier tags 2021-01-26 16:43:43 +01:00
Julien Fontanet
e5dac06d91 feat(xo-server): add x-forwarded headers on proxied requests 2021-01-26 10:34:32 +01:00
Rajaa.BARHTAOUI
e9f82558ed feat(xo-web/vm/console): ability to open RDP session (#5523)
Fixes #5495
See xoa-support#3254
2021-01-25 16:14:20 +01:00
badrAZ
26f5ef5e31 feat(xo-server/metadata-backups): list proxy backups (#5517) 2021-01-23 12:42:55 +01:00
Rajaa.BARHTAOUI
874e889b36 fix(xo-web/dashboard/health): filter out snapshots from "duplicated MAC addresses" table (#5524)
See fb3f2d46fa (commitcomment-46167022)
2021-01-22 16:06:57 +01:00
badrAZ
bece5f7083 feat(xo-server, xo-web/metadata-backup): ability to define a proxy for the backup (#4206) 2021-01-21 13:27:33 +01:00
Rajaa.BARHTAOUI
2f535e6db1 fix(xo-web): SR_NOT_ATTACHED when migration network is selected (#5516)
See xoa-support#3248
Introduced by 062fb3ba30 and 4dd7d86ea8

- Issue:  
  When choosing a network for VM migration within a pool: 
    - default SR is shared: the VMs' VDIs will be migrated to this SR
    - if not: `SR_NOT_ATTACHED` error will be thrown.
- Fix: when the migration network is defined, the SR will be required.
2021-01-21 12:07:42 +01:00
badrAZ
61c3057060 feat(xo-server/metadata-backups): run backups through proxy (#5499) 2021-01-21 12:04:30 +01:00
badrAZ
063d7d5cc4 fix(xo-web/backup/overview): fix proxy item not updated on ID change (#5522) 2021-01-21 10:55:35 +01:00
Rajaa.BARHTAOUI
0e0211050b feat(xo-server,xo-web/pool): ability to set default migration network (#5465)
See xoa-support#3118
See https://github.com/vatesfr/xen-orchestra/issues/3788#issuecomment-743207834
2021-01-21 09:44:09 +01:00
Rajaa.BARHTAOUI
c8c7245da1 fix(xo-web/home/SR): sort SR usage in % (#5513)
Fixes #5463
2021-01-20 16:53:59 +01:00
Julien Fontanet
3e27e50bab feat(xo-server/utils/parseXml): silent validation
Related to #5497

Error is longed ATM to avoid breaking existing code, but will be thrown in the future.
2021-01-20 12:03:03 +01:00
badrAZ
6b9d3ed60e fix(xo-server/remotes): update remote error on test (#5514)
See xoa-support#3255
2021-01-20 08:37:51 +01:00
Pierre Donias
11a78111de fix(xo-web/home,xo-server): fix ghost missing patch on XCP-ng (#5509)
Fixes #4922
Fixes xoa-support#3216

- xo-server: get error message from updater.py plugin's message and throw it
- xo-web: when counting missing patches, ignore hosts that failed
2021-01-19 10:12:59 +01:00
Mathieu
2655421171 fix(xo-web/host/stats): network throughput legend labels (#5483)
See xoa-support#3211
2021-01-15 10:02:10 +01:00
Pierre Donias
c6bc2ea485 fix(xo-server,xo-web/reattach SR): multiple fixes (#5488)
Fixes xoa-support#3227
Fixes #4546

- Fix already attached SRs not being displayed and show their names
- Refresh SR list after SR has been reattached
- Properly reattach SR:
   - Introduce SR (already done)
   - Compute device config from form data
   - Create PBDs for each host
   - Plug in PBDs
- Fix SR list key props to fix loading feedback inconsistencies
- Always show form summary once the SR location has been selected
2021-01-14 23:34:31 +01:00
Nicolas Raynaud
289b7a3dbe fix(fs/s3): TimeoutError: Connection timed out after 120000ms (#5397) 2021-01-14 23:23:40 +01:00
badrAZ
70083c6dca fix(xo-server): check remote is enabled even when bound to proxy (#5501) 2021-01-14 17:37:30 +01:00
Julien Fontanet
3e25b92369 chore: update dependencies 2021-01-14 16:57:44 +01:00
Rajaa.BARHTAOUI
806eaaf14b fix(xo-server/vif#set): changing network set locking mode to 'network_default' (#5500) 2021-01-14 16:53:38 +01:00
Mathieu
fb3f2d46fa feat(xo-web/dashboard/health): duplicated MAC addresses (#5468)
Fixes #5448
2021-01-14 15:26:54 +01:00
Julien Fontanet
14d06fe754 fix(xo-server/store): dont fail on serializing circular values
See https://github.com/vatesfr/xen-orchestra/pull/5397#discussion_r555170305
2021-01-14 14:59:08 +01:00
Rajaa.BARHTAOUI
752146028b feat(xo-web): assign custom date-time fields (#5473)
Fixes #4730

On pools, hosts, SRs, and VMs
2021-01-14 14:22:07 +01:00
badrAZ
6c6ae30ce5 fix(xo-web/restore/metadata): ignore disabled remotes (#5504) 2021-01-14 09:10:02 +01:00
Nicolas Raynaud
b00750bfa3 chore(xo-vmdk-to-vhd): fix integration tests (#5490) 2021-01-09 19:19:34 +01:00
Pierre Donias
55eac005a0 feat(xo-web/XOA/update): add link to channel's changelog (#5494)
See xoa-support#3257
2021-01-08 16:35:47 +01:00
badrAZ
257524de18 fix(xo-server-backup-reports): fix markdown (#5479)
Observed while investigating #3195

This PR:
  - removes extra indent
  - add a line between sections to handle the case when it was before a nested list
2021-01-08 15:26:18 +01:00
Julien Fontanet
d4f78056dd feat(xo-lib): 0.10.1 2021-01-08 14:50:06 +01:00
Julien Fontanet
66c054f24b fix(xo-lib): correctly use . as default URL base
Fixes #5489

Introduced by b25adf7f5
2021-01-08 14:50:06 +01:00
Julien Fontanet
711b722118 fix(xo-server-backup-reports/test): don't swallow errors (#5491)
See #5486
2021-01-08 14:24:13 +01:00
Mathieu
26614b5f40 feat(xo-server-web-books): waiting response from server (#5420)
Fixes #4948
2021-01-08 12:12:52 +01:00
Pierre Donias
9240211f3e fix(xo-server config): change restartHostTimeout from 5min to 20min (#5493)
Fixes #5492
2021-01-08 09:37:56 +01:00
badrAZ
67d84d956e chore(xo-server/docs): fix command (#5487) 2021-01-07 11:11:21 +01:00
Julien Fontanet
97b620f98f fix(xo-server): rm xenStore entries after use (#5482)
This should already be done by the deploy scripts but in case it's not, xo-server should do it.
2021-01-06 11:50:36 +01:00
Julien Fontanet
2f5c91a1e1 feat(docs/CR/manual seed): percent encoding 2021-01-06 11:25:24 +01:00
Rajaa.BARHTAOUI
038dad834d fix(xo-server): set VIF locking mode to 'locked' when adding allowed IPs (#5472)
Introduced by #5357
See xoa-support#2929 (last comment)
2021-01-05 09:54:16 +01:00
Rajaa.BARHTAOUI
b3cd265955 fix(CHANGELOG.md): fix packages versions (#5478) 2021-01-04 16:23:56 +01:00
Olivier Lambert
2c670bc838 docs(infra mgmt): add maintenance mode explanation (#5480)
Fixes #5477
2021-01-04 16:04:10 +01:00
Julien Fontanet
30c2b8e192 fix(backups-cli clean-vms): document --merge 2021-01-02 23:29:37 +01:00
Julien Fontanet
a00d45522b chore(xo-server/utils): remove unused formatXml 2020-12-31 15:57:48 +01:00
Julien Fontanet
525369e0ce chore(xo-server/utils/parseXml): use fast-xml-parser instead of xml2js
It's faster, the API is simpler and it appears to be better maintained.
2020-12-31 10:51:25 +01:00
Julien Fontanet
ba413f3e8f feat: release 5.54.0 2020-12-29 15:56:53 +01:00
Julien Fontanet
4afebca77b feat(@xen-orchestra/backups-cli): 0.3.0 2020-12-23 10:43:44 +01:00
Julien Fontanet
d2eb92143d feat(backups-cli/clean-vms): split --merge out of --force 2020-12-23 10:43:32 +01:00
Olivier Lambert
e01d3c64fe docs(supported hosts): add XCP-ng 8.2 LTS (#5469) 2020-12-18 13:15:15 +01:00
Pierre Donias
9f497c9c2c docs(users): LDAP groups synchronization (#5459)
See #1884
2020-12-18 10:28:57 +01:00
Julien Fontanet
9aae154c4e fix(xo-web/xoa/update): handle installer2 namespace 2020-12-17 14:23:03 +01:00
Pierre Donias
339f012794 feat: technical release (#5464) 2020-12-16 17:53:43 +01:00
Julien Fontanet
af500d7b7b fix(yarn.lock): sync 2020-12-16 17:39:43 +01:00
Pierre Donias
16a71b3917 feat(xo-web): set rolling pool updates plan (#5462) 2020-12-16 17:30:08 +01:00
Pierre Donias
7dfa104f65 feat(xo-server,xo-web/user): prevent setting email/pwd of LDAP users (#5460)
See #1884
2020-12-16 15:28:13 +01:00
Julien Fontanet
44a7b1761f fix(xo-server/vm.export): fail instead of waiting when queue is full
Fixes xoa-support#3035

Otherwise the client request may timeout before the transfer starts.
2020-12-15 21:57:02 +01:00
Julien Fontanet
22c8ea255c feat(xo-cli): 0.11.1 2020-12-15 12:54:53 +01:00
Julien Fontanet
a1c10828d8 feat(xo-lib): 0.10.0 2020-12-15 12:52:56 +01:00
Julien Fontanet
25d69d1bd7 fix(xo-lib): handle URLs ending with /
Thanks @rushikeshjadhav
2020-12-15 12:51:20 +01:00
Mathieu
a84961f8ba feat(xo-server,xo-web/host): maintenance mode (#5421)
ON: disable & evacuate host
OFF: enable host
2020-12-14 17:15:27 +01:00
Mathieu
e17b6790b5 fix(xo-web/dashboard): filter out udev SRs (#5453)
Fixes #5423
2020-12-14 17:01:57 +01:00
badrAZ
815aed52d3 fix(xo-web/file-restore): re-initialize partitions' list on backup/disk change (#5454) 2020-12-14 14:48:36 +01:00
Mathieu
a03581ccd3 fix(xo-web/host): component not loaded if controller is undefined (#5417) 2020-12-14 14:29:31 +01:00
Mathieu
c10f6e6c6a fix(xo-web/host): dont fetch missing patches when host is halted (#5407)
Fixes #5053
See fe7901ca7f
2020-12-14 11:22:34 +01:00
Pierre Donias
18abd0384f feat: rolling pool updates (#5430)
See #5286
2020-12-14 11:08:19 +01:00
Julien Fontanet
4292bdd7b4 feat(xo-server): 5.72.1 2020-12-11 09:56:12 +01:00
Julien Fontanet
1149648399 feat(xo-server): update hashy to 0.10.0 2020-12-11 09:51:59 +01:00
Rajaa.BARHTAOUI
b6846eb21d feat: release 5.53.1 (#5449) 2020-12-10 17:04:29 +01:00
Rajaa.BARHTAOUI
d19546fcb4 feat: technical release (#5447) 2020-12-10 16:23:41 +01:00
Julien Fontanet
6a1eb198d1 chore(xo-server/docs): better part listing formatting 2020-12-10 16:12:00 +01:00
badrAZ
e4757d4345 chore(xo-server/docs): add "partx" on a raw disk (#5446) 2020-12-10 15:52:45 +01:00
Rajaa.BARHTAOUI
3873a59a37 feat(xo-web/{vm,sr}/disks): improve VDI actions tooltips (#5435) 2020-12-10 15:16:33 +01:00
Pierre Donias
cf9f6c10d7 feat(xo-server,xo-web/host): set control domain memory (#5437)
Fixes #2218
2020-12-10 15:05:42 +01:00
badrAZ
8bcd9debc2 Chore(xo-server/docs/file-restoration): add tips (#5438) 2020-12-09 11:27:30 +01:00
Pierre Donias
510a159eee fix(xo-web/modal/form): pass onChange and value to form's body component (#5434)
Fixes #4705
2020-12-08 16:46:55 +01:00
Rajaa.BARHTAOUI
062fb3ba30 feat(xo-web/home/vm): ability to choose network for bulk migration within a pool (#5427)
See xoa-support#3118
2020-12-08 16:45:12 +01:00
badrAZ
3bc477d21b fix(xo-server/docs/file-restoration): use sizelimit options (#5433)
When creating a loop device, the `sizelimit` options is necessary to indicate the end of the data to mount, otherwise the following error is thrown when trying to mount multiple parts of the disk:

```
overlapping loop device exists for /tmp/proxy1/vhdi1.
```

As an example, let's take this disk:

```
[ partition 0 | partition 1 | partition 2 ]
```

Mounting *partition 1* without `sizelimit` will mount the whole space starting from *partition 1* up to the end, which prevents *partition 2* from being mounted.

`man losetup`: https://manpages.ubuntu.com/manpages/precise/en/man8/losetup.8.html
2020-12-08 16:24:03 +01:00
Rajaa.BARHTAOUI
79eb2feb2c feat(xo-web/home): sort VMs by disk physical usage (#5418)
See xoa-support#3059
2020-12-08 14:15:15 +01:00
Julien Fontanet
1fa42a5753 chore(xo-server): update hashy to 0.9.0
BREAKING: requires Node >=10.

See https://xcp-ng.org/forum/topic/3107/python3-support
2020-12-08 11:57:35 +01:00
Mathieu
2eaab408dd fix(xo-server/jobs): bug fix when run job manually (#5426) 2020-12-08 10:34:05 +01:00
Nicolas Raynaud
f7fd0d9121 fix(upload-ova): compatibility with latest API (#5432) 2020-12-07 11:11:37 +01:00
badrAZ
3b7b776ac4 feat(xo-server/backups-ng): ability to delete VM backups though proxy (#5428) 2020-12-07 11:05:30 +01:00
Rajaa.BARHTAOUI
43abc8440b feat(xo-server,xo-web/new/sr): show serial and ID in LUN selector (#5422)
See xoa-support#3080
2020-12-04 16:55:25 +01:00
Julien Fontanet
37515b5da9 chore(xo-web/common/xo/index.js): fix formatting 2020-12-04 12:10:09 +01:00
Julien Fontanet
2dec327013 chore: update dependencies 2020-12-04 12:09:32 +01:00
Julien Fontanet
8f4dae3134 chore(multi-key-map/README): sync with USAGE 2020-12-03 14:16:13 +01:00
Julien Fontanet
a584daa92d chore(emit-async/README): minor improvements/fixes 2020-12-03 14:16:13 +01:00
Julien Fontanet
43431aa9a0 chore(fs/outputStream): remove duplicate await 2020-12-03 14:16:13 +01:00
Mathieu
f196d2abec feat(xo-web/plugins): user feedback on successful test (#5409) 2020-12-03 09:10:57 +01:00
Julien Fontanet
4a6724f664 fea: release 5.53.0 (#5416) 2020-11-30 15:39:32 +01:00
Julien Fontanet
a960737207 feat: technical release (#5415) 2020-11-30 15:33:14 +01:00
badrAZ
da08bd7fff fix(xo-server/backups-ng): invalidate cache in case of proxy backup (#5414) 2020-11-30 15:19:44 +01:00
Julien Fontanet
517430f23d feat(xo-server/vm.set memory{,Max}): better error when DMC disabled and VM running 2020-11-30 14:39:36 +01:00
Julien Fontanet
48e82ac15b feat(xo-server/vm.set memory{,Max}): handle MEMORY_CONSTRAINT_VIOLATION_MAXPIN
Fixes #4978
Fixes #5326
Fixes xoa-support#1187

This error is used when DMC is disabled.
2020-11-30 14:39:36 +01:00
Julien Fontanet
eead64ff71 feat(xo-server/authenticateUser): make throttling delay configurable 2020-11-30 12:53:40 +01:00
Rajaa.BARHTAOUI
9ac6db2f4c fix(xo-web/vm/snapshots): missing color on bulk delete (#5410) 2020-11-30 11:59:14 +01:00
Julien Fontanet
92cf6bb887 chore(xo-server/authentication): parseDuration in constructor 2020-11-30 11:23:49 +01:00
Mathieu
1d3978ce2f fix(xo-web/host): unsubscribe missing patches when the props change (#5370) 2020-11-30 11:20:28 +01:00
badrAZ
16c71da487 feat: technical release (#5406) 2020-11-27 16:22:15 +01:00
badrAZ
214dbafd62 fix(xo-server/jobs): don't throw when the job owner doesn't exist (#5405)
Introduced by 31b19725b7
2020-11-27 16:11:48 +01:00
badrAZ
89b162704c feat: technical release (#5404) 2020-11-27 15:15:00 +01:00
Rajaa.BARHTAOUI
fbf906d97c feat(xo-web/SortedTable): allow to change the number of items per page (#5355)
See xoa-support#3020
2020-11-27 14:20:33 +01:00
Rajaa.BARHTAOUI
7961ff0785 feat(xo-server, xo-web): expose and edit custom fields (#5387)
See #4730
2020-11-27 13:39:08 +01:00
Pierre Donias
00e53f455b feat(xo-web/Dashboard): make Overview & Health available on all plans (#5401) 2020-11-27 11:10:32 +01:00
Mathieu
d1d4839a09 feat(xo-web/trial): end of trial info banner (#5374)
See company#558
2020-11-27 10:37:51 +01:00
Mathieu
31b19725b7 feat(xo-server/jobs): backup job support for webhooks (#5360)
Fixes #5205
2020-11-27 10:15:51 +01:00
badrAZ
a776eaf61a feat(xo-server,xo-web): file restore via proxies (#5359) 2020-11-26 17:14:06 +01:00
badrAZ
ae2a92d229 feat(xo-server,fs): stricter perms for backup dirs (#5378)
Fixes xoa-support#3088
2020-11-26 11:02:33 +01:00
badrAZ
dedc4aa8b9 feat(xo-server/callProxyMethod): support binary response (#5399) 2020-11-25 18:16:20 +01:00
Julien Fontanet
7a8ca2f068 chore: change print width to 120 chars 2020-11-24 10:51:35 +01:00
Nicolas Raynaud
fdf52a3d59 feat(OVA/VMDK import): transmit VMDK tables in multipart POST request (#5372)
See xoa-support#3060

The VMDK block tables could become bigger than the max allowed size of a websocket message. The tables are now sent in a multipart POST in the same transaction as the file.
2020-11-23 10:27:35 +01:00
Pierre Donias
e0987059d3 fix(xo-server-auth-ldap): typo defaults → default (#5388)
The "Check certificate" option's default value was incorrectly set in the UI. So if it was left untouched by the user (showing as OFF since `undefined`), it would be saved as `undefined`, and then fallback to the actual default value (`true`) when used in the code. So it would try to check the certificate even though the user didn't want to.
2020-11-20 14:10:58 +01:00
Pierre Donias
ee7217c7c9 feat(xo-server,xo-web/VIF): set any allowed IP as an admin (#5367)
Fixes #2535
See #1872
See #5358
2020-11-20 10:35:23 +01:00
Pierre Donias
1027659f34 fix(xo-web/backup/restore): refresh button loading feedback (#5381)
See xoa-support#3093
Introduced by 48eeab974c
2020-11-20 10:05:21 +01:00
Albin Hedman
424a212cc3 feat(xo-web/dashboard/health): add 'missing guest tools' section (#5376) 2020-11-18 09:34:12 +01:00
Nicolas Raynaud
949ddbdcd7 feat(new SR): use zfs type when XCP-ng 8.2+ #5302 (#5330) 2020-11-16 15:04:39 +01:00
Rajaa.BARHTAOUI
7fcfc306f9 fix(xo-server/vif.set): don't change locking mode automatically (#5357)
See xoa-support#2929
2020-11-10 15:15:54 +01:00
Rajaa.BARHTAOUI
a691e033eb fix(xo-web/pool/network): remove unnecessary braces (#5366) 2020-11-10 09:19:24 +01:00
Rajaa.BARHTAOUI
b76f62d470 fix(xo-web): missing key props (#5365) 2020-11-10 09:16:52 +01:00
Julien Fontanet
01a90a1694 feat(xapi-explore-sr): 0.3.0 2020-11-09 12:33:45 +01:00
badrAZ
97bcc7afb6 feat(@vates): add MultiKeyMap (#5362) 2020-11-09 12:30:35 +01:00
Olivier Lambert
9fa0ec440d fix(xapi-explore-sr): replace XenServer by Host (#5363) 2020-11-09 12:19:44 +01:00
922 changed files with 24358 additions and 33330 deletions

View File

@@ -1,13 +1,5 @@
module.exports = {
extends: [
'plugin:eslint-comments/recommended',
'standard',
'standard-jsx',
'prettier',
'prettier/standard',
'prettier/react',
],
extends: ['plugin:eslint-comments/recommended', 'standard', 'standard-jsx', 'prettier'],
globals: {
__DEV__: true,
$Dict: true,
@@ -21,19 +13,13 @@ module.exports = {
overrides: [
{
files: ['cli.js', '*-cli.js', '**/*cli*/**/*.js'],
files: ['cli.{,c,m}js', '*-cli.{,c,m}js', '**/*cli*/**/*.{,c,m}js'],
rules: {
'no-console': 'off',
},
},
],
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
legacyDecorators: true,
},
},
rules: {
// disabled because XAPI objects are using camel case
camelcase: ['off'],
@@ -48,9 +34,5 @@ module.exports = {
'lines-between-class-members': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-var': 'error',
'node/no-extraneous-import': 'error',
'node/no-extraneous-require': 'error',
'prefer-const': 'error',
},
}

10
.gitignore vendored
View File

@@ -4,20 +4,24 @@
/lerna-debug.log
/lerna-debug.log.*
/@vates/*/dist/
/@vates/*/node_modules/
/@xen-orchestra/*/dist/
/@xen-orchestra/*/node_modules/
/packages/*/dist/
/packages/*/node_modules/
/@xen-orchestra/proxy/src/app/mixins/index.mjs
/packages/vhd-cli/src/commands/index.js
/packages/xen-api/examples/node_modules/
/packages/xen-api/plot.dat
/packages/xo-server/.xo-server.*
/packages/xo-server/src/api/index.js
/packages/xo-server/src/xapi/mixins/index.js
/packages/xo-server/src/xo-mixins/index.js
/packages/xo-server/src/api/index.mjs
/packages/xo-server/src/xapi/mixins/index.mjs
/packages/xo-server/src/xo-mixins/index.mjs
/packages/xo-server-auth-ldap/ldap.cache.conf

View File

@@ -3,4 +3,9 @@ module.exports = {
jsxSingleQuote: true,
semi: false,
singleQuote: true,
// 2020-11-24: Requested by nraynaud and approved by the rest of the team
//
// https://team.vates.fr/vates/pl/a1i8af1b9id7pgzm3jcg4toacy
printWidth: 120,
}

View File

@@ -1,6 +1,6 @@
language: node_js
node_js:
- 12
- 14
# Use containers.
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -20,9 +20,6 @@
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"files": [
"index.js"
],
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"

1
@vates/compose/.npmignore Symbolic link
View File

@@ -0,0 +1 @@
../../scripts/npmignore

81
@vates/compose/README.md Normal file
View File

@@ -0,0 +1,81 @@
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
# @vates/compose
[![Package Version](https://badgen.net/npm/v/@vates/compose)](https://npmjs.org/package/@vates/compose) ![License](https://badgen.net/npm/license/@vates/compose) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/compose)](https://bundlephobia.com/result?p=@vates/compose) [![Node compatibility](https://badgen.net/npm/node/@vates/compose)](https://npmjs.org/package/@vates/compose)
> Compose functions from left to right
## Install
Installation of the [npm package](https://npmjs.org/package/@vates/compose):
```
> npm install --save @vates/compose
```
## Usage
```js
import { compose } from '@vates/compose'
const add2 = x => x + 2
const mul3 = x => x * 3
// const f = x => mul3(add2(x))
const f = compose(add2, mul3)
console.log(f(5))
// → 21
```
> The call context (`this`) of the composed function is forwarded to all functions.
The first function is called with all arguments of the composed function:
```js
const add = (x, y) => x + y
const mul3 = x => x * 3
// const f = (x, y) => mul3(add(x, y))
const f = compose(add, mul3)
console.log(f(4, 5))
// → 27
```
Functions may also be passed in an array:
```js
const f = compose([add2, mul3])
```
Options can be passed as first parameter:
```js
const f = compose(
{
// compose async functions
async: true,
// compose from right to left
right: true,
},
[add2, mul3]
)
```
## 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)

48
@vates/compose/USAGE.md Normal file
View File

@@ -0,0 +1,48 @@
```js
import { compose } from '@vates/compose'
const add2 = x => x + 2
const mul3 = x => x * 3
// const f = x => mul3(add2(x))
const f = compose(add2, mul3)
console.log(f(5))
// → 21
```
> The call context (`this`) of the composed function is forwarded to all functions.
The first function is called with all arguments of the composed function:
```js
const add = (x, y) => x + y
const mul3 = x => x * 3
// const f = (x, y) => mul3(add(x, y))
const f = compose(add, mul3)
console.log(f(4, 5))
// → 27
```
Functions may also be passed in an array:
```js
const f = compose([add2, mul3])
```
Options can be passed as first parameter:
```js
const f = compose(
{
// compose async functions
async: true,
// compose from right to left
right: true,
},
[add2, mul3]
)
```

46
@vates/compose/index.js Normal file
View File

@@ -0,0 +1,46 @@
'use strict'
const defaultOpts = { async: false, right: false }
exports.compose = function compose(opts, fns) {
if (Array.isArray(opts)) {
fns = opts
opts = defaultOpts
} else if (typeof opts === 'object') {
opts = Object.assign({}, defaultOpts, opts)
if (!Array.isArray(fns)) {
fns = Array.prototype.slice.call(arguments, 1)
}
} else {
fns = Array.from(arguments)
opts = defaultOpts
}
const n = fns.length
if (n === 0) {
throw new TypeError('at least one function must be passed')
}
if (n === 1) {
return fns[0]
}
if (opts.right) {
fns.reverse()
}
return opts.async
? async function () {
let value = await fns[0].apply(this, arguments)
for (let i = 1; i < n; ++i) {
value = await fns[i].call(this, value)
}
return value
}
: function () {
let value = fns[0].apply(this, arguments)
for (let i = 1; i < n; ++i) {
value = fns[i].call(this, value)
}
return value
}
}

View File

@@ -0,0 +1,66 @@
/* eslint-env jest */
const { compose } = require('./')
const add2 = x => x + 2
const mul3 = x => x * 3
describe('compose()', () => {
it('throws when no functions is passed', () => {
expect(() => compose()).toThrow(TypeError)
expect(() => compose([])).toThrow(TypeError)
})
it('applies from left to right', () => {
expect(compose(add2, mul3)(5)).toBe(21)
})
it('accepts functions in an array', () => {
expect(compose([add2, mul3])(5)).toBe(21)
})
it('can apply from right to left', () => {
expect(compose({ right: true }, add2, mul3)(5)).toBe(17)
})
it('accepts options with functions in an array', () => {
expect(compose({ right: true }, [add2, mul3])(5)).toBe(17)
})
it('can compose async functions', async () => {
expect(
await compose(
{ async: true },
async x => x + 2,
async x => x * 3
)(5)
).toBe(21)
})
it('forwards all args to first function', () => {
expect.assertions(1)
const expectedArgs = [Math.random(), Math.random()]
compose(
(...args) => {
expect(args).toEqual(expectedArgs)
},
// add a second function to avoid the one function special case
Function.prototype
)(...expectedArgs)
})
it('forwards context to all functions', () => {
expect.assertions(2)
const expectedThis = {}
compose(
function () {
expect(this).toBe(expectedThis)
},
function () {
expect(this).toBe(expectedThis)
}
).call(expectedThis)
})
})

View File

@@ -0,0 +1,24 @@
{
"private": false,
"name": "@vates/compose",
"description": "Compose functions from left to right",
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/compose",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
"directory": "@vates/compose",
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "ISC",
"version": "2.0.0",
"engines": {
"node": ">=7.6"
},
"scripts": {
"postversion": "npm publish --access public"
}
}

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -0,0 +1,89 @@
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
# @vates/disposable
[![Package Version](https://badgen.net/npm/v/@vates/disposable)](https://npmjs.org/package/@vates/disposable) ![License](https://badgen.net/npm/license/@vates/disposable) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/disposable)](https://bundlephobia.com/result?p=@vates/disposable) [![Node compatibility](https://badgen.net/npm/node/@vates/disposable)](https://npmjs.org/package/@vates/disposable)
> Utilities for disposables
## Install
Installation of the [npm package](https://npmjs.org/package/@vates/disposable):
```
> npm install --save @vates/disposable
```
## Usage
This library contains utilities for disposables as defined by the [`promise-toolbox` library](https://github.com/JsCommunity/promise-toolbox#resource-management).
### `deduped(fn, keyFn)`
Creates a new function that wraps `fn` and instead of creating a new disposables at each call, returns copies of the same one when `keyFn` returns the same keys.
Those copies contains the same value and can be disposed independently, the source disposable will only be disposed when all copies are disposed.
`keyFn` is called with the same context and arguments as the wrapping function and must returns an array of keys which will be used to identify which disposables should be grouped together.
```js
import { deduped } from '@vates/disposable/deduped'
// the connection with the passed host will be established once at the first call, then, it will be shared with the next calls
const getConnection = deduped(async function (host)) {
const connection = new Connection(host)
return new Disposabe(connection, () => connection.close())
}, host => [host])
```
### `debounceResource(disposable, delay)`
Creates a new disposable with the same value and with a delayed disposer.
On calling this disposer, the source disposable will be disposed when the `delay` is passed.
```js
import { createDebounceResource } from '@vates/disposable/debounceResource'
const debounceResource = createDebounceResource()
// it will wait for 10 seconds before calling the disposer
Disposable.use(debounceResource(getConnection(host), 10e3), connection => {})
```
### `debounceResource.flushAll()`
Disposes all delayed disposers and cancels the delaying of the disposables that are in usage.
```js
import { createDebounceResource } from '@vates/disposable/debounceResource'
const debounceResource = createDebounceResource()
const res1 = await debounceResource(res, 10e3)
const res2 = await debounceResource(res, 10e3)
const res3 = await debounceResource(res, 10e3)
rest1.dispose()
rest2.dispose()
// res3 is in usage
debounceResource.flushAll()
// res1 and res2 are immediately disposed
// res3 will be disposed immediately when its disposer will be called
```
## 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)

View File

@@ -0,0 +1,56 @@
This library contains utilities for disposables as defined by the [`promise-toolbox` library](https://github.com/JsCommunity/promise-toolbox#resource-management).
### `deduped(fn, keyFn)`
Creates a new function that wraps `fn` and instead of creating a new disposables at each call, returns copies of the same one when `keyFn` returns the same keys.
Those copies contains the same value and can be disposed independently, the source disposable will only be disposed when all copies are disposed.
`keyFn` is called with the same context and arguments as the wrapping function and must returns an array of keys which will be used to identify which disposables should be grouped together.
```js
import { deduped } from '@vates/disposable/deduped'
// the connection with the passed host will be established once at the first call, then, it will be shared with the next calls
const getConnection = deduped(async function (host)) {
const connection = new Connection(host)
return new Disposabe(connection, () => connection.close())
}, host => [host])
```
### `debounceResource(disposable, delay)`
Creates a new disposable with the same value and with a delayed disposer.
On calling this disposer, the source disposable will be disposed when the `delay` is passed.
```js
import { createDebounceResource } from '@vates/disposable/debounceResource'
const debounceResource = createDebounceResource()
// it will wait for 10 seconds before calling the disposer
Disposable.use(debounceResource(getConnection(host), 10e3), connection => {})
```
### `debounceResource.flushAll()`
Disposes all delayed disposers and cancels the delaying of the disposables that are in usage.
```js
import { createDebounceResource } from '@vates/disposable/debounceResource'
const debounceResource = createDebounceResource()
const res1 = await debounceResource(res, 10e3)
const res2 = await debounceResource(res, 10e3)
const res3 = await debounceResource(res, 10e3)
rest1.dispose()
rest2.dispose()
// res3 is in usage
debounceResource.flushAll()
// res1 and res2 are immediately disposed
// res3 will be disposed immediately when its disposer will be called
```

View File

@@ -0,0 +1,56 @@
const { asyncMap } = require('@xen-orchestra/async-map')
const { createLogger } = require('@xen-orchestra/log')
const { warn } = createLogger('vates:disposable:debounceResource')
exports.createDebounceResource = () => {
const flushers = new Set()
async function debounceResource(pDisposable, delay = debounceResource.defaultDelay) {
if (delay === 0) {
return pDisposable
}
const disposable = await pDisposable
let timeoutId
const disposeWrapper = async () => {
if (timeoutId !== undefined) {
clearTimeout(timeoutId)
timeoutId = undefined
flushers.delete(flusher)
try {
await disposable.dispose()
} catch (error) {
warn(error)
}
}
}
const flusher = () => {
const shouldDisposeNow = timeoutId !== undefined
if (shouldDisposeNow) {
return disposeWrapper()
} else {
// will dispose ASAP
delay = 0
}
}
flushers.add(flusher)
return {
dispose() {
timeoutId = setTimeout(disposeWrapper, delay)
},
value: disposable.value,
}
}
debounceResource.flushAll = () => {
// iterate on a sync way in order to not remove a flusher added on processing flushers
const promise = asyncMap(flushers, flush => flush())
flushers.clear()
return promise
}
return debounceResource
}

View File

@@ -0,0 +1,29 @@
/* eslint-env jest */
const { createDebounceResource } = require('./debounceResource')
jest.useFakeTimers()
describe('debounceResource()', () => {
it('calls the resource disposer after 10 seconds', async () => {
const debounceResource = createDebounceResource()
const delay = 10e3
const dispose = jest.fn()
const resource = await debounceResource(
Promise.resolve({
value: '',
dispose,
}),
delay
)
resource.dispose()
expect(dispose).not.toBeCalled()
jest.advanceTimersByTime(delay)
expect(dispose).toBeCalled()
})
})

View File

@@ -0,0 +1,52 @@
const ensureArray = require('ensure-array')
const { MultiKeyMap } = require('@vates/multi-key-map')
function State(factory) {
this.factory = factory
this.users = 0
}
const call = fn => fn()
exports.deduped = (factory, keyFn = (...args) => args) =>
(function () {
const states = new MultiKeyMap()
return function () {
const keys = ensureArray(keyFn.apply(this, arguments))
let state = states.get(keys)
if (state === undefined) {
const result = factory.apply(this, arguments)
const createFactory = disposable => {
const wrapper = {
dispose() {
if (--state.users === 0) {
states.delete(keys)
return disposable.dispose()
}
},
value: disposable.value,
}
return () => {
return wrapper
}
}
if (typeof result.then !== 'function') {
state = new State(createFactory(result))
} else {
result.catch(() => {
states.delete(keys)
})
const pFactory = result.then(createFactory)
state = new State(() => pFactory.then(call))
}
states.set(keys, state)
}
++state.users
return state.factory()
}
})()

View File

@@ -0,0 +1,76 @@
/* eslint-env jest */
const { deduped } = require('./deduped')
describe('deduped()', () => {
it('calls the resource function only once', async () => {
const value = {}
const getResource = jest.fn(async () => ({
value,
dispose: Function.prototype,
}))
const dedupedGetResource = deduped(getResource)
const { value: v1 } = await dedupedGetResource()
const { value: v2 } = await dedupedGetResource()
expect(getResource).toHaveBeenCalledTimes(1)
expect(v1).toBe(value)
expect(v2).toBe(value)
})
it('only disposes the source disposable when its all copies dispose', async () => {
const dispose = jest.fn()
const getResource = async () => ({
value: '',
dispose,
})
const dedupedGetResource = deduped(getResource)
const { dispose: d1 } = await dedupedGetResource()
const { dispose: d2 } = await dedupedGetResource()
d1()
expect(dispose).not.toHaveBeenCalled()
d2()
expect(dispose).toHaveBeenCalledTimes(1)
})
it('works with sync factory', () => {
const value = {}
const dispose = jest.fn()
const dedupedGetResource = deduped(() => ({ value, dispose }))
const d1 = dedupedGetResource()
expect(d1.value).toBe(value)
const d2 = dedupedGetResource()
expect(d2.value).toBe(value)
d1.dispose()
expect(dispose).not.toHaveBeenCalled()
d2.dispose()
expect(dispose).toHaveBeenCalledTimes(1)
})
it('no race condition on dispose before async acquisition', async () => {
const dispose = jest.fn()
const dedupedGetResource = deduped(async () => ({ value: 42, dispose }))
const d1 = await dedupedGetResource()
dedupedGetResource()
d1.dispose()
expect(dispose).not.toHaveBeenCalled()
})
})

View File

@@ -0,0 +1,30 @@
{
"private": false,
"name": "@vates/disposable",
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/disposable",
"description": "Utilities for disposables",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
"directory": "@vates/disposable",
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "ISC",
"version": "0.1.1",
"engines": {
"node": ">=8.10"
},
"scripts": {
"postversion": "npm publish --access public"
},
"dependencies": {
"@vates/multi-key-map": "^0.1.0",
"@xen-orchestra/async-map": "^0.1.2",
"@xen-orchestra/log": "^0.2.0",
"ensure-array": "^1.0.0"
}
}

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -0,0 +1,53 @@
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
# @vates/multi-key-map
[![Package Version](https://badgen.net/npm/v/@vates/multi-key-map)](https://npmjs.org/package/@vates/multi-key-map) ![License](https://badgen.net/npm/license/@vates/multi-key-map) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/multi-key-map)](https://bundlephobia.com/result?p=@vates/multi-key-map) [![Node compatibility](https://badgen.net/npm/node/@vates/multi-key-map)](https://npmjs.org/package/@vates/multi-key-map)
> Create map with values affected to multiple keys
## Install
Installation of the [npm package](https://npmjs.org/package/@vates/multi-key-map):
```
> npm install --save @vates/multi-key-map
```
## Usage
```js
import { MultiKeyMap } from '@vates/multi-key-map'
const map = new MultiKeyMap()
const OBJ = {}
map.set([], 0)
map.set(['foo'], 1)
map.set(['foo', 'bar'], 2)
map.set(['bar', 'foo'], 3)
map.set([OBJ], 4)
map.set([{}], 5)
map.get([]) // 0
map.get(['foo']) // 1
map.get(['foo', 'bar']) // 2
map.get(['bar', 'foo']) // 3
map.get([OBJ]) // 4
map.get([{}]) // undefined
```
## 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)

View File

@@ -0,0 +1,20 @@
```js
import { MultiKeyMap } from '@vates/multi-key-map'
const map = new MultiKeyMap()
const OBJ = {}
map.set([], 0)
map.set(['foo'], 1)
map.set(['foo', 'bar'], 2)
map.set(['bar', 'foo'], 3)
map.set([OBJ], 4)
map.set([{}], 5)
map.get([]) // 0
map.get(['foo']) // 1
map.get(['foo', 'bar']) // 2
map.get(['bar', 'foo']) // 3
map.get([OBJ]) // 4
map.get([{}]) // undefined
```

View File

@@ -67,7 +67,7 @@ function set(node, i, keys, value) {
return node
}
export default class MultiKeyMap {
exports.MultiKeyMap = class MultiKeyMap {
constructor() {
// each node is either a value or a Node if it contains children
this._root = undefined

View File

@@ -1,6 +1,6 @@
/* eslint-env jest */
import MultiKeyMap from './_MultiKeyMap'
const { MultiKeyMap } = require('./')
describe('MultiKeyMap', () => {
it('works', () => {

View File

@@ -0,0 +1,28 @@
{
"private": false,
"name": "@vates/multi-key-map",
"description": "Create map with values affected to multiple keys",
"keywords": [
"cache",
"map"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/multi-key-map",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
"directory": "@vates/multi-key-map",
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "ISC",
"version": "0.1.0",
"engines": {
"node": ">=8.10"
},
"scripts": {
"postversion": "npm publish --access public"
}
}

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -44,4 +44,4 @@ You may:
## License
[AGPL-3.0-or-later](https://spdx.org/licenses/AGPL-3.0-or-later) © [Vates SAS](https://vates.fr)
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)

View File

@@ -6,7 +6,7 @@ exports.parseDuration = value => {
}
const duration = ms(value)
if (duration === undefined) {
throw new TypeError(`not a valid duration: ${duration}`)
throw new TypeError(`not a valid duration: ${value}`)
}
return duration
}

View File

@@ -18,8 +18,8 @@
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "AGPL-3.0-or-later",
"version": "0.1.0",
"license": "ISC",
"version": "0.1.1",
"engines": {
"node": ">=8.10"
},

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -1,27 +1,30 @@
exports.readChunk = (stream, size) =>
new Promise((resolve, reject) => {
function onEnd() {
resolve(null)
removeListeners()
}
function onError(error) {
reject(error)
removeListeners()
}
function onReadable() {
const data = stream.read(size)
if (data !== null) {
resolve(data)
removeListeners()
}
}
function removeListeners() {
stream.removeListener('end', onEnd)
stream.removeListener('error', onError)
stream.removeListener('readable', onReadable)
}
stream.on('end', onEnd)
stream.on('error', onError)
stream.on('readable', onReadable)
onReadable()
})
const readChunk = (stream, size) =>
size === 0
? Promise.resolve(Buffer.alloc(0))
: new Promise((resolve, reject) => {
function onEnd() {
resolve(null)
removeListeners()
}
function onError(error) {
reject(error)
removeListeners()
}
function onReadable() {
const data = stream.read(size)
if (data !== null) {
resolve(data)
removeListeners()
}
}
function removeListeners() {
stream.removeListener('end', onEnd)
stream.removeListener('error', onError)
stream.removeListener('readable', onReadable)
}
stream.on('end', onEnd)
stream.on('error', onError)
stream.on('readable', onReadable)
onReadable()
})
exports.readChunk = readChunk

View File

@@ -0,0 +1,43 @@
/* eslint-env jest */
const { Readable } = require('stream')
const { readChunk } = require('./')
const makeStream = it => Readable.from(it, { objectMode: false })
makeStream.obj = Readable.from
describe('readChunk', () => {
it('returns null if stream is empty', async () => {
expect(await readChunk(makeStream([]))).toBe(null)
})
describe('with binary stream', () => {
it('returns the first chunk of data', async () => {
expect(await readChunk(makeStream(['foo', 'bar']))).toEqual(Buffer.from('foo'))
})
it('returns a chunk of the specified size (smaller than first)', async () => {
expect(await readChunk(makeStream(['foo', 'bar']), 2)).toEqual(Buffer.from('fo'))
})
it('returns a chunk of the specified size (larger than first)', async () => {
expect(await readChunk(makeStream(['foo', 'bar']), 4)).toEqual(Buffer.from('foob'))
})
it('returns less data if stream ends', async () => {
expect(await readChunk(makeStream(['foo', 'bar']), 10)).toEqual(Buffer.from('foobar'))
})
it('returns an empty buffer if the specified size is 0', async () => {
expect(await readChunk(makeStream(['foo', 'bar']), 0)).toEqual(Buffer.alloc(0))
})
})
describe('with object stream', () => {
it('returns the first chunk of data verbatim', async () => {
const chunks = [{}, {}]
expect(await readChunk(makeStream.obj(chunks))).toBe(chunks[0])
})
})
})

View File

@@ -19,7 +19,7 @@
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"version": "0.1.1",
"version": "0.1.2",
"engines": {
"node": ">=8.10"
},

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -0,0 +1,59 @@
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
# @vates/toggle-scripts
[![Package Version](https://badgen.net/npm/v/@vates/toggle-scripts)](https://npmjs.org/package/@vates/toggle-scripts) ![License](https://badgen.net/npm/license/@vates/toggle-scripts) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/toggle-scripts)](https://bundlephobia.com/result?p=@vates/toggle-scripts) [![Node compatibility](https://badgen.net/npm/node/@vates/toggle-scripts)](https://npmjs.org/package/@vates/toggle-scripts)
> Easily enable/disable scripts in package.json
## Install
Installation of the [npm package](https://npmjs.org/package/@vates/toggle-scripts):
```
> npm install --save @vates/toggle-scripts
```
## Usage
```
Usage: toggle-scripts options...
Easily enable/disable scripts in package.json
Options
+<script> Enable the script <script>, ie remove the prefix `_`
-<script> Disable the script <script>, ie prefix it with `_`
Examples
toggle-scripts +postinstall +preuninstall
toggle-scripts -postinstall -preuninstall
```
For example, if you want `postinstall` hook only in dev:
```json
// package.json
{
"scripts": {
"postinstall": "<some dev only command>",
"prepublishOnly": "toggle-scripts -postinstall",
"postpublish": "toggle-scripts +postinstall"
}
}
```
## 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)

View File

@@ -0,0 +1,26 @@
```
Usage: toggle-scripts options...
Easily enable/disable scripts in package.json
Options
+<script> Enable the script <script>, ie remove the prefix `_`
-<script> Disable the script <script>, ie prefix it with `_`
Examples
toggle-scripts +postinstall +preuninstall
toggle-scripts -postinstall -preuninstall
```
For example, if you want `postinstall` hook only in dev:
```json
// package.json
{
"scripts": {
"postinstall": "<some dev only command>",
"prepublishOnly": "toggle-scripts -postinstall",
"postpublish": "toggle-scripts +postinstall"
}
}
```

60
@vates/toggle-scripts/index.js Executable file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env node
const fs = require('fs')
const mapKeys = (object, iteratee) => {
const result = {}
for (const key of Object.keys(object)) {
result[iteratee(key, object)] = object[key]
}
return result
}
const args = process.argv.slice(2)
if (args.length === 0) {
const { description, name, version } = require('./package.json')
const bin = 'toggle-scripts'
process.stdout.write(`Usage: ${bin} options...
${description}
Options
+<script> Enable the script <script>, ie remove the prefix \`_\`
-<script> Disable the script <script>, ie prefix it with \`_\`
Examples
${bin} +postinstall +preuninstall
${bin} -postinstall -preuninstall
${name} v${version}
`)
process.exit()
}
const plan = { __proto__: null }
for (const arg of args) {
const action = arg[0]
const script = arg.slice(1)
if (action === '+') {
plan['_' + script] = script
} else if (action === '-') {
plan[script] = '_' + script
} else {
throw new Error('invalid param: ' + arg)
}
}
const pkgPath = process.env.npm_package_json || './package.json'
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
pkg.scripts = mapKeys(pkg.scripts, (name, scripts) => {
const newName = plan[name]
if (newName === undefined) {
return name
}
if (newName in scripts) {
throw new Error('script already defined: ' + name)
}
return newName
})
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')

View File

@@ -0,0 +1,38 @@
{
"private": false,
"name": "@vates/toggle-scripts",
"description": "Easily enable/disable scripts in package.json",
"keywords": [
"dev",
"disable",
"enable",
"lifecycle",
"npm",
"package.json",
"pinst",
"postinstall",
"script",
"scripts",
"toggle"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/toggle-scripts",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
"directory": "@vates/toggle-scripts",
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"license": "ISC",
"version": "1.0.0",
"engines": {
"node": ">=6"
},
"bin": "./index.js",
"scripts": {
"postversion": "npm publish --access public"
}
}

View File

@@ -1,3 +0,0 @@
module.exports = require('../../@xen-orchestra/babel-config')(
require('./package.json')
)

View File

@@ -1,24 +0,0 @@
/benchmark/
/benchmarks/
*.bench.js
*.bench.js.map
/examples/
example.js
example.js.map
*.example.js
*.example.js.map
/fixture/
/fixtures/
*.fixture.js
*.fixture.js.map
*.fixtures.js
*.fixtures.js.map
/test/
/tests/
*.spec.js
*.spec.js.map
__snapshots__/

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -4,7 +4,7 @@
[![Package Version](https://badgen.net/npm/v/@xen-orchestra/async-map)](https://npmjs.org/package/@xen-orchestra/async-map) ![License](https://badgen.net/npm/license/@xen-orchestra/async-map) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@xen-orchestra/async-map)](https://bundlephobia.com/result?p=@xen-orchestra/async-map) [![Node compatibility](https://badgen.net/npm/node/@xen-orchestra/async-map)](https://npmjs.org/package/@xen-orchestra/async-map)
> Similar to Promise.all + lodash.map but wait for all promises to be settled
> Promise.all + map for all iterables
## Install
@@ -16,10 +16,61 @@ Installation of the [npm package](https://npmjs.org/package/@xen-orchestra/async
## Usage
```js
import asyncMap from '@xen-orchestra/async-map'
### `asyncMap(iterable, iteratee, thisArg = iterable)`
const array = await asyncMap(collection, iteratee)
Similar to `Promise.all + Array#map` for all iterables: calls `iteratee` for each item in `iterable`, and returns a promise of an array containing the awaited result of each calls to `iteratee`.
It rejects as soon as te first call to `iteratee` rejects.
```js
import { asyncMap } from '@xen-orchestra/async-map'
const array = await asyncMap(iterable, iteratee, thisArg)
```
It can be used with any iterables (`Array`, `Map`, etc.):
```js
const map = new Map()
map.set('foo', 42)
map.set('bar', 3.14)
const array = await asyncMap(map, async function ([key, value]) {
// TODO: do async computation
//
// the map can be accessed via `this`
})
```
#### Use with plain objects
Plain objects are not iterable, but you can use `Object.keys`, `Object.values` or `Object.entries` to help:
```js
const object = {
foo: 42,
bar: 3.14,
}
const array = await asyncMap(
Object.entries(object),
async function ([key, value]) {
// TODO: do async computation
//
// the object can be accessed via `this` because it's been passed as third arg
},
object
)
```
### `asyncMapSettled(iterable, iteratee, thisArg = iterable)`
Similar to `asyncMap` but waits for all promises to settle before rejecting.
```js
import { asyncMapSettled } from '@xen-orchestra/async-map'
const array = await asyncMapSettled(iterable, iteratee, thisArg)
```
## Contributions

View File

@@ -1,5 +1,56 @@
```js
import asyncMap from '@xen-orchestra/async-map'
### `asyncMap(iterable, iteratee, thisArg = iterable)`
const array = await asyncMap(collection, iteratee)
Similar to `Promise.all + Array#map` for all iterables: calls `iteratee` for each item in `iterable`, and returns a promise of an array containing the awaited result of each calls to `iteratee`.
It rejects as soon as te first call to `iteratee` rejects.
```js
import { asyncMap } from '@xen-orchestra/async-map'
const array = await asyncMap(iterable, iteratee, thisArg)
```
It can be used with any iterables (`Array`, `Map`, etc.):
```js
const map = new Map()
map.set('foo', 42)
map.set('bar', 3.14)
const array = await asyncMap(map, async function ([key, value]) {
// TODO: do async computation
//
// the map can be accessed via `this`
})
```
#### Use with plain objects
Plain objects are not iterable, but you can use `Object.keys`, `Object.values` or `Object.entries` to help:
```js
const object = {
foo: 42,
bar: 3.14,
}
const array = await asyncMap(
Object.entries(object),
async function ([key, value]) {
// TODO: do async computation
//
// the object can be accessed via `this` because it's been passed as third arg
},
object
)
```
### `asyncMapSettled(iterable, iteratee, thisArg = iterable)`
Similar to `asyncMap` but waits for all promises to settle before rejecting.
```js
import { asyncMapSettled } from '@xen-orchestra/async-map'
const array = await asyncMapSettled(iterable, iteratee, thisArg)
```

View File

@@ -0,0 +1,71 @@
const wrapCall = (fn, arg, thisArg) => {
try {
return Promise.resolve(fn.call(thisArg, arg))
} catch (error) {
return Promise.reject(error)
}
}
/**
* Similar to Promise.all + Array#map but supports all iterables and does not trigger ESLint array-callback-return
*
* WARNING: Does not handle plain objects
*
* @template Item,This
* @param {Iterable<Item>} iterable
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
* @param {This} [thisArg]
* @returns {Promise<Item[]>}
*/
exports.asyncMap = function asyncMap(iterable, mapFn, thisArg = iterable) {
return Promise.all(Array.from(iterable, mapFn, thisArg))
}
/**
* Like `asyncMap` but wait for all promises to settle before rejecting
*
* @template Item,This
* @param {Iterable<Item>} iterable
* @param {(this: This, item: Item) => (Item | PromiseLike<Item>)} mapFn
* @param {This} [thisArg]
* @returns {Promise<Item[]>}
*/
exports.asyncMapSettled = function asyncMapSettled(iterable, mapFn, thisArg = iterable) {
return new Promise((resolve, reject) => {
const onError = e => {
if (result !== undefined) {
error = e
result = undefined
}
if (--n === 0) {
reject(error)
}
}
const onValue = (i, value) => {
const hasError = result === undefined
if (!hasError) {
result[i] = value
}
if (--n === 0) {
if (hasError) {
reject(error)
} else {
resolve(result)
}
}
}
let n = 0
for (const item of iterable) {
const i = n++
wrapCall(mapFn, item, thisArg).then(value => onValue(i, value), onError)
}
if (n === 0) {
return resolve([])
}
let error
let result = new Array(n)
})
}

View File

@@ -0,0 +1,71 @@
/* eslint-env jest */
const { asyncMapSettled } = require('./')
const noop = Function.prototype
describe('asyncMapSettled', () => {
it('works', async () => {
const values = [Math.random(), Math.random()]
const spy = jest.fn(async v => v * 2)
const iterable = new Set(values)
// returns an array containing the result of each calls
expect(await asyncMapSettled(iterable, spy)).toEqual(values.map(value => value * 2))
for (let i = 0, n = values.length; i < n; ++i) {
// each call receive the current item as sole argument
expect(spy.mock.calls[i]).toEqual([values[i]])
// each call as this bind to the iterable
expect(spy.mock.instances[i]).toBe(iterable)
}
})
it('can use a specified thisArg', () => {
const thisArg = {}
const spy = jest.fn()
asyncMapSettled(['foo'], spy, thisArg)
expect(spy.mock.instances[0]).toBe(thisArg)
})
it('rejects only when all calls as resolved', async () => {
const defers = []
const promise = asyncMapSettled([1, 2], () => {
let resolve, reject
// eslint-disable-next-line promise/param-names
const promise = new Promise((_resolve, _reject) => {
resolve = _resolve
reject = _reject
})
defers.push({ promise, resolve, reject })
return promise
})
let hasSettled = false
promise.catch(noop).then(() => {
hasSettled = true
})
const error = new Error()
defers[0].reject(error)
// wait for all microtasks to settle
await new Promise(resolve => setImmediate(resolve))
expect(hasSettled).toBe(false)
defers[1].resolve()
// wait for all microtasks to settle
await new Promise(resolve => setImmediate(resolve))
expect(hasSettled).toBe(true)
await expect(promise).rejects.toBe(error)
})
it('issues when latest promise rejects', async () => {
const error = new Error()
await expect(asyncMapSettled([1], () => Promise.reject(error))).rejects.toBe(error)
})
})

View File

@@ -9,14 +9,18 @@
// (V1, K) => MaybePromise<V2>
// ): Promise<V2[]>
import map from 'lodash/map'
const map = require('lodash/map')
// Similar to map() + Promise.all() but wait for all promises to
// settle before rejecting (with the first error)
const asyncMap = (collection, iteratee) => {
/**
* Similar to map() + Promise.all() but wait for all promises to settle before
* rejecting (with the first error)
*
* @deprecated Don't support iterables, please use new implementations
*/
module.exports = function asyncMapLegacy(collection, iteratee) {
let then
if (collection != null && typeof (then = collection.then) === 'function') {
return then.call(collection, collection => asyncMap(collection, iteratee))
return then.call(collection, collection => asyncMapLegacy(collection, iteratee))
}
let errorContainer
@@ -39,5 +43,3 @@ const asyncMap = (collection, iteratee) => {
return values
})
}
export { asyncMap as default }

View File

@@ -1,10 +1,17 @@
{
"private": false,
"name": "@xen-orchestra/async-map",
"version": "0.0.0",
"version": "0.1.2",
"license": "ISC",
"description": "Similar to Promise.all + lodash.map but wait for all promises to be settled",
"keywords": [],
"description": "Promise.all + map for all iterables",
"keywords": [
"array",
"async",
"iterable",
"map",
"settled",
"typescript"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/async-map",
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"repository": {
@@ -17,36 +24,13 @@
"url": "https://vates.fr"
},
"preferGlobal": false,
"main": "dist/",
"bin": {},
"files": [
"dist/"
],
"browserslist": [
">2%"
],
"engines": {
"node": ">=6"
},
"dependencies": {
"lodash": "^4.17.4"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"babel-plugin-lodash": "^3.3.2",
"cross-env": "^7.0.2",
"rimraf": "^3.0.0"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
"clean": "rimraf dist/",
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
"prebuild": "yarn run clean",
"predev": "yarn run prebuild",
"prepublishOnly": "yarn run build",
"postversion": "npm publish"
}
}

View File

@@ -1,3 +1 @@
module.exports = require('../../@xen-orchestra/babel-config')(
require('./package.json')
)
module.exports = require('../../@xen-orchestra/babel-config')(require('./package.json'))

View File

@@ -0,0 +1 @@
../../scripts/babel-eslintrc.js

View File

@@ -1,24 +0,0 @@
/benchmark/
/benchmarks/
*.bench.js
*.bench.js.map
/examples/
example.js
example.js.map
*.example.js
*.example.js.map
/fixture/
/fixtures/
*.fixture.js
*.fixture.js.map
*.fixtures.js
*.fixtures.js.map
/test/
/tests/
*.spec.js
*.spec.js.map
__snapshots__/

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -26,14 +26,14 @@
"@babel/plugin-proposal-decorators": "^7.8.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.0",
"@babel/preset-env": "^7.7.4",
"cross": "^1.0.0",
"cross-env": "^7.0.2",
"rimraf": "^3.0.0"
},
"dependencies": {
"@vates/decorate-with": "^0.0.1",
"@xen-orchestra/log": "^0.2.0",
"core-js": "^3.6.4",
"golike-defer": "^0.4.1",
"lodash": "^4.17.15",
"golike-defer": "^0.5.1",
"object-hash": "^2.0.1"
},
"private": false,

View File

@@ -2,9 +2,10 @@
import 'core-js/features/symbol/async-iterator'
import assert from 'assert'
import createLogger from '@xen-orchestra/log'
import defer from 'golike-defer'
import hash from 'object-hash'
import { createLogger } from '@xen-orchestra/log'
import { decorateWith } from '@vates/decorate-with'
import { defer } from 'golike-defer'
const log = createLogger('xo:audit-core')
@@ -65,7 +66,7 @@ export class AuditCore {
this._storage = storage
}
@defer
@decorateWith(defer)
async add($defer, subject, event, data) {
const time = Date.now()
$defer(await this._storage.acquireLock())
@@ -119,9 +120,7 @@ export class AuditCore {
if (record === undefined) {
throw new MissingRecordError(newest, nValid)
}
if (
newest !== createHash(record, newest.slice(1, newest.indexOf('$', 1)))
) {
if (newest !== createHash(record, newest.slice(1, newest.indexOf('$', 1)))) {
throw new AlteredRecordError(newest, nValid, record)
}
newest = record.previousId
@@ -152,7 +151,7 @@ export class AuditCore {
}
}
@defer
@decorateWith(defer)
async deleteRangeAndRewrite($defer, newest, oldest) {
assert.notStrictEqual(newest, undefined)
assert.notStrictEqual(oldest, undefined)

View File

@@ -1,12 +1,6 @@
/* eslint-env jest */
import {
AlteredRecordError,
AuditCore,
MissingRecordError,
NULL_ID,
Storage,
} from '.'
import { AlteredRecordError, AuditCore, MissingRecordError, NULL_ID, Storage } from '.'
const asyncIteratorToArray = async asyncIterator => {
const array = []
@@ -88,16 +82,13 @@ describe('auditCore', () => {
it('detects that a record is missing', async () => {
const [newestRecord, deletedRecord] = await storeAuditRecords()
const nValidRecords = await auditCore.checkIntegrity(
NULL_ID,
newestRecord.id
)
const nValidRecords = await auditCore.checkIntegrity(NULL_ID, newestRecord.id)
expect(nValidRecords).toBe(DATA.length)
await db.del(deletedRecord.id)
await expect(
auditCore.checkIntegrity(NULL_ID, newestRecord.id)
).rejects.toEqual(new MissingRecordError(deletedRecord.id, 1))
await expect(auditCore.checkIntegrity(NULL_ID, newestRecord.id)).rejects.toEqual(
new MissingRecordError(deletedRecord.id, 1)
)
})
it('detects that a record has been altered', async () => {
@@ -106,9 +97,7 @@ describe('auditCore', () => {
alteredRecord.event = ''
await db.put(alteredRecord)
await expect(
auditCore.checkIntegrity(NULL_ID, newestRecord.id)
).rejects.toEqual(
await expect(auditCore.checkIntegrity(NULL_ID, newestRecord.id)).rejects.toEqual(
new AlteredRecordError(alteredRecord.id, 1, alteredRecord)
)
})

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -14,58 +14,39 @@ const configs = {
'@babel/plugin-proposal-pipeline-operator': {
proposal: 'minimal',
},
'@babel/preset-env'(pkg) {
return {
debug: !__TEST__,
'@babel/preset-env': {
debug: !__TEST__,
// disabled until https://github.com/babel/babel/issues/8323 is resolved
// loose: true,
// disabled until https://github.com/babel/babel/issues/8323 is resolved
// loose: true,
shippedProposals: true,
targets: (() => {
let node = (pkg.engines || {}).node
if (node !== undefined) {
const trimChars = '^=>~'
while (trimChars.includes(node[0])) {
node = node.slice(1)
}
}
return { browsers: pkg.browserslist, node }
})(),
}
shippedProposals: true,
},
}
const getConfig = (key, ...args) => {
const config = configs[key]
return config === undefined
? {}
: typeof config === 'function'
? config(...args)
: config
return config === undefined ? {} : typeof config === 'function' ? config(...args) : config
}
// some plugins must be used in a specific order
const pluginsOrder = [
'@babel/plugin-proposal-decorators',
'@babel/plugin-proposal-class-properties',
]
const pluginsOrder = ['@babel/plugin-proposal-decorators', '@babel/plugin-proposal-class-properties']
module.exports = function (pkg, plugins, presets) {
plugins === undefined && (plugins = {})
presets === undefined && (presets = {})
module.exports = function (pkg, configs = {}) {
const plugins = {}
const presets = {}
Object.keys(pkg.devDependencies || {}).forEach(name => {
if (!(name in presets) && PLUGINS_RE.test(name)) {
plugins[name] = getConfig(name, pkg)
plugins[name] = { ...getConfig(name, pkg), ...configs[name] }
} else if (!(name in presets) && PRESETS_RE.test(name)) {
presets[name] = getConfig(name, pkg)
presets[name] = { ...getConfig(name, pkg), ...configs[name] }
}
})
return {
comments: !__PROD__,
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
ignore: __PROD__ ? [/\.spec\.js$/] : undefined,
plugins: Object.keys(plugins)
.map(plugin => [plugin, plugins[plugin]])
.sort(([a], [b]) => {
@@ -74,5 +55,15 @@ module.exports = function (pkg, plugins, presets) {
return oA !== -1 && oB !== -1 ? oA - oB : a < b ? -1 : 1
}),
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
targets: (() => {
let node = (pkg.engines || {}).node
if (node !== undefined) {
const trimChars = '^=>~'
while (trimChars.includes(node[0])) {
node = node.slice(1)
}
}
return { browsers: pkg.browserslist, node }
})(),
}
}

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -12,6 +12,26 @@ Installation of the [npm package](https://npmjs.org/package/@xen-orchestra/backu
> npm install --global @xen-orchestra/backups-cli
```
## Usage
```
> xo-backups --help
Usage:
xo-backups clean-vms [--merge] [--remove] xo-vm-backups/*
Detects and repair issues with VM backups.
Options:
-m, --merge Merge (or continue merging) VHD files that are unused
-r, --remove Remove unused, incomplete, orphan, or corrupted files
xo-backups create-symlink-index xo-vm-backups <field path>
xo-backups info xo-vm-backups/*
```
## Contributions
Contributions are _very_ welcomed, either on the documentation or on

View File

@@ -0,0 +1,17 @@
```
> xo-backups --help
Usage:
xo-backups clean-vms [--merge] [--remove] xo-vm-backups/*
Detects and repair issues with VM backups.
Options:
-m, --merge Merge (or continue merging) VHD files that are unused
-r, --remove Remove unused, incomplete, orphan, or corrupted files
xo-backups create-symlink-index xo-vm-backups <field path>
xo-backups info xo-vm-backups/*
```

View File

@@ -1,7 +0,0 @@
const curryRight = require('lodash/curryRight')
module.exports = curryRight((iterable, fn) =>
Promise.all(
Array.isArray(iterable) ? iterable.map(fn) : Array.from(iterable, fn)
)
)

View File

@@ -1,340 +1,33 @@
#!/usr/bin/env node
// assigned when options are parsed by the main function
let force
// -----------------------------------------------------------------------------
const assert = require('assert')
const flatten = require('lodash/flatten')
const asyncMap = require('lodash/curryRight')(require('@xen-orchestra/async-map').asyncMap)
const getopts = require('getopts')
const limitConcurrency = require('limit-concurrency-decorator').default
const lockfile = require('proper-lockfile')
const pipe = require('promise-toolbox/pipe')
const { default: Vhd, mergeVhd } = require('vhd-lib')
const { dirname, resolve } = require('path')
const { DISK_TYPE_DIFFERENCING } = require('vhd-lib/dist/_constants')
const { isValidXva } = require('@xen-orchestra/backups/isValidXva')
const { RemoteAdapter } = require('@xen-orchestra/backups/RemoteAdapter')
const { resolve } = require('path')
const asyncMap = require('../_asyncMap')
const fs = require('../_fs')
const handler = require('@xen-orchestra/fs').getHandler({ url: 'file://' })
// -----------------------------------------------------------------------------
// chain is an array of VHDs from child to parent
//
// the whole chain will be merged into parent, parent will be renamed to child
// and all the others will deleted
const mergeVhdChain = limitConcurrency(1)(async function mergeVhdChain(chain) {
assert(chain.length >= 2)
let child = chain[0]
const parent = chain[chain.length - 1]
const children = chain.slice(0, -1).reverse()
console.warn('Unused parents of VHD', child)
chain
.slice(1)
.reverse()
.forEach(parent => {
console.warn(' ', parent)
})
force && console.warn(' merging…')
console.warn('')
if (force) {
// `mergeVhd` does not work with a stream, either
// - make it accept a stream
// - or create synthetic VHD which is not a stream
if (children.length !== 1) {
console.warn('TODO: implement merging multiple children')
children.length = 1
child = children[0]
}
let done, total
const handle = setInterval(() => {
if (done !== undefined) {
console.log('merging %s: %s/%s', child, done, total)
}
}, 10e3)
await mergeVhd(
handler,
parent,
handler,
child,
// children.length === 1
// ? child
// : await createSyntheticStream(handler, children),
{
onProgress({ done: d, total: t }) {
done = d
total = t
},
}
)
clearInterval(handle)
}
await Promise.all([
force && fs.rename(parent, child),
asyncMap(children.slice(0, -1), child => {
console.warn('Unused VHD', child)
force && console.warn(' deleting…')
console.warn('')
return force && handler.unlink(child)
}),
])
})
const listVhds = pipe([
vmDir => vmDir + '/vdis',
fs.readdir2,
asyncMap(fs.readdir2),
flatten,
asyncMap(fs.readdir2),
flatten,
_ => _.filter(_ => _.endsWith('.vhd')),
])
async function handleVm(vmDir) {
const vhds = new Set()
const vhdParents = { __proto__: null }
const vhdChildren = { __proto__: null }
// remove broken VHDs
await asyncMap(await listVhds(vmDir), async path => {
try {
const vhd = new Vhd(handler, path)
await vhd.readHeaderAndFooter()
vhds.add(path)
if (vhd.footer.diskType === DISK_TYPE_DIFFERENCING) {
const parent = resolve(dirname(path), vhd.header.parentUnicodeName)
vhdParents[path] = parent
if (parent in vhdChildren) {
const error = new Error(
'this script does not support multiple VHD children'
)
error.parent = parent
error.child1 = vhdChildren[parent]
error.child2 = path
throw error // should we throw?
}
vhdChildren[parent] = path
}
} catch (error) {
console.warn('Error while checking VHD', path)
console.warn(' ', error)
if (error != null && error.code === 'ERR_ASSERTION') {
force && console.warn(' deleting…')
console.warn('')
force && (await handler.unlink(path))
}
}
})
// remove VHDs with missing ancestors
{
const deletions = []
// return true if the VHD has been deleted or is missing
const deleteIfOrphan = vhd => {
const parent = vhdParents[vhd]
if (parent === undefined) {
return
}
// no longer needs to be checked
delete vhdParents[vhd]
deleteIfOrphan(parent)
if (!vhds.has(parent)) {
vhds.delete(vhd)
console.warn('Error while checking VHD', vhd)
console.warn(' missing parent', parent)
force && console.warn(' deleting…')
console.warn('')
force && deletions.push(handler.unlink(vhd))
}
}
// > A property that is deleted before it has been visited will not be
// > visited later.
// >
// > -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Deleted_added_or_modified_properties
for (const child in vhdParents) {
deleteIfOrphan(child)
}
await Promise.all(deletions)
}
const [jsons, xvas, xvaSums] = await fs
.readdir2(vmDir)
.then(entries => [
entries.filter(_ => _.endsWith('.json')),
new Set(entries.filter(_ => _.endsWith('.xva'))),
entries.filter(_ => _.endsWith('.xva.cheksum')),
])
await asyncMap(xvas, async path => {
// check is not good enough to delete the file, the best we can do is report
// it
if (!(await isValidXva(path))) {
console.warn('Potential broken XVA', path)
console.warn('')
}
})
const unusedVhds = new Set(vhds)
const unusedXvas = new Set(xvas)
// compile the list of unused XVAs and VHDs, and remove backup metadata which
// reference a missing XVA/VHD
await asyncMap(jsons, async json => {
const metadata = JSON.parse(await fs.readFile(json))
const { mode } = metadata
if (mode === 'full') {
const linkedXva = resolve(vmDir, metadata.xva)
if (xvas.has(linkedXva)) {
unusedXvas.delete(linkedXva)
} else {
console.warn('Error while checking backup', json)
console.warn(' missing file', linkedXva)
force && console.warn(' deleting…')
console.warn('')
force && (await handler.unlink(json))
}
} else if (mode === 'delta') {
const linkedVhds = (() => {
const { vhds } = metadata
return Object.keys(vhds).map(key => resolve(vmDir, vhds[key]))
})()
// FIXME: find better approach by keeping as much of the backup as
// possible (existing disks) even if one disk is missing
if (linkedVhds.every(_ => vhds.has(_))) {
linkedVhds.forEach(_ => unusedVhds.delete(_))
} else {
console.warn('Error while checking backup', json)
const missingVhds = linkedVhds.filter(_ => !vhds.has(_))
console.warn(
' %i/%i missing VHDs',
missingVhds.length,
linkedVhds.length
)
missingVhds.forEach(vhd => {
console.warn(' ', vhd)
})
force && console.warn(' deleting…')
console.warn('')
force && (await handler.unlink(json))
}
}
})
// TODO: parallelize by vm/job/vdi
const unusedVhdsDeletion = []
{
// VHD chains (as list from child to ancestor) to merge indexed by last
// ancestor
const vhdChainsToMerge = { __proto__: null }
const toCheck = new Set(unusedVhds)
const getUsedChildChainOrDelete = vhd => {
if (vhd in vhdChainsToMerge) {
const chain = vhdChainsToMerge[vhd]
delete vhdChainsToMerge[vhd]
return chain
}
if (!unusedVhds.has(vhd)) {
return [vhd]
}
// no longer needs to be checked
toCheck.delete(vhd)
const child = vhdChildren[vhd]
if (child !== undefined) {
const chain = getUsedChildChainOrDelete(child)
if (chain !== undefined) {
chain.push(vhd)
return chain
}
}
console.warn('Unused VHD', vhd)
force && console.warn(' deleting…')
console.warn('')
force && unusedVhdsDeletion.push(handler.unlink(vhd))
}
toCheck.forEach(vhd => {
vhdChainsToMerge[vhd] = getUsedChildChainOrDelete(vhd)
})
Object.keys(vhdChainsToMerge).forEach(key => {
const chain = vhdChainsToMerge[key]
if (chain !== undefined) {
unusedVhdsDeletion.push(mergeVhdChain(chain))
}
})
}
await Promise.all([
unusedVhdsDeletion,
asyncMap(unusedXvas, path => {
console.warn('Unused XVA', path)
force && console.warn(' deleting…')
console.warn('')
return force && handler.unlink(path)
}),
asyncMap(xvaSums, path => {
// no need to handle checksums for XVAs deleted by the script, they will be handled by `unlink()`
if (!xvas.has(path.slice(0, -'.checksum'.length))) {
console.warn('Unused XVA checksum', path)
force && console.warn(' deleting…')
console.warn('')
return force && handler.unlink(path)
}
}),
])
}
// -----------------------------------------------------------------------------
const adapter = new RemoteAdapter(require('@xen-orchestra/fs').getHandler({ url: 'file://' }))
module.exports = async function main(args) {
const opts = getopts(args, {
const { _, remove, merge } = getopts(args, {
alias: {
force: 'f',
remove: 'r',
merge: 'm',
},
boolean: ['force'],
boolean: ['merge', 'remove'],
default: {
force: false,
merge: false,
remove: false,
},
})
;({ force } = opts)
await asyncMap(opts._, async vmDir => {
await asyncMap(_, async vmDir => {
vmDir = resolve(vmDir)
// TODO: implement this in `xo-server`, not easy because not compatible with
// `@xen-orchestra/fs`.
const release = await lockfile.lock(vmDir)
try {
await handleVm(vmDir)
await adapter.cleanVm(vmDir, { remove, merge, onLog: log => console.warn(log) })
} catch (error) {
console.error('handleVm', vmDir, error)
} finally {
await release()
console.error('adapter.cleanVm', vmDir, error)
}
})
}

View File

@@ -1,8 +1,8 @@
const filenamify = require('filenamify')
const get = require('lodash/get')
const { asyncMap } = require('@xen-orchestra/async-map')
const { dirname, join, relative } = require('path')
const asyncMap = require('../_asyncMap')
const { mktree, readdir2, readFile, symlink2 } = require('../_fs')
module.exports = async function createSymlinkIndex([backupDir, fieldPath]) {

View File

@@ -1,8 +1,8 @@
const groupBy = require('lodash/groupBy')
const { asyncMap } = require('@xen-orchestra/async-map')
const { createHash } = require('crypto')
const { dirname, resolve } = require('path')
const asyncMap = require('../_asyncMap')
const { readdir2, readFile, getSize } = require('../_fs')
const sha512 = str => createHash('sha512').update(str).digest('hex')
@@ -10,9 +10,7 @@ const sum = values => values.reduce((a, b) => a + b)
module.exports = async function info(vmDirs) {
const jsonFiles = (
await asyncMap(vmDirs, async vmDir =>
(await readdir2(vmDir)).filter(_ => _.endsWith('.json'))
)
await asyncMap(vmDirs, async vmDir => (await readdir2(vmDir)).filter(_ => _.endsWith('.json')))
).flat()
const hashes = { __proto__: null }
@@ -39,9 +37,7 @@ module.exports = async function info(vmDirs) {
size:
json.length +
(await (metadata.mode === 'delta'
? asyncMap(Object.values(metadata.vhds), _ =>
getSize(resolve(jsonDir, _))
).then(sum)
? asyncMap(Object.values(metadata.vhds), _ => getSize(resolve(jsonDir, _))).then(sum)
: getSize(resolve(jsonDir, metadata.xva)))),
}
} catch (error) {

View File

@@ -5,7 +5,14 @@ require('./_composeCommands')({
get main() {
return require('./commands/clean-vms')
},
usage: '[--force] xo-vm-backups/*',
usage: `[--merge] [--remove] xo-vm-backups/*
Detects and repair issues with VM backups.
Options:
-m, --merge Merge (or continue merging) VHD files that are unused
-r, --remove Remove unused, incomplete, orphan, or corrupted files
`,
},
'create-symlink-index': {
get main() {

View File

@@ -6,23 +6,17 @@
"preferGlobal": true,
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
"dependencies": {
"@xen-orchestra/backups": "^0.1.1",
"@xen-orchestra/fs": "^0.11.1",
"@xen-orchestra/async-map": "^0.1.2",
"@xen-orchestra/backups": "^0.11.0",
"@xen-orchestra/fs": "^0.17.0",
"filenamify": "^4.1.0",
"getopts": "^2.2.5",
"limit-concurrency-decorator": "^0.4.0",
"lodash": "^4.17.15",
"promise-toolbox": "^0.15.0",
"proper-lockfile": "^4.1.1",
"vhd-lib": "^0.8.0"
"promise-toolbox": "^0.19.2"
},
"engines": {
"node": ">=7.10.1"
},
"files": [
"commands",
"*.js"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@xen-orchestra/backups-cli",
"name": "@xen-orchestra/backups-cli",
"repository": {
@@ -33,7 +27,7 @@
"scripts": {
"postversion": "npm publish --access public"
},
"version": "0.2.1",
"version": "0.6.0",
"license": "AGPL-3.0-or-later",
"author": {
"name": "Vates SAS",

View File

@@ -0,0 +1 @@
../../scripts/npmignore

View File

@@ -0,0 +1,263 @@
const { asyncMap, asyncMapSettled } = require('@xen-orchestra/async-map')
const Disposable = require('promise-toolbox/Disposable.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const { compileTemplate } = require('@xen-orchestra/template')
const { limitConcurrency } = require('limit-concurrency-decorator')
const { extractIdsFromSimplePattern } = require('./_extractIdsFromSimplePattern.js')
const { PoolMetadataBackup } = require('./_PoolMetadataBackup.js')
const { Task } = require('./Task.js')
const { VmBackup } = require('./_VmBackup.js')
const { XoMetadataBackup } = require('./_XoMetadataBackup.js')
const noop = Function.prototype
const getAdaptersByRemote = adapters => {
const adaptersByRemote = {}
adapters.forEach(({ adapter, remoteId }) => {
adaptersByRemote[remoteId] = adapter
})
return adaptersByRemote
}
const runTask = (...args) => Task.run(...args).catch(noop) // errors are handled by logs
exports.Backup = class Backup {
constructor({ config, getAdapter, getConnectedRecord, job, schedule }) {
this._config = config
this._getRecord = getConnectedRecord
this._job = job
this._schedule = schedule
this._getAdapter = Disposable.factory(function* (remoteId) {
return {
adapter: yield getAdapter(remoteId),
remoteId,
}
})
this._getSnapshotNameLabel = compileTemplate(config.snapshotNameLabelTpl, {
'{job.name}': job.name,
'{vm.name_label}': vm => vm.name_label,
})
}
run() {
const type = this._job.type
if (type === 'backup') {
return this._runVmBackup()
} else if (type === 'metadataBackup') {
return this._runMetadataBackup()
} else {
throw new Error(`No runner for the backup type ${type}`)
}
}
async _runMetadataBackup() {
const schedule = this._schedule
const job = this._job
const remoteIds = extractIdsFromSimplePattern(job.remotes)
if (remoteIds.length === 0) {
throw new Error('metadata backup job cannot run without remotes')
}
const config = this._config
const settings = {
...config.defaultSettings,
...config.metadata.defaultSettings,
...job.settings[''],
...job.settings[schedule.id],
}
const poolIds = extractIdsFromSimplePattern(job.pools)
const isEmptyPools = poolIds.length === 0
const isXoMetadata = job.xoMetadata !== undefined
if (!isXoMetadata && isEmptyPools) {
throw new Error('no metadata mode found')
}
const { retentionPoolMetadata, retentionXoMetadata } = settings
if (
(retentionPoolMetadata === 0 && retentionXoMetadata === 0) ||
(!isXoMetadata && retentionPoolMetadata === 0) ||
(isEmptyPools && retentionXoMetadata === 0)
) {
throw new Error('no retentions corresponding to the metadata modes found')
}
await Disposable.use(
Disposable.all(
poolIds.map(id =>
this._getRecord('pool', id).catch(error => {
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
runTask(
{
name: 'get pool record',
data: { type: 'pool', id },
},
() => Promise.reject(error)
)
})
)
),
Disposable.all(
remoteIds.map(id =>
this._getAdapter(id).catch(error => {
// See https://github.com/vatesfr/xen-orchestra/commit/6aa6cfba8ec939c0288f0fa740f6dfad98c43cbb
runTask(
{
name: 'get remote adapter',
data: { type: 'remote', id },
},
() => Promise.reject(error)
)
})
)
),
async (pools, remoteAdapters) => {
// remove adapters that failed (already handled)
remoteAdapters = remoteAdapters.filter(_ => _ !== undefined)
if (remoteAdapters.length === 0) {
return
}
remoteAdapters = getAdaptersByRemote(remoteAdapters)
// remove pools that failed (already handled)
pools = pools.filter(_ => _ !== undefined)
const promises = []
if (pools.length !== 0 && settings.retentionPoolMetadata !== 0) {
promises.push(
asyncMap(pools, async pool =>
runTask(
{
name: `Starting metadata backup for the pool (${pool.$id}). (${job.id})`,
data: {
id: pool.$id,
pool,
poolMaster: await ignoreErrors.call(pool.$xapi.getRecord('host', pool.master)),
type: 'pool',
},
},
() =>
new PoolMetadataBackup({
config,
job,
pool,
remoteAdapters,
schedule,
settings,
}).run()
)
)
)
}
if (job.xoMetadata !== undefined && settings.retentionXoMetadata !== 0) {
promises.push(
runTask(
{
name: `Starting XO metadata backup. (${job.id})`,
data: {
type: 'xo',
},
},
() =>
new XoMetadataBackup({
config,
job,
remoteAdapters,
schedule,
settings,
}).run()
)
)
}
await Promise.all(promises)
}
)
}
async _runVmBackup() {
const job = this._job
// FIXME: proper SimpleIdPattern handling
const getSnapshotNameLabel = this._getSnapshotNameLabel
const schedule = this._schedule
const config = this._config
const { settings } = job
const scheduleSettings = {
...config.defaultSettings,
...config.vm.defaultSettings,
...settings[''],
...settings[schedule.id],
}
await Disposable.use(
Disposable.all(
extractIdsFromSimplePattern(job.srs).map(id =>
this._getRecord('SR', id).catch(error => {
runTask(
{
name: 'get SR record',
data: { type: 'SR', id },
},
() => Promise.reject(error)
)
})
)
),
Disposable.all(
extractIdsFromSimplePattern(job.remotes).map(id =>
this._getAdapter(id).catch(error => {
runTask(
{
name: 'get remote adapter',
data: { type: 'remote', id },
},
() => Promise.reject(error)
)
})
)
),
async (srs, remoteAdapters) => {
// remove adapters that failed (already handled)
remoteAdapters = remoteAdapters.filter(_ => _ !== undefined)
// remove srs that failed (already handled)
srs = srs.filter(_ => _ !== undefined)
if (remoteAdapters.length === 0 && srs.length === 0 && scheduleSettings.snapshotRetention === 0) {
return
}
const vmIds = extractIdsFromSimplePattern(job.vms)
Task.info('vms', { vms: vmIds })
remoteAdapters = getAdaptersByRemote(remoteAdapters)
const handleVm = vmUuid =>
runTask({ name: 'backup VM', data: { type: 'VM', id: vmUuid } }, () =>
Disposable.use(this._getRecord('VM', vmUuid), vm =>
new VmBackup({
config,
getSnapshotNameLabel,
job,
// remotes,
remoteAdapters,
schedule,
settings: { ...scheduleSettings, ...settings[vmUuid] },
srs,
vm,
}).run()
)
)
const { concurrency } = scheduleSettings
await asyncMapSettled(vmIds, concurrency === 0 ? handleVm : limitConcurrency(concurrency)(handleVm))
}
)
}
}

View File

@@ -0,0 +1,40 @@
const { asyncMap } = require('@xen-orchestra/async-map')
exports.DurablePartition = class DurablePartition {
// private resource API is used exceptionally to be able to separate resource creation and release
#partitionDisposers = {}
flushAll() {
const partitionDisposers = this.#partitionDisposers
return asyncMap(Object.keys(partitionDisposers), path => {
const disposers = partitionDisposers[path]
delete partitionDisposers[path]
return asyncMap(disposers, d => d(path).catch(noop => {}))
})
}
async mount(adapter, diskId, partitionId) {
const { value: path, dispose } = await adapter.getPartition(diskId, partitionId)
const partitionDisposers = this.#partitionDisposers
if (partitionDisposers[path] === undefined) {
partitionDisposers[path] = []
}
partitionDisposers[path].push(dispose)
return path
}
async unmount(path) {
const partitionDisposers = this.#partitionDisposers
const disposers = partitionDisposers[path]
if (disposers === undefined) {
throw new Error(`No partition corresponding to the path ${path} found`)
}
await disposers.pop()()
if (disposers.length === 0) {
delete partitionDisposers[path]
}
}
}

View File

@@ -0,0 +1,66 @@
const assert = require('assert')
const { formatFilenameDate } = require('./_filenameDate.js')
const { importDeltaVm } = require('./_deltaVm.js')
const { Task } = require('./Task.js')
const { watchStreamSize } = require('./_watchStreamSize.js')
exports.ImportVmBackup = class ImportVmBackup {
constructor({ adapter, metadata, srUuid, xapi, settings: { newMacAddresses } = {} }) {
this._adapter = adapter
this._importDeltaVmSettings = { newMacAddresses }
this._metadata = metadata
this._srUuid = srUuid
this._xapi = xapi
}
async run() {
const adapter = this._adapter
const metadata = this._metadata
const isFull = metadata.mode === 'full'
const sizeContainer = { size: 0 }
let backup
if (isFull) {
backup = await adapter.readFullVmBackup(metadata)
watchStreamSize(backup, sizeContainer)
} else {
assert.strictEqual(metadata.mode, 'delta')
backup = await adapter.readDeltaVmBackup(metadata)
Object.values(backup.streams).forEach(stream => watchStreamSize(stream, sizeContainer))
}
return Task.run(
{
name: 'transfer',
},
async () => {
const xapi = this._xapi
const srRef = await xapi.call('SR.get_by_uuid', this._srUuid)
const vmRef = isFull
? await xapi.VM_import(backup, srRef)
: await importDeltaVm(backup, await xapi.getRecord('SR', srRef), {
...this._importDeltaVmSettings,
detectBase: false,
})
await Promise.all([
xapi.call('VM.add_tags', vmRef, 'restored from backup'),
xapi.call(
'VM.set_name_label',
vmRef,
`${metadata.vm.name_label} (${formatFilenameDate(metadata.timestamp)})`
),
])
return {
size: sizeContainer.size,
id: await xapi.getField('VM', vmRef, 'uuid'),
}
}
)
}
}

View File

@@ -0,0 +1,559 @@
const { asyncMap, asyncMapSettled } = require('@xen-orchestra/async-map')
const Disposable = require('promise-toolbox/Disposable.js')
const fromCallback = require('promise-toolbox/fromCallback.js')
const fromEvent = require('promise-toolbox/fromEvent.js')
const pDefer = require('promise-toolbox/defer.js')
const pump = require('pump')
const { basename, dirname, join, normalize, resolve } = require('path')
const { createLogger } = require('@xen-orchestra/log')
const { createSyntheticStream, mergeVhd, default: Vhd } = require('vhd-lib')
const { deduped } = require('@vates/disposable/deduped.js')
const { execFile } = require('child_process')
const { readdir, stat } = require('fs-extra')
const { ZipFile } = require('yazl')
const { BACKUP_DIR } = require('./_getVmBackupDir.js')
const { cleanVm } = require('./_cleanVm.js')
const { getTmpDir } = require('./_getTmpDir.js')
const { isMetadataFile, isVhdFile } = require('./_backupType.js')
const { isValidXva } = require('./_isValidXva.js')
const { listPartitions, LVM_PARTITION_TYPE } = require('./_listPartitions.js')
const { lvs, pvs } = require('./_lvm.js')
const DIR_XO_CONFIG_BACKUPS = 'xo-config-backups'
exports.DIR_XO_CONFIG_BACKUPS = DIR_XO_CONFIG_BACKUPS
const DIR_XO_POOL_METADATA_BACKUPS = 'xo-pool-metadata-backups'
exports.DIR_XO_POOL_METADATA_BACKUPS = DIR_XO_POOL_METADATA_BACKUPS
const { warn } = createLogger('xo:backups:RemoteAdapter')
const compareTimestamp = (a, b) => a.timestamp - b.timestamp
const noop = Function.prototype
const resolveRelativeFromFile = (file, path) => resolve('/', dirname(file), path).slice(1)
const resolveSubpath = (root, path) => resolve(root, `.${resolve('/', path)}`)
const RE_VHDI = /^vhdi(\d+)$/
async function addDirectory(files, realPath, metadataPath) {
try {
const subFiles = await readdir(realPath)
await asyncMap(subFiles, file => addDirectory(files, realPath + '/' + file, metadataPath + '/' + file))
} catch (error) {
if (error == null || error.code !== 'ENOTDIR') {
throw error
}
files.push({
realPath,
metadataPath,
})
}
}
const createSafeReaddir = (handler, methodName) => (path, options) =>
handler.list(path, options).catch(error => {
if (error?.code !== 'ENOENT') {
warn(`${methodName} ${path}`, { error })
}
return []
})
const debounceResourceFactory = factory =>
function () {
return this._debounceResource(factory.apply(this, arguments))
}
class RemoteAdapter {
constructor(handler, { debounceResource = res => res, dirMode } = {}) {
this._debounceResource = debounceResource
this._dirMode = dirMode
this._handler = handler
}
get handler() {
return this._handler
}
async _deleteVhd(path) {
const handler = this._handler
const vhds = await asyncMapSettled(
await handler.list(dirname(path), {
filter: isVhdFile,
prependDir: true,
}),
async path => {
try {
const vhd = new Vhd(handler, path)
await vhd.readHeaderAndFooter()
return {
footer: vhd.footer,
header: vhd.header,
path,
}
} catch (error) {
// Do not fail on corrupted VHDs (usually uncleaned temporary files),
// they are probably inconsequent to the backup process and should not
// fail it.
warn(`BackupNg#_deleteVhd ${path}`, { error })
}
}
)
const base = basename(path)
const child = vhds.find(_ => _ !== undefined && _.header.parentUnicodeName === base)
if (child === undefined) {
await handler.unlink(path)
return 0
}
try {
const childPath = child.path
const mergedDataSize = await mergeVhd(handler, path, handler, childPath)
await handler.rename(path, childPath)
return mergedDataSize
} catch (error) {
handler.unlink(path).catch(warn)
throw error
}
}
async _findPartition(devicePath, partitionId) {
const partitions = await listPartitions(devicePath)
const partition = partitions.find(_ => _.id === partitionId)
if (partition === undefined) {
throw new Error(`partition ${partitionId} not found`)
}
return partition
}
_getLvmLogicalVolumes = Disposable.factory(this._getLvmLogicalVolumes)
_getLvmLogicalVolumes = deduped(this._getLvmLogicalVolumes, (devicePath, pvId, vgName) => [devicePath, pvId, vgName])
_getLvmLogicalVolumes = debounceResourceFactory(this._getLvmLogicalVolumes)
async *_getLvmLogicalVolumes(devicePath, pvId, vgName) {
yield this._getLvmPhysicalVolume(devicePath, pvId && (await this._findPartition(devicePath, pvId)))
await fromCallback(execFile, 'vgchange', ['-ay', vgName])
try {
yield lvs(['lv_name', 'lv_path'], vgName)
} finally {
await fromCallback(execFile, 'vgchange', ['-an', vgName])
}
}
_getLvmPhysicalVolume = Disposable.factory(this._getLvmPhysicalVolume)
_getLvmPhysicalVolume = deduped(this._getLvmPhysicalVolume, (devicePath, partition) => [devicePath, partition?.id])
_getLvmPhysicalVolume = debounceResourceFactory(this._getLvmPhysicalVolume)
async *_getLvmPhysicalVolume(devicePath, partition) {
const args = []
if (partition !== undefined) {
args.push('-o', partition.start * 512, '--sizelimit', partition.size)
}
args.push('--show', '-f', devicePath)
const path = (await fromCallback(execFile, 'losetup', args)).trim()
try {
await fromCallback(execFile, 'pvscan', ['--cache', path])
yield path
} finally {
try {
const vgNames = await pvs('vg_name', path)
await fromCallback(execFile, 'vgchange', ['-an', ...vgNames])
} finally {
await fromCallback(execFile, 'losetup', ['-d', path])
}
}
}
_getPartition = Disposable.factory(this._getPartition)
_getPartition = deduped(this._getPartition, (devicePath, partition) => [devicePath, partition?.id])
_getPartition = debounceResourceFactory(this._getPartition)
async *_getPartition(devicePath, partition) {
const options = ['loop', 'ro']
if (partition !== undefined) {
const { size, start } = partition
options.push(`sizelimit=${size}`)
if (start !== undefined) {
options.push(`offset=${start * 512}`)
}
}
const path = yield getTmpDir()
const mount = options => {
return fromCallback(execFile, 'mount', [
`--options=${options.join(',')}`,
`--source=${devicePath}`,
`--target=${path}`,
])
}
// `norecovery` option is used for ext3/ext4/xfs, if it fails it might be
// another fs, try without
try {
await mount([...options, 'norecovery'])
} catch (error) {
await mount(options)
}
try {
yield path
} finally {
await fromCallback(execFile, 'umount', ['--lazy', path])
}
}
_listLvmLogicalVolumes(devicePath, partition, results = []) {
return Disposable.use(this._getLvmPhysicalVolume(devicePath, partition), async path => {
const lvs = await pvs(['lv_name', 'lv_path', 'lv_size', 'vg_name'], path)
const partitionId = partition !== undefined ? partition.id : ''
lvs.forEach((lv, i) => {
const name = lv.lv_name
if (name !== '') {
results.push({
id: `${partitionId}/${lv.vg_name}/${name}`,
name,
size: lv.lv_size,
})
}
})
return results
})
}
_usePartitionFiles = Disposable.factory(this._usePartitionFiles)
async *_usePartitionFiles(diskId, partitionId, paths) {
const path = yield this.getPartition(diskId, partitionId)
const files = []
await asyncMap(paths, file =>
addDirectory(files, resolveSubpath(path, file), normalize('./' + file).replace(/\/+$/, ''))
)
return files
}
fetchPartitionFiles(diskId, partitionId, paths) {
const { promise, reject, resolve } = pDefer()
Disposable.use(
async function* () {
const files = yield this._usePartitionFiles(diskId, partitionId, paths)
const zip = new ZipFile()
files.forEach(({ realPath, metadataPath }) => zip.addFile(realPath, metadataPath))
zip.end()
const { outputStream } = zip
resolve(outputStream)
await fromEvent(outputStream, 'end')
}.bind(this)
).catch(error => {
warn(error)
reject(error)
})
return promise
}
async deleteDeltaVmBackups(backups) {
const handler = this._handler
let mergedDataSize = 0
await asyncMapSettled(backups, ({ _filename, vhds }) =>
Promise.all([
handler.unlink(_filename),
asyncMap(Object.values(vhds), async _ => {
mergedDataSize += await this._deleteVhd(resolveRelativeFromFile(_filename, _))
}),
])
)
return mergedDataSize
}
async deleteMetadataBackup(backupId) {
const uuidReg = '\\w{8}(-\\w{4}){3}-\\w{12}'
const metadataDirReg = 'xo-(config|pool-metadata)-backups'
const timestampReg = '\\d{8}T\\d{6}Z'
const regexp = new RegExp(`^${metadataDirReg}/${uuidReg}(/${uuidReg})?/${timestampReg}`)
if (!regexp.test(backupId)) {
throw new Error(`The id (${backupId}) not correspond to a metadata folder`)
}
await this._handler.rmtree(backupId)
}
async deleteOldMetadataBackups(dir, retention) {
const handler = this.handler
let list = await handler.list(dir)
list.sort()
list = list.filter(timestamp => /^\d{8}T\d{6}Z$/.test(timestamp)).slice(0, -retention)
await asyncMapSettled(list, timestamp => handler.rmtree(`${dir}/${timestamp}`))
}
async deleteFullVmBackups(backups) {
const handler = this._handler
await asyncMapSettled(backups, ({ _filename, xva }) =>
Promise.all([handler.unlink(_filename), handler.unlink(resolveRelativeFromFile(_filename, xva))])
)
}
async deleteVmBackup(filename) {
const metadata = JSON.parse(String(await this._handler.readFile(filename)))
metadata._filename = filename
if (metadata.mode === 'delta') {
await this.deleteDeltaVmBackups([metadata])
} else if (metadata.mode === 'full') {
await this.deleteFullVmBackups([metadata])
} else {
throw new Error(`no deleter for backup mode ${metadata.mode}`)
}
}
getDisk = Disposable.factory(this.getDisk)
getDisk = deduped(this.getDisk, diskId => [diskId])
getDisk = debounceResourceFactory(this.getDisk)
async *getDisk(diskId) {
const handler = this._handler
const diskPath = handler._getFilePath('/' + diskId)
const mountDir = yield getTmpDir()
await fromCallback(execFile, 'vhdimount', [diskPath, mountDir])
try {
let max = 0
let maxEntry
const entries = await readdir(mountDir)
entries.forEach(entry => {
const matches = RE_VHDI.exec(entry)
if (matches !== null) {
const value = +matches[1]
if (value > max) {
max = value
maxEntry = entry
}
}
})
if (max === 0) {
throw new Error('no disks found')
}
yield `${mountDir}/${maxEntry}`
} finally {
await fromCallback(execFile, 'fusermount', ['-uz', mountDir])
}
}
// partitionId values:
//
// - undefined: raw disk
// - `<partitionId>`: partitioned disk
// - `<pvId>/<vgName>/<lvName>`: LVM on a partitioned disk
// - `/<vgName>/lvName>`: LVM on a raw disk
getPartition = Disposable.factory(this.getPartition)
async *getPartition(diskId, partitionId) {
const devicePath = yield this.getDisk(diskId)
if (partitionId === undefined) {
return yield this._getPartition(devicePath)
}
const isLvmPartition = partitionId.includes('/')
if (isLvmPartition) {
const [pvId, vgName, lvName] = partitionId.split('/')
const lvs = yield this._getLvmLogicalVolumes(devicePath, pvId !== '' ? pvId : undefined, vgName)
return yield this._getPartition(lvs.find(_ => _.lv_name === lvName).lv_path)
}
return yield this._getPartition(devicePath, await this._findPartition(devicePath, partitionId))
}
async listAllVmBackups() {
const handler = this._handler
const backups = { __proto__: null }
await asyncMap(await handler.list(BACKUP_DIR), async vmUuid => {
const vmBackups = await this.listVmBackups(vmUuid)
backups[vmUuid] = vmBackups
})
return backups
}
listPartitionFiles(diskId, partitionId, path) {
return Disposable.use(this.getPartition(diskId, partitionId), async rootPath => {
path = resolveSubpath(rootPath, path)
const entriesMap = {}
await asyncMap(await readdir(path), async name => {
try {
const stats = await stat(`${path}/${name}`)
entriesMap[stats.isDirectory() ? `${name}/` : name] = {}
} catch (error) {
if (error == null || error.code !== 'ENOENT') {
throw error
}
}
})
return entriesMap
})
}
listPartitions(diskId) {
return Disposable.use(this.getDisk(diskId), async devicePath => {
const partitions = await listPartitions(devicePath)
if (partitions.length === 0) {
try {
// handle potential raw LVM physical volume
return await this._listLvmLogicalVolumes(devicePath, undefined, partitions)
} catch (error) {
return []
}
}
const results = []
await asyncMapSettled(partitions, partition =>
partition.type === LVM_PARTITION_TYPE
? this._listLvmLogicalVolumes(devicePath, partition, results)
: results.push(partition)
)
return results
})
}
async listPoolMetadataBackups() {
const handler = this._handler
const safeReaddir = createSafeReaddir(handler, 'listPoolMetadataBackups')
const backupsByPool = {}
await asyncMap(await safeReaddir(DIR_XO_POOL_METADATA_BACKUPS, { prependDir: true }), async scheduleDir =>
asyncMap(await safeReaddir(scheduleDir), async poolId => {
const backups = backupsByPool[poolId] ?? (backupsByPool[poolId] = [])
return asyncMap(await safeReaddir(`${scheduleDir}/${poolId}`, { prependDir: true }), async backupDir => {
try {
backups.push({
id: backupDir,
...JSON.parse(String(await handler.readFile(`${backupDir}/metadata.json`))),
})
} catch (error) {
warn(`listPoolMetadataBackups ${backupDir}`, {
error,
})
}
})
})
)
// delete empty entries and sort backups
Object.keys(backupsByPool).forEach(poolId => {
const backups = backupsByPool[poolId]
if (backups.length === 0) {
delete backupsByPool[poolId]
} else {
backups.sort(compareTimestamp)
}
})
return backupsByPool
}
async listVmBackups(vmUuid, predicate) {
const handler = this._handler
const backups = []
try {
const files = await handler.list(`${BACKUP_DIR}/${vmUuid}`, {
filter: isMetadataFile,
prependDir: true,
})
await asyncMap(files, async file => {
try {
const metadata = await this.readVmBackupMetadata(file)
if (predicate === undefined || predicate(metadata)) {
// inject an id usable by importVmBackupNg()
metadata.id = metadata._filename
backups.push(metadata)
}
} catch (error) {
warn(`listVmBackups ${file}`, { error })
}
})
} catch (error) {
let code
if (error == null || ((code = error.code) !== 'ENOENT' && code !== 'ENOTDIR')) {
throw error
}
}
return backups.sort(compareTimestamp)
}
async listXoMetadataBackups() {
const handler = this._handler
const safeReaddir = createSafeReaddir(handler, 'listXoMetadataBackups')
const backups = []
await asyncMap(await safeReaddir(DIR_XO_CONFIG_BACKUPS, { prependDir: true }), async scheduleDir =>
asyncMap(await safeReaddir(scheduleDir, { prependDir: true }), async backupDir => {
try {
backups.push({
id: backupDir,
...JSON.parse(String(await handler.readFile(`${backupDir}/metadata.json`))),
})
} catch (error) {
warn(`listXoMetadataBackups ${backupDir}`, { error })
}
})
)
return backups.sort(compareTimestamp)
}
async outputStream(path, input, { checksum = true, validator = noop } = {}) {
await this._handler.outputStream(path, input, {
checksum,
dirMode: this._dirMode,
async validator() {
await input.task
return validator.apply(this, arguments)
},
})
}
async readDeltaVmBackup(metadata) {
const handler = this._handler
const { vbds, vdis, vhds, vifs, vm } = metadata
const dir = dirname(metadata._filename)
const streams = {}
await asyncMapSettled(Object.keys(vdis), async id => {
streams[`${id}.vhd`] = await createSyntheticStream(handler, join(dir, vhds[id]))
})
return {
streams,
vbds,
vdis,
version: '1.0.0',
vifs,
vm,
}
}
readFullVmBackup(metadata) {
return this._handler.createReadStream(resolve('/', dirname(metadata._filename), metadata.xva))
}
async readVmBackupMetadata(path) {
return Object.defineProperty(JSON.parse(await this._handler.readFile(path)), '_filename', { value: path })
}
}
Object.assign(RemoteAdapter.prototype, {
cleanVm(vmDir, { lock = true } = {}) {
if (lock) {
return Disposable.use(this._handler.lock(vmDir), () => cleanVm.apply(this, arguments))
} else {
return cleanVm.apply(this, arguments)
}
},
isValidXva,
})
exports.RemoteAdapter = RemoteAdapter

View File

@@ -0,0 +1,24 @@
const { DIR_XO_POOL_METADATA_BACKUPS } = require('./RemoteAdapter.js')
const { PATH_DB_DUMP } = require('./_PoolMetadataBackup.js')
exports.RestoreMetadataBackup = class RestoreMetadataBackup {
constructor({ backupId, handler, xapi }) {
this._backupId = backupId
this._handler = handler
this._xapi = xapi
}
async run() {
const backupId = this._backupId
const handler = this._handler
const xapi = this._xapi
if (backupId.split('/')[0] === DIR_XO_POOL_METADATA_BACKUPS) {
return xapi.putResource(await handler.createReadStream(`${backupId}/data`), PATH_DB_DUMP, {
task: xapi.task_create('Import pool metadata'),
})
} else {
return String(await handler.readFile(`${backupId}/data.json`))
}
}
}

View File

@@ -0,0 +1,151 @@
const CancelToken = require('promise-toolbox/CancelToken.js')
const Zone = require('node-zone')
const logAfterEnd = () => {
throw new Error('task has already ended')
}
const noop = Function.prototype
// 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,
message: error.message,
name: error.name,
stack: error.stack,
}
: error
const $$task = Symbol('@xen-orchestra/backups/Task')
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(),
})
}
}
exports.Task = Task
for (const method of ['info', 'warning']) {
Task[method] = (...args) => Zone.current.data[$$task]?.[method](...args)
}

View File

@@ -0,0 +1,75 @@
const { asyncMap } = require('@xen-orchestra/async-map')
const { DIR_XO_POOL_METADATA_BACKUPS } = require('./RemoteAdapter.js')
const { forkStreamUnpipe } = require('./_forkStreamUnpipe.js')
const { formatFilenameDate } = require('./_filenameDate.js')
const { Task } = require('./Task.js')
const PATH_DB_DUMP = '/pool/xmldbdump'
exports.PATH_DB_DUMP = PATH_DB_DUMP
exports.PoolMetadataBackup = class PoolMetadataBackup {
constructor({ config, job, pool, remoteAdapters, schedule, settings }) {
this._config = config
this._job = job
this._pool = pool
this._remoteAdapters = remoteAdapters
this._schedule = schedule
this._settings = settings
}
_exportPoolMetadata() {
const xapi = this._pool.$xapi
return xapi.getResource(PATH_DB_DUMP, {
task: xapi.task_create('Export pool metadata'),
})
}
async run() {
const timestamp = Date.now()
const { _job: job, _schedule: schedule, _pool: pool } = this
const poolDir = `${DIR_XO_POOL_METADATA_BACKUPS}/${schedule.id}/${pool.$id}`
const dir = `${poolDir}/${formatFilenameDate(timestamp)}`
const stream = await this._exportPoolMetadata()
const fileName = `${dir}/data`
const metadata = JSON.stringify(
{
jobId: job.id,
jobName: job.name,
pool,
poolMaster: pool.$master,
scheduleId: schedule.id,
scheduleName: schedule.name,
timestamp,
},
null,
2
)
const metaDataFileName = `${dir}/metadata.json`
await asyncMap(
Object.entries(this._remoteAdapters),
([remoteId, adapter]) =>
Task.run(
{
name: `Starting metadata backup for the pool (${pool.$id}) for the remote (${remoteId}). (${job.id})`,
data: {
id: remoteId,
type: 'remote',
},
},
async () => {
// forkStreamUnpipe should be used in a sync way, do not wait for a promise before using it
await adapter.outputStream(fileName, forkStreamUnpipe(stream), { checksum: false })
await adapter.handler.outputFile(metaDataFileName, metadata, {
dirMode: this._config.dirMode,
})
await adapter.deleteOldMetadataBackups(poolDir, this._settings.retentionPoolMetadata)
}
).catch(() => {}) // errors are handled by logs
)
}
}

View File

@@ -0,0 +1,382 @@
const assert = require('assert')
const findLast = require('lodash/findLast.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const keyBy = require('lodash/keyBy.js')
const mapValues = require('lodash/mapValues.js')
const { asyncMap, asyncMapSettled } = require('@xen-orchestra/async-map')
const { createLogger } = require('@xen-orchestra/log')
const { defer } = require('golike-defer')
const { formatDateTime } = require('@xen-orchestra/xapi')
const { DeltaBackupWriter } = require('./writers/DeltaBackupWriter.js')
const { DeltaReplicationWriter } = require('./writers/DeltaReplicationWriter.js')
const { exportDeltaVm } = require('./_deltaVm.js')
const { forkStreamUnpipe } = require('./_forkStreamUnpipe.js')
const { FullBackupWriter } = require('./writers/FullBackupWriter.js')
const { FullReplicationWriter } = require('./writers/FullReplicationWriter.js')
const { getOldEntries } = require('./_getOldEntries.js')
const { Task } = require('./Task.js')
const { watchStreamSize } = require('./_watchStreamSize.js')
const { debug, warn } = createLogger('xo:backups:VmBackup')
const asyncEach = async (iterable, fn, thisArg = iterable) => {
for (const item of iterable) {
await fn.call(thisArg, item)
}
}
const forkDeltaExport = deltaExport =>
Object.create(deltaExport, {
streams: {
value: mapValues(deltaExport.streams, forkStreamUnpipe),
},
})
exports.VmBackup = class VmBackup {
constructor({ config, getSnapshotNameLabel, job, remoteAdapters, remotes, schedule, settings, srs, vm }) {
this.config = config
this.job = job
this.remoteAdapters = remoteAdapters
this.remotes = remotes
this.scheduleId = schedule.id
this.timestamp = undefined
// VM currently backed up
this.vm = vm
const { tags } = this.vm
// VM (snapshot) that is really exported
this.exportedVm = undefined
this._fullVdisRequired = undefined
this._getSnapshotNameLabel = getSnapshotNameLabel
this._isDelta = job.mode === 'delta'
this._jobId = job.id
this._jobSnapshots = undefined
this._xapi = vm.$xapi
// Base VM for the export
this._baseVm = undefined
// Settings for this specific run (job, schedule, VM)
if (tags.includes('xo-memory-backup')) {
settings.checkpointSnapshot = true
}
if (tags.includes('xo-offline-backup')) {
settings.offlineSnapshot = true
}
this._settings = settings
// Create writers
{
const writers = new Set()
this._writers = writers
const [BackupWriter, ReplicationWriter] = this._isDelta
? [DeltaBackupWriter, DeltaReplicationWriter]
: [FullBackupWriter, FullReplicationWriter]
const allSettings = job.settings
Object.keys(remoteAdapters).forEach(remoteId => {
const targetSettings = {
...settings,
...allSettings[remoteId],
}
if (targetSettings.exportRetention !== 0) {
writers.add(new BackupWriter({ backup: this, remoteId, settings: targetSettings }))
}
})
srs.forEach(sr => {
const targetSettings = {
...settings,
...allSettings[sr.uuid],
}
if (targetSettings.copyRetention !== 0) {
writers.add(new ReplicationWriter({ backup: this, sr, settings: targetSettings }))
}
})
}
}
// calls fn for each function, warns of any errors, and throws only if there are no writers left
async _callWriters(fn, warnMessage, parallel = true) {
const writers = this._writers
if (writers.size === 0) {
return
}
await (parallel ? asyncMap : asyncEach)(writers, async function (writer) {
try {
await fn(writer)
} catch (error) {
this.delete(writer)
warn(warnMessage, { error, writer: writer.constructor.name })
}
})
if (writers.size === 0) {
throw new Error('all targets have failed, step: ' + warnMessage)
}
}
// ensure the VM itself does not have any backup metadata which would be
// copied on manual snapshots and interfere with the backup jobs
async _cleanMetadata() {
const { vm } = this
if ('xo:backup:job' in vm.other_config) {
await vm.update_other_config({
'xo:backup:datetime': null,
'xo:backup:deltaChainLength': null,
'xo:backup:exported': null,
'xo:backup:job': null,
'xo:backup:schedule': null,
'xo:backup:vm': null,
})
}
}
async _snapshot() {
const { vm } = this
const xapi = this._xapi
const settings = this._settings
const doSnapshot =
this._isDelta || (!settings.offlineBackup && vm.power_state === 'Running') || settings.snapshotRetention !== 0
if (doSnapshot) {
await Task.run({ name: 'snapshot' }, async () => {
if (!settings.bypassVdiChainsCheck) {
await vm.$assertHealthyVdiChains()
}
const snapshotRef = await vm[settings.checkpointSnapshot ? '$checkpoint' : '$snapshot']({
name_label: this._getSnapshotNameLabel(vm),
})
this.timestamp = Date.now()
await xapi.setFieldEntries('VM', snapshotRef, 'other_config', {
'xo:backup:datetime': formatDateTime(this.timestamp),
'xo:backup:job': this._jobId,
'xo:backup:schedule': this.scheduleId,
'xo:backup:vm': vm.uuid,
})
this.exportedVm = await xapi.getRecord('VM', snapshotRef)
return this.exportedVm.uuid
})
} else {
this.exportedVm = vm
this.timestamp = Date.now()
}
}
async _copyDelta() {
const { exportedVm } = this
const baseVm = this._baseVm
const fullVdisRequired = this._fullVdisRequired
const isFull = fullVdisRequired === undefined || fullVdisRequired.size !== 0
await this._callWriters(writer => writer.prepare({ isFull }), 'writer.prepare()')
const deltaExport = await exportDeltaVm(exportedVm, baseVm, {
fullVdisRequired,
})
const sizeContainers = mapValues(deltaExport.streams, stream => watchStreamSize(stream))
const timestamp = Date.now()
await this._callWriters(
writer =>
writer.transfer({
deltaExport: forkDeltaExport(deltaExport),
sizeContainers,
timestamp,
}),
'writer.transfer()'
)
this._baseVm = exportedVm
if (baseVm !== undefined) {
await exportedVm.update_other_config(
'xo:backup:deltaChainLength',
String(+(baseVm.other_config['xo:backup:deltaChainLength'] ?? 0) + 1)
)
}
// not the case if offlineBackup
if (exportedVm.is_a_snapshot) {
await exportedVm.update_other_config('xo:backup:exported', 'true')
}
const size = Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0)
const end = Date.now()
const duration = end - timestamp
debug('transfer complete', {
duration,
speed: duration !== 0 ? (size * 1e3) / 1024 / 1024 / duration : 0,
size,
})
await this._callWriters(writer => writer.cleanup(), 'writer.cleanup()')
}
async _copyFull() {
const { compression } = this.job
const stream = await this._xapi.VM_export(this.exportedVm.$ref, {
compress: Boolean(compression) && (compression === 'native' ? 'gzip' : 'zstd'),
useSnapshot: false,
})
const sizeContainer = watchStreamSize(stream)
const timestamp = Date.now()
await this._callWriters(
writer =>
writer.run({
sizeContainer,
stream: forkStreamUnpipe(stream),
timestamp,
}),
'writer.run()'
)
const { size } = sizeContainer
const end = Date.now()
const duration = end - timestamp
debug('transfer complete', {
duration,
speed: duration !== 0 ? (size * 1e3) / 1024 / 1024 / duration : 0,
size,
})
}
async _fetchJobSnapshots() {
const jobId = this._jobId
const vmRef = this.vm.$ref
const xapi = this._xapi
const snapshotsRef = await xapi.getField('VM', vmRef, 'snapshots')
const snapshotsOtherConfig = await asyncMap(snapshotsRef, ref => xapi.getField('VM', ref, 'other_config'))
const snapshots = []
snapshotsOtherConfig.forEach((other_config, i) => {
if (other_config['xo:backup:job'] === jobId) {
snapshots.push({ other_config, $ref: snapshotsRef[i] })
}
})
snapshots.sort((a, b) => (a.other_config['xo:backup:datetime'] < b.other_config['xo:backup:datetime'] ? -1 : 1))
this._jobSnapshots = snapshots
}
async _removeUnusedSnapshots() {
// TODO: handle all schedules (no longer existing schedules default to 0 retention)
const { scheduleId } = this
const scheduleSnapshots = this._jobSnapshots.filter(_ => _.other_config['xo:backup:schedule'] === scheduleId)
const baseVmRef = this._baseVm?.$ref
const xapi = this._xapi
await asyncMap(getOldEntries(this._settings.snapshotRetention, scheduleSnapshots), ({ $ref }) => {
if ($ref !== baseVmRef) {
return xapi.VM_destroy($ref)
}
})
}
async _selectBaseVm() {
const xapi = this._xapi
let baseVm = findLast(this._jobSnapshots, _ => 'xo:backup:exported' in _.other_config)
if (baseVm === undefined) {
return
}
const fullInterval = this._settings.fullInterval
const deltaChainLength = +(baseVm.other_config['xo:backup:deltaChainLength'] ?? 0) + 1
if (!(fullInterval === 0 || fullInterval > deltaChainLength)) {
return
}
const srcVdis = keyBy(await xapi.getRecords('VDI', await this.vm.$getDisks()), '$ref')
// resolve full record
baseVm = await xapi.getRecord('VM', baseVm.$ref)
const baseUuidToSrcVdi = new Map()
await asyncMap(await baseVm.$getDisks(), async baseRef => {
const snapshotOf = await xapi.getField('VDI', baseRef, 'snapshot_of')
const srcVdi = srcVdis[snapshotOf]
if (srcVdi !== undefined) {
baseUuidToSrcVdi.set(await xapi.getField('VDI', baseRef, 'uuid'), srcVdi)
}
})
const presentBaseVdis = new Map(baseUuidToSrcVdi)
await this._callWriters(
writer => presentBaseVdis.size !== 0 && writer.checkBaseVdis(presentBaseVdis, baseVm),
'writer.checkBaseVdis()',
false
)
const fullVdisRequired = new Set()
baseUuidToSrcVdi.forEach((srcVdi, baseUuid) => {
if (!presentBaseVdis.has(baseUuid)) {
fullVdisRequired.add(srcVdi.uuid)
}
})
this._baseVm = baseVm
this._fullVdisRequired = fullVdisRequired
}
run = defer(this.run)
async run($defer) {
const settings = this._settings
assert(
!settings.offlineBackup || settings.snapshotRetention === 0,
'offlineBackup is not compatible with snapshotRetention'
)
await this._callWriters(async writer => {
await writer.beforeBackup()
$defer(() => writer.afterBackup())
}, 'writer.beforeBackup()')
await this._fetchJobSnapshots()
if (this._isDelta) {
await this._selectBaseVm()
}
await this._cleanMetadata()
await this._removeUnusedSnapshots()
const { vm } = this
const isRunning = vm.power_state === 'Running'
const startAfter = isRunning && (settings.offlineBackup ? 'backup' : settings.offlineSnapshot && 'snapshot')
if (startAfter) {
await vm.$callAsync('clean_shutdown')
}
try {
await this._snapshot()
if (startAfter === 'snapshot') {
ignoreErrors.call(vm.$callAsync('start', false, false))
}
if (this._writers.size !== 0) {
await (this._isDelta ? this._copyDelta() : this._copyFull())
}
} finally {
if (startAfter) {
ignoreErrors.call(vm.$callAsync('start', false, false))
}
await this._fetchJobSnapshots()
await this._removeUnusedSnapshots()
}
}
}

View File

@@ -0,0 +1,62 @@
const { asyncMap } = require('@xen-orchestra/async-map')
const { DIR_XO_CONFIG_BACKUPS } = require('./RemoteAdapter.js')
const { formatFilenameDate } = require('./_filenameDate.js')
const { Task } = require('./Task.js')
exports.XoMetadataBackup = class XoMetadataBackup {
constructor({ config, job, remoteAdapters, schedule, settings }) {
this._config = config
this._job = job
this._remoteAdapters = remoteAdapters
this._schedule = schedule
this._settings = settings
}
async run() {
const timestamp = Date.now()
const { _job: job, _schedule: schedule } = this
const scheduleDir = `${DIR_XO_CONFIG_BACKUPS}/${schedule.id}`
const dir = `${scheduleDir}/${formatFilenameDate(timestamp)}`
const data = job.xoMetadata
const fileName = `${dir}/data.json`
const metadata = JSON.stringify(
{
jobId: job.id,
jobName: job.name,
scheduleId: schedule.id,
scheduleName: schedule.name,
timestamp,
},
null,
2
)
const metaDataFileName = `${dir}/metadata.json`
await asyncMap(
Object.entries(this._remoteAdapters),
([remoteId, adapter]) =>
Task.run(
{
name: `Starting XO metadata backup for the remote (${remoteId}). (${job.id})`,
data: {
id: remoteId,
type: 'remote',
},
},
async () => {
const handler = adapter.handler
const dirMode = this._config.dirMode
await handler.outputFile(fileName, data, { dirMode })
await handler.outputFile(metaDataFileName, metadata, {
dirMode,
})
await adapter.deleteOldMetadataBackups(scheduleDir, this._settings.retentionXoMetadata)
}
).catch(() => {}) // errors are handled by logs
)
}
}

View File

@@ -0,0 +1,4 @@
exports.isMetadataFile = filename => filename.endsWith('.json')
exports.isVhdFile = filename => filename.endsWith('.vhd')
exports.isXvaFile = filename => filename.endsWith('.xva')
exports.isXvaSumFile = filename => filename.endsWith('.xva.cheksum')

View File

@@ -0,0 +1,155 @@
require('@xen-orchestra/log/configure.js').catchGlobalErrors(
require('@xen-orchestra/log').createLogger('xo:backups:worker')
)
const Disposable = require('promise-toolbox/Disposable.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const { compose } = require('@vates/compose')
const { createDebounceResource } = require('@vates/disposable/debounceResource.js')
const { deduped } = require('@vates/disposable/deduped.js')
const { getHandler } = require('@xen-orchestra/fs')
const { parseDuration } = require('@vates/parse-duration')
const { Xapi } = require('@xen-orchestra/xapi')
const { Backup } = require('./Backup.js')
const { RemoteAdapter } = require('./RemoteAdapter.js')
const { Task } = require('./Task.js')
class BackupWorker {
#config
#job
#recordToXapi
#remoteOptions
#remotes
#schedule
#xapiOptions
#xapis
constructor({ config, job, recordToXapi, remoteOptions, remotes, resourceCacheDelay, schedule, xapiOptions, xapis }) {
this.#config = config
this.#job = job
this.#recordToXapi = recordToXapi
this.#remoteOptions = remoteOptions
this.#remotes = remotes
this.#schedule = schedule
this.#xapiOptions = xapiOptions
this.#xapis = xapis
const debounceResource = createDebounceResource()
debounceResource.defaultDelay = parseDuration(resourceCacheDelay)
this.debounceResource = debounceResource
}
run() {
return new Backup({
config: this.#config,
getAdapter: remoteId => this.getAdapter(this.#remotes[remoteId]),
getConnectedRecord: Disposable.factory(async function* getConnectedRecord(type, uuid) {
const xapiId = this.#recordToXapi[uuid]
if (xapiId === undefined) {
throw new Error('no XAPI associated to ' + uuid)
}
const xapi = yield this.getXapi(this.#xapis[xapiId])
return xapi.getRecordByUuid(type, uuid)
}).bind(this),
job: this.#job,
schedule: this.#schedule,
}).run()
}
getAdapter = Disposable.factory(this.getAdapter)
getAdapter = deduped(this.getAdapter, remote => [remote.url])
getAdapter = compose(this.getAdapter, function (resource) {
return this.debounceResource(resource)
})
async *getAdapter(remote) {
const handler = getHandler(remote, this.#remoteOptions)
await handler.sync()
try {
yield new RemoteAdapter(handler, {
debounceResource: this.debounceResource,
dirMode: this.#config.dirMode,
})
} finally {
await handler.forget()
}
}
getXapi = Disposable.factory(this.getXapi)
getXapi = deduped(this.getXapi, ({ url }) => [url])
getXapi = compose(this.getXapi, function (resource) {
return this.debounceResource(resource)
})
async *getXapi({ credentials: { username: user, password }, ...opts }) {
const xapi = new Xapi({
...this.#xapiOptions,
...opts,
auth: {
user,
password,
},
})
await xapi.connect()
try {
await xapi.objectsFetched
yield xapi
} finally {
await xapi.disconnect()
}
}
}
// Received message:
//
// Message {
// action: 'run'
// data: object
// runWithLogs: boolean
// }
//
// Sent message:
//
// Message {
// type: 'log' | 'result'
// data?: object
// status?: 'success' | 'failure'
// result?: any
// }
process.on('message', async message => {
if (message.action === 'run') {
const backupWorker = new BackupWorker(message.data)
try {
const result = message.runWithLogs
? await Task.run(
{
name: 'backup run',
onLog: data =>
process.send({
data,
type: 'log',
}),
},
() => backupWorker.run()
)
: await backupWorker.run()
process.send({
type: 'result',
result,
status: 'success',
})
} catch (error) {
process.send({
type: 'result',
result: error,
status: 'failure',
})
} finally {
await ignoreErrors.call(backupWorker.debounceResource.flushAll())
process.disconnect()
}
}
})

View File

@@ -0,0 +1,20 @@
const cancelable = require('promise-toolbox/cancelable.js')
const CancelToken = require('promise-toolbox/CancelToken.js')
// Similar to `Promise.all` + `map` but pass a cancel token to the callback
//
// If any of the executions fails, the cancel token will be triggered and the
// first reason will be rejected.
exports.cancelableMap = cancelable(async function cancelableMap($cancelToken, iterable, callback) {
const { cancel, token } = CancelToken.source([$cancelToken])
try {
return await Promise.all(
Array.from(iterable, function (item) {
return callback.call(this, token, item)
})
)
} catch (error) {
await cancel()
throw error
}
})

View File

@@ -0,0 +1,332 @@
const assert = require('assert')
const { asyncMap } = require('@xen-orchestra/async-map')
const { default: Vhd, mergeVhd } = require('vhd-lib')
const { dirname, resolve } = require('path')
const { DISK_TYPE_DIFFERENCING } = require('vhd-lib/dist/_constants.js')
const { isMetadataFile, isVhdFile, isXvaFile, isXvaSumFile } = require('./_backupType.js')
const { limitConcurrency } = require('limit-concurrency-decorator')
// chain is an array of VHDs from child to parent
//
// the whole chain will be merged into parent, parent will be renamed to child
// and all the others will deleted
const mergeVhdChain = limitConcurrency(1)(async function mergeVhdChain(chain, { handler, onLog, remove, merge }) {
assert(chain.length >= 2)
let child = chain[0]
const parent = chain[chain.length - 1]
const children = chain.slice(0, -1).reverse()
chain
.slice(1)
.reverse()
.forEach(parent => {
onLog(`the parent ${parent} of the child ${child} is unused`)
})
if (merge) {
// `mergeVhd` does not work with a stream, either
// - make it accept a stream
// - or create synthetic VHD which is not a stream
if (children.length !== 1) {
// TODO: implement merging multiple children
children.length = 1
child = children[0]
}
onLog(`merging ${child} into ${parent}`)
let done, total
const handle = setInterval(() => {
if (done !== undefined) {
onLog(`merging ${child}: ${done}/${total}`)
}
}, 10e3)
await mergeVhd(
handler,
parent,
handler,
child,
// children.length === 1
// ? child
// : await createSyntheticStream(handler, children),
{
onProgress({ done: d, total: t }) {
done = d
total = t
},
}
)
clearInterval(handle)
await Promise.all([
handler.rename(parent, child),
asyncMap(children.slice(0, -1), child => {
onLog(`the VHD ${child} is unused`)
if (remove) {
onLog(`deleting unused VHD ${child}`)
return handler.unlink(child)
}
}),
])
}
})
const noop = Function.prototype
const INTERRUPTED_VHDS_REG = /^(?:(.+)\/)?\.(.+)\.merge.json$/
const listVhds = async (handler, vmDir) => {
const vhds = []
const interruptedVhds = new Set()
await asyncMap(
await handler.list(`${vmDir}/vdis`, {
ignoreMissing: true,
prependDir: true,
}),
async jobDir =>
asyncMap(
await handler.list(jobDir, {
prependDir: true,
}),
async vdiDir => {
const list = await handler.list(vdiDir, {
filter: file => isVhdFile(file) || INTERRUPTED_VHDS_REG.test(file),
prependDir: true,
})
list.forEach(file => {
const res = INTERRUPTED_VHDS_REG.exec(file)
if (res === null) {
vhds.push(file)
} else {
const [, dir, file] = res
interruptedVhds.add(`${dir}/${file}`)
}
})
}
)
)
return { vhds, interruptedVhds }
}
exports.cleanVm = async function cleanVm(vmDir, { remove, merge, onLog = noop }) {
const handler = this._handler
const vhds = new Set()
const vhdParents = { __proto__: null }
const vhdChildren = { __proto__: null }
const vhdsList = await listVhds(handler, vmDir)
// remove broken VHDs
await asyncMap(vhdsList.vhds, async path => {
try {
const vhd = new Vhd(handler, path)
await vhd.readHeaderAndFooter(!vhdsList.interruptedVhds.has(path))
vhds.add(path)
if (vhd.footer.diskType === DISK_TYPE_DIFFERENCING) {
const parent = resolve('/', dirname(path), vhd.header.parentUnicodeName)
vhdParents[path] = parent
if (parent in vhdChildren) {
const error = new Error('this script does not support multiple VHD children')
error.parent = parent
error.child1 = vhdChildren[parent]
error.child2 = path
throw error // should we throw?
}
vhdChildren[parent] = path
}
} catch (error) {
onLog(`error while checking the VHD with path ${path}`, { error })
if (error?.code === 'ERR_ASSERTION' && remove) {
onLog(`deleting broken ${path}`)
await handler.unlink(path)
}
}
})
// remove VHDs with missing ancestors
{
const deletions = []
// return true if the VHD has been deleted or is missing
const deleteIfOrphan = vhd => {
const parent = vhdParents[vhd]
if (parent === undefined) {
return
}
// no longer needs to be checked
delete vhdParents[vhd]
deleteIfOrphan(parent)
if (!vhds.has(parent)) {
vhds.delete(vhd)
onLog(`the parent ${parent} of the VHD ${vhd} is missing`)
if (remove) {
onLog(`deleting orphan VHD ${vhd}`)
deletions.push(handler.unlink(vhd))
}
}
}
// > A property that is deleted before it has been visited will not be
// > visited later.
// >
// > -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Deleted_added_or_modified_properties
for (const child in vhdParents) {
deleteIfOrphan(child)
}
await Promise.all(deletions)
}
const jsons = []
const xvas = new Set()
const xvaSums = []
const entries = await handler.list(vmDir, {
prependDir: true,
})
entries.forEach(path => {
if (isMetadataFile(path)) {
jsons.push(path)
} else if (isXvaFile(path)) {
xvas.add(path)
} else if (isXvaSumFile(path)) {
xvaSums.push(path)
}
})
await asyncMap(xvas, async path => {
// check is not good enough to delete the file, the best we can do is report
// it
if (!(await this.isValidXva(path))) {
onLog(`the XVA with path ${path} is potentially broken`)
}
})
const unusedVhds = new Set(vhds)
const unusedXvas = new Set(xvas)
// compile the list of unused XVAs and VHDs, and remove backup metadata which
// reference a missing XVA/VHD
await asyncMap(jsons, async json => {
const metadata = JSON.parse(await handler.readFile(json))
const { mode } = metadata
if (mode === 'full') {
const linkedXva = resolve('/', vmDir, metadata.xva)
if (xvas.has(linkedXva)) {
unusedXvas.delete(linkedXva)
} else {
onLog(`the XVA linked to the metadata ${json} is missing`)
if (remove) {
onLog(`deleting incomplete backup ${json}`)
await handler.unlink(json)
}
}
} else if (mode === 'delta') {
const linkedVhds = (() => {
const { vhds } = metadata
return Object.keys(vhds).map(key => resolve('/', vmDir, vhds[key]))
})()
// FIXME: find better approach by keeping as much of the backup as
// possible (existing disks) even if one disk is missing
if (linkedVhds.every(_ => vhds.has(_))) {
linkedVhds.forEach(_ => unusedVhds.delete(_))
} else {
onLog(`Some VHDs linked to the metadata ${json} are missing`)
if (remove) {
onLog(`deleting incomplete backup ${json}`)
await handler.unlink(json)
}
}
}
})
// TODO: parallelize by vm/job/vdi
const unusedVhdsDeletion = []
{
// VHD chains (as list from child to ancestor) to merge indexed by last
// ancestor
const vhdChainsToMerge = { __proto__: null }
const toCheck = new Set(unusedVhds)
const getUsedChildChainOrDelete = vhd => {
if (vhd in vhdChainsToMerge) {
const chain = vhdChainsToMerge[vhd]
delete vhdChainsToMerge[vhd]
return chain
}
if (!unusedVhds.has(vhd)) {
return [vhd]
}
// no longer needs to be checked
toCheck.delete(vhd)
const child = vhdChildren[vhd]
if (child !== undefined) {
const chain = getUsedChildChainOrDelete(child)
if (chain !== undefined) {
chain.push(vhd)
return chain
}
}
onLog(`the VHD ${vhd} is unused`)
if (remove) {
onLog(`deleting unused VHD ${vhd}`)
unusedVhdsDeletion.push(handler.unlink(vhd))
}
}
toCheck.forEach(vhd => {
vhdChainsToMerge[vhd] = getUsedChildChainOrDelete(vhd)
})
// merge interrupted VHDs
if (merge) {
vhdsList.interruptedVhds.forEach(parent => {
vhdChainsToMerge[parent] = [vhdChildren[parent], parent]
})
}
Object.keys(vhdChainsToMerge).forEach(key => {
const chain = vhdChainsToMerge[key]
if (chain !== undefined) {
unusedVhdsDeletion.push(mergeVhdChain(chain, { handler, onLog, remove, merge }))
}
})
}
await Promise.all([
...unusedVhdsDeletion,
asyncMap(unusedXvas, path => {
onLog(`the XVA ${path} is unused`)
if (remove) {
onLog(`deleting unused XVA ${path}`)
return handler.unlink(path)
}
}),
asyncMap(xvaSums, path => {
// no need to handle checksums for XVAs deleted by the script, they will be handled by `unlink()`
if (!xvas.has(path.slice(0, -'.checksum'.length))) {
onLog(`the XVA checksum ${path} is unused`)
if (remove) {
onLog(`deleting unused XVA checksum ${path}`)
return handler.unlink(path)
}
}
}),
])
}

View File

@@ -0,0 +1,349 @@
const compareVersions = require('compare-versions')
const find = require('lodash/find.js')
const groupBy = require('lodash/groupBy.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const omit = require('lodash/omit.js')
const { asyncMap } = require('@xen-orchestra/async-map')
const { CancelToken } = require('promise-toolbox')
const { createVhdStreamWithLength } = require('vhd-lib')
const { defer } = require('golike-defer')
const { cancelableMap } = require('./_cancelableMap.js')
const TAG_BASE_DELTA = 'xo:base_delta'
exports.TAG_BASE_DELTA = TAG_BASE_DELTA
const TAG_COPY_SRC = 'xo:copy_of'
exports.TAG_COPY_SRC = TAG_COPY_SRC
const ensureArray = value => (value === undefined ? [] : Array.isArray(value) ? value : [value])
exports.exportDeltaVm = async function exportDeltaVm(
vm,
baseVm,
{
cancelToken = CancelToken.none,
// Sets of UUIDs of VDIs that must be exported as full.
fullVdisRequired = new Set(),
disableBaseTags = false,
} = {}
) {
// refs of VM's VDIs → base's VDIs.
const baseVdis = {}
baseVm &&
baseVm.$VBDs.forEach(vbd => {
let vdi, snapshotOf
if ((vdi = vbd.$VDI) && (snapshotOf = vdi.$snapshot_of) && !fullVdisRequired.has(snapshotOf.uuid)) {
baseVdis[vdi.snapshot_of] = vdi
}
})
const streams = {}
const vdis = {}
const vbds = {}
await cancelableMap(cancelToken, vm.$VBDs, async (cancelToken, vbd) => {
let vdi
if (vbd.type !== 'Disk' || !(vdi = vbd.$VDI)) {
// Ignore this VBD.
return
}
// If the VDI name start with `[NOBAK]`, do not export it.
if (vdi.name_label.startsWith('[NOBAK]')) {
// FIXME: find a way to not create the VDI snapshot in the
// first time.
//
// The snapshot must not exist otherwise it could break the
// next export.
ignoreErrors.call(vdi.$destroy())
return
}
vbds[vbd.$ref] = vbd
const vdiRef = vdi.$ref
if (vdiRef in vdis) {
// This VDI has already been managed.
return
}
// Look for a snapshot of this vdi in the base VM.
const baseVdi = baseVdis[vdi.snapshot_of]
vdis[vdiRef] = {
...vdi,
other_config: {
...vdi.other_config,
[TAG_BASE_DELTA]: baseVdi && !disableBaseTags ? baseVdi.uuid : undefined,
},
$snapshot_of$uuid: vdi.$snapshot_of?.uuid,
$SR$uuid: vdi.$SR.uuid,
}
streams[`${vdiRef}.vhd`] = await vdi.$exportContent({
baseRef: baseVdi?.$ref,
cancelToken,
format: 'vhd',
})
})
const suspendVdi = vm.$suspend_VDI
if (suspendVdi !== undefined) {
const vdiRef = suspendVdi.$ref
vdis[vdiRef] = {
...suspendVdi,
$SR$uuid: suspendVdi.$SR.uuid,
}
streams[`${vdiRef}.vhd`] = await suspendVdi.$exportContent({
cancelToken,
format: 'vhd',
})
}
const vifs = {}
vm.$VIFs.forEach(vif => {
const network = vif.$network
vifs[vif.$ref] = {
...vif,
$network$uuid: network.uuid,
$network$name_label: network.name_label,
$network$VLAN: network.$PIFs[0]?.VLAN,
}
})
return Object.defineProperty(
{
version: '1.1.0',
vbds,
vdis,
vifs,
vm: {
...vm,
other_config:
baseVm && !disableBaseTags
? {
...vm.other_config,
[TAG_BASE_DELTA]: baseVm.uuid,
}
: omit(vm.other_config, TAG_BASE_DELTA),
},
},
'streams',
{
configurable: true,
value: streams,
writable: true,
}
)
}
exports.importDeltaVm = defer(async function importDeltaVm(
$defer,
deltaVm,
sr,
{ cancelToken = CancelToken.none, detectBase = true, mapVdisSrs = {}, newMacAddresses = false } = {}
) {
const { version } = deltaVm
if (compareVersions(version, '1.0.0') < 0) {
throw new Error(`Unsupported delta backup version: ${version}`)
}
const vmRecord = deltaVm.vm
const xapi = sr.$xapi
let baseVm
if (detectBase) {
const remoteBaseVmUuid = vmRecord.other_config[TAG_BASE_DELTA]
if (remoteBaseVmUuid) {
baseVm = find(xapi.objects.all, obj => (obj = obj.other_config) && obj[TAG_COPY_SRC] === remoteBaseVmUuid)
if (!baseVm) {
throw new Error(`could not find the base VM (copy of ${remoteBaseVmUuid})`)
}
}
}
const baseVdis = {}
baseVm &&
baseVm.$VBDs.forEach(vbd => {
const vdi = vbd.$VDI
if (vdi !== undefined) {
baseVdis[vbd.VDI] = vbd.$VDI
}
})
const vdiRecords = deltaVm.vdis
// 0. Create suspend_VDI
let suspendVdi
if (vmRecord.power_state === 'Suspended') {
const vdi = vdiRecords[vmRecord.suspend_VDI]
suspendVdi = await xapi.getRecord(
'VDI',
await xapi.VDI_create({
...vdi,
other_config: {
...vdi.other_config,
[TAG_BASE_DELTA]: undefined,
[TAG_COPY_SRC]: vdi.uuid,
},
sr: mapVdisSrs[vdi.uuid] ?? sr.$ref,
})
)
$defer.onFailure(() => suspendVdi.$destroy())
}
// 1. Create the VM.
const vmRef = await xapi.VM_create(
{
...vmRecord,
affinity: undefined,
blocked_operations: {
...vmRecord.blocked_operations,
start: 'Importing…',
},
ha_always_run: false,
is_a_template: false,
name_label: '[Importing…] ' + vmRecord.name_label,
other_config: {
...vmRecord.other_config,
[TAG_COPY_SRC]: vmRecord.uuid,
},
},
{
bios_strings: vmRecord.bios_strings,
generateMacSeed: newMacAddresses,
suspend_VDI: suspendVdi?.$ref,
}
)
$defer.onFailure.call(xapi, 'VM_destroy', vmRef)
// 2. Delete all VBDs which may have been created by the import.
await asyncMap(await xapi.getField('VM', vmRef, 'VBDs'), ref => ignoreErrors.call(xapi.call('VBD.destroy', ref)))
// 3. Create VDIs & VBDs.
const vbdRecords = deltaVm.vbds
const vbds = groupBy(vbdRecords, 'VDI')
const newVdis = {}
await asyncMap(Object.keys(vdiRecords), async vdiRef => {
const vdi = vdiRecords[vdiRef]
let newVdi
const remoteBaseVdiUuid = detectBase && vdi.other_config[TAG_BASE_DELTA]
if (remoteBaseVdiUuid) {
const baseVdi = find(baseVdis, vdi => vdi.other_config[TAG_COPY_SRC] === remoteBaseVdiUuid)
if (!baseVdi) {
throw new Error(`missing base VDI (copy of ${remoteBaseVdiUuid})`)
}
newVdi = await xapi.getRecord('VDI', await baseVdi.$clone())
$defer.onFailure(() => newVdi.$destroy())
await newVdi.update_other_config(TAG_COPY_SRC, vdi.uuid)
} else if (vdiRef === vmRecord.suspend_VDI) {
// suspendVDI has already created
newVdi = suspendVdi
} else {
newVdi = await xapi.getRecord(
'VDI',
await xapi.VDI_create({
...vdi,
other_config: {
...vdi.other_config,
[TAG_BASE_DELTA]: undefined,
[TAG_COPY_SRC]: vdi.uuid,
},
SR: mapVdisSrs[vdi.uuid] ?? sr.$ref,
})
)
$defer.onFailure(() => newVdi.$destroy())
}
const vdiVbds = vbds[vdiRef]
if (vdiVbds !== undefined) {
await asyncMap(Object.values(vdiVbds), vbd =>
xapi.VBD_create({
...vbd,
VDI: newVdi.$ref,
VM: vmRef,
})
)
}
newVdis[vdiRef] = newVdi
})
const networksByNameLabelByVlan = {}
let defaultNetwork
Object.values(xapi.objects.all).forEach(object => {
if (object.$type === 'network') {
const pif = object.$PIFs[0]
if (pif === undefined) {
// ignore network
return
}
const vlan = pif.VLAN
const networksByNameLabel = networksByNameLabelByVlan[vlan] || (networksByNameLabelByVlan[vlan] = {})
defaultNetwork = networksByNameLabel[object.name_label] = object
}
})
const { streams } = deltaVm
await Promise.all([
// Import VDI contents.
cancelableMap(cancelToken, Object.entries(newVdis), async (cancelToken, [id, vdi]) => {
for (let stream of ensureArray(streams[`${id}.vhd`])) {
if (typeof stream === 'function') {
stream = await stream()
}
if (stream.length === undefined) {
stream = await createVhdStreamWithLength(stream)
}
await vdi.$importContent(stream, { cancelToken, format: 'vhd' })
}
}),
// Wait for VDI export tasks (if any) termination.
Promise.all(Object.values(streams).map(stream => stream.task)),
// Create VIFs.
asyncMap(Object.values(deltaVm.vifs), vif => {
let network = vif.$network$uuid && xapi.getObjectByUuid(vif.$network$uuid, undefined)
if (network === undefined) {
const { $network$VLAN: vlan = -1 } = vif
const networksByNameLabel = networksByNameLabelByVlan[vlan]
if (networksByNameLabel !== undefined) {
network = networksByNameLabel[vif.$network$name_label]
if (network === undefined) {
network = networksByNameLabel[Object.keys(networksByNameLabel)[0]]
}
} else {
network = defaultNetwork
}
}
if (network) {
return xapi.VIF_create(
{
...vif,
network: network.$ref,
VM: vmRef,
},
{
MAC: newMacAddresses ? undefined : vif.MAC,
}
)
}
}),
])
await Promise.all([
deltaVm.vm.ha_always_run && xapi.setField('VM', vmRef, 'ha_always_run', true),
xapi.setField('VM', vmRef, 'name_label', deltaVm.vm.name_label),
])
return vmRef
})

View File

@@ -1,4 +1,4 @@
function extractIdsFromSimplePattern(pattern) {
exports.extractIdsFromSimplePattern = function extractIdsFromSimplePattern(pattern) {
if (pattern === undefined) {
return []
}
@@ -27,4 +27,3 @@ function extractIdsFromSimplePattern(pattern) {
throw new Error('invalid pattern')
}
exports.extractIdsFromSimplePattern = extractIdsFromSimplePattern

View File

@@ -0,0 +1,28 @@
const eos = require('end-of-stream')
const { PassThrough } = require('stream')
// create a new readable stream from an existing one which may be piped later
//
// in case of error in the new readable stream, it will simply be unpiped
// from the original one
exports.forkStreamUnpipe = function forkStreamUnpipe(stream) {
const { forks = 0 } = stream
stream.forks = forks + 1
const proxy = new PassThrough()
stream.pipe(proxy)
eos(stream, error => {
if (error !== undefined) {
proxy.destroy(error)
}
})
eos(proxy, _ => {
stream.forks--
stream.unpipe(proxy)
if (stream.forks === 0) {
stream.destroy(new Error('no more consumers for this stream'))
}
})
return proxy
}

View File

@@ -0,0 +1,4 @@
// returns all entries but the last retention-th
exports.getOldEntries = function getOldEntries(retention, entries) {
return entries === undefined ? [] : retention > 0 ? entries.slice(0, -retention) : entries
}

View File

@@ -0,0 +1,20 @@
const Disposable = require('promise-toolbox/Disposable.js')
const { join } = require('path')
const { mkdir, rmdir } = require('fs-extra')
const { tmpdir } = require('os')
const MAX_ATTEMPTS = 3
exports.getTmpDir = async function getTmpDir() {
for (let i = 0; true; ++i) {
const path = join(tmpdir(), Math.random().toString(36).slice(2))
try {
await mkdir(path)
return new Disposable(() => rmdir(path), path)
} catch (error) {
if (i === MAX_ATTEMPTS) {
throw error
}
}
}
}

View File

@@ -0,0 +1,6 @@
const BACKUP_DIR = 'xo-vm-backups'
exports.BACKUP_DIR = BACKUP_DIR
exports.getVmBackupDir = function getVmBackupDir(uuid) {
return `${BACKUP_DIR}/${uuid}`
}

View File

@@ -1,13 +1,10 @@
const assert = require('assert')
const fs = require('fs-extra')
const isGzipFile = async fd => {
const isGzipFile = async (handler, fd) => {
// https://tools.ietf.org/html/rfc1952.html#page-5
const magicNumber = Buffer.allocUnsafe(2)
assert.strictEqual(
(await fs.read(fd, magicNumber, 0, magicNumber.length, 0)).bytesRead,
magicNumber.length
)
assert.strictEqual((await handler.read(fd, magicNumber, 0)).bytesRead, magicNumber.length)
return magicNumber[0] === 31 && magicNumber[1] === 139
}
@@ -24,35 +21,33 @@ const isGzipFile = async fd => {
// /^Ref:\d+/\d+\.checksum$/ and then validating the tar structure from it
//
// https://github.com/npm/node-tar/issues/234#issuecomment-538190295
const isValidTar = async (size, fd) => {
const isValidTar = async (handler, size, fd) => {
if (size <= 1024 || size % 512 !== 0) {
return false
}
const buf = Buffer.allocUnsafe(1024)
assert.strictEqual(
(await fs.read(fd, buf, 0, buf.length, size - buf.length)).bytesRead,
buf.length
)
assert.strictEqual((await handler.read(fd, buf, size - buf.length)).bytesRead, buf.length)
return buf.every(_ => _ === 0)
}
// TODO: find an heuristic for compressed files
const isValidXva = async path => {
async function isValidXva(path) {
const handler = this._handler
try {
const fd = await fs.open(path, 'r')
const fd = await handler.openFile(path, 'r')
try {
const { size } = await fs.fstat(fd)
const size = await handler.getSize(fd)
if (size < 20) {
// neither a valid gzip not tar
return false
}
return (await isGzipFile(fd))
return (await isGzipFile(handler, fd))
? true // gzip files cannot be validated at this time
: await isValidTar(size, fd)
: await isValidTar(handler, size, fd)
} finally {
fs.close(fd).catch(noop)
handler.closeFile(fd).catch(noop)
}
} catch (error) {
// never throw, log and report as valid to avoid side effects

View File

@@ -0,0 +1,52 @@
const fromCallback = require('promise-toolbox/fromCallback.js')
const { createLogger } = require('@xen-orchestra/log')
const { createParser } = require('parse-pairs')
const { execFile } = require('child_process')
const { debug } = createLogger('xo:backups:listPartitions')
const IGNORED_PARTITION_TYPES = {
// https://github.com/jhermsmeier/node-mbr/blob/master/lib/partition.js#L38
0x05: true,
0x0f: true,
0x15: true,
0x5e: true,
0x5f: true,
0x85: true,
0x91: true,
0x9b: true,
0xc5: true,
0xcf: true,
0xd5: true,
0x82: true, // swap
}
const LVM_PARTITION_TYPE = 0x8e
exports.LVM_PARTITION_TYPE = LVM_PARTITION_TYPE
const parsePartxLine = createParser({
keyTransform: key => (key === 'UUID' ? 'id' : key.toLowerCase()),
valueTransform: (value, key) => (key === 'start' || key === 'size' || key === 'type' ? +value : value),
})
// returns an empty array in case of a non-partitioned disk
exports.listPartitions = async function listPartitions(devicePath) {
const parts = await fromCallback(execFile, 'partx', [
'--bytes',
'--output=NR,START,SIZE,NAME,UUID,TYPE',
'--pairs',
devicePath,
]).catch(error => {
// partx returns 1 since v2.33 when failing to read partitions.
//
// Prior versions are correctly handled by the nominal case.
debug('listPartitions', { error })
return ''
})
return parts
.split(/\r?\n/)
.map(parsePartxLine)
.filter(({ type }) => type != null && !(type in IGNORED_PARTITION_TYPES))
}

View File

@@ -0,0 +1,29 @@
const fromCallback = require('promise-toolbox/fromCallback.js')
const { createParser } = require('parse-pairs')
const { execFile } = require('child_process')
// ===================================================================
const parse = createParser({
keyTransform: key => key.slice(5).toLowerCase(),
})
const makeFunction = command => async (fields, ...args) => {
const info = await fromCallback(execFile, command, [
'--noheading',
'--nosuffix',
'--nameprefixes',
'--unbuffered',
'--units',
'b',
'-o',
String(fields),
...args,
])
return info
.trim()
.split(/\r?\n/)
.map(Array.isArray(fields) ? parse : line => parse(line)[fields])
}
exports.lvs = makeFunction('lvs')
exports.pvs = makeFunction('pvs')

View File

@@ -0,0 +1,7 @@
exports.watchStreamSize = function watchStreamSize(stream, container = { size: 0 }) {
stream.on('data', data => {
container.size += data.length
})
stream.pause()
return container
}

View File

@@ -0,0 +1,34 @@
const mapValues = require('lodash/mapValues.js')
const { dirname } = require('path')
function formatVmBackup(backup) {
return {
disks:
backup.vhds === undefined
? []
: Object.keys(backup.vhds).map(vdiId => {
const vdi = backup.vdis[vdiId]
return {
id: `${dirname(backup._filename)}/${backup.vhds[vdiId]}`,
name: vdi.name_label,
uuid: vdi.uuid,
}
}),
id: backup.id,
jobId: backup.jobId,
mode: backup.mode,
scheduleId: backup.scheduleId,
size: backup.size,
timestamp: backup.timestamp,
vm: {
name_description: backup.vm.name_description,
name_label: backup.vm.name_label,
},
}
}
// format all backups as returned by RemoteAdapter#listAllVmBackups()
exports.formatVmBackups = function formatVmBackups(backupsByVM) {
return mapValues(backupsByVM, backups => backups.map(formatVmBackup))
}

View File

@@ -1,7 +0,0 @@
// returns all entries but the last retention-th
exports.getOldEntries = (retention, entries) =>
entries === undefined
? []
: retention > 0
? entries.slice(0, -retention)
: entries

View File

@@ -8,16 +8,37 @@
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"version": "0.1.1",
"version": "0.11.0",
"engines": {
"node": ">=8.10"
"node": ">=14.6"
},
"scripts": {
"postversion": "npm publish --access public"
},
"dependencies": {
"@vates/compose": "^2.0.0",
"@vates/disposable": "^0.1.1",
"@vates/parse-duration": "^0.1.1",
"@xen-orchestra/async-map": "^0.1.2",
"@xen-orchestra/fs": "^0.17.0",
"@xen-orchestra/log": "^0.2.0",
"@xen-orchestra/template": "^0.1.0",
"compare-versions": "^3.6.0",
"d3-time-format": "^3.0.0",
"fs-extra": "^9.0.0"
"end-of-stream": "^1.4.4",
"fs-extra": "^9.0.0",
"golike-defer": "^0.5.1",
"limit-concurrency-decorator": "^0.5.0",
"lodash": "^4.17.20",
"node-zone": "^0.4.0",
"parse-pairs": "^1.1.0",
"pump": "^3.0.0",
"promise-toolbox": "^0.19.2",
"vhd-lib": "^1.0.0",
"yazl": "^2.5.1"
},
"peerDependencies": {
"@xen-orchestra/xapi": "^0.6.2"
},
"license": "AGPL-3.0-or-later",
"author": {

View File

@@ -0,0 +1,23 @@
const { DIR_XO_CONFIG_BACKUPS, DIR_XO_POOL_METADATA_BACKUPS } = require('./RemoteAdapter.js')
exports.parseMetadataBackupId = function parseMetadataBackupId(backupId) {
const [dir, ...rest] = backupId.split('/')
if (dir === DIR_XO_CONFIG_BACKUPS) {
const [scheduleId, timestamp] = rest
return {
type: 'xoConfig',
scheduleId,
timestamp,
}
} else if (dir === DIR_XO_POOL_METADATA_BACKUPS) {
const [scheduleId, poolUuid, timestamp] = rest
return {
type: 'pool',
poolUuid,
scheduleId,
timestamp,
}
}
throw new Error(`not supported backup dir (${dir})`)
}

View File

@@ -0,0 +1,38 @@
const path = require('path')
const { createLogger } = require('@xen-orchestra/log')
const { fork } = require('child_process')
const { warn } = createLogger('xo:backups:backupWorker')
const PATH = path.resolve(__dirname, '_backupWorker.js')
exports.runBackupWorker = function runBackupWorker(params, onLog) {
return new Promise((resolve, reject) => {
const worker = fork(PATH)
worker.on('exit', code => reject(new Error(`worker exited with code ${code}`)))
worker.on('error', reject)
worker.on('message', message => {
try {
if (message.type === 'result') {
if (message.status === 'success') {
resolve(message.result)
} else {
reject(message.result)
}
} else if (message.type === 'log') {
onLog(message.data)
}
} catch (error) {
warn(error)
}
})
worker.send({
action: 'run',
data: params,
runWithLogs: onLog !== undefined,
})
})
}

View File

@@ -1,11 +0,0 @@
exports.watchStreamSize = stream => {
const container = { size: 0 }
const isPaused = stream.isPaused()
stream.on('data', data => {
container.size += data.length
})
if (isPaused) {
stream.pause()
}
return container
}

View File

@@ -0,0 +1,227 @@
const assert = require('assert')
const map = require('lodash/map.js')
const mapValues = require('lodash/mapValues.js')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const { asyncMap } = require('@xen-orchestra/async-map')
const { chainVhd, checkVhdChain, default: Vhd } = require('vhd-lib')
const { createLogger } = require('@xen-orchestra/log')
const { dirname } = require('path')
const { formatFilenameDate } = require('../_filenameDate.js')
const { getOldEntries } = require('../_getOldEntries.js')
const { getVmBackupDir } = require('../_getVmBackupDir.js')
const { Task } = require('../Task.js')
const { MixinBackupWriter } = require('./_MixinBackupWriter.js')
const { AbstractDeltaWriter } = require('./_AbstractDeltaWriter.js')
const { checkVhd } = require('./_checkVhd.js')
const { packUuid } = require('./_packUuid.js')
const { warn } = createLogger('xo:backups:DeltaBackupWriter')
exports.DeltaBackupWriter = class DeltaBackupWriter extends MixinBackupWriter(AbstractDeltaWriter) {
async checkBaseVdis(baseUuidToSrcVdi) {
const { handler } = this._adapter
const backup = this._backup
const backupDir = getVmBackupDir(backup.vm.uuid)
const vdisDir = `${backupDir}/vdis/${backup.job.id}`
await asyncMap(baseUuidToSrcVdi, async ([baseUuid, srcVdi]) => {
let found = false
try {
const vhds = await handler.list(`${vdisDir}/${srcVdi.uuid}`, {
filter: _ => _[0] !== '.' && _.endsWith('.vhd'),
prependDir: true,
})
await asyncMap(vhds, async path => {
try {
await checkVhdChain(handler, path)
const vhd = new Vhd(handler, path)
await vhd.readHeaderAndFooter()
found = found || vhd.footer.uuid.equals(packUuid(baseUuid))
} catch (error) {
warn('checkBaseVdis', { error })
await ignoreErrors.call(handler.unlink(path))
}
})
} catch (error) {
warn('checkBaseVdis', { error })
}
if (!found) {
baseUuidToSrcVdi.delete(baseUuid)
}
})
}
async beforeBackup() {
await super.beforeBackup()
return this._cleanVm({ merge: true })
}
prepare({ isFull }) {
// create the task related to this export and ensure all methods are called in this context
const task = new Task({
name: 'export',
data: {
id: this._remoteId,
isFull,
type: 'remote',
},
})
this.transfer = task.wrapFn(this.transfer)
this.cleanup = task.wrapFn(this.cleanup, true)
return task.run(() => this._prepare())
}
async _prepare() {
const adapter = this._adapter
const settings = this._settings
const { scheduleId, vm } = this._backup
const oldEntries = getOldEntries(
settings.exportRetention - 1,
await adapter.listVmBackups(vm.uuid, _ => _.mode === 'delta' && _.scheduleId === scheduleId)
)
this._oldEntries = oldEntries
// FIXME: implement optimized multiple VHDs merging with synthetic
// delta
//
// For the time being, limit the number of deleted backups by run
// because it can take a very long time and can lead to
// interrupted backup with broken VHD chain.
//
// The old backups will be eventually merged in future runs of the
// job.
const { maxMergedDeltasPerRun } = this._settings
if (oldEntries.length > maxMergedDeltasPerRun) {
oldEntries.length = maxMergedDeltasPerRun
}
if (settings.deleteFirst) {
await this._deleteOldEntries()
}
}
async cleanup() {
if (!this._settings.deleteFirst) {
await this._deleteOldEntries()
}
}
async _deleteOldEntries() {
return Task.run({ name: 'merge' }, async () => {
const adapter = this._adapter
const oldEntries = this._oldEntries
let size = 0
// delete sequentially from newest to oldest to avoid unnecessary merges
for (let i = oldEntries.length; i-- > 0; ) {
size += await adapter.deleteDeltaVmBackups([oldEntries[i]])
}
return {
size,
}
})
}
async transfer({ timestamp, deltaExport, sizeContainers }) {
const adapter = this._adapter
const backup = this._backup
const { job, scheduleId, vm } = backup
const jobId = job.id
const handler = adapter.handler
const backupDir = getVmBackupDir(vm.uuid)
// TODO: clean VM backup directory
const basename = formatFilenameDate(timestamp)
const vhds = mapValues(
deltaExport.vdis,
vdi =>
`vdis/${jobId}/${
vdi.type === 'suspend'
? // doesn't make sense to group by parent for memory because we
// don't do delta for it
vdi.uuid
: vdi.$snapshot_of$uuid
}/${basename}.vhd`
)
const metadataFilename = `${backupDir}/${basename}.json`
const metadataContent = {
jobId,
mode: job.mode,
scheduleId,
timestamp,
vbds: deltaExport.vbds,
vdis: deltaExport.vdis,
version: '2.0.0',
vifs: deltaExport.vifs,
vhds,
vm,
vmSnapshot: this._backup.exportedVm,
}
const { size } = await Task.run({ name: 'transfer' }, async () => {
await Promise.all(
map(deltaExport.vdis, async (vdi, id) => {
const path = `${backupDir}/${vhds[id]}`
const isDelta = vdi.other_config['xo:base_delta'] !== undefined
let parentPath
if (isDelta) {
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}`)
parentPath = parentPath.slice(1) // remove leading slash
// TODO remove when this has been done before the export
await checkVhd(handler, parentPath)
}
await adapter.outputStream(path, deltaExport.streams[`${id}.vhd`], {
// no checksum for VHDs, because they will be invalidated by
// merges and chainings
checksum: false,
validator: tmpPath => checkVhd(handler, tmpPath),
})
if (isDelta) {
await chainVhd(handler, parentPath, handler, path)
}
// set the correct UUID in the VHD
const vhd = new Vhd(handler, path)
await vhd.readHeaderAndFooter()
vhd.footer.uuid = packUuid(vdi.uuid)
await vhd.readBlockAllocationTable() // required by writeFooter()
await vhd.writeFooter()
})
)
return {
size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0),
}
})
metadataContent.size = size
await handler.outputFile(metadataFilename, JSON.stringify(metadataContent), {
dirMode: backup.config.dirMode,
})
// TODO: run cleanup?
}
}

View File

@@ -0,0 +1,124 @@
const { asyncMap, asyncMapSettled } = require('@xen-orchestra/async-map')
const ignoreErrors = require('promise-toolbox/ignoreErrors.js')
const { formatDateTime } = require('@xen-orchestra/xapi')
const { formatFilenameDate } = require('../_filenameDate.js')
const { getOldEntries } = require('../_getOldEntries.js')
const { importDeltaVm, TAG_COPY_SRC } = require('../_deltaVm.js')
const { Task } = require('../Task.js')
const { AbstractDeltaWriter } = require('./_AbstractDeltaWriter.js')
const { MixinReplicationWriter } = require('./_MixinReplicationWriter.js')
const { listReplicatedVms } = require('./_listReplicatedVms.js')
exports.DeltaReplicationWriter = class DeltaReplicationWriter extends MixinReplicationWriter(AbstractDeltaWriter) {
async checkBaseVdis(baseUuidToSrcVdi, baseVm) {
const sr = this._sr
const replicatedVm = listReplicatedVms(sr.$xapi, this._backup.job.id, sr.uuid, this._backup.vm.uuid).find(
vm => vm.other_config[TAG_COPY_SRC] === baseVm.uuid
)
if (replicatedVm === undefined) {
return baseUuidToSrcVdi.clear()
}
const xapi = replicatedVm.$xapi
const replicatedVdis = new Set(
await asyncMap(await replicatedVm.$getDisks(), async vdiRef => {
const otherConfig = await xapi.getField('VDI', vdiRef, 'other_config')
return otherConfig[TAG_COPY_SRC]
})
)
for (const uuid of baseUuidToSrcVdi.keys()) {
if (!replicatedVdis.has(uuid)) {
baseUuidToSrcVdi.delete(uuid)
}
}
}
prepare({ isFull }) {
// create the task related to this export and ensure all methods are called in this context
const task = new Task({
name: 'export',
data: {
id: this._sr.uuid,
isFull,
type: 'SR',
},
})
this.transfer = task.wrapFn(this.transfer)
this.cleanup = task.wrapFn(this.cleanup, true)
return task.run(() => this._prepare())
}
async _prepare() {
const settings = this._settings
const { uuid: srUuid, $xapi: xapi } = this._sr
const { scheduleId, vm } = this._backup
// delete previous interrupted copies
ignoreErrors.call(asyncMapSettled(listReplicatedVms(xapi, scheduleId, undefined, vm.uuid), vm => vm.$destroy))
this._oldEntries = getOldEntries(settings.copyRetention - 1, listReplicatedVms(xapi, scheduleId, srUuid, vm.uuid))
if (settings.deleteFirst) {
await this._deleteOldEntries()
}
}
async cleanup() {
if (!this._settings.deleteFirst) {
await this._deleteOldEntries()
}
}
async _deleteOldEntries() {
return asyncMapSettled(this._oldEntries, vm => vm.$destroy())
}
async transfer({ timestamp, deltaExport, sizeContainers }) {
const sr = this._sr
const { job, scheduleId, vm } = this._backup
const { uuid: srUuid, $xapi: xapi } = sr
let targetVmRef
await Task.run({ name: 'transfer' }, async () => {
targetVmRef = await importDeltaVm(
{
__proto__: deltaExport,
vm: {
...deltaExport.vm,
tags: [...deltaExport.vm.tags, 'Continuous Replication'],
},
},
sr
)
return {
size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0),
}
})
const targetVm = await xapi.getRecord('VM', targetVmRef)
await Promise.all([
targetVm.ha_restart_priority !== '' &&
Promise.all([targetVm.set_ha_restart_priority(''), targetVm.add_tags('HA disabled')]),
targetVm.set_name_label(`${vm.name_label} - ${job.name} - (${formatFilenameDate(timestamp)})`),
targetVm.update_blocked_operations(
'start',
'Start operation for this vm is blocked, clone it if you want to use it.'
),
targetVm.update_other_config({
'xo:backup:sr': srUuid,
// these entries need to be added in case of offline backup
'xo:backup:datetime': formatDateTime(timestamp),
'xo:backup:job': job.id,
'xo:backup:schedule': scheduleId,
'xo:backup:vm': vm.uuid,
}),
])
}
}

Some files were not shown because too many files have changed in this diff Show More