UNPKG

@joergmittaglawo/dmvconfig

Version:

DMV Configuration scripts for Lawo V__matrix Distributed Multiviewers.

251 lines 12.6 kB
"use strict"; /** * Runs the Nodes Configuration * @packageDocumentation * * @version 0.0.0-alpha.0 * @date 2020-04-15 * @author Mittag, Jörg (Lawo) <joerg.mittag@lawo.com> * @license SPDX-License-Identifier: MIT */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runNodesConfigAll = void 0; const vapi_1 = require("vapi"); const fs_1 = require("fs"); const node_fetch_1 = __importDefault(require("node-fetch")); const vscript_1 = require("vscript"); /** * Runs the Node Configuration for one node * * @param node The Node Configuration for one node * @param scriptIp The IP to connect to */ async function runNodeConfig1(node, scriptIp, syslog, clusterVersion) { /** * Endpoint for the current blade */ const blade = await vapi_1.VMatrix.open({ ip: scriptIp, towel: 'DMV Configuration' }); try { /** * All network ports of the current blade * * @default [0, 1, 2, 3] */ const __PORTS__ = (await blade.network_interfaces.ports.rows()).sort((a, b) => a.index - b.index); /** * All management ports of the current blade * * @default [2, 3] * */ const __MANAGEMENT_PORTS__ = __PORTS__.slice(-2); /** * All streaming ports of the current blade * * @default [0, 1] * */ const __STREAMING_PORTS__ = __PORTS__.slice(0, -2); /** * All P1 streaming ports of the current blade * * @default [0] * */ const __P1_PORTS__ = __STREAMING_PORTS__.slice(0, __STREAMING_PORTS__.length / 2); /** * The P1 streaming port * * @default 0 * */ const __P1_PORT__ = __P1_PORTS__[0]; /** * All P2 streaming ports of the current blade * * @default [1] * */ const __P2_PORTS__ = __STREAMING_PORTS__.slice(__STREAMING_PORTS__.length / 2); /** * The P2 streaming port * * @default 1 * */ const __P2_PORT__ = __P2_PORTS__[0]; console.log(`Configuring Node ${scriptIp}`); if (node.hostname) { const { hostname } = blade.network_interfaces; await hostname.desired_configuration.write(node.hostname); await hostname.save_hostname_config.write('Click'); } if (node.interfaces) { const { interfaces: IFACES } = node; if (IFACES.management) { const { management: MGMT } = IFACES; if (MGMT.back) { const { back: BACK } = MGMT; if (BACK.ip) { const { ip: IP, mask: MASK } = BACK; await Promise.all((await __MANAGEMENT_PORTS__[1].desired_configuration.base.ip_addresses.rows()).map((row) => row.delete_ip_address.write('Click'))); await __MANAGEMENT_PORTS__[1].desired_configuration.base.add_ip_address.write('Click'); await Promise.all([ __MANAGEMENT_PORTS__[1].desired_configuration.base.ip_addresses.row(0).ip_address.write(IP), __MANAGEMENT_PORTS__[1].desired_configuration.base.ip_addresses.row(0).prefix.write(MASK), ]); } if (BACK.gw) { const { gw: GW } = BACK; await Promise.all((await __MANAGEMENT_PORTS__[1].desired_configuration.base.routes.rows()).map((route) => route.delete_route.write('Click'))); await __MANAGEMENT_PORTS__[1].desired_configuration.base.add_route.write('Click'); await Promise.all([ __MANAGEMENT_PORTS__[1].desired_configuration.base.routes.row(0).via.write(GW), // __MANAGEMENT_PORTS__[1].desired_configuration.base.routes.row(0).dst.write(null), // __MANAGEMENT_PORTS__[1].desired_configuration.base.routes.row(0).weight.write(null), // __MANAGEMENT_PORTS__[1].desired_configuration.base.routes.row(0).dst.write(""), // should be `null` ]); } } if (MGMT.front) { const { front: FRONT } = MGMT; if (FRONT.ip) { const { ip: IP, mask: MASK } = FRONT; await Promise.all((await __MANAGEMENT_PORTS__[0].desired_configuration.base.ip_addresses.rows()).map((row) => row.delete_ip_address.write('Click'))); await __MANAGEMENT_PORTS__[0].desired_configuration.base.add_ip_address.write('Click'); await Promise.all([ __MANAGEMENT_PORTS__[0].desired_configuration.base.ip_addresses.row(0).ip_address.write(IP), __MANAGEMENT_PORTS__[0].desired_configuration.base.ip_addresses.row(0).prefix.write(MASK), ]); } if (FRONT.gw) { const { gw: GW } = FRONT; await Promise.all((await __MANAGEMENT_PORTS__[0].desired_configuration.base.routes.rows()).map((route) => route.delete_route.write('Click'))); await __MANAGEMENT_PORTS__[0].desired_configuration.base.add_route.write('Click'); await Promise.all([ __MANAGEMENT_PORTS__[0].desired_configuration.base.routes.row(0).via.write(GW), // __MANAGEMENT_PORTS__[0].desired_configuration.base.routes.row(0).dst.write(null), // __MANAGEMENT_PORTS__[0].desired_configuration.base.routes.row(0).weight.write(null), // __MANAGEMENT_PORTS__[0].desired_configuration.base.routes.row(0).dst.write(""), // should be `null` ]); } } } if (IFACES.media) { const { media: MEDIA } = IFACES; if (MEDIA.p1) { const { p1: P1 } = MEDIA; if (P1.ip) { const { ip: IP, mask: MASK } = P1; await Promise.all((await __P1_PORT__.desired_configuration.base.ip_addresses.rows()).map((row) => row.delete_ip_address.write('Click'))); await __P1_PORT__.desired_configuration.base.add_ip_address.write('Click'); await Promise.all([ __P1_PORT__.desired_configuration.base.ip_addresses.row(0).ip_address.write(IP), __P1_PORT__.desired_configuration.base.ip_addresses.row(0).prefix.write(MASK), ]); } if (P1.gw) { const { gw: GW } = P1; await Promise.all((await __P1_PORT__.desired_configuration.base.routes.rows()).map((route) => route.delete_route.write('Click'))); await __P1_PORT__.desired_configuration.base.add_route.write('Click'); await Promise.all([ __P1_PORT__.desired_configuration.base.routes.row(0).via.write(GW), // __P1_PORT__.desired_configuration.base.routes.row(0).dst.write(null), // __P1_PORT__.desired_configuration.base.routes.row(0).weight.write(null), // __P1_PORT__.desired_configuration.base.routes.row(0).dst.write(""), // should be `null` ]); } } if (MEDIA.p2) { const { p2: P2 } = MEDIA; if (P2.ip) { const { ip: IP, mask: MASK } = P2; await Promise.all((await __P2_PORT__.desired_configuration.base.ip_addresses.rows()).map((row) => row.delete_ip_address.write('Click'))); await __P2_PORT__.desired_configuration.base.add_ip_address.write('Click'); await Promise.all([ __P2_PORT__.desired_configuration.base.ip_addresses.row(0).ip_address.write(IP), __P2_PORT__.desired_configuration.base.ip_addresses.row(0).prefix.write(MASK), ]); } if (P2.gw) { const { gw: GW } = P2; await Promise.all((await __P2_PORT__.desired_configuration.base.routes.rows()).map((route) => route.delete_route.write('Click'))); await __P2_PORT__.desired_configuration.base.add_route.write('Click'); await Promise.all([ __P2_PORT__.desired_configuration.base.routes.row(0).via.write(GW), // __P2_PORT__.desired_configuration.base.routes.row(0).dst.write(undefined), // __P2_PORT__.desired_configuration.base.routes.row(0).weight.write(undefined), // __P2_PORT__.desired_configuration.base.routes.row(0).dst.write(""), // should be `undefined` ]); } } } if (syslog) { let iface; switch (syslog.interface) { case 'P1': iface = __P1_PORT__; break; case 'P2': iface = __P2_PORT__; break; case 'back': iface = __MANAGEMENT_PORTS__[1]; break; case 'front': [iface] = __MANAGEMENT_PORTS__; break; default: throw new Error(`Interface for syslog configuration is ${syslog.interface}, but should be one of 'P1', 'P2', 'back', or 'front'!`); } await iface.desired_syslog_configuration.syslog_servers.row(0).address.write(syslog.server); await iface.save_syslog_config.write('Click'); } } await vscript_1.pause(2); await blade.network_interfaces.save_config.write('Click'); /** * The version of the currently booted partition */ const version = vscript_1.SoftwareVersion.from_string(await blade.system.partitions.booted.read().then((bootedPartition) => bootedPartition?.version.read()) ?? ''); if (version && version.compare(vscript_1.SoftwareVersion.from_string('1.11')) < 0) { // V__api doesn't support 1.10 and thus doesn't know about `"MULTIVIEWER_40GbE"` // @ts-expect-error await blade.system.select_fpga.command.write('MULTIVIEWER_40GbE'); } else { await blade.system.select_fpga.command.write('DMV_40GbE'); } await vscript_1.pause(2); await blade.raw.reset(); await vscript_1.pause(10); if (clusterVersion && clusterVersion.compare(version) !== 0) { console.error(`Node ${scriptIp} software version ${version.to_string()} does not match Cluster software version ${clusterVersion.to_string()}!`); const updateFile = fs_1.readFileSync(`V_matrix_${clusterVersion.to_string()}`); await node_fetch_1.default(`http://${scriptIp}/software_update`, { method: 'PUT', body: updateFile }); await blade.software_update.install.write('Click'); } if (node.hostname) { await blade.system.usrinfo.short_desc.write(node.hostname); } } catch (error) { console.error(error); } finally { await blade.close(); await vscript_1.pause(2); } } /** * Runs the Nodes Configuration * * @param config The DMV Configuration */ const runNodesConfigAll = (config) => Promise.all(config.nodes.map((node) => runNodeConfig1(node, node.scriptIp, config.cluster.syslog, config.cluster.version ? vscript_1.SoftwareVersion.from_string(config.cluster.version) : undefined))); exports.runNodesConfigAll = runNodesConfigAll; exports.default = exports.runNodesConfigAll; //# sourceMappingURL=nodes.js.map