UNPKG

n8n-nodes-netdevices

Version:

n8n node to interact with network devices (Cisco, MikroTik, Arista, Extreme Networks, Dell, Juniper, HP, Aruba, Ubiquiti, Palo Alto, Fortinet - ISP, data center, campus, and edge)

96 lines 3.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VyosConnection = void 0; const cisco_connection_1 = require("../cisco/cisco-connection"); const no_enable_1 = require("../no-enable"); class VyosConnectionBase extends cisco_connection_1.CiscoConnection { async sessionPreparation() { await this.createShellChannel(); await Promise.all([this.setTerminalWidth(), this.disablePaging()]); await this.setBasePrompt(); } async enterConfigMode() { if (this.inConfigMode) { return; } try { await this.writeChannel('configure' + this.newline); const output = await this.readUntilPrompt('[edit]', 3000); if (output.includes('[edit]')) { this.inConfigMode = true; } else { throw new Error('Failed to enter configuration mode'); } } catch (error) { throw new Error(`Failed to enter configuration mode: ${error}`); } } async exitConfigMode() { if (!this.inConfigMode) { return; } try { await this.writeChannel('exit' + this.newline); let output = await this.readChannel(3000); if (output.includes('Cannot exit: configuration modified')) { await this.writeChannel('exit discard' + this.newline); output = await this.readUntilPrompt(undefined, 3000); } if (!output.includes('[edit]')) { this.inConfigMode = false; } else { throw new Error('Failed to exit configuration mode'); } } catch (error) { throw new Error(`Failed to exit configuration mode: ${error}`); } } async commit() { try { await this.enterConfigMode(); await this.writeChannel('commit' + this.newline); const output = await this.readUntilPrompt(undefined, 120000); if (output.includes('Failed to generate committed config') || output.includes('Commit failed')) { throw new Error(`Commit failed with following errors:\n\n${output}`); } return output; } catch (error) { throw new Error(`Failed to commit configuration: ${error}`); } } async saveConfig() { try { await this.enterConfigMode(); await this.writeChannel('save' + this.newline); const output = await this.readUntilPrompt(undefined, 30000); await this.exitConfigMode(); if (!output.includes('Done')) { throw new Error(`Save failed with following errors:\n\n${output}`); } return { command: 'save', output: output, success: true, }; } catch (error) { throw new Error(`Failed to save configuration: ${error}`); } } async setBasePrompt() { await this.writeChannel(this.returnChar); const output = await this.readChannel(3000); const lines = output.trim().split('\n'); const lastLine = lines[lines.length - 1]; this.basePrompt = lastLine.replace(/[>#$]\s*$/, '').trim(); this.enabledPrompt = this.basePrompt + '#'; this.configPrompt = this.basePrompt + '[edit]'; } } exports.VyosConnection = (0, no_enable_1.NoEnable)(VyosConnectionBase); //# sourceMappingURL=vyos-connection.js.map