fix create_ami command. also prepend unix user name to deployments

This commit is contained in:
Lloyd Hilaiel 2012-05-31 21:01:26 +03:00
Родитель afb8a99ac7
Коммит 1d39e55643
2 изменённых файлов: 35 добавлений и 17 удалений

Просмотреть файл

@ -87,7 +87,7 @@ verbs['create'] = function(args) {
var name = opts.n || "noname";
validateName(name);
var hostname = name;
var longName = process.title + ' deployment (' + name + ')';
var longName = process.env['USER'] + "'s " + process.title + ' deployment (' + name + ')';
console.log("reading .awsbox.json");
@ -154,6 +154,7 @@ verbs['create_ami'] = function(args) {
var hostname = name;
console.log("restoring to a pristine state, and creating AMI image from " + name);
vm.describe(name, function(err, deets) {
console.log("instance found, ip " + deets.ipAddress + ", restoring");
checkErr(err);
@ -163,9 +164,20 @@ verbs['create_ami'] = function(args) {
vm.createAMI(name, function(err, imageId) {
checkErr(err);
console.log("Created image:", imageId, "- waiting for creation and making it public (can take a while)");
vm.makeAMIPublic(imageId, function(err, imageId) {
console.log("All done!");
vm.makeAMIPublic(imageId, function(err) {
console.log(" ... still waiting:", err);
}, function(err, imageId) {
checkErr(err);
vm.destroy(name, function(err, deets) {
checkErr(err);
if (deets && deets.ipAddress) {
process.stdout.write("trying to remove git remote: ");
git.removeRemote(name, deets.ipAddress, function(err) {
checkErr(err);
console.log("All done!");
});
}
});
});
});
});

Просмотреть файл

@ -4,7 +4,7 @@ jsel = require('JSONSelect'),
key = require('./key.js'),
sec = require('./sec.js');
const TEMPLATE_IMAGE_ID = 'ami-dcbf1eb5';
const TEMPLATE_IMAGE_ID = 'ami-b68021df';
function extractInstanceDeets(horribleBlob) {
var instance = {};
@ -17,7 +17,7 @@ function extractInstanceDeets(horribleBlob) {
instance.fullName = name[0];
// if this is a 'awsbox deployment', we'll only display the hostname chosen by the
// user
var m = /^awsbox deployment \((.*)\)$/.exec(instance.fullName);
var m = /awsbox deployment \((.*)\)$/.exec(instance.fullName);
instance.name = m ? m[1] : instance.fullName;
} else {
instance.name = instance.instanceId;
@ -56,7 +56,7 @@ function findInstance(r, name) {
if (x.length) return x[0];
// is what the human typed in the vm "short name" ?
var fn = "awsbox deployment (" + name + ")";
var fn = process.env['USER'] + "'s awsbox deployment (" + name + ")";
var x = jsel.match('.?:has(:root > .instanceId).', [ fn ], r);
if (x.length) return x[0];
@ -112,7 +112,7 @@ exports.createAMI = function(name, cb) {
});
};
exports.makeAMIPublic = function(imageId, cb) {
exports.makeAMIPublic = function(imageId, progress, cb) {
var startTime = new Date();
function attempt() {
@ -120,24 +120,30 @@ exports.makeAMIPublic = function(imageId, cb) {
ImageId: imageId,
'LaunchPermission.Add.1.Group': 'all'
}, function(result) {
if (result && result.return === 'true') {
return cb(null);
}
var e;
try {
if (result.Errors.Error.Message) {
if (result.Errors.Error.Message.indexOf('currently pending') !== -1) {
throw "pending"
if (result.Errors.Error.Message.indexOf('currently pending') === -1) {
return cb(result.Errors.Error.Message);
}
return cb(result.Errors.Error.Message);
e = result.Errors.Error.Message;
}
} catch(e) {
e = "unknown";
};
cb(null);
} catch(e) {};
if (new Date() - startTime > 120 * 1000) {
if (new Date() - startTime > 240 * 1000) {
return cb("timed out waiting for instance to become public");
}
setTimeout(function() { attempt(); }, 2000);
setTimeout(function() {
if (typeof progress === 'function') progress(e || "unknown");
attempt();
}, 10000);
});
}