changes according to latest code review from Trent

This commit is contained in:
Julien Gilli 2017-03-23 13:12:24 -07:00
parent cd8d6a0658
commit f00d1bd9c0
4 changed files with 37 additions and 36 deletions

View File

@ -2378,7 +2378,9 @@ function waitForVolumeStates(opts, callback) {
assert.func(callback, 'callback'); assert.func(callback, 'callback');
var interval = (opts.interval === undefined ? 1000 : opts.interval); 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'); assert.ok(interval > 0, 'interval must be a positive number');
var startTime = process.hrtime(); var startTime = process.hrtime();

View File

@ -90,6 +90,8 @@ function do_create(subcmd, opts, args, cb) {
}, },
function maybeWait(ctx, next) { function maybeWait(ctx, next) {
var distraction; var distraction;
var waitTimeout = opts.wait_timeout === undefined ?
undefined : opts.wait_timeout * 1000;
if (!opts.wait) { if (!opts.wait) {
next(); next();
@ -103,7 +105,7 @@ function do_create(subcmd, opts, args, cb) {
self.top.tritonapi.cloudapi.waitForVolumeStates({ self.top.tritonapi.cloudapi.waitForVolumeStates({
id: ctx.volume.id, id: ctx.volume.id,
states: ['ready', 'failed'], states: ['ready', 'failed'],
timeout: opts.wait_timeout * 1000 timeout: waitTimeout
}, function onWaitDone(waitErr, volume) { }, function onWaitDone(waitErr, volume) {
if (distraction) { if (distraction) {
distraction.destroy(); distraction.destroy();
@ -182,9 +184,7 @@ do_create.options = [
{ {
names: ['wait-timeout'], names: ['wait-timeout'],
type: 'positiveInteger', type: 'positiveInteger',
default: 120, help: 'The number of seconds to wait before timing out with an error.'
help: 'The number of seconds to wait before timing out with an error. '
+ 'The default is 120 seconds.'
} }
]; ];

View File

@ -121,17 +121,16 @@ function do_delete(subcmd, opts, args, cb) {
self.top.tritonapi.deleteVolume({ self.top.tritonapi.deleteVolume({
id: volumeId, id: volumeId,
wait: opts.wait && opts.wait.length > 0, wait: opts.wait && opts.wait.length > 0,
waitTimeout: opts.wait_timeout * 1000, waitTimeout: opts.wait_timeout * 1000
tritonapi: self.top.tritonapi
}, function onVolDeleted(volDelErr) { }, function onVolDeleted(volDelErr) {
if (volDelErr) { if (!volDelErr) {
console.error('Error when deleting volume %s, '
+ 'reason: %s', volumeId, volDelErr);
} else {
console.log('Deleted volume %s', volumeId); console.log('Deleted volume %s', volumeId);
} else {
console.error('Error when deleting volume %s: %s',
volumeId, volDelErr);
} }
done(); done(volDelErr);
}); });
}, },
inputs: ctx.volumeIds inputs: ctx.volumeIds

View File

@ -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` * 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 * 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. * Deletes a volume by ID, exact name, or short ID, in that order.
* *