diff --git a/lib/common.js b/lib/common.js
index 15e87e5..f89cc80 100755
--- a/lib/common.js
+++ b/lib/common.js
@@ -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('');
}
diff --git a/lib/do_create.js b/lib/do_create.js
deleted file mode 100644
index 797f481..0000000
--- a/lib/do_create.js
+++ /dev/null
@@ -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 ');
- assert.string(opts['package'], '--package ');
- 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: '',
- 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: '',
- help: 'The machine image with which to provision. Required.'
- },
- {
- names: ['package', 'p'],
- type: 'string',
- helpArg: '',
- help: 'The package or instance type for the new machine(s). Required.'
- },
- {
- names: ['name', 'n'],
- type: 'string',
- helpArg: '',
- 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: '',
- help: 'The number of machines to provision. Default is 1.'
- },
-];
-do_create.help = (
- 'Create a new instance.\n'
- + '\n'
- + 'Usage:\n'
- + ' {{name}} create \n'
- + '\n'
- + '{{options}}'
-);
-do_create.aliases = ['create-inst'];
-
-module.exports = do_create;
diff --git a/lib/do_create_instance.js b/lib/do_create_instance.js
index cc3e858..41dd710 100644
--- a/lib/do_create_instance.js
+++ b/lib/do_create_instance.js
@@ -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',