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)
136 lines • 4.37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DellOS10Connection = void 0;
const cisco_connection_1 = require("../cisco/cisco-connection");
class DellOS10Connection extends cisco_connection_1.CiscoConnection {
constructor(credentials) {
super(credentials);
}
async sessionPreparation() {
await this.createCiscoShellChannel();
if (this.fastMode) {
await this.setBasePrompt();
}
else {
await this.setBasePrompt();
await this.setTerminalWidth();
await this.disablePaging();
try {
await this.checkAndEnterEnableMode();
}
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) {
try {
await this.enterEnableMode();
}
catch (error) {
}
}
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-configuration');
}
async saveConfig() {
return await this.sendCommand('copy running-configuration startup-configuration');
}
async showVersion() {
return await this.sendCommand('show version');
}
async showInterfaces() {
return await this.sendCommand('show interface');
}
async showInventory() {
return await this.sendCommand('show system');
}
async systemCommand(linuxCommand) {
return await this.sendCommand(`system "${linuxCommand}"`);
}
async rebootDevice() {
try {
await this.writeChannel('reload' + this.newline);
let output = await this.readChannel(5000);
if (output.toLowerCase().includes('proceed') || output.includes('[confirm]')) {
await this.writeChannel('yes' + this.newline);
output += await this.readChannel(5000);
}
return {
command: 'reload',
output: output,
success: true
};
}
catch (error) {
return {
command: 'reload',
output: '',
success: false,
error: error instanceof Error ? error.message : 'Unknown error'
};
}
}
sanitizeOutput(output, command) {
const lines = output.split('\n');
if (lines[0].includes(command)) {
lines.shift();
}
if (lines.length > 0) {
const lastLine = lines[lines.length - 1];
const promptRegex = new RegExp(`^${this.escapeRegex(this.basePrompt)}[>#$]`);
if (promptRegex.test(lastLine) || lastLine.includes(')#')) {
lines.pop();
}
}
return lines.join('\n').trim();
}
}
exports.DellOS10Connection = DellOS10Connection;
//# sourceMappingURL=dell-os10-connection.js.map