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: [
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);
}

View File

@ -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);
}
}