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)

149 lines 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtremeExosConnection = void 0; const cisco_connection_1 = require("../cisco/cisco-connection"); class ExtremeExosConnection extends cisco_connection_1.CiscoConnection { constructor(credentials) { super(credentials); this.promptIdPattern = /[\*\s]*(.*)\.\d+/; } async sessionPreparation() { await this.createCiscoShellChannel(); if (this.fastMode) { await this.setBasePrompt(); } else { await this.setBasePrompt(); await this.disableExosPaging(); await this.disableExosPrompting(); } } 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]; let prompt = lastLine.replace(/[>#$]\s*$/, '').trim(); const match = prompt.match(this.promptIdPattern); if (match) { this.basePrompt = match[1]; } else { this.basePrompt = prompt; } } async disableExosPaging() { try { await this.writeChannel('disable clipaging' + this.newline); await this.readChannel(2000); } catch (error) { } } async disableExosPrompting() { try { await this.writeChannel('disable cli prompting' + this.newline); await this.readChannel(2000); } catch (error) { } } async sendCommand(command) { try { if (!this.isConnected || !this.currentChannel) { throw new Error('Not connected to device'); } await this.setBasePrompt(); await this.writeChannel(command + this.newline); const output = await this.readUntilPrompt(undefined, 10000); const cleanOutput = this.sanitizeExosOutput(output, command); return { command, output: cleanOutput, success: true }; } catch (error) { return { command, output: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } async sendConfig(configCommands) { try { if (!this.isConnected || !this.currentChannel) { throw new Error('Not connected to device'); } let allOutput = ''; for (const command of configCommands) { const result = await this.sendCommand(command); if (!result.success) { throw new Error(`Command failed: ${command} - ${result.error}`); } allOutput += result.output + '\n'; } return { command: configCommands.join('; '), output: allOutput.trim(), success: true }; } catch (error) { return { command: configCommands.join('; '), output: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } async getCurrentConfig() { return await this.sendCommand('show configuration'); } async saveConfig() { return await this.sendCommand('save configuration primary'); } async showSwitch() { return await this.sendCommand('show switch'); } async showSystem() { return await this.sendCommand('show version'); } async rebootDevice() { try { await this.writeChannel('reboot' + this.newline); const output = await this.readChannel(3000); return { command: 'reboot', output: output, success: true }; } catch (error) { return { command: 'reboot', output: '', success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } sanitizeExosOutput(output, command) { const lines = output.split('\n'); if (lines.length > 0 && lines[0].includes(command)) { lines.shift(); } if (lines.length > 0) { const lastLine = lines[lines.length - 1]; if (this.promptIdPattern.test(lastLine) || lastLine.includes('#') || lastLine.includes('>')) { lines.pop(); } } return lines.join('\n').trim(); } } exports.ExtremeExosConnection = ExtremeExosConnection; //# sourceMappingURL=extreme-exos-connection.js.map