triton create --dry-run
This commit is contained in:
parent
e61c6099b3
commit
d6ac9fed33
@ -170,6 +170,9 @@ function humanDurationFromMs(ms) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bits.length > 1 && bits[bits.length - 1].slice(-2) === 'ms') {
|
||||
bits.pop();
|
||||
}
|
||||
return bits.slice(0, 2).join('');
|
||||
}
|
||||
|
||||
|
106
lib/do_create.js
106
lib/do_create.js
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Joyent Inc. All rights reserved.
|
||||
*
|
||||
* `triton images ...`
|
||||
*/
|
||||
|
||||
var format = require('util').format;
|
||||
var tabula = require('tabula');
|
||||
|
||||
var errors = require('./errors');
|
||||
|
||||
|
||||
function do_create(subcmd, opts, args, callback) {
|
||||
if (opts.help) {
|
||||
this.do_help('help', {}, [subcmd], callback);
|
||||
return;
|
||||
} else if (args.length > 1) {
|
||||
return callback(new Error('too many args: ' + args));
|
||||
}
|
||||
var triton = this.triton;
|
||||
|
||||
// XXX The smarts here should move to Triton class.
|
||||
|
||||
assert.string(opts.image, '--image <img>');
|
||||
assert.string(opts['package'], '--package <pkg>');
|
||||
assert.number(opts.count)
|
||||
|
||||
// XXX
|
||||
/*
|
||||
* Should all this move into sdc.createMachine? yes
|
||||
*
|
||||
* - lookup image, package, networks from args
|
||||
* - assign names
|
||||
* - start provisions (slight stagger, max N at a time)
|
||||
* - return immediately, or '-w|--wait'
|
||||
*/
|
||||
async.series([
|
||||
function lookups(next) {
|
||||
async.parallel([
|
||||
//XXX
|
||||
//sdc.lookup(image)
|
||||
])
|
||||
},
|
||||
function provisions(next) {
|
||||
|
||||
},
|
||||
function wait(next) {
|
||||
next();
|
||||
}
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
do_create.options = [
|
||||
{
|
||||
names: ['help', 'h'],
|
||||
type: 'bool',
|
||||
help: 'Show this help.'
|
||||
},
|
||||
{
|
||||
names: ['dc', 'd'],
|
||||
type: 'string',
|
||||
helpArg: '<dc>',
|
||||
help: 'The datacenter in which to provision. Required if the current'
|
||||
+ ' profile includes more than one datacenter. Use `sdc profile`'
|
||||
+ ' to list profiles and `sdc dcs` to list available datacenters.'
|
||||
},
|
||||
{
|
||||
names: ['image', 'i'],
|
||||
type: 'string',
|
||||
helpArg: '<img>',
|
||||
help: 'The machine image with which to provision. Required.'
|
||||
},
|
||||
{
|
||||
names: ['package', 'p'],
|
||||
type: 'string',
|
||||
helpArg: '<pkg>',
|
||||
help: 'The package or instance type for the new machine(s). Required.'
|
||||
},
|
||||
{
|
||||
names: ['name', 'n'],
|
||||
type: 'string',
|
||||
helpArg: '<name>',
|
||||
help: 'A name for the machine. If not specified, a short random name'
|
||||
+ ' will be generated.',
|
||||
// TODO: for count>1 support '%d' code in name: foo0, foo1, ...
|
||||
},
|
||||
{
|
||||
names: ['count', 'c'],
|
||||
type: 'positiveInteger',
|
||||
'default': 1,
|
||||
helpArg: '<n>',
|
||||
help: 'The number of machines to provision. Default is 1.'
|
||||
},
|
||||
];
|
||||
do_create.help = (
|
||||
'Create a new instance.\n'
|
||||
+ '\n'
|
||||
+ 'Usage:\n'
|
||||
+ ' {{name}} create <options>\n'
|
||||
+ '\n'
|
||||
+ '{{options}}'
|
||||
);
|
||||
do_create.aliases = ['create-inst'];
|
||||
|
||||
module.exports = do_create;
|
@ -73,8 +73,21 @@ function do_create_instance(subcmd, opts, args, callback) {
|
||||
networks: ctx.nets && ctx.nets.map(
|
||||
function (net) { return net.id; })
|
||||
};
|
||||
log.trace({createOpts: createOpts}, 'create-instance createOpts');
|
||||
|
||||
log.trace({dryRun: opts.dry_run, createOpts: createOpts},
|
||||
'create-instance createOpts');
|
||||
ctx.start = Date.now();
|
||||
if (opts.dry_run) {
|
||||
var inst = ctx.inst = {
|
||||
id: 'beefbeef-4c0e-11e5-86cd-a7fd38d2a50b',
|
||||
name: 'm00'
|
||||
};
|
||||
console.log('Creating instance %s (%s, %s@%s%s)',
|
||||
inst.name, inst.id, ctx.img.name, ctx.img.version,
|
||||
inst.package ? format(', %s', inst.package) : '');
|
||||
return next();
|
||||
}
|
||||
|
||||
cloudapi.createMachine(createOpts, function (err, inst) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@ -83,9 +96,9 @@ function do_create_instance(subcmd, opts, args, callback) {
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(inst));
|
||||
} else {
|
||||
console.log('Creating instance %s (%s, %s@%s, %s)',
|
||||
console.log('Creating instance %s (%s, %s@%s%s)',
|
||||
inst.name, inst.id, ctx.img.name, ctx.img.version,
|
||||
inst.package);
|
||||
inst.package ? format(', %s', inst.package) : '');
|
||||
}
|
||||
next();
|
||||
});
|
||||
@ -107,7 +120,17 @@ function do_create_instance(subcmd, opts, args, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
cloudapi.waitForMachineStates({
|
||||
// Dry-run: fake wait for a few seconds.
|
||||
var waiter = (opts.dry_run ?
|
||||
function dryWait(waitOpts, waitCb) {
|
||||
setTimeout(function () {
|
||||
ctx.inst.state = 'running';
|
||||
waitCb(null, ctx.inst);
|
||||
}, 5000);
|
||||
}
|
||||
: cloudapi.waitForMachineStates);
|
||||
|
||||
waiter({
|
||||
id: ctx.inst.id,
|
||||
states: ['running', 'failed']
|
||||
}, function (err, inst) {
|
||||
@ -165,6 +188,11 @@ do_create_instance.options = [
|
||||
{
|
||||
group: 'Other options'
|
||||
},
|
||||
{
|
||||
names: ['dry-run'],
|
||||
type: 'bool',
|
||||
help: 'Go through the motions without actually creating an instance.'
|
||||
},
|
||||
{
|
||||
names: ['wait', 'w'],
|
||||
type: 'bool',
|
||||
|
Reference in New Issue
Block a user