From 21f2d29c861b442094415c8c7915b7f17cd74703 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 16 Sep 2016 16:01:38 -0700 Subject: [PATCH] joyent/node-triton#130 `triton` image caching should include disabled images Reviewed by: Cody Peter Mello Approved by: Cody Peter Mello --- CHANGES.md | 5 +++-- lib/do_fwrule/do_instances.js | 6 ++++-- lib/do_instance/do_list.js | 6 ++++-- lib/tritonapi.js | 11 ++++++----- package.json | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ef2b151..94dfc0d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,9 +5,10 @@ Known issues: - `triton ssh ...` disables ssh ControlMaster to avoid issue #52. -## 4.13.1 (not yet released) +## 4.14.0 (not yet released) -(nothing yet) +- [#130] Include disabled images when using an image cache (e.g. for filling in + image name and version details in `triton ls` output. ## 4.13.0 diff --git a/lib/do_fwrule/do_instances.js b/lib/do_fwrule/do_instances.js index 34911a0..65a3c65 100644 --- a/lib/do_fwrule/do_instances.js +++ b/lib/do_fwrule/do_instances.js @@ -56,8 +56,10 @@ function do_instances(subcmd, opts, args, cb) { vasync.parallel({funcs: [ function getTheImages(next) { - tritonapi.listImages({useCache: true}, - function (err, _imgs) { + tritonapi.listImages({ + useCache: true, + state: 'all' + }, function (err, _imgs) { if (err) { next(err); } else { diff --git a/lib/do_instance/do_list.js b/lib/do_instance/do_list.js index 61e7884..79c1b7b 100644 --- a/lib/do_instance/do_list.js +++ b/lib/do_instance/do_list.js @@ -76,8 +76,10 @@ function do_list(subcmd, opts, args, callback) { vasync.parallel({funcs: [ function getTheImages(next) { - self.top.tritonapi.listImages({useCache: true}, - function (err, _imgs) { + self.top.tritonapi.listImages({ + state: 'all', + useCache: true + }, function (err, _imgs) { if (err) { if (err.statusCode === 403) { /* diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 8746000..e749132 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -282,8 +282,9 @@ TritonApi.prototype._cacheGetJson = function _cacheGetJson(key, cb) { * * @param opts {Object} Optional. * - useCache {Boolean} Default false. Whether to use Triton's local cache. - * Note that the *current* implementation will only use the cache - * when there are no filter options. + * Currently the cache is only used and updated if the filters are + * exactly `{state: "all"}`. IOW, the ListImages call that returns + * all visible images. * - ... all other cloudapi ListImages options per * * @param {Function} callback `function (err, imgs)` @@ -304,10 +305,10 @@ TritonApi.prototype.listImages = function listImages(opts, cb) { // For now at least, we only cache full results (no filtering). var useCache = Boolean(opts.useCache); var cacheKey; - if (Object.keys(listOpts).length > 0) { - useCache = false; - } else { + if (Object.keys(listOpts).length === 1 && listOpts.state === 'all') { cacheKey = 'images.json'; + } else { + useCache = false; } var cached; var fetched; diff --git a/package.json b/package.json index 06df03b..6cb6114 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "triton", "description": "Joyent Triton CLI and client (https://www.joyent.com/triton)", - "version": "4.13.1", + "version": "4.14.0", "author": "Joyent (joyent.com)", "dependencies": { "assert-plus": "0.2.0",