2016-03-11 16:07:11 +02:00
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Joyent, Inc.
|
|
|
|
*
|
|
|
|
* `triton instance enable-firewall ...`
|
|
|
|
*/
|
|
|
|
|
|
|
|
var assert = require('assert-plus');
|
|
|
|
var format = require('util').format;
|
|
|
|
var vasync = require('vasync');
|
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
var common = require('../common');
|
2016-03-11 16:07:11 +02:00
|
|
|
var errors = require('../errors');
|
|
|
|
|
|
|
|
|
|
|
|
function do_enable_firewall(subcmd, opts, args, cb) {
|
|
|
|
assert.func(cb, 'cb');
|
|
|
|
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], cb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length === 0) {
|
2016-06-09 00:13:16 +03:00
|
|
|
cb(new errors.UsageError('missing INST argument(s)'));
|
2016-03-11 16:07:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cli = this.top;
|
|
|
|
|
2016-03-11 21:24:44 +02:00
|
|
|
function wait(name, id, next) {
|
|
|
|
cli.tritonapi.cloudapi.waitForMachineFirewallEnabled({
|
|
|
|
id: id,
|
2016-03-11 16:07:11 +02:00
|
|
|
state: true
|
|
|
|
}, function (err, inst) {
|
|
|
|
if (err) {
|
2016-03-11 21:24:44 +02:00
|
|
|
next(err);
|
|
|
|
return;
|
2016-03-11 16:07:11 +02:00
|
|
|
}
|
2016-03-11 21:24:44 +02:00
|
|
|
assert.ok(inst.firewall_enabled, format(
|
|
|
|
'inst %s firewall_enabled not in expected state after '
|
|
|
|
+ 'waitForMachineFirewallEnabled', id));
|
2016-03-11 16:07:11 +02:00
|
|
|
|
2016-03-11 21:24:44 +02:00
|
|
|
console.log('Enabled firewall for instance "%s"', name);
|
|
|
|
next();
|
2016-03-11 16:07:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:04:41 +02:00
|
|
|
common.cliSetupTritonApi({cli: this.top}, function onSetup(setupErr) {
|
|
|
|
if (setupErr) {
|
|
|
|
cb(setupErr);
|
2016-03-11 16:07:11 +02:00
|
|
|
}
|
2016-12-13 20:04:41 +02:00
|
|
|
vasync.forEachParallel({
|
|
|
|
inputs: args,
|
|
|
|
func: function enableOne(name, nextInst) {
|
|
|
|
cli.tritonapi.enableInstanceFirewall({
|
|
|
|
id: name
|
|
|
|
}, function (err, fauxInst) {
|
|
|
|
if (err) {
|
|
|
|
nextInst(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Enabling firewall for instance "%s"', name);
|
|
|
|
|
|
|
|
if (opts.wait) {
|
|
|
|
wait(name, fauxInst.id, nextInst);
|
|
|
|
} else {
|
|
|
|
nextInst();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, function (err) {
|
|
|
|
cb(err);
|
|
|
|
});
|
2016-03-11 16:07:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_enable_firewall.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['wait', 'w'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Wait for the firewall to be enabled.'
|
|
|
|
}
|
|
|
|
];
|
2016-06-09 00:13:16 +03:00
|
|
|
do_enable_firewall.synopses = [
|
|
|
|
'{{name}} enable-firewall [OPTIONS] INST [INST ...]'
|
|
|
|
];
|
2016-03-11 16:07:11 +02:00
|
|
|
do_enable_firewall.help = [
|
|
|
|
'Enable the firewall of one or more instances.',
|
|
|
|
'',
|
2016-06-09 00:13:16 +03:00
|
|
|
'{{usage}}',
|
2016-03-11 16:07:11 +02:00
|
|
|
'',
|
2016-06-09 00:13:16 +03:00
|
|
|
'{{options}}',
|
|
|
|
'Where "INST" is an instance name, id, or short id.'
|
2016-03-11 16:07:11 +02:00
|
|
|
].join('\n');
|
|
|
|
|
2016-03-11 21:24:44 +02:00
|
|
|
do_enable_firewall.completionArgtypes = ['tritoninstance'];
|
|
|
|
|
2016-03-11 16:07:11 +02:00
|
|
|
module.exports = do_enable_firewall;
|