Skip to content

WIP: initial pure js impl for IBM i AIX variant #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions aix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

const execa = require("execa");

const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?";

const checkVariant = () => {if (require("os").type() !== "OS400") throw new Error("Unsupported AIX variant"); };

const parse = stdout => {
let result;
try {
const resultObj = JSON.parse(stdout);
const gateway = resultObj.records[0].NEXT_HOP;
const iface = resultObj.records[0].LOCAL_BINDING_INTERFACE;
result = {gateway, iface};
} catch {}
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};

const promise = family => {
checkVariant();
return execa.stdout("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]).then(stdout => {
return parse(stdout);
});
};

const sync = family => {
checkVariant();
const result = execa.sync("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]);
return parse(result.stdout);
};

module.exports.v4 = () => promise("IPV4");
module.exports.v6 = () => promise("IPV6");

module.exports.v4.sync = () => sync("IPV4");
module.exports.v6.sync = () => sync("IPV6");
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if ([
"openbsd",
"sunos",
"win32",
"aix",
].indexOf(platform) !== -1) {
const families = require(`./${platform}`);
module.exports.v4 = () => families.v4();
Expand Down