diff --git a/lib/cloudapi2.js b/lib/cloudapi2.js index c147c57..eeb617f 100644 --- a/lib/cloudapi2.js +++ b/lib/cloudapi2.js @@ -2378,7 +2378,9 @@ function waitForVolumeStates(opts, callback) { assert.func(callback, 'callback'); var interval = (opts.interval === undefined ? 1000 : opts.interval); - interval = Math.min(interval, opts.timeout); + if (opts.timeout !== undefined) { + interval = Math.min(interval, opts.timeout); + } assert.ok(interval > 0, 'interval must be a positive number'); var startTime = process.hrtime(); diff --git a/lib/do_volume/do_create.js b/lib/do_volume/do_create.js index 90aed80..369c15a 100644 --- a/lib/do_volume/do_create.js +++ b/lib/do_volume/do_create.js @@ -90,6 +90,8 @@ function do_create(subcmd, opts, args, cb) { }, function maybeWait(ctx, next) { var distraction; + var waitTimeout = opts.wait_timeout === undefined ? + undefined : opts.wait_timeout * 1000; if (!opts.wait) { next(); @@ -103,7 +105,7 @@ function do_create(subcmd, opts, args, cb) { self.top.tritonapi.cloudapi.waitForVolumeStates({ id: ctx.volume.id, states: ['ready', 'failed'], - timeout: opts.wait_timeout * 1000 + timeout: waitTimeout }, function onWaitDone(waitErr, volume) { if (distraction) { distraction.destroy(); @@ -182,9 +184,7 @@ do_create.options = [ { names: ['wait-timeout'], type: 'positiveInteger', - default: 120, - help: 'The number of seconds to wait before timing out with an error. ' - + 'The default is 120 seconds.' + help: 'The number of seconds to wait before timing out with an error.' } ]; diff --git a/lib/do_volume/do_delete.js b/lib/do_volume/do_delete.js index f244e94..ad5bf3a 100644 --- a/lib/do_volume/do_delete.js +++ b/lib/do_volume/do_delete.js @@ -121,17 +121,16 @@ function do_delete(subcmd, opts, args, cb) { self.top.tritonapi.deleteVolume({ id: volumeId, wait: opts.wait && opts.wait.length > 0, - waitTimeout: opts.wait_timeout * 1000, - tritonapi: self.top.tritonapi + waitTimeout: opts.wait_timeout * 1000 }, function onVolDeleted(volDelErr) { - if (volDelErr) { - console.error('Error when deleting volume %s, ' - + 'reason: %s', volumeId, volDelErr); - } else { + if (!volDelErr) { console.log('Deleted volume %s', volumeId); + } else { + console.error('Error when deleting volume %s: %s', + volumeId, volDelErr); } - done(); + done(volDelErr); }); }, inputs: ctx.volumeIds diff --git a/lib/tritonapi.js b/lib/tritonapi.js index d102fea..6355c06 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -184,6 +184,30 @@ function _stepInstId(arg, next) { } } +/** + * A function appropriate for `vasync.pipeline` funcs that takes a `arg.id` + * volume name, shortid or uuid, and determines the volume id (setting it + * as `arg.volId`). + */ +function _stepVolId(arg, next) { + assert.object(arg.client, 'arg.client'); + assert.string(arg.id, 'arg.id'); + + if (common.isUUID(arg.id)) { + arg.volId = arg.id; + next(); + } else { + arg.client.getVolume(arg.id, function onGetVolume(getVolErr, vol) { + if (getVolErr) { + next(getVolErr); + } else { + arg.volId = vol.id; + next(); + } + }); + } +} + /** * A function appropriate for `vasync.pipeline` funcs that takes a `arg.package` * package name, short id or uuid, and determines the package id (setting it @@ -2663,30 +2687,6 @@ TritonApi.prototype.getVolume = function getVolume(name, cb) { } }; -/** - * A function appropriate for `vasync.pipeline` funcs that takes a `arg.id` - * volume name, shortid or uuid, and determines the volume id (setting it - * as `arg.volId`). - */ -function _stepVolId(arg, next) { - assert.object(arg.client, 'arg.client'); - assert.string(arg.id, 'arg.id'); - - if (common.isUUID(arg.id)) { - arg.volId = arg.id; - next(); - } else { - arg.client.getVolume(arg.id, function onGetVolume(getVolErr, vol) { - if (getVolErr) { - next(getVolErr); - } else { - arg.volId = vol.id; - next(); - } - }); - } -} - /** * Deletes a volume by ID, exact name, or short ID, in that order. *