2014-02-07 23:21:24 +02:00
|
|
|
/*
|
2015-08-25 22:14:16 +03:00
|
|
|
* Copyright (c) 2015 Joyent Inc. All rights reserved.
|
2014-02-07 23:21:24 +02:00
|
|
|
*
|
2015-08-25 22:14:16 +03:00
|
|
|
* The `triton` CLI class.
|
2014-02-07 23:21:24 +02:00
|
|
|
*/
|
|
|
|
|
2015-08-25 22:14:16 +03:00
|
|
|
var assert = require('assert-plus');
|
|
|
|
var bunyan = require('bunyan');
|
2014-02-07 23:21:24 +02:00
|
|
|
var child_process = require('child_process'),
|
|
|
|
spawn = child_process.spawn,
|
|
|
|
exec = child_process.exec;
|
|
|
|
var cmdln = require('cmdln'),
|
|
|
|
Cmdln = cmdln.Cmdln;
|
2015-08-25 22:14:16 +03:00
|
|
|
var fs = require('fs');
|
|
|
|
var util = require('util'),
|
|
|
|
format = util.format;
|
|
|
|
var vasync = require('vasync');
|
2014-02-07 23:21:24 +02:00
|
|
|
|
|
|
|
var common = require('./common');
|
2014-02-08 10:15:26 +02:00
|
|
|
var errors = require('./errors');
|
2015-08-25 23:11:40 +03:00
|
|
|
var Triton = require('./triton');
|
2014-02-07 23:21:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---- globals
|
|
|
|
|
2015-08-25 22:14:16 +03:00
|
|
|
var p = console.log;
|
|
|
|
|
2014-02-07 23:21:24 +02:00
|
|
|
var pkg = require('../package.json');
|
2015-08-25 22:14:16 +03:00
|
|
|
var name = 'triton';
|
2014-02-07 23:21:24 +02:00
|
|
|
var log = bunyan.createLogger({
|
|
|
|
name: name,
|
|
|
|
serializers: bunyan.stdSerializers,
|
|
|
|
stream: process.stderr,
|
|
|
|
level: 'warn'
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---- CLI class
|
|
|
|
|
|
|
|
function CLI() {
|
|
|
|
Cmdln.call(this, {
|
|
|
|
name: pkg.name,
|
|
|
|
desc: pkg.description,
|
|
|
|
options: [
|
|
|
|
{names: ['help', 'h'], type: 'bool', help: 'Print help and exit.'},
|
|
|
|
{name: 'version', type: 'bool', help: 'Print version and exit.'},
|
|
|
|
{names: ['verbose', 'v'], type: 'bool',
|
2014-02-08 04:23:18 +02:00
|
|
|
help: 'Verbose/debug output.'},
|
2015-08-26 01:10:13 +03:00
|
|
|
// XXX disable profile selection for now
|
|
|
|
//{names: ['profile', 'p'], type: 'string', env: 'TRITON_PROFILE',
|
|
|
|
// helpArg: 'NAME', help: 'Triton client profile to use.'}
|
2014-02-07 23:21:24 +02:00
|
|
|
],
|
|
|
|
helpOpts: {
|
|
|
|
includeEnv: true,
|
2015-08-26 07:34:47 +03:00
|
|
|
minHelpCol: 30
|
2015-08-26 01:10:13 +03:00
|
|
|
},
|
|
|
|
helpSubcmds: [
|
|
|
|
'help',
|
2015-08-26 06:44:08 +03:00
|
|
|
{ group: 'Operator Commands' },
|
|
|
|
'account',
|
2015-08-26 07:16:41 +03:00
|
|
|
'info',
|
2015-08-26 07:40:32 +03:00
|
|
|
'keys',
|
2015-08-26 01:15:02 +03:00
|
|
|
{ group: 'Instances (aka VMs/Machines/Containers)' },
|
2015-08-26 06:53:48 +03:00
|
|
|
'create-instance',
|
2015-08-26 01:15:02 +03:00
|
|
|
'instances',
|
2015-08-26 03:27:46 +03:00
|
|
|
'instance',
|
2015-08-26 01:15:02 +03:00
|
|
|
'instance-audit',
|
2015-08-26 04:09:32 +03:00
|
|
|
'start-instance',
|
|
|
|
'stop-instance',
|
|
|
|
'reboot-instance',
|
2015-08-26 08:25:26 +03:00
|
|
|
'delete-instance',
|
2015-08-26 06:25:00 +03:00
|
|
|
'ssh',
|
2015-08-26 01:10:13 +03:00
|
|
|
{ group: 'Images' },
|
|
|
|
'images',
|
2015-08-26 01:47:29 +03:00
|
|
|
'image',
|
2015-08-26 02:12:35 +03:00
|
|
|
{ group: 'Packages' },
|
|
|
|
'packages',
|
|
|
|
'package'
|
2015-08-26 01:10:13 +03:00
|
|
|
]
|
2014-02-07 23:21:24 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
util.inherits(CLI, Cmdln);
|
|
|
|
|
|
|
|
CLI.prototype.init = function (opts, args, callback) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (opts.version) {
|
|
|
|
p(this.name, pkg.version);
|
|
|
|
callback(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.opts = opts;
|
|
|
|
if (opts.verbose) {
|
|
|
|
log.level('trace');
|
|
|
|
log.src = true;
|
|
|
|
}
|
|
|
|
|
2015-08-25 23:11:40 +03:00
|
|
|
this.__defineGetter__('triton', function () {
|
|
|
|
if (self._triton === undefined) {
|
|
|
|
self._triton = new Triton({log: log, profile: opts.profile});
|
|
|
|
}
|
|
|
|
return self._triton;
|
|
|
|
});
|
2014-02-07 23:21:24 +02:00
|
|
|
|
|
|
|
// Cmdln class handles `opts.help`.
|
|
|
|
Cmdln.prototype.init.apply(this, arguments);
|
|
|
|
};
|
|
|
|
|
2015-08-25 23:11:40 +03:00
|
|
|
|
|
|
|
|
2015-08-26 01:10:13 +03:00
|
|
|
//CLI.prototype.do_profile = require('./do_profile');
|
2014-02-07 23:21:24 +02:00
|
|
|
|
2015-08-26 06:44:08 +03:00
|
|
|
// Operator
|
|
|
|
CLI.prototype.do_account = require('./do_account');
|
2015-08-26 07:16:41 +03:00
|
|
|
CLI.prototype.do_info = require('./do_info');
|
2015-08-26 07:40:32 +03:00
|
|
|
CLI.prototype.do_keys = require('./do_keys');
|
2015-08-26 06:44:08 +03:00
|
|
|
|
2015-08-26 01:10:13 +03:00
|
|
|
// Images
|
2015-08-26 00:25:30 +03:00
|
|
|
CLI.prototype.do_images = require('./do_images');
|
2015-08-26 01:47:29 +03:00
|
|
|
CLI.prototype.do_image = require('./do_image');
|
2015-08-26 00:25:30 +03:00
|
|
|
|
2015-08-26 01:15:02 +03:00
|
|
|
// Instances (aka VMs/containers/machines)
|
2015-08-26 03:27:46 +03:00
|
|
|
CLI.prototype.do_instance = require('./do_instance');
|
2015-08-26 01:15:02 +03:00
|
|
|
CLI.prototype.do_instances = require('./do_instances');
|
2015-08-26 06:53:48 +03:00
|
|
|
CLI.prototype.do_create_instance = require('./do_create_instance');
|
2015-08-26 01:15:02 +03:00
|
|
|
CLI.prototype.do_instance_audit = require('./do_instance_audit');
|
2015-08-26 04:46:14 +03:00
|
|
|
CLI.prototype.do_stop_instance = require('./do_startstop_instance')('stop');
|
|
|
|
CLI.prototype.do_start_instance = require('./do_startstop_instance')('start');
|
|
|
|
CLI.prototype.do_reboot_instance = require('./do_startstop_instance')('reboot');
|
2015-08-26 08:25:26 +03:00
|
|
|
CLI.prototype.do_delete_instance = require('./do_delete_instance');
|
2015-08-26 06:25:00 +03:00
|
|
|
CLI.prototype.do_ssh = require('./do_ssh');
|
2014-02-07 23:21:24 +02:00
|
|
|
|
2015-08-26 01:30:25 +03:00
|
|
|
// Packages
|
|
|
|
CLI.prototype.do_packages = require('./do_packages');
|
2015-08-26 02:12:35 +03:00
|
|
|
CLI.prototype.do_package = require('./do_package');
|
2015-08-26 01:30:25 +03:00
|
|
|
|
2015-08-26 02:12:35 +03:00
|
|
|
// Hidden commands
|
2015-08-26 01:30:25 +03:00
|
|
|
CLI.prototype.do_cloudapi = require('./do_cloudapi');
|
2015-08-26 02:12:35 +03:00
|
|
|
CLI.prototype.do_badger = require('./do_badger');
|
2014-02-07 23:21:24 +02:00
|
|
|
|
|
|
|
|
2015-07-26 08:45:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-25 22:14:16 +03:00
|
|
|
//---- mainline
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
var cli = new CLI();
|
|
|
|
cmdln.main(cli, {showNoCommandErr: false});
|
|
|
|
}
|
2014-02-07 23:21:24 +02:00
|
|
|
|
|
|
|
//---- exports
|
|
|
|
|
|
|
|
module.exports = CLI;
|