Repository navigation
Expand file tree
/
Copy pathnetwork.js
More file actions
50 lines (49 loc) · 1.8 KB
/
Copy pathnetwork.js
File metadata and controls
50 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* network.js
*
* This module provides the factory function for creating the network manager.
*
* TODO: For consistency with how we've organized most of the packages, it might be better to move this to a network/index.js module
*/
var config = require("./config");
var log = require("./log").logger("network");
// Create and return the network manager. You should only call this function once.
// It consults the os and plaform and fishes the appropriate network manager object out of the network/ directory
// If no such manager is defined or there's a problem creating it, an exception is thrown.
exports.createNetworkManager = function (name, callback) {
// The OS comes from node, and is something like 'linux' or 'darwin'
// The platform is now defined in the engine configuration - it's something like 'raspberry-pi'
var OS = config.platform;
var PLATFORM = config.engine.get("platform");
log.info("OS is:" + OS);
log.info("PLATFORM is:" + PLATFORM);
try {
var NetworkManager = require("./network/" +
OS +
"/" +
PLATFORM).NetworkManager;
var nm = new NetworkManager();
nm.os = OS;
nm.platform = PLATFORM;
if (!name && nm.platform === "raspberry-pi") {
// eslint-disable-next-line no-unused-vars
nm.set_serialnum(function (machine_id) {
callback(null, nm);
});
} else {
callback(null, nm);
}
} catch (e) {
log.error("Network Management configuration failure" + e);
callback(
new Error(
"Cannot load network manager for " +
OS +
"/" +
PLATFORM +
": " +
e.message
)
);
}
};