This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/lib/do_reboot_instance.js

68 lines
1.4 KiB
JavaScript

/*
* Copyright 2015 Joyent Inc.
*
* `triton reboot-instance ...`
*/
var common = require('./common');
function do_reboot_instance(subcmd, opts, args, callback) {
var self = this;
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 1) {
callback(new Error('invalid args: ' + args));
return;
}
var arg = args[0];
var uuid;
if (common.isUUID(arg)) {
uuid = arg;
go1();
} else {
self.triton.getMachineByAlias(arg, function (err, machine) {
if (err) {
callback(err);
return;
}
uuid = machine.id;
go1();
});
}
function go1() {
// called when "uuid" is set
self.triton.cloudapi.rebootMachine(uuid, function (err, body, res) {
if (err) {
callback(err);
return;
}
callback();
});
}
}
do_reboot_instance.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
];
do_reboot_instance.help = (
'Stop a single instance.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} reboot <alias|id>\n'
+ '\n'
+ '{{options}}'
);
do_reboot_instance.aliases = ['reboot'];
module.exports = do_reboot_instance;