diff --git a/CHANGES.md b/CHANGES.md index 976b1f0..776ea36 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 4.3.2 (not yet released) +- #79 Fix `triton instance get NAME` to make sure it gets the `dns_names` CNS + field. - PUBAPI-1227: Note that `triton image list` doesn't include Docker images, at least currently. diff --git a/lib/tritonapi.js b/lib/tritonapi.js index 0213f32..1926867 100644 --- a/lib/tritonapi.js +++ b/lib/tritonapi.js @@ -547,6 +547,7 @@ TritonApi.prototype.getInstance = function getInstance(name, cb) { var res; var shortId; var inst; + var instFromList; vasync.pipeline({funcs: [ function tryUuid(_, next) { @@ -575,7 +576,7 @@ TritonApi.prototype.getInstance = function getInstance(name, cb) { }, function tryName(_, next) { - if (inst) { + if (inst || instFromList) { return next(); } @@ -585,7 +586,7 @@ TritonApi.prototype.getInstance = function getInstance(name, cb) { } for (var i = 0; i < insts.length; i++) { if (insts[i].name === name) { - inst = insts[i]; + instFromList = insts[i]; // Relying on rule that instance name is unique // for a user and DC. return next(); @@ -596,7 +597,7 @@ TritonApi.prototype.getInstance = function getInstance(name, cb) { }, function tryShortId(_, next) { - if (inst || !shortId) { + if (inst || instFromList || !shortId) { return next(); } var nextOnce = once(next); @@ -622,10 +623,34 @@ TritonApi.prototype.getInstance = function getInstance(name, cb) { }); s.on('end', function () { if (match) { - inst = match; + instFromList = match; } nextOnce(); }); + }, + + /* + * There can be fields that only exist on the machine object from + * GetMachine, and not from ListMachine. `dns_names` is one of these. + * Therefore, if we got the machine from filtering ListMachine, then + * we need to re-GetMachine. + */ + function reGetIfFromList(_, next) { + if (inst || !instFromList) { + next(); + return; + } + var uuid = instFromList.id; + self.cloudapi.getMachine(uuid, function (err, inst_, res_) { + res = res_; + inst = inst_; + if (err && err.restCode === 'ResourceNotFound') { + // The CloudApi 404 error message sucks: "VM not found". + err = new errors.ResourceNotFoundError(err, + format('instance with id %s was not found', name)); + } + next(err); + }); } ]}, function (err) { if (err) {