triton create support image name@version format, fixes #25

This commit is contained in:
Dave Eddy 2015-09-21 16:37:26 -04:00
parent 5ed72ea117
commit 44ce942d97
2 changed files with 23 additions and 5 deletions

View File

@ -33,8 +33,14 @@ function do_create_instance(subcmd, opts, args, callback) {
vasync.pipeline({arg: {}, funcs: [ vasync.pipeline({arg: {}, funcs: [
function getImg(ctx, next) { function getImg(ctx, next) {
// XXX don't get the image object if it is a UUID, waste of time var id = args[0];
self.tritonapi.getImage(args[0], function (err, img) { if (common.isUUID(id)) {
ctx.img = id;
next();
return;
}
self.tritonapi.getImage(id, function (err, img) {
if (err) { if (err) {
return next(err); return next(err);
} }
@ -47,8 +53,15 @@ function do_create_instance(subcmd, opts, args, callback) {
if (args.length < 2) { if (args.length < 2) {
return next(); 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) { if (err) {
return next(err); return next(err);
} }

View File

@ -263,6 +263,9 @@ TritonApi.prototype.getImage = function getImage(name, cb) {
} }
}); });
} else { } else {
var s = name.split('@');
name = s[0];
var version = s[1];
this.cloudapi.listImages(function (err, imgs) { this.cloudapi.listImages(function (err, imgs) {
if (err) { if (err) {
return cb(err); return cb(err);
@ -272,10 +275,12 @@ TritonApi.prototype.getImage = function getImage(name, cb) {
var shortIdMatches = []; var shortIdMatches = [];
for (var i = 0; i < imgs.length; i++) { for (var i = 0; i < imgs.length; i++) {
var img = imgs[i]; var img = imgs[i];
if (version && img.version !== version)
continue;
if (img.name === name) { if (img.name === name) {
nameMatches.push(img); nameMatches.push(img);
} }
if (img.id.slice(0, 8) === name) { if (common.uuidToShortId(img.id) === name) {
shortIdMatches.push(img); shortIdMatches.push(img);
} }
} }