'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
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 provision # triton create-machine ??
triton create # triton create-instance
triton create -p PKG [...] IMG
triton create -i IMG -p PKG [-n NAME] [...]
# 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 --shell # or whatever, repl
triton --shell # or whatever, repl

View File

@ -64,6 +64,7 @@ function CLI() {
'instance-audit',
{ group: 'Images' },
'images',
'image',
{ group: 'Other', unmatched: true }
]
});
@ -101,6 +102,7 @@ CLI.prototype.init = function (opts, args, callback) {
// Images
CLI.prototype.do_images = require('./do_images');
CLI.prototype.do_image = require('./do_image');
// Instances (aka VMs/containers/machines)
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
* - {String} path - URL endpoint to hit
* - {String} method - HTTP(s) request method
* @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;
if (typeof options === 'string')
options = {path: options};
@ -224,6 +224,8 @@ CloudAPI.prototype.request = function _request(options, callback) {
});
};
// ---- accounts
/**
@ -281,32 +283,32 @@ CloudAPI.prototype.listImages = function listImages(options, callback) {
assert.object(options, 'options');
assert.func(callback, 'callback');
var query = {
name: options.name,
os: options.os,
version: options.version,
public: options.public,
state: options.state,
owner: options.owner,
type: options.type
};
var endpoint = self._path(format('/%s/images', self.user), options);
self._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};
self._getAuthHeaders(function (hErr, headers) {
if (hErr) {
callback(hErr);
return;
}
var opts = {
path: self._path(format('/%s/images', self.user), query),
headers: headers
};
self.client.get(opts, function (err, req, res, body) {
if (err) {
callback(err, null, res);
} else {
callback(null, body, res);
}
});
/**
* <http://apidocs.joyent.com/cloudapi/#ListImages>
*
* @param {Object} options
* - id {UUID}
* @param {Function} callback of the form `function (err, image, res)`
*/
CloudAPI.prototype.getImage = function getImage(options, callback) {
if (callback === undefined) {
callback = options;
options = {};
}
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);
self.request(endpoint, function (err, req, res, body) {
if (err) {
callback(err);
return;
}
callback(null, body);
self._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};

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.'
}
];
do_images.help = (
'List images.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} images\n'
+ '\n'
+ '{{options}}'
);
do_images.help = (
/* BEGIN JSSTYLED */
'List images.\n' +
'\n' +
'Usage:\n' +
' {{name}} list [<options>] [<filters>]\n' +
' {{name}} images [<options>] [<filters>]\n' +
'\n' +
'Filters:\n' +
' FIELD=VALUE Field equality filter. Supported fields: \n' +