From cc07717008f9ecdf2aacc87cc9a65622ced3bfab Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 6 Mar 2019 17:25:00 -0800 Subject: [PATCH] joyent/node-triton#258 triton instance create picks disabled image Reviewed by: Brian Bennett Approved by: Brian Bennett --- CHANGES.md | 13 +++++++++++++ lib/do_image/do_get.js | 15 ++++++++++++++- lib/do_instance/do_create.js | 3 ++- lib/tritonapi.js | 15 ++++++++++----- package.json | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e171277..fd420d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,19 @@ Known issues: ## not yet released +(nothing) + +## 7.0.0 + +- [Backward incompatible.] `triton image get NAME|SHORTID` will now *exclude* + inactive images by default. Before this change inactive images (e.g. those + with a state of "creating" or "unactivated" or "disabled") would be + included. Use the new `-a,--all` option to include inactive images. This + matches the behavior of `triton image list [-a,--all] ...`. + +- [joyent/node-triton#258] `triton instance create IMAGE ...` will now exclude + inactive images when looking for an image with the given name. + ## 6.3.0 - [joyent/node-triton#259] Added basic support for use of SSH bastion hosts diff --git a/lib/do_image/do_get.js b/lib/do_image/do_get.js index eaa9f1a..06832ed 100644 --- a/lib/do_image/do_get.js +++ b/lib/do_image/do_get.js @@ -31,7 +31,11 @@ function do_get(subcmd, opts, args, callback) { callback(setupErr); return; } - tritonapi.getImage(args[0], function onRes(err, img) { + var getOpts = { + name: args[0], + excludeInactive: !opts.all + }; + tritonapi.getImage(getOpts, function onRes(err, img) { if (err) { return callback(err); } @@ -56,6 +60,15 @@ do_get.options = [ names: ['json', 'j'], type: 'bool', help: 'JSON stream output.' + }, + { + group: 'Filtering options' + }, + { + names: ['all', 'a'], + type: 'bool', + help: 'Include all images when matching by name or short ID, not ' + + 'just "active" ones. By default only active images are included.' } ]; diff --git a/lib/do_instance/do_create.js b/lib/do_instance/do_create.js index cbedb35..4cc056b 100644 --- a/lib/do_instance/do_create.js +++ b/lib/do_instance/do_create.js @@ -5,7 +5,7 @@ */ /* - * Copyright 2018 Joyent, Inc. + * Copyright 2019 Joyent, Inc. * * `triton instance create ...` */ @@ -203,6 +203,7 @@ function do_create(subcmd, opts, args, cb) { function getImg(ctx, next) { var _opts = { name: args[0], + excludeInactive: true, useCache: true }; tritonapi.getImage(_opts, function (err, img) { diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 6e26c1d..77575c1 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018, Joyent, Inc. + * Copyright 2019 Joyent, Inc. */ /* BEGIN JSSTYLED */ @@ -693,6 +693,10 @@ TritonApi.prototype.listImages = function listImages(opts, cb) { * * If there is more than one image with that name, then the latest * (by published_at) is returned. + * + * @param {Boolean} opts.excludeInactive - Exclude inactive images when + * matching. By default inactive images are included. This param is *not* + * used when a full image ID (a UUID) is given. */ TritonApi.prototype.getImage = function getImage(opts, cb) { var self = this; @@ -700,10 +704,13 @@ TritonApi.prototype.getImage = function getImage(opts, cb) { opts = {name: opts}; assert.object(opts, 'opts'); assert.string(opts.name, 'opts.name'); + assert.optionalBool(opts.excludeInactive, 'opts.excludeInactive'); assert.optionalBool(opts.useCache, 'opts.useCache'); assert.func(cb, 'cb'); + var excludeInactive = Boolean(opts.excludeInactive); var img; + if (common.isUUID(opts.name)) { vasync.pipeline({funcs: [ function tryCache(_, next) { @@ -755,10 +762,8 @@ TritonApi.prototype.getImage = function getImage(opts, cb) { var version = s[1]; var nameSelector; - var listOpts = { - // Explicitly include inactive images. - state: 'all' - }; + var listOpts = {}; + listOpts.state = (excludeInactive ? 'active' : 'all'); if (version) { nameSelector = name + '@' + version; listOpts.name = name; diff --git a/package.json b/package.json index 78ca693..bc3c39b 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": "6.3.0", + "version": "7.0.0", "author": "Joyent (joyent.com)", "homepage": "https://github.com/joyent/node-triton", "dependencies": {