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)

132 lines 4.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HPProcurveConnection = void 0; const cisco_connection_1 = require("../cisco/cisco-connection"); class HPProcurveConnection extends cisco_connection_1.CiscoConnection { constructor(credentials) { super(credentials); } async sessionPreparation() { await this.createCiscoShellChannel(); if (this.fastMode) { await this.handleContinuePrompt(); await this.setBasePrompt(); } else { await this.handleContinuePrompt(); await this.setBasePrompt(); await this.checkAndEnterEnableMode(); await this.setTerminalWidth(); await this.disableHPPaging(); } } async handleContinuePrompt() { try { const output = await this.readChannel(2000); if (output.toLowerCase().includes('any key to continue')) { await this.writeChannel(this.returnChar); await this.readChannel(3000); } } catch (error) { } } async disableHPPaging() { try { await this.writeChannel('no page' + this.newline); await this.readChannel(2000); } catch (error) { } } async setTerminalWidth() { try { await this.writeChannel('terminal width 511' + this.newline); await this.readChannel(2000); } catch (error) { } } async checkConfigMode() { try { await this.writeChannel(this.returnChar); const output = await this.readChannel(2000); return output.includes(')#'); } catch (error) { return false; } } async enterConfigMode() { if (await this.checkConfigMode()) { this.inConfigMode = true; return; } if (!this.inEnableMode) { await this.enterEnableMode(); } try { await this.writeChannel('configure terminal' + this.newline); const output = await this.readChannel(3000); if (output.includes(')#')) { 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); const output = await this.readChannel(3000); if (output.includes('#') && !output.includes(')#')) { this.inConfigMode = false; } else { throw new Error('Failed to exit configuration mode'); } } catch (error) { throw new Error(`Failed to exit configuration mode: ${error}`); } } async getCurrentConfig() { return await this.sendCommand('show running-config'); } async saveConfig() { return await this.sendCommand('write memory'); } async disconnect() { if (!this.isConnected) { return; } try { if (this.inConfigMode) { await this.exitConfigMode(); } await this.writeChannel('logout' + this.newline); let output = await this.readChannel(2000); if (output.toLowerCase().includes('do you want to save')) { await this.writeChannel('n' + this.newline); output = await this.readChannel(2000); } if (output.toLowerCase().includes('do you want to log out')) { await this.writeChannel('y' + this.newline); } } catch (error) { } finally { await super.disconnect(); } } } exports.HPProcurveConnection = HPProcurveConnection; //# sourceMappingURL=hp-procurve-connection.js.map