Skip to content

Commit

Permalink
Merge branch 'master' into events-and-snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
wankdanker committed Jun 22, 2016
2 parents 91bd5a5 + 59157a7 commit 38998ca
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.*.swp
.idea
.vscode
65 changes: 47 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ $ npm install --save zfs
# Usage

```
var zfs-filesystem = require('zfs');
var zfsFilesystem = require('zfs');
```

##Now you can address the zfs library as follows:

### To use the zfs command implementation:
```
zfs-filesystem.zfs.
zfsFilesystem.zfs.
```
###To use the zpool implementation:

```
zfs-filesystem.zpool.
zfsFilesystem.zpool.
```

## Implemented commands for the ZFS tool
Expand All @@ -47,7 +47,7 @@ zfs-filesystem.zpool.
The list command lists a specific zfs dataset or all datasets. All possible options can be found inside the lib/zfs.js file.

```
zfs-filesystem.zfs.list(function (err, list) {
zfsFilesystem.zfs.list(function (err, list) {
console.log(list)
});
```
Expand All @@ -62,7 +62,7 @@ var opts = {
property: 'quota'
};

zfs-filesystem.zfs.get(opts, function (err, options) {
zfsFilesystem.zfs.get(opts, function (err, options) {
console.log(options);
});
```
Expand All @@ -78,7 +78,7 @@ var opts = {
value: '1024G'
};

zfs-filesystem.zfs.set(opts, function (err, output) {
zfsFilesystem.zfs.set(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -92,7 +92,7 @@ var opts = {
name: 'my-dataset-name'
};

zfs-filesystem.zfs.destroy(opts, function (err, output) {
zfsFilesystem.zfs.destroy(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -106,7 +106,7 @@ var opts = {
name: 'my-new-dataset-name'
};

zfs-filesystem.zfs.create(opts, function (err, output) {
zfsFilesystem.zfs.create(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -121,7 +121,7 @@ var opts = {
dataset: 'my-dataset-name'
};

zfs-filesystem.zfs.snapshot(opts, function (err, output) {
zfsFilesystem.zfs.snapshot(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -136,7 +136,36 @@ var opts = {
dataset: 'my-mountpoint-name'
};

zfs-filesystem.zfs.clone(opts, function (err, output) {
zfsFilesystem.zfs.clone(opts, function (err, output) {
console.log(output);
});
```


### ZFS Mount

Mount the filesystem with the specified name or all filesystems. All possible options can be found inside the lib/zfs.js file.

```js
var opts = {
dataset: 'my-filesystem-name'
};

zfsFilesystem.zfs.mount(opts, function (err, output) {
console.log(output);
});
```
### ZFS Unmount

Unmount the filesystem or the mountpoint or all filesystems. All possible options can be found inside the lib/zfs.js file.

```js
var opts = {
name: 'my-filesystem-name',
force: true
};

zfsFilesystem.zfs.unmount(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -151,7 +180,7 @@ var opts = {
verbose : true
};

zfs-filesystem.zfs.send(opts, function (err, sendStream) {
zfsFilesystem.zfs.send(opts, function (err, sendStream) {
sendStream.on('error', function (err) {
console.error(err);
});
Expand All @@ -176,7 +205,7 @@ var opts = {
verbose : true
};

zfs-filesystem.zfs.receive(opts, function (err, receiveStream) {
zfsFilesystem.zfs.receive(opts, function (err, receiveStream) {
receiveStream.on('error', function (err) {
console.error(err);
});
Expand All @@ -203,7 +232,7 @@ var opts = {
devices: ['/dev/vdb', '/dev/vdc']
};

zfs-filesystem.zpool.create(opts, function (err, output) {
zfsFilesystem.zpool.create(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -218,7 +247,7 @@ var opts = {
devices: '/dev/vdd'
};

zfs-filesystem.zpool.add(opts, function (err, output) {
zfsFilesystem.zpool.add(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -234,7 +263,7 @@ var opts = {
value: 'Added some comment to a datastore'
};

zfs-filesystem.zpool.set(opts, function (err, output) {
zfsFilesystem.zpool.set(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -248,7 +277,7 @@ var opts = {
name: 'my-datastore',
};

zfs-filesystem.zpool.destroy(opts, function (err, output) {
zfsFilesystem.zpool.destroy(opts, function (err, output) {
console.log(output);
});
```
Expand All @@ -258,7 +287,7 @@ zfs-filesystem.zpool.destroy(opts, function (err, output) {
Lists the given pools along with a health status and space usage. If no pools are specified, all pools in the system are listed.

```js
zfs-filesystem.zpool.list(function (err, output) {
zfsFilesystem.zpool.list(function (err, output) {
console.log(output);
});
```
Expand All @@ -268,7 +297,7 @@ zfs-filesystem.zpool.list(function (err, output) {
Retrieves the given list of properties. When no name and property specified, it shows all properties for all datastores. See the zpool manpage for possible options and values.

```js
zfs-filesystem.zpool.get(function (err, output) {
zfsFilesystem.zpool.get(function (err, output) {
console.log(output);
});
```
Expand Down
4 changes: 4 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ exports.destroy = zfs.destroy;
exports.create = zfs.create;
exports.snapshot = zfs.snapshot;
exports.clone = zfs.clone;
exports.mount = zfs.mount;
exports.unmount = zfs.unmount;
exports.send = zfs.send;
exports.receive = zfs.receive;

Expand All @@ -20,6 +22,8 @@ exports.zfs = {
list: zfs.list,
snapshot: zfs.snapshot,
clone: zfs.clone,
mount: zfs.mount,
unmount: zfs.unmount,
send : zfs.send,
receive : zfs.receive
};
Expand Down
74 changes: 74 additions & 0 deletions lib/zfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,78 @@ function clone(opts, cb) {
zfs(params, cb);
}

/*
*
* Mount the specified dataset/all datasets to the mountpoint
*
* PARAMS:
* opts: {
* dataset: string // the name of the zfs dataset. if the dataset is null, then mount all datasets with '-a'
* overlay: boolean // whether use overlay mode
* options: [string, string, ...] // the temporal properties set for the mount duration,
* such as ro/rw for readonly and readwrite (optional)
* }
*/
function mount(opts, cb) {
"use strict";

var params = [ 'mount' ];

if (opts.overlay) {
params.push('-O');
}

if (opts.options) {
if (opts.options.length) {
//opts.options is an array
for (var x =0; x < opts.options.length; x++) {
params.push('-o', opts.options[x]);
}
} else {
//opts.options is a single object, callback err and return
cb({error:'invalid argu: the options should be a string array'});
return;
}
}

if (opts.dataset) {
params.push(opts.dataset);
} else {
params.push('-a');
}

zfs(params, cb);
}

/*
*
* Unmount the specified filesystem|mountpoint
*
* PARAMS:
* opts: {
* name: string // the name of the zfs dataset or the path of the mountpoint.
* if the dataset is null, then unmount all available filesystems with '-a'
* force: boolean // whether forcely unmount even if the filesystem is still in use.
* }
*/
function unmount(opts, cb) {
"use strict";

var params = [ 'unmount' ];

if (opts.force) {
params.push('-f');
}

if (opts.name) {
params.push(opts.name);
} else {
params.push('-a');
}

zfs(params, cb);
}

/*
*
* Initiates a send operation of a given snapshot
Expand Down Expand Up @@ -520,5 +592,7 @@ exports.destroy = destroy;
exports.create = create;
exports.snapshot = snapshot;
exports.clone = clone;
exports.mount = mount;
exports.unmount = unmount;
exports.send = send;
exports.receive = receive;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"smartos"
],
"homepage": "http://nym.se/node-zfs/docs/",
"version": "1.1.1",
"version": "1.3.0",
"main": "lib/main.js",
"scripts": {
"test": "NODE_PATH=lib PATH=test:$PATH node_modules/.bin/mocha -R spec",
Expand Down

0 comments on commit 38998ca

Please sign in to comment.