From 40430bf58aa6977a145a44dae9d6f236ab0c6913 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Tue, 5 Jan 2016 01:11:28 +0000 Subject: [PATCH] Using nc -z as portScanner fails in parallel. Moving gce script --- node_modules/c9/gce.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 node_modules/c9/gce.js diff --git a/node_modules/c9/gce.js b/node_modules/c9/gce.js new file mode 100644 index 00000000..1a5691b0 --- /dev/null +++ b/node_modules/c9/gce.js @@ -0,0 +1,40 @@ +var childProcess = require("child_process"); + + +function findServers(pattern, options, callback) { + if (!callback && typeof options == "function") { + return findServers(pattern, {}, options); + } + + childProcess.exec("gssh --print-names " + pattern, function (err, stdout) { + if (err) return callback(err); + + var serverNames = stdout.split("\n") + .filter(function(name) { return !!name; }) + .map(function (name) { return name.replace(/ubuntu@/, ""); }); + + return callback(null, serverNames); + }); + +} + +function runCommand(pattern, command, options, callback) { + if (!callback && typeof options == "function") { + return runCommand(pattern, command, {}, options); + } + + var parallel = "" + if (options.parallel) { + parallel = " -P" + } + + var gsshCommand = "gssh " + parallel + " " + pattern + " '" + command + "'"; + childProcess.exec(gsshCommand, function (err, stdout) { + return callback(err, stdout); + }); +} + +module.exports = { + find: findServers, + run: runCommand +} \ No newline at end of file