'triton image ID', update TODO.txt

This commit is contained in:
Trent Mick 2015-08-25 15:47:29 -07:00
parent 7afaadbd29
commit 0987881887
5 changed files with 112 additions and 55 deletions

View File

@ -1,26 +1,26 @@
# today # today
triton triton instances|insts # list machines
triton instance|inst ID|NAME|UNIQUE-NAME-SUBSTRING # get machine
# -1 for unique match, a la 'vmadm lookup -1'
triton -v # bunyan trace logging
triton vms|containers|machines # list machines
triton vm|container|machine ID|ALIAS # get machine
# -1 for unique match
triton images # list
triton packages # list
triton image IMAGE
triton package PACKAGE triton package PACKAGE
triton provision # triton create-machine ?? triton create # triton create-instance
triton create -p PKG [...] IMG triton create -p PKG [...] IMG
triton create -i IMG -p PKG [-n NAME] [...] triton create -i IMG -p PKG [-n NAME] [...]
# example: triton create base64 -p t4-standard-1g # example: triton create base64 -p t4-standard-1g
# DONE
triton
triton -v # bunyan trace logging
triton images # list images
triton packages # list packages
triton image IMAGE # get image
@ -86,4 +86,4 @@ For today: only the implicit 'env' profile.
triton config get|set|list # see 'npm config' triton config get|set|list # see 'npm config'
triton --shell # or whatever, repl triton --shell # or whatever, repl

View File

@ -64,6 +64,7 @@ function CLI() {
'instance-audit', 'instance-audit',
{ group: 'Images' }, { group: 'Images' },
'images', 'images',
'image',
{ group: 'Other', unmatched: true } { group: 'Other', unmatched: true }
] ]
}); });
@ -101,6 +102,7 @@ CLI.prototype.init = function (opts, args, callback) {
// Images // Images
CLI.prototype.do_images = require('./do_images'); CLI.prototype.do_images = require('./do_images');
CLI.prototype.do_image = require('./do_image');
// Instances (aka VMs/containers/machines) // Instances (aka VMs/containers/machines)
CLI.prototype.do_create = require('./do_create'); CLI.prototype.do_create = require('./do_create');

View File

@ -194,14 +194,14 @@ CloudAPI.prototype._path = function _path(subpath /*, qparams, ... */) {
/** /**
* cloud API requset wrapper - modeled after http.request * Cloud API request wrapper - modeled after http.request
* *
* @param {Object|String} options - object or string for endpoint * @param {Object|String} options - object or string for endpoint
* - {String} path - URL endpoint to hit * - {String} path - URL endpoint to hit
* - {String} method - HTTP(s) request method * - {String} method - HTTP(s) request method
* @param {Function} callback passed via the restify client * @param {Function} callback passed via the restify client
*/ */
CloudAPI.prototype.request = function _request(options, callback) { CloudAPI.prototype._request = function _request(options, callback) {
var self = this; var self = this;
if (typeof options === 'string') if (typeof options === 'string')
options = {path: options}; options = {path: options};
@ -224,6 +224,8 @@ CloudAPI.prototype.request = function _request(options, callback) {
}); });
}; };
// ---- accounts // ---- accounts
/** /**
@ -281,32 +283,32 @@ CloudAPI.prototype.listImages = function listImages(options, callback) {
assert.object(options, 'options'); assert.object(options, 'options');
assert.func(callback, 'callback'); assert.func(callback, 'callback');
var query = { var endpoint = self._path(format('/%s/images', self.user), options);
name: options.name, self._request(endpoint, function (err, req, res, body) {
os: options.os, callback(err, body, res);
version: options.version, });
public: options.public, };
state: options.state,
owner: options.owner,
type: options.type
};
self._getAuthHeaders(function (hErr, headers) {
if (hErr) { /**
callback(hErr); * <http://apidocs.joyent.com/cloudapi/#ListImages>
return; *
} * @param {Object} options
var opts = { * - id {UUID}
path: self._path(format('/%s/images', self.user), query), * @param {Function} callback of the form `function (err, image, res)`
headers: headers */
}; CloudAPI.prototype.getImage = function getImage(options, callback) {
self.client.get(opts, function (err, req, res, body) { if (callback === undefined) {
if (err) { callback = options;
callback(err, null, res); options = {};
} else { }
callback(null, body, res); assert.object(options, 'options');
} assert.uuid(options.id, 'ID');
}); assert.func(callback, 'callback');
var endpoint = this._path(format('/%s/images/%s', this.user, options.id));
this._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
}); });
}; };
@ -439,12 +441,8 @@ CloudAPI.prototype.listPackages = function listPackages(options, callback) {
} }
var endpoint = self._path(format('/%s/packages', self.user), options); var endpoint = self._path(format('/%s/packages', self.user), options);
self.request(endpoint, function (err, req, res, body) { self._request(endpoint, function (err, req, res, body) {
if (err) { callback(err, body, res);
callback(err);
return;
}
callback(null, body);
}); });
}; };

65
lib/do_image.js Normal file
View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2015 Joyent Inc. All rights reserved.
*
* `triton image ...`
*/
var format = require('util').format;
var tabula = require('tabula');
var errors = require('./errors');
function do_image(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 1) {
return callback(new errors.UsageError(format(
'incorrect number of args (%d): %s', args.length, args.join(' '))));
}
var getOpts = {
id: args[0]
};
this.triton.cloudapi.getImage(getOpts, function onRes(err, img, res) {
if (err) {
return callback(err);
}
if (opts.json) {
console.log(JSON.stringify(img));
} else {
console.log(JSON.stringify(img, null, 4));
}
callback();
});
};
do_image.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON stream output.'
}
];
do_image.help = (
/* BEGIN JSSTYLED */
'Get an image.\n' +
'\n' +
'Note: Currently this dumps prettified JSON by default. That might change\n' +
'in the future. Use "-j" to explicitly get JSON output.\n' +
'\n' +
'Usage:\n' +
' {{name}} image [<options>] ID\n' +
'\n' +
'{{options}}'
/* END JSSTYLED */
);
module.exports = do_image;

View File

@ -121,20 +121,12 @@ do_images.options = [
help: 'JSON stream output.' help: 'JSON stream output.'
} }
]; ];
do_images.help = (
'List images.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} images\n'
+ '\n'
+ '{{options}}'
);
do_images.help = ( do_images.help = (
/* BEGIN JSSTYLED */ /* BEGIN JSSTYLED */
'List images.\n' + 'List images.\n' +
'\n' + '\n' +
'Usage:\n' + 'Usage:\n' +
' {{name}} list [<options>] [<filters>]\n' + ' {{name}} images [<options>] [<filters>]\n' +
'\n' + '\n' +
'Filters:\n' + 'Filters:\n' +
' FIELD=VALUE Field equality filter. Supported fields: \n' + ' FIELD=VALUE Field equality filter. Supported fields: \n' +