diff --git a/@vates/fuse-vhd/.USAGE.md b/@vates/fuse-vhd/.USAGE.md new file mode 100644 index 000000000..c45ecfbf8 --- /dev/null +++ b/@vates/fuse-vhd/.USAGE.md @@ -0,0 +1,28 @@ +Mount a vhd generated by xen-orchestra to filesystem + +### Library + +```js +import { mount } from 'fuse-vhd' + +// return a disposable, see promise-toolbox/Disposable +// unmount automatically when disposable is disposed +// in case of differencing VHD, it mounts the full chain +await mount(handler, diskId, mountPoint) +``` + +### cli + +From the install folder : + +``` +cli.mjs +``` + +After installing the package + +``` +xo-fuse-vhd +``` + +remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root` diff --git a/@vates/fuse-vhd/README.md b/@vates/fuse-vhd/README.md new file mode 100644 index 000000000..58ad73926 --- /dev/null +++ b/@vates/fuse-vhd/README.md @@ -0,0 +1,59 @@ + + +# @vates/fuse-vhd + +[![Package Version](https://badgen.net/npm/v/@vates/fuse-vhd)](https://npmjs.org/package/@vates/fuse-vhd) ![License](https://badgen.net/npm/license/@vates/fuse-vhd) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/fuse-vhd)](https://bundlephobia.com/result?p=@vates/fuse-vhd) [![Node compatibility](https://badgen.net/npm/node/@vates/fuse-vhd)](https://npmjs.org/package/@vates/fuse-vhd) + +## Install + +Installation of the [npm package](https://npmjs.org/package/@vates/fuse-vhd): + +```sh +npm install --save @vates/fuse-vhd +``` + +## Usage + +Mount a vhd generated by xen-orchestra to filesystem + +### Library + +```js +import { mount } from 'fuse-vhd' + +// return a disposable, see promise-toolbox/Disposable +// unmount automatically when disposable is disposed +// in case of differencing VHD, it mounts the full chain +await mount(handler, diskId, mountPoint) +``` + +### cli + +From the install folder : + +``` +cli.mjs +``` + +After installing the package + +``` +xo-fuse-vhd +``` + +remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root` + +## Contributions + +Contributions are _very_ welcomed, either on the documentation or on +the code. + +You may: + +- report any [issue](https://github.com/vatesfr/xen-orchestra/issues) + you've encountered; +- fork and create a pull request. + +## License + +[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr) diff --git a/@vates/fuse-vhd/cli.mjs b/@vates/fuse-vhd/cli.mjs new file mode 100755 index 000000000..e482989e6 --- /dev/null +++ b/@vates/fuse-vhd/cli.mjs @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +import Disposable from 'promise-toolbox/Disposable' +import { getSyncedHandler } from '@xen-orchestra/fs' + +import { mount } from './index.mjs' + +async function* main([remoteUrl, vhdPathInRemote, mountPoint]) { + if (mountPoint === undefined) { + throw new TypeError('missing arg: cli ') + } + const handler = yield getSyncedHandler({ url: remoteUrl }) + const mounted = await mount(handler, vhdPathInRemote, mountPoint) + + let disposePromise + process.on('SIGINT', async () => { + // ensure single dispose + if (!disposePromise) { + disposePromise = mounted.dispose() + } + await disposePromise + process.exit() + }) +} + +Disposable.wrap(main)(process.argv.slice(2)) diff --git a/@vates/fuse-vhd/package.json b/@vates/fuse-vhd/package.json index a4f4e4902..3b1c744fd 100644 --- a/@vates/fuse-vhd/package.json +++ b/@vates/fuse-vhd/package.json @@ -19,11 +19,15 @@ }, "main": "./index.mjs", "dependencies": { + "@xen-orchestra/fs": "^4.1.3", "fuse-native": "^2.2.6", "lru-cache": "^7.14.0", "promise-toolbox": "^0.21.0", "vhd-lib": "^4.9.0" }, + "bin": { + "xo-fuse-vhd": "./cli.mjs" + }, "scripts": { "postversion": "npm publish --access public" } diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 628af84cc..bb07e6cf4 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -56,7 +56,7 @@ - @vates/decorate-with minor -- @vates/fuse-vhd patch +- @vates/fuse-vhd minor - @xen-orchestra/backups patch - @xen-orchestra/self-signed minor - @xen-orchestra/xapi minor