Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

List snapshots.

  • Loading branch information...
commit d6ee2ec4efc5d712a9ccd9c90112df57ec9f73ae 1 parent fc0ba7d
@calmh authored
Showing with 71 additions and 14 deletions.
  1. +2 −0  .gitignore
  2. +17 −7 lib/zfs.js
  3. +26 −6 test/zfs
  4. +26 −1 test/zfs.js
View
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules
+.*.swp
View
24 lib/zfs.js
@@ -1,8 +1,6 @@
var _ = require('underscore');
var spawn = require('child_process').spawn;
-exports.unittest = Object.create({});
-
function ZFS(info) {
"use strict";
@@ -17,7 +15,9 @@ function ZFS(info) {
obj.name = info[0];
obj.used = parseInt(info[1], 10);
- obj.avail = parseInt(info[2], 10);
+ if (info[2] !== '-') { // Snapshots don't have 'avail' field.
+ obj.avail = parseInt(info[2], 10);
+ }
obj.refer = parseInt(info[3], 10);
obj.mountpoint = info[4];
@@ -46,7 +46,6 @@ function Property(info) {
return obj
}
-exports.unittest.getZfsList = getZfsList;
function getZfsList(data) {
"use strict";
@@ -54,7 +53,6 @@ function getZfsList(data) {
return lines.map(function (x) { return new ZFS(x); });
}
-exports.unittest.getZfsGet = getZfsGet;
function getZfsGet(data) {
"use strict";
@@ -63,11 +61,23 @@ function getZfsGet(data) {
}
exports.list = list;
-function list(cb) {
+function list(opts, cb) {
"use strict";
+ if (typeof opts == 'function') {
+ cb = opts;
+ opts = undefined;
+ }
+
+ var params = ['list', '-pH'];
+
+ if (opts && opts.type) {
+ params.push('-t');
+ params.push(opts.type);
+ }
+
var buf = '';
- var cp = spawn('zfs', ['list', '-pH']);
+ var cp = spawn('zfs', params);
cp.stdout.on('data', function (data) {
buf += data;
View
32 test/zfs
@@ -1,19 +1,39 @@
#!/bin/sh
-case $1 in
- list)
- cat <<EOD
+function listFs {
+cat <<EOD
zones 1004799731712 956926580736 328704 /zones
zones/f78f9208-9c26-47f7-9e03-881a96d17c04 590843904 10146574336 694054400 /zones/f78f9208-9c26-47f7-9e03-881a96d17c04
zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data 73728 10146574336 31744 /data
EOD
- ;;
- get)
- cat <<EOD
+}
+
+function listSnaps {
+cat << EOD
+zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430 1024 - 32768 -
+zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120501 1024 - 32768 -
+zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120502 1024 - 32768 -
+EOD
+}
+
+function getAllProps {
+cat <<EOD
zones compression on local
zones/f78f9208-9c26-47f7-9e03-881a96d17c04 compression on inherited from zones
zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data compression on inherited from zones
zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430 compression - -
EOD
+}
+
+case $1 in
+list)
+ if [ "$3" = "-t" -a "$4" = "snapshot" ] ; then
+ listSnaps
+ else
+ listFs
+ fi
+ ;;
+get)
+ getAllProps
;;
esac
View
27 test/zfs.js
@@ -4,7 +4,7 @@ var zfs = require('zfs');
describe('zfs', function () {
describe('list', function () {
- it('returns a list of ZFS objects', function (done) {
+ it('returns a list of ZFS filesystems', function (done) {
var expected = [ {
name: 'zones',
used: 1004799731712,
@@ -32,6 +32,31 @@ describe('zfs', function () {
done();
});
});
+ it('returns a list of ZFS snapshots', function (done) {
+ var expected = [ {
+ name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120430',
+ used: 1024,
+ refer: 32768,
+ mountpoint: '-'
+ },
+ {
+ name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120501',
+ used: 1024,
+ refer: 32768,
+ mountpoint: '-'
+ },
+ {
+ name: 'zones/f78f9208-9c26-47f7-9e03-881a96d17c04/data@daily-20120502',
+ used: 1024,
+ refer: 32768,
+ mountpoint: '-'
+ } ];
+ zfs.list({ type: 'snapshot' }, function (err, list) {
+ should.not.exist(err);
+ list.should.eql(expected);
+ done();
+ });
+ });
});
describe('get', function (done) {
it('returns a list of property', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.