From 44ce942d9795e70a1ab7187a3e2c19fc09d36c8f Mon Sep 17 00:00:00 2001 From: Dave Eddy Date: Mon, 21 Sep 2015 16:37:26 -0400 Subject: [PATCH] triton create support image name@version format, fixes #25 --- lib/do_create_instance.js | 21 +++++++++++++++++---- lib/tritonapi.js | 7 ++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/do_create_instance.js b/lib/do_create_instance.js index 30dea0f..ffa74f0 100644 --- a/lib/do_create_instance.js +++ b/lib/do_create_instance.js @@ -33,8 +33,14 @@ function do_create_instance(subcmd, opts, args, callback) { vasync.pipeline({arg: {}, funcs: [ function getImg(ctx, next) { - // XXX don't get the image object if it is a UUID, waste of time - self.tritonapi.getImage(args[0], function (err, img) { + var id = args[0]; + if (common.isUUID(id)) { + ctx.img = id; + next(); + return; + } + + self.tritonapi.getImage(id, function (err, img) { if (err) { return next(err); } @@ -47,8 +53,15 @@ function do_create_instance(subcmd, opts, args, callback) { if (args.length < 2) { return next(); } - // XXX don't get the package object if it is a UUID, waste of time - self.tritonapi.getPackage(args[1], function (err, pkg) { + + var id = args[1]; + if (common.isUUID(id)) { + ctx.img = id; + next(); + return; + } + + self.tritonapi.getPackage(id, function (err, pkg) { if (err) { return next(err); } diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 0bad6c2..e31ef74 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -263,6 +263,9 @@ TritonApi.prototype.getImage = function getImage(name, cb) { } }); } else { + var s = name.split('@'); + name = s[0]; + var version = s[1]; this.cloudapi.listImages(function (err, imgs) { if (err) { return cb(err); @@ -272,10 +275,12 @@ TritonApi.prototype.getImage = function getImage(name, cb) { var shortIdMatches = []; for (var i = 0; i < imgs.length; i++) { var img = imgs[i]; + if (version && img.version !== version) + continue; if (img.name === name) { nameMatches.push(img); } - if (img.id.slice(0, 8) === name) { + if (common.uuidToShortId(img.id) === name) { shortIdMatches.push(img); } }