joyent/node-triton#68 Support specifying networks at instance create time

This commit is contained in:
Trent Mick 2015-12-31 09:55:31 -08:00
parent 04905ccc22
commit adb4c851b9
6 changed files with 60 additions and 22 deletions

View File

@ -1,8 +1,10 @@
# node-triton changelog
## 3.5.1 (not yet released)
## 3.6.0 (not yet released)
(nothing yet)
- #67 Add `triton create --network,-N NETWORK ...` option for specifying
networks for instance creation. "NETWORK" is a network id, name, or
short id; or a comma-separated array of networks.
## 3.5.0

View File

@ -152,6 +152,33 @@ var OPTIONS = [
];
// ---- other support stuff
function parseCommaSepStringNoEmpties(option, optstr, arg) {
// JSSTYLED
return arg.trim().split(/\s*,\s*/g)
.filter(function (part) { return part; });
}
cmdln.dashdash.addOptionType({
name: 'commaSepString',
takesArg: true,
helpArg: 'STRING',
parseArg: parseCommaSepStringNoEmpties
});
cmdln.dashdash.addOptionType({
name: 'arrayOfCommaSepString',
takesArg: true,
helpArg: 'STRING',
parseArg: parseCommaSepStringNoEmpties,
array: true,
arrayFlatten: true
});
//---- CLI class
function CLI() {

View File

@ -369,16 +369,24 @@ function do_create_instance(subcmd, opts, args, cb) {
});
},
function getNets(ctx, next) {
if (!opts.networks) {
if (!opts.network) {
return next();
}
self.tritonapi.getNetworks(opts.networks, function (err, nets) {
if (err) {
return next(err);
// TODO: want an error or warning on no networks?
ctx.nets = [];
vasync.forEachPipeline({
inputs: opts.network,
func: function getOneNetwork(name, nextNet) {
self.tritonapi.getNetwork(name, function (err, net) {
if (err) {
nextNet(err);
} else {
ctx.nets.push(net);
nextNet();
}
});
}
ctx.nets = nets;
next();
});
}, next);
},
function createInst(ctx, next) {
var createOpts = {
@ -548,12 +556,14 @@ do_create_instance.options = [
'(if first char is "{"), or a "@FILE" to have tags be ' +
'loaded from FILE. This option can be used multiple times.'
},
// XXX arrayOfCommaSepString dashdash type
//{
// names: ['networks', 'nets'],
// type: 'arrayOfCommaSepString',
// help: 'One or more (comma-separated) networks IDs.'
//},
{
names: ['network', 'N'],
type: 'arrayOfCommaSepString',
helpArg: 'NETWORK',
help: 'One or more comma-separated networks (ID, name or short id). ' +
'This option can be used multiple times.'
},
// XXX locality: near, far
{

View File

@ -1,15 +1,14 @@
{
"name": "triton",
"description": "Joyent Triton CLI and client (https://www.joyent.com/triton)",
"version": "3.5.1",
"version": "3.6.0",
"author": "Joyent (joyent.com)",
"dependencies": {
"assert-plus": "0.2.0",
"backoff": "2.4.1",
"bigspinner": "3.1.0",
"bunyan": "1.5.1",
"cmdln": "3.3.0",
"dashdash": "1.10.0",
"cmdln": "3.4.2",
"extsprintf": "1.0.2",
"lomstream": "1.1.0",
"mkdirp": "0.5.1",

View File

@ -13,7 +13,7 @@
*/
var assert = require('assert-plus');
var dashdash = require('dashdash');
var cmdln = require('cmdln');
var format = require('util').format;
var test = require('tape');
@ -180,7 +180,7 @@ test('metadataFromOpts', function (tt) {
tt.test(testName, function (t) {
debug('--', num);
debug('c: %j', c);
var parser = new dashdash.Parser({options: OPTIONS});
var parser = new cmdln.dashdash.Parser({options: OPTIONS});
var opts = parser.parse({argv: c.argv});
debug('opts: %j', opts);

View File

@ -13,7 +13,7 @@
*/
var assert = require('assert-plus');
var dashdash = require('dashdash');
var cmdln = require('cmdln');
var format = require('util').format;
var test = require('tape');
@ -146,7 +146,7 @@ test('tagsFromOpts', function (tt) {
tt.test(testName, function (t) {
debug('--', num);
debug('c: %j', c);
var parser = new dashdash.Parser({options: OPTIONS});
var parser = new cmdln.dashdash.Parser({options: OPTIONS});
var opts = parser.parse({argv: c.argv});
debug('opts: %j', opts);