it("can get the security groups of a given instance", function (next) { instance.getSecurityGroups(outcome.e(next).s(function (securityGroups) { expect(securityGroups.length).to.be(1); expect(securityGroups[0].get("_id")).to.be(securityGroup.get("_id")); next(); })); });
region.instances.create({ type: "t1.micro", imageId: helpers.images.ubuntu._id, keyPair: keyPair }, outcome.e(next).s(function (model) { expect(model.get("keyName")).to.be("test-keypair"); model.getKeyPair(outcome.e(next).s(function (keyPair) { expect(keyPair.get("name")).to.be("test-keypair"); model.destroy(next); })); }));
return function(source, args, cb) { var map = []; loop(source, function(item, next) { try { /*var args2 = args.concat(), orgNext; if(args2[args2.length - 1] == "function") { orgNext = args2[args2.length - 1]; args2[args2.length - 1] = function(result) { orgNext.call(null, null, result); map.push } }*/ item[method].apply(item, args.concat(outcome.e(next).s(function(result) { // map.push(Array.prototype.slice.call(arguments, 0)); map.push(result); next(); }))); } catch(e) { return next(e); } }, outcome.e(cb).s(function() { cb(null, map); })); }
it("can return the list of volumes for an instance ", function (next) { instance.getVolumes(outcome.e(next).s(function (volumes) { expect(volumes.length).to.be(1); expect(volumes[0].get("attachments.0.instanceId")).to.be(instance.get("_id")); next(); })); });
it("can authorize an array of port ranges", function (next) { securityGroup.authorize({ ports: [{ from: 80, to: 90 }]}, outcome.e(next).s(function () { expect(securityGroup.get("permissions.0.fromPort")).to.be(80); expect(securityGroup.get("permissions.0.toPort")).to.be(90); next(); })); });
before(function (next) { aws = awsm(helpers.config); aws.ec2.regions.findOne("us-east-1", outcome.e(next).s(function (model) { region = model; next(); })); });
it("can authorize a port", function (next) { securityGroup.authorize(80, outcome.e(next).s(function () { expect(securityGroup.get("permissions.0.fromPort")).to.be(80); expect(securityGroup.get("permissions.0.toPort")).to.be(80); next(); })); });
it("can authorize a port range", function (next) { securityGroup.authorize({ from: 91, to: 100 }, outcome.e(next).s(function () { expect(securityGroup.get("permissions.0.fromPort")).to.be(91); expect(securityGroup.get("permissions.0.toPort")).to.be(100); securityGroup.revoke({ from: 90, to: 100 }, next); })); });
load: function (complete) { var self = this; this.app.mediator.execute("getAvailableLaunchers", outcome.e(complete).s(function (launchers) { self.reset(launchers.map(_.bind(self._createModel, self))); complete(null, self); })); },
attach: function (instanceId, device, next) { if (typeof instanceId === "object") { instanceId = instanceId.get("_id"); } if (arguments.length === 2) { next = device; device = "/dev/sdh"; // or xvdh } var self = this; var ops = { VolumeId : this.get("_id"), InstanceId : instanceId, Device : device }; this.logger.notice("attach(%s)", ops); this.api.attachVolume(ops, outcome.e(next).s(function () { self.region.instances.reload(function () { self.reload(next); }); })); },
it("can be detached from an instance", function (next) { address.detach(outcome.e(next).s(function () { address.getInstance(function (err, instance) { expect(!!instance).to.be(false); next(); }); })); });
it("can create an instance with a security group", function (next) { region.instances.create({ type: "t1.micro", imageId: helpers.images.ubuntu._id, securityGroup: securityGroup }, outcome.e(next).s(function (model) { instance = model; console.log(JSON.stringify(instance.context(), null, 2)); expect(instance.get("type")).to.be("t1.micro"); next(); })); });
"getAllServers": function(callback) { async.map(this._services, function(service, next) { console.log("fetching servers from %s", service.provider); service.getServers(function(err, servers) { if(!servers) return next(err); next(null, servers); }); }, outcome.e(callback).s(function(servers) { callback(null, Array.prototype.concat.apply([], servers)); })); },
var init = function(entries, callback) { var on = outcome.e(callback); async.map(entries, includeEntry, on.s(function(entries) { var deps = __loaded.files; callback(null, { entries: entries, dependencies: deps }); })); }
it("can be associated with an instance", function (next) { address.attach(instance, outcome.e(next).s(function (address) { instance.getAddress(function (err, address2) { expect(address.get("_id")).to.be(address2.get("_id")); address.getInstance(function (err, instance2) { expect(instance.get("_id")).to.be(instance2.get("_id")); expect(instance.get("addresses.publicIp")).to.equal(address.get("publicIp")); next(); }) }); })); });
_load: function (options, next) { this.api.describeAvailabilityZones(outcome.e(next).s(function (result) { next(null, result.AvailabilityZones.map(function (zone) { return { _id : zone.ZoneName, state : zone.State, name : zone.ZoneName, region : zone.RegionName } })) })); }
detach: function (next) { var self = this; this.logger.notice("detach()"); this.api.detachVolume({ VolumeId: this.get("_id") }, outcome.e(next).s(function () { self.region.instances.reload(function () { self.reload(next); }); })); },
_load: function (options, next) { var ops = {}; this.api.listHostedZones(ops, outcome.e(next).s(function (response) { next(null, response.HostedZones.map(function (hostedZone) { return { _id : hostedZone.Id, name : hostedZone.Name, config : hostedZone.Config } })); })); }
return function(source, args, cb) { var map = []; loop(source, function(item, next) { try { map.push(item[method].apply(item, args)); next(); } catch(e) { next(e); } }, outcome.e(cb).s(function() { cb(null, map); })); }
var includeEntry = function(dirOrScript, callback) { var on = outcome.e(callback); step( /** */ function() { fs.lstat(dirOrScript, this); }, /** */ on.s(function(stats) { //dir specified? scan EVERYTHING if(stats.isDirectory()) { includeDir(dirOrScript, this); //otherwise scan for require() statements } else { var script = this.script = pathInfo.getPathInfo(dirOrScript); includeScript(script, this); } }), /** */ on.s(function() { this(null, this.script); }), /** */ callback ) }
var findDeps = module.exports.findDeps = function(entry, callback) { //incase getPathInfo stuff is passed... if(entry.path) entry = entry.path; var cwd = path.dirname(entry), on = outcome.e(callback), content = null; step( /** */ function() { fs.readFile(entry, "utf8", this); }, /** */ on.s(function(cn) { content = cn; var next = this, d; scanRequired(content, cwd, on.s(function(deps) { scanInclude(content, cwd, on.s(function(incDeps) { next(null, deps.concat(incDeps)); })); })); }), /** */ on.success(function(deps) { deps.forEach(function(dep) { dep.source = entry; }); callback(null, deps); }) ); }
var includeScript = function(script, callback) { //script already used? skip. if(isUsed(script) || !script.path) return callback(); //script is core, and platform is node? if(script.core && ops.platform == "node") { script.alias = script.moduleName; return callback(); } use(script); var on = outcome.e(function(e) { callback(new Error("unable to include script " + script.path + " from "+script.source+", e: " + e.stack)) }); step( /** * first get the dependencies */ function() { findDeps(script.path, this); }, /** * deps found? load THOSE in! */ on.s(function(deps) { script.dependencies = deps; async.forEach(deps, includeScript, this); }), /** */ callback ) }
module.exports = function(ops, next) { /** * first analyze the dependencies. This works a few ways: * * 1. dir specified, so scan ALL scripts, including third-party modules. * 2. entry point specified, so scan ONLY scripts which are used ~ (look for require() stmts) */ var entries = toarray(ops.entry || ops.entries), buildId = ops.buildId || Date.now(); analyzeDeps({ entries : entries, platform : ops.platform || "browser", prefix : ops.prefix }, outcome.e(next).s(function(result) { next(null, new Bundle(dependencies(result.entries), dependencies(result.dependencies))); })); }
call: function (keyPath, next) { if (arguments.length === 1) { var next = keyPath; keyPath = path.join(defaultKeyDir, this.get("region"), this.get("name")); } keyPath = keyPath.replace("~", process.env.HOME).replace(/^\./, process.cwd()); this.set("keyPath", keyPath); var self = this; function onSave () { next(null, self); } try { mkdirp.sync(path.dirname(keyPath)); } catch (e) { } fs.writeFile(keyPath, this.get("material"), outcome.e(next).s(onSave)); }
before(function (next) { region.instances.create({ type: "t1.micro", securityGroup: securityGroup, imageId: helpers.images.ubuntu._id }, outcome.e(next).s(function (model) { instance = model; next(); })); });
it("can find items", function(done) { col.find({ age: {$lt: 25}}, outcome.e(done).s(function(items) { expect(items.length).to.be(2); done(); })); });
before(function (next) { region.keyPairs.create("test-keypair", outcome.e(next).s(function (model) { keyPair = model; next(); })); });
before(function (next) { region.securityGroups.create({ name: "test-sg-" + Date.now() }, outcome.e(next).s(function (model) { securityGroup = model; next(); })); });
it("can't find people ages < 25", function(done) { col.find({ age: {$lt: 25}}, outcome.e(done).s(function(items) { expect(items.length).to.be(0); done(); })); })
it("can find new people ages > 25", function(done) { col.find({ age: {$gte:25}}, outcome.e(done).s(function(items) { expect(items.length).to.be(1); done(); })); });