clistyle: part of 'triton instance ...'
This commit is contained in:
		
							parent
							
								
									96216c6e61
								
							
						
					
					
						commit
						e21635eaa3
					
				@ -194,10 +194,9 @@ function CLI() {
 | 
				
			|||||||
            'help',
 | 
					            'help',
 | 
				
			||||||
            'profile',
 | 
					            'profile',
 | 
				
			||||||
            { group: 'Instances (aka VMs/Machines/Containers)' },
 | 
					            { group: 'Instances (aka VMs/Machines/Containers)' },
 | 
				
			||||||
            'create-instance',
 | 
					 | 
				
			||||||
            'instances',
 | 
					 | 
				
			||||||
            'instance',
 | 
					            'instance',
 | 
				
			||||||
            'instance-audit',
 | 
					            'instances',
 | 
				
			||||||
 | 
					            'create',
 | 
				
			||||||
            'start-instance',
 | 
					            'start-instance',
 | 
				
			||||||
            'stop-instance',
 | 
					            'stop-instance',
 | 
				
			||||||
            'reboot-instance',
 | 
					            'reboot-instance',
 | 
				
			||||||
@ -349,8 +348,7 @@ CLI.prototype.do_image = require('./do_image');
 | 
				
			|||||||
// Instances (aka VMs/containers/machines)
 | 
					// Instances (aka VMs/containers/machines)
 | 
				
			||||||
CLI.prototype.do_instance = require('./do_instance');
 | 
					CLI.prototype.do_instance = require('./do_instance');
 | 
				
			||||||
CLI.prototype.do_instances = require('./do_instances');
 | 
					CLI.prototype.do_instances = require('./do_instances');
 | 
				
			||||||
CLI.prototype.do_create_instance = require('./do_create_instance');
 | 
					CLI.prototype.do_create = require('./do_create');
 | 
				
			||||||
CLI.prototype.do_instance_audit = require('./do_instance_audit');
 | 
					 | 
				
			||||||
CLI.prototype.do_stop_instance = require('./do_startstop_instance')('stop');
 | 
					CLI.prototype.do_stop_instance = require('./do_startstop_instance')('stop');
 | 
				
			||||||
CLI.prototype.do_start_instance = require('./do_startstop_instance')('start');
 | 
					CLI.prototype.do_start_instance = require('./do_startstop_instance')('start');
 | 
				
			||||||
CLI.prototype.do_reboot_instance = require('./do_startstop_instance')('reboot');
 | 
					CLI.prototype.do_reboot_instance = require('./do_startstop_instance')('reboot');
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								lib/do_create.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								lib/do_create.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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 2015 Joyent, Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * `triton create ...` bwcompat shortcut for `triton instance create ...`.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function do_create(subcmd, opts, args, callback) {
 | 
				
			||||||
 | 
					    var subcmdArgv = ['node', 'triton', 'instance', 'create'].concat(args);
 | 
				
			||||||
 | 
					    this.dispatch('instance', subcmdArgv, callback);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_create.help = [
 | 
				
			||||||
 | 
					    'A shortcut for "triton instance create".',
 | 
				
			||||||
 | 
					    '',
 | 
				
			||||||
 | 
					    'Usage:',
 | 
				
			||||||
 | 
					    '    {{name}} create ...'
 | 
				
			||||||
 | 
					].join('\n');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = do_create;
 | 
				
			||||||
@ -7,7 +7,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton images ...` bwcompat shortcut for `triton images list ...`.
 | 
					 * `triton images ...` bwcompat shortcut for `triton image list ...`.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_images(subcmd, opts, args, callback) {
 | 
					function do_images(subcmd, opts, args, callback) {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,14 +7,14 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton instance-audit ...`
 | 
					 * `triton instance audit ...`
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var format = require('util').format;
 | 
					var format = require('util').format;
 | 
				
			||||||
var tabula = require('tabula');
 | 
					var tabula = require('tabula');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var common = require('./common');
 | 
					var common = require('../common');
 | 
				
			||||||
var errors = require('./errors');
 | 
					var errors = require('../errors');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// columns default without -o
 | 
					// columns default without -o
 | 
				
			||||||
var columnsDefault = 'shortid,time,action,success';
 | 
					var columnsDefault = 'shortid,time,action,success';
 | 
				
			||||||
@ -25,7 +25,8 @@ var columnsDefaultLong = 'id,time,action,success';
 | 
				
			|||||||
// sort default with -s
 | 
					// sort default with -s
 | 
				
			||||||
var sortDefault = 'id,time';
 | 
					var sortDefault = 'id,time';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_instance_audit(subcmd, opts, args, cb) {
 | 
					
 | 
				
			||||||
 | 
					function do_audit(subcmd, opts, args, cb) {
 | 
				
			||||||
    var self = this;
 | 
					    var self = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (opts.help) {
 | 
					    if (opts.help) {
 | 
				
			||||||
@ -53,7 +54,7 @@ function do_instance_audit(subcmd, opts, args, cb) {
 | 
				
			|||||||
        uuid = arg;
 | 
					        uuid = arg;
 | 
				
			||||||
        go1();
 | 
					        go1();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        self.tritonapi.getInstance(arg, function (err, inst) {
 | 
					        self.top.tritonapi.getInstance(arg, function (err, inst) {
 | 
				
			||||||
            if (err) {
 | 
					            if (err) {
 | 
				
			||||||
                cb(err);
 | 
					                cb(err);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@ -64,7 +65,7 @@ function do_instance_audit(subcmd, opts, args, cb) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function go1() {
 | 
					    function go1() {
 | 
				
			||||||
        self.tritonapi.cloudapi.machineAudit(uuid, function (err, audit) {
 | 
					        self.top.tritonapi.cloudapi.machineAudit(uuid, function (err, audit) {
 | 
				
			||||||
            if (err) {
 | 
					            if (err) {
 | 
				
			||||||
                cb(err);
 | 
					                cb(err);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@ -90,9 +91,9 @@ function do_instance_audit(subcmd, opts, args, cb) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_instance_audit.aliases = ['audit'];
 | 
					do_audit.aliases = ['audit'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_instance_audit.options = [
 | 
					do_audit.options = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        names: ['help', 'h'],
 | 
					        names: ['help', 'h'],
 | 
				
			||||||
        type: 'bool',
 | 
					        type: 'bool',
 | 
				
			||||||
@ -103,13 +104,13 @@ do_instance_audit.options = [
 | 
				
			|||||||
    sortDefault: sortDefault
 | 
					    sortDefault: sortDefault
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_instance_audit.help = (
 | 
					do_audit.help = (
 | 
				
			||||||
    'List instance actions.\n'
 | 
					    'List instance actions.\n'
 | 
				
			||||||
    + '\n'
 | 
					    + '\n'
 | 
				
			||||||
    + 'Usage:\n'
 | 
					    + 'Usage:\n'
 | 
				
			||||||
    + '     {{name}} instance-audit <machine>\n'
 | 
					    + '     {{name}} audit <alias|id>\n'
 | 
				
			||||||
    + '\n'
 | 
					    + '\n'
 | 
				
			||||||
    + '{{options}}'
 | 
					    + '{{options}}'
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = do_instance_audit;
 | 
					module.exports = do_audit;
 | 
				
			||||||
@ -7,7 +7,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton create ...`
 | 
					 * `triton instance create ...`
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var assert = require('assert-plus');
 | 
					var assert = require('assert-plus');
 | 
				
			||||||
@ -18,9 +18,9 @@ var tabula = require('tabula');
 | 
				
			|||||||
var tilde = require('tilde-expansion');
 | 
					var tilde = require('tilde-expansion');
 | 
				
			||||||
var vasync = require('vasync');
 | 
					var vasync = require('vasync');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var common = require('./common');
 | 
					var common = require('../common');
 | 
				
			||||||
var distractions = require('./distractions');
 | 
					var distractions = require('../distractions');
 | 
				
			||||||
var errors = require('./errors');
 | 
					var errors = require('../errors');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ---- loading/parsing metadata (and tags) from relevant options
 | 
					// ---- loading/parsing metadata (and tags) from relevant options
 | 
				
			||||||
@ -293,7 +293,7 @@ function _addMetadatumFromFile(ilk, metadata, key, file, from, cb) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// ---- the command
 | 
					// ---- the command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_create_instance(subcmd, opts, args, cb) {
 | 
					function do_create(subcmd, opts, args, cb) {
 | 
				
			||||||
    var self = this;
 | 
					    var self = this;
 | 
				
			||||||
    if (opts.help) {
 | 
					    if (opts.help) {
 | 
				
			||||||
        this.do_help('help', {}, [subcmd], cb);
 | 
					        this.do_help('help', {}, [subcmd], cb);
 | 
				
			||||||
@ -302,8 +302,8 @@ function do_create_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
        return cb(new errors.UsageError('incorrect number of args'));
 | 
					        return cb(new errors.UsageError('incorrect number of args'));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var log = this.tritonapi.log;
 | 
					    var log = this.top.log;
 | 
				
			||||||
    var cloudapi = this.tritonapi.cloudapi;
 | 
					    var cloudapi = this.top.tritonapi.cloudapi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vasync.pipeline({arg: {}, funcs: [
 | 
					    vasync.pipeline({arg: {}, funcs: [
 | 
				
			||||||
        function loadMetadata(ctx, next) {
 | 
					        function loadMetadata(ctx, next) {
 | 
				
			||||||
@ -338,7 +338,7 @@ function do_create_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
                name: args[0],
 | 
					                name: args[0],
 | 
				
			||||||
                useCache: true
 | 
					                useCache: true
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            self.tritonapi.getImage(_opts, function (err, img) {
 | 
					            self.top.tritonapi.getImage(_opts, function (err, img) {
 | 
				
			||||||
                if (err) {
 | 
					                if (err) {
 | 
				
			||||||
                    return next(err);
 | 
					                    return next(err);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -359,7 +359,7 @@ function do_create_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.tritonapi.getPackage(id, function (err, pkg) {
 | 
					            self.top.tritonapi.getPackage(id, function (err, pkg) {
 | 
				
			||||||
                if (err) {
 | 
					                if (err) {
 | 
				
			||||||
                    return next(err);
 | 
					                    return next(err);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -377,7 +377,7 @@ function do_create_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
            vasync.forEachPipeline({
 | 
					            vasync.forEachPipeline({
 | 
				
			||||||
                inputs: opts.network,
 | 
					                inputs: opts.network,
 | 
				
			||||||
                func: function getOneNetwork(name, nextNet) {
 | 
					                func: function getOneNetwork(name, nextNet) {
 | 
				
			||||||
                    self.tritonapi.getNetwork(name, function (err, net) {
 | 
					                    self.top.tritonapi.getNetwork(name, function (err, net) {
 | 
				
			||||||
                        if (err) {
 | 
					                        if (err) {
 | 
				
			||||||
                            nextNet(err);
 | 
					                            nextNet(err);
 | 
				
			||||||
                        } else {
 | 
					                        } else {
 | 
				
			||||||
@ -497,7 +497,7 @@ function do_create_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_create_instance.options = [
 | 
					do_create.options = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        names: ['help', 'h'],
 | 
					        names: ['help', 'h'],
 | 
				
			||||||
        type: 'bool',
 | 
					        type: 'bool',
 | 
				
			||||||
@ -587,25 +587,25 @@ do_create_instance.options = [
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_create_instance.help = (
 | 
					do_create.help = (
 | 
				
			||||||
    /* BEGIN JSSTYLED */
 | 
					    /* BEGIN JSSTYLED */
 | 
				
			||||||
    'Create a new instance.\n' +
 | 
					    'Create a new instance.\n' +
 | 
				
			||||||
    '\n' +
 | 
					    '\n' +
 | 
				
			||||||
    'Usage:\n' +
 | 
					    'Usage:\n' +
 | 
				
			||||||
    '    {{name}} create-instance [<options>] IMAGE PACKAGE\n' +
 | 
					    '    {{name}} create [<options>] IMAGE PACKAGE\n' +
 | 
				
			||||||
    '\n' +
 | 
					    '\n' +
 | 
				
			||||||
    '{{options}}'
 | 
					    '{{options}}'
 | 
				
			||||||
    /* END JSSTYLED */
 | 
					    /* END JSSTYLED */
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_create_instance.helpOpts = {
 | 
					do_create.helpOpts = {
 | 
				
			||||||
    maxHelpCol: 18
 | 
					    maxHelpCol: 18
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_create_instance.aliases = ['create'];
 | 
					do_create.aliases = ['create'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = do_create_instance;
 | 
					module.exports = do_create;
 | 
				
			||||||
do_create_instance.metadataFromOpts = metadataFromOpts; // export for testing
 | 
					do_create.metadataFromOpts = metadataFromOpts; // export for testing
 | 
				
			||||||
do_create_instance.tagsFromOpts = tagsFromOpts; // export for testing
 | 
					do_create.tagsFromOpts = tagsFromOpts; // export for testing
 | 
				
			||||||
@ -7,19 +7,19 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton instance ...`
 | 
					 * `triton instance get ...`
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var common = require('./common');
 | 
					var common = require('../common');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_instance(subcmd, opts, args, cb) {
 | 
					function do_get(subcmd, opts, args, cb) {
 | 
				
			||||||
    if (opts.help) {
 | 
					    if (opts.help) {
 | 
				
			||||||
        return this.do_help('help', {}, [subcmd], cb);
 | 
					        return this.do_help('help', {}, [subcmd], cb);
 | 
				
			||||||
    } else if (args.length !== 1) {
 | 
					    } else if (args.length !== 1) {
 | 
				
			||||||
        return cb(new Error('invalid args: ' + args));
 | 
					        return cb(new Error('invalid args: ' + args));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.tritonapi.getInstance(args[0], function (err, inst) {
 | 
					    this.top.tritonapi.getInstance(args[0], function (err, inst) {
 | 
				
			||||||
        if (err) {
 | 
					        if (err) {
 | 
				
			||||||
            return cb(err);
 | 
					            return cb(err);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -33,7 +33,7 @@ function do_instance(subcmd, opts, args, cb) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_instance.options = [
 | 
					do_get.options = [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        names: ['help', 'h'],
 | 
					        names: ['help', 'h'],
 | 
				
			||||||
        type: 'bool',
 | 
					        type: 'bool',
 | 
				
			||||||
@ -45,7 +45,7 @@ do_instance.options = [
 | 
				
			|||||||
        help: 'JSON output.'
 | 
					        help: 'JSON output.'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
do_instance.help = (
 | 
					do_get.help = (
 | 
				
			||||||
    /* BEGIN JSSTYLED */
 | 
					    /* BEGIN JSSTYLED */
 | 
				
			||||||
    'Get an instance.\n'
 | 
					    'Get an instance.\n'
 | 
				
			||||||
    + '\n'
 | 
					    + '\n'
 | 
				
			||||||
@ -59,6 +59,4 @@ do_instance.help = (
 | 
				
			|||||||
    /* END JSSTYLED */
 | 
					    /* END JSSTYLED */
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
do_instance.aliases = ['inst'];
 | 
					module.exports = do_get;
 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports = do_instance;
 | 
					 | 
				
			||||||
							
								
								
									
										156
									
								
								lib/do_instance/do_list.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								lib/do_instance/do_list.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,156 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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 2015 Joyent, Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * `triton instance list ...`
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var format = require('util').format;
 | 
				
			||||||
 | 
					var tabula = require('tabula');
 | 
				
			||||||
 | 
					var vasync = require('vasync');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var common = require('../common');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// to be passed as query string args to /my/machines
 | 
				
			||||||
 | 
					var validFilters = [
 | 
				
			||||||
 | 
					    'name',
 | 
				
			||||||
 | 
					    'image',
 | 
				
			||||||
 | 
					    'state',
 | 
				
			||||||
 | 
					    'memory',
 | 
				
			||||||
 | 
					    'tombstone',
 | 
				
			||||||
 | 
					    'credentials'
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// columns default without -o
 | 
				
			||||||
 | 
					var columnsDefault = 'shortid,name,img,state,primaryIp,ago';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// columns default with -l
 | 
				
			||||||
 | 
					var columnsDefaultLong = 'id,name,img,package,state,primaryIp,created';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// sort default with -s
 | 
				
			||||||
 | 
					var sortDefault = 'created';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function do_list(subcmd, opts, args, callback) {
 | 
				
			||||||
 | 
					    var self = this;
 | 
				
			||||||
 | 
					    if (opts.help) {
 | 
				
			||||||
 | 
					        this.do_help('help', {}, [subcmd], callback);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var columns = columnsDefault;
 | 
				
			||||||
 | 
					    if (opts.o) {
 | 
				
			||||||
 | 
					        columns = opts.o;
 | 
				
			||||||
 | 
					    } else if (opts.long) {
 | 
				
			||||||
 | 
					        columns = columnsDefaultLong;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    columns = columns.split(',');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var sort = opts.s.split(',');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var listOpts;
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        listOpts = common.kvToObj(args, validFilters);
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					        callback(e);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var imgs;
 | 
				
			||||||
 | 
					    var insts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vasync.parallel({funcs: [
 | 
				
			||||||
 | 
					        function getTheImages(next) {
 | 
				
			||||||
 | 
					            self.top.tritonapi.listImages({useCache: true},
 | 
				
			||||||
 | 
					                    function (err, _imgs) {
 | 
				
			||||||
 | 
					                if (err) {
 | 
				
			||||||
 | 
					                    next(err);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    imgs = _imgs;
 | 
				
			||||||
 | 
					                    next();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        function getTheMachines(next) {
 | 
				
			||||||
 | 
					            self.top.tritonapi.cloudapi.listMachines(listOpts,
 | 
				
			||||||
 | 
					                    function (err, _insts) {
 | 
				
			||||||
 | 
					                if (err) {
 | 
				
			||||||
 | 
					                    next(err);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    insts = _insts;
 | 
				
			||||||
 | 
					                    next();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]}, function (err, results) {
 | 
				
			||||||
 | 
					        /*
 | 
				
			||||||
 | 
					         * Error handling: vasync.parallel's `err` is always a MultiError. We
 | 
				
			||||||
 | 
					         * want to prefer the `getTheMachines` err, e.g. if both get a
 | 
				
			||||||
 | 
					         * self-signed cert error.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        if (err) {
 | 
				
			||||||
 | 
					            err = results.operations[1].err || err;
 | 
				
			||||||
 | 
					            return callback(err);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // map "uuid" => "image_name"
 | 
				
			||||||
 | 
					        var imgmap = {};
 | 
				
			||||||
 | 
					        imgs.forEach(function (img) {
 | 
				
			||||||
 | 
					            imgmap[img.id] = format('%s@%s', img.name, img.version);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Add extra fields for nice output.
 | 
				
			||||||
 | 
					        // XXX FWIW, the "extra fields" for images and packages are not added
 | 
				
			||||||
 | 
					        //     for `opts.json`. Thoughts? We should be consistent there. --TM
 | 
				
			||||||
 | 
					        var now = new Date();
 | 
				
			||||||
 | 
					        insts.forEach(function (inst) {
 | 
				
			||||||
 | 
					            var created = new Date(inst.created);
 | 
				
			||||||
 | 
					            inst.ago = common.longAgo(created, now);
 | 
				
			||||||
 | 
					            inst.img = imgmap[inst.image] || inst.image;
 | 
				
			||||||
 | 
					            inst.shortid = inst.id.split('-', 1)[0];
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (opts.json) {
 | 
				
			||||||
 | 
					            common.jsonStream(insts);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            tabula(insts, {
 | 
				
			||||||
 | 
					                skipHeader: opts.H,
 | 
				
			||||||
 | 
					                columns: columns,
 | 
				
			||||||
 | 
					                sort: sort,
 | 
				
			||||||
 | 
					                dottedLookup: true
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        callback();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_list.options = [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        names: ['help', 'h'],
 | 
				
			||||||
 | 
					        type: 'bool',
 | 
				
			||||||
 | 
					        help: 'Show this help.'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					].concat(common.getCliTableOptions({
 | 
				
			||||||
 | 
					    includeLong: true,
 | 
				
			||||||
 | 
					    sortDefault: sortDefault
 | 
				
			||||||
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_list.help = (
 | 
				
			||||||
 | 
					    'List instances.\n'
 | 
				
			||||||
 | 
					    + '\n'
 | 
				
			||||||
 | 
					    + 'Usage:\n'
 | 
				
			||||||
 | 
					    + '     {{name}} instance list [<filters>...]\n'
 | 
				
			||||||
 | 
					    + '\n'
 | 
				
			||||||
 | 
					    + '{{options}}'
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					do_list.aliases = ['ls'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = do_list;
 | 
				
			||||||
							
								
								
									
										56
									
								
								lib/do_instance/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								lib/do_instance/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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 2015 Joyent, Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * `triton instance ...`
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Cmdln = require('cmdln').Cmdln;
 | 
				
			||||||
 | 
					var util = require('util');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ---- CLI class
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function InstanceCLI(top) {
 | 
				
			||||||
 | 
					    this.top = top;
 | 
				
			||||||
 | 
					    Cmdln.call(this, {
 | 
				
			||||||
 | 
					        name: top.name + ' instance',
 | 
				
			||||||
 | 
					        /* BEGIN JSSTYLED */
 | 
				
			||||||
 | 
					        desc: [
 | 
				
			||||||
 | 
					            'List, get, create and manage Triton instances.'
 | 
				
			||||||
 | 
					        ].join('\n'),
 | 
				
			||||||
 | 
					        /* END JSSTYLED */
 | 
				
			||||||
 | 
					        helpOpts: {
 | 
				
			||||||
 | 
					            minHelpCol: 24 /* line up with option help */
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        helpSubcmds: [
 | 
				
			||||||
 | 
					            'help',
 | 
				
			||||||
 | 
					            'list',
 | 
				
			||||||
 | 
					            'get',
 | 
				
			||||||
 | 
					            'create',
 | 
				
			||||||
 | 
					            'audit'
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					util.inherits(InstanceCLI, Cmdln);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					InstanceCLI.prototype.init = function init(opts, args, cb) {
 | 
				
			||||||
 | 
					    this.log = this.top.log;
 | 
				
			||||||
 | 
					    Cmdln.prototype.init.apply(this, arguments);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					InstanceCLI.prototype.do_list = require('./do_list');
 | 
				
			||||||
 | 
					InstanceCLI.prototype.do_get = require('./do_get');
 | 
				
			||||||
 | 
					InstanceCLI.prototype.do_create = require('./do_create');
 | 
				
			||||||
 | 
					InstanceCLI.prototype.do_audit = require('./do_audit');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					InstanceCLI.aliases = ['inst'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = InstanceCLI;
 | 
				
			||||||
@ -7,149 +7,21 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton instances ...`
 | 
					 * `triton instances ...` bwcompat shortcut for `triton instance list ...`.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var format = require('util').format;
 | 
					 | 
				
			||||||
var tabula = require('tabula');
 | 
					 | 
				
			||||||
var vasync = require('vasync');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var common = require('./common');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// to be passed as query string args to /my/machines
 | 
					 | 
				
			||||||
var validFilters = [
 | 
					 | 
				
			||||||
    'name',
 | 
					 | 
				
			||||||
    'image',
 | 
					 | 
				
			||||||
    'state',
 | 
					 | 
				
			||||||
    'memory',
 | 
					 | 
				
			||||||
    'tombstone',
 | 
					 | 
				
			||||||
    'credentials'
 | 
					 | 
				
			||||||
];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// columns default without -o
 | 
					 | 
				
			||||||
var columnsDefault = 'shortid,name,img,state,primaryIp,ago';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// columns default with -l
 | 
					 | 
				
			||||||
var columnsDefaultLong = 'id,name,img,package,state,primaryIp,created';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// sort default with -s
 | 
					 | 
				
			||||||
var sortDefault = 'created';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function do_instances(subcmd, opts, args, callback) {
 | 
					function do_instances(subcmd, opts, args, callback) {
 | 
				
			||||||
    var self = this;
 | 
					    var subcmdArgv = ['node', 'triton', 'instance', 'list'].concat(args);
 | 
				
			||||||
    if (opts.help) {
 | 
					    this.dispatch('instance', subcmdArgv, callback);
 | 
				
			||||||
        this.do_help('help', {}, [subcmd], callback);
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var columns = columnsDefault;
 | 
					do_instances.help = [
 | 
				
			||||||
    if (opts.o) {
 | 
					    'A shortcut for "triton instance list".',
 | 
				
			||||||
        columns = opts.o;
 | 
					    '',
 | 
				
			||||||
    } else if (opts.long) {
 | 
					    'Usage:',
 | 
				
			||||||
        columns = columnsDefaultLong;
 | 
					    '    {{name}} instances ...'
 | 
				
			||||||
    }
 | 
					].join('\n');
 | 
				
			||||||
    columns = columns.split(',');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var sort = opts.s.split(',');
 | 
					do_instances.aliases = ['insts', 'ls'];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    var listOpts;
 | 
					 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
        listOpts = common.kvToObj(args, validFilters);
 | 
					 | 
				
			||||||
    } catch (e) {
 | 
					 | 
				
			||||||
        callback(e);
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    var imgs;
 | 
					 | 
				
			||||||
    var insts;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    vasync.parallel({funcs: [
 | 
					 | 
				
			||||||
        function getTheImages(next) {
 | 
					 | 
				
			||||||
            self.tritonapi.listImages({useCache: true}, function (err, _imgs) {
 | 
					 | 
				
			||||||
                if (err) {
 | 
					 | 
				
			||||||
                    next(err);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    imgs = _imgs;
 | 
					 | 
				
			||||||
                    next();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        function getTheMachines(next) {
 | 
					 | 
				
			||||||
            self.tritonapi.cloudapi.listMachines(listOpts,
 | 
					 | 
				
			||||||
                    function (err, _insts) {
 | 
					 | 
				
			||||||
                if (err) {
 | 
					 | 
				
			||||||
                    next(err);
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    insts = _insts;
 | 
					 | 
				
			||||||
                    next();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    ]}, function (err, results) {
 | 
					 | 
				
			||||||
        /*
 | 
					 | 
				
			||||||
         * Error handling: vasync.parallel's `err` is always a MultiError. We
 | 
					 | 
				
			||||||
         * want to prefer the `getTheMachines` err, e.g. if both get a
 | 
					 | 
				
			||||||
         * self-signed cert error.
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
        if (err) {
 | 
					 | 
				
			||||||
            err = results.operations[1].err || err;
 | 
					 | 
				
			||||||
            return callback(err);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // map "uuid" => "image_name"
 | 
					 | 
				
			||||||
        var imgmap = {};
 | 
					 | 
				
			||||||
        imgs.forEach(function (img) {
 | 
					 | 
				
			||||||
            imgmap[img.id] = format('%s@%s', img.name, img.version);
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Add extra fields for nice output.
 | 
					 | 
				
			||||||
        // XXX FWIW, the "extra fields" for images and packages are not added
 | 
					 | 
				
			||||||
        //     for `opts.json`. Thoughts? We should be consistent there. --TM
 | 
					 | 
				
			||||||
        var now = new Date();
 | 
					 | 
				
			||||||
        insts.forEach(function (inst) {
 | 
					 | 
				
			||||||
            var created = new Date(inst.created);
 | 
					 | 
				
			||||||
            inst.ago = common.longAgo(created, now);
 | 
					 | 
				
			||||||
            inst.img = imgmap[inst.image] || inst.image;
 | 
					 | 
				
			||||||
            inst.shortid = inst.id.split('-', 1)[0];
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (opts.json) {
 | 
					 | 
				
			||||||
            common.jsonStream(insts);
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            tabula(insts, {
 | 
					 | 
				
			||||||
                skipHeader: opts.H,
 | 
					 | 
				
			||||||
                columns: columns,
 | 
					 | 
				
			||||||
                sort: sort,
 | 
					 | 
				
			||||||
                dottedLookup: true
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        callback();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
do_instances.options = [
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        names: ['help', 'h'],
 | 
					 | 
				
			||||||
        type: 'bool',
 | 
					 | 
				
			||||||
        help: 'Show this help.'
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
].concat(common.getCliTableOptions({
 | 
					 | 
				
			||||||
    includeLong: true,
 | 
					 | 
				
			||||||
    sortDefault: sortDefault
 | 
					 | 
				
			||||||
}));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
do_instances.help = (
 | 
					 | 
				
			||||||
    'List instances.\n'
 | 
					 | 
				
			||||||
    + '\n'
 | 
					 | 
				
			||||||
    + 'Usage:\n'
 | 
					 | 
				
			||||||
    + '     {{name}} instances [<filters>...]\n'
 | 
					 | 
				
			||||||
    + '\n'
 | 
					 | 
				
			||||||
    + '{{options}}'
 | 
					 | 
				
			||||||
);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
do_instances.aliases = ['insts', 'list', 'ls'];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = do_instances;
 | 
					module.exports = do_instances;
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright 2015 Joyent, Inc.
 | 
					 * Copyright 2015 Joyent, Inc.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * `triton packages ...` bwcompat shortcut for `triton packages list ...`.
 | 
					 * `triton packages ...` bwcompat shortcut for `triton package list ...`.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function do_packages(subcmd, opts, args, callback) {
 | 
					function do_packages(subcmd, opts, args, callback) {
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,8 @@ var cmdln = require('cmdln');
 | 
				
			|||||||
var format = require('util').format;
 | 
					var format = require('util').format;
 | 
				
			||||||
var test = require('tape');
 | 
					var test = require('tape');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var metadataFromOpts = require('../../lib/do_create_instance').metadataFromOpts;
 | 
					var metadataFromOpts =
 | 
				
			||||||
 | 
					    require('../../lib/do_instance/do_create').metadataFromOpts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ---- globals
 | 
					// ---- globals
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@ var cmdln = require('cmdln');
 | 
				
			|||||||
var format = require('util').format;
 | 
					var format = require('util').format;
 | 
				
			||||||
var test = require('tape');
 | 
					var test = require('tape');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var tagsFromOpts = require('../../lib/do_create_instance').tagsFromOpts;
 | 
					var tagsFromOpts = require('../../lib/do_instance/do_create').tagsFromOpts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ---- globals
 | 
					// ---- globals
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user