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)
82 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CienaSaosConnection = void 0;
const base_connection_1 = require("../base-connection");
class CienaSaosConnection extends base_connection_1.BaseConnection {
constructor(credentials) {
super(credentials);
}
async sessionPreparation() {
await this.createCienaShellChannel();
await this.setBasePrompt();
await this.disablePaging();
}
async createCienaShellChannel() {
return new Promise((resolve, reject) => {
this.client.shell((err, channel) => {
if (err) {
reject(err);
return;
}
this.currentChannel = channel;
this.currentChannel.setEncoding(this.encoding);
setTimeout(() => resolve(), this.fastMode ? 200 : 600);
});
});
}
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 + '#';
}
async disablePaging() {
try {
await this.writeChannel('system shell session set more off' + this.newline);
await this.readChannel(2000);
}
catch (error) {
}
}
async saveConfig() {
try {
await this.writeChannel('configuration save' + this.newline);
const output = await this.readUntilPrompt(undefined, 10000);
return {
command: 'configuration save',
output: this.sanitizeOutput(output, 'configuration save'),
success: true
};
}
catch (error) {
return {
command: 'configuration save',
output: '',
success: false,
error: error instanceof Error ? error.message : String(error)
};
}
}
async enterConfigMode() { return; }
async exitConfigMode() { return; }
isInConfigMode() { return false; }
sanitizeOutput(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];
const promptRegex = new RegExp(`^${this.escapeRegex(this.basePrompt)}[>#$]`);
if (promptRegex.test(lastLine)) {
lines.pop();
}
}
return lines.join('\n').trim();
}
}
exports.CienaSaosConnection = CienaSaosConnection;
//# sourceMappingURL=ciena-saos-connection.js.map