-
Notifications
You must be signed in to change notification settings - Fork 245
/
mkzpool.js
58 lines (47 loc) · 1.04 KB
/
mkzpool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/node/0.8/bin/node
/*
* Copyright 2012 Joyent, Inc. All rights reserved.
*/
var fs = require('fs');
var zfs = require('/usr/node/node_modules/zfs');
var getopt = require('/usr/node/node_modules/getopt');
function
fatal(msg)
{
console.log('fatal error: ' + msg);
process.exit(-1);
}
function
usage()
{
console.log('usage: ' + process.argv[0] + '[-f] <pool> <file.json>');
process.exit(-1);
}
var json;
var config;
var pool;
var option;
var opt_f = false;
var parser = new getopt.BasicParser('f', process.argv);
while ((option = parser.getopt()) !== undefined && !option.error) {
switch (option.option) {
case 'f':
opt_f = true;
break;
default:
usage();
break;
}
}
if (option && option.error)
usage();
if (!process.argv[parser.optind()] || !process.argv[parser.optind() + 1])
usage();
pool = process.argv[parser.optind()];
json = fs.readFileSync(process.argv[parser.optind() + 1], 'utf8');
config = JSON.parse(json);
zfs.zpool.create(pool, config, opt_f, function (err) {
if (err) {
fatal('pool creation failed: ' + err);
}
});