Skip to content

Commit

Permalink
cisco-iosxe: add timeout support
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffhouse committed May 14, 2024
1 parent 103cea9 commit 6abcf5b
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 30 deletions.
30 changes: 18 additions & 12 deletions src/modules/cisco-iosxe/client/components/InterfaceList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function InterfaceList({ panelId, stackId = null }) {
event.stopPropagation();
let result = await renameDialog({
title: "Edit interface name",
defaultValue: item["description"],
defaultValue: item["description"] === "." ? "" : item["description"],
placeholder: item["interfaceId"],
confirmButtonText: "Rename",
allowBlank: true,
Expand Down Expand Up @@ -288,17 +288,23 @@ export default function InterfaceList({ panelId, stackId = null }) {
minWidth: "150px",
noWrap: true,
title: "Name",
content: (item) => (
<>
<BugTableLinkButton
disabled={item._protected}
onClick={(event) => handleRenameClicked(event, item)}
>
{item.description ? item.description : item.interfaceId}
</BugTableLinkButton>
{getItemSubName(item)}
</>
),
content: (item) => {
return (
<>
<BugTableLinkButton
disabled={item._protected}
onClick={(event) => handleRenameClicked(event, item)}
>
{item.description
? item.description === "."
? item.interfaceId
: item.description
: item.interfaceId}
</BugTableLinkButton>
{getItemSubName(item)}
</>
);
},
},
{
title: "VLAN",
Expand Down
19 changes: 19 additions & 0 deletions src/modules/cisco-iosxe/client/panels/ConfigPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useConfigFormHandler } from "@hooks/ConfigFormHandler";
import BugConfigWrapper from "@core/BugConfigWrapper";
import BugConfigFormChipInput from "@core/BugConfigFormChipInput";
import BugConfigFormMultiPanelSelect from "@core/BugConfigFormMultiPanelSelect";
import InputAdornment from "@mui/material/InputAdornment";

export default function ConfigPanel() {
const panelConfig = useSelector((state) => state.panelConfig);
Expand Down Expand Up @@ -113,6 +114,24 @@ export default function ConfigPanel() {
/>
</Grid>

<Grid item xs={6}>
<BugConfigFormTextField
name="timeout"
control={control}
fullWidth
error={errors.timeout}
defaultValue={panelConfig.data.timeout === undefined ? 5 : panelConfig.data.timeout}
label="Default timeout"
filter={/[^0-9]/}
numeric
min={1000}
max={60000}
InputProps={{
endAdornment: <InputAdornment position="end">ms</InputAdornment>,
}}
/>
</Grid>

<Grid item xs={12}>
<BugConfigFormChipInput
name="protectedInterfaces"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cisco-iosxe/container/services/device-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = async () => {
host: config["address"],
path: `/restconf/operations/cisco-ia:save-config/`,
data: null,
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = async (interfaceId) => {
enabled: false,
},
},
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = async (interfaceId) => {
enabled: true,
},
},
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
});
Expand Down
11 changes: 8 additions & 3 deletions src/modules/cisco-iosxe/container/services/interface-rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ module.exports = async (interfaceId, newName) => {
console.log(`interface-rename: interface ${interfaceId} not found`);
return false;
}

// cisco can't set an empty description
const nonEmptyNewName = newName.trim() ? newName.trim() : ".";

const result = await ciscoIOSXEApi.update({
host: config["address"],
path: `/restconf/data/Cisco-IOS-XE-native:native/interface/${dbInterface.type}=${encodeURIComponent(
dbInterface.portIndex
)}`,
data: {
[dbInterface.type]: {
description: newName,
description: nonEmptyNewName,
},
},
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
debug: true,
});
if (result) {
console.log(`interface-rename: success - updating DB`);
try {
const dbResult = await interfacesCollection.updateOne(
{ interfaceId: interfaceId },
{ $set: { description: newName } }
{ $set: { description: nonEmptyNewName } }
);
console.log(`interface-rename: ${JSON.stringify(dbResult.result)}`);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = async (interfaceId, untaggedVlan = "1") => {
},
},
},
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = async (interfaceId, untaggedVlan = 1, taggedVlans = []) => {
},
},
},
timeout: 5000,
timeout: config["timeout"],
username: config["username"],
password: config["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const register = require("module-alias/register");
const mongoDb = require("@core/mongo-db");
const mongoCollection = require("@core/mongo-collection");
const ciscoIOSXEApi = require("@utils/ciscoiosxe-api");
const { SlowBuffer } = require("buffer");

// Tell the manager the things you care about
parentPort.postMessage({
Expand Down Expand Up @@ -41,7 +42,7 @@ const convertPortSpeed = (speed) => {
};

const parseReason = (reason) => {
if (reason.indexOf("port-err-") === 0) {
if (reason?.indexOf("port-err-") === 0) {
return reason.split("-")[2];
}
return reason;
Expand Down Expand Up @@ -69,7 +70,7 @@ const main = async () => {
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface",
data: data,
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const main = async () => {
const result = await ciscoIOSXEApi.get({
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-matm-oper:matm-oper-data/matm-table",
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down Expand Up @@ -107,7 +107,7 @@ const main = async () => {
const lldpResult = await ciscoIOSXEApi.get({
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-lldp-oper:lldp-entries/lldp-intf-details",
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const main = async () => {
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface",
data: data,
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const main = async () => {
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface",
data: data,
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parentPort.postMessage({
const snmpAwait = new SnmpAwait({
host: workerData.address,
community: workerData.snmpCommunity,
timeout: workerData["timeout"],
});

const main = async () => {
Expand Down Expand Up @@ -51,7 +52,7 @@ const main = async () => {
host: workerData["address"],
path: `/restconf/data/Cisco-IOS-XE-native:native/interface/${eachType}`,
data: data,
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cisco-iosxe/container/workers/worker-vlans.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const main = async () => {
host: workerData["address"],
path: "/restconf/data/Cisco-IOS-XE-vlan-oper:vlans/vlan",
data: data,
timeout: 5000,
timeout: parseInt(workerData["timeout"] ? workerData["timeout"] : 5000),
username: workerData["username"],
password: workerData["password"],
});
Expand Down
5 changes: 3 additions & 2 deletions src/modules/cisco-iosxe/module.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cisco-iosxe",
"longname": "Cisco IOS-XE Switch",
"version": "1.0.3",
"version": "1.0.4",
"description": "Monitoring and control of Cisco IOS-XE based switches",
"capabilities": ["network-switch"],
"icon": "SettingsEthernet",
Expand All @@ -27,6 +27,7 @@
"password": "",
"snmpCommunity": "public",
"protectedInterfaces": [],
"dhcpSources": []
"dhcpSources": [],
"timeout": 5
}
}

0 comments on commit 6abcf5b

Please sign in to comment.