mirror of
https://github.com/Jerryplusy/AI-powered-switches.git
synced 2025-10-14 09:49:19 +00:00
Compare commits
4 Commits
2980489b5b
...
1776a6bd2c
Author | SHA1 | Date | |
---|---|---|---|
1776a6bd2c | |||
71243319e4 | |||
54fbecbab0 | |||
d6e8dfa13f |
3
.idea/AI-powered-switches.iml
generated
3
.idea/AI-powered-switches.iml
generated
@ -9,8 +9,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.11 (AI-powered-switches)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Python 3.13 interpreter library" level="application" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.13" />
|
<option name="sdkName" value="Python 3.13" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (AI-powered-switches)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
@ -29,6 +29,7 @@ const testMode = ConfigTool.load().testMode;
|
|||||||
const ConfigPage = () => {
|
const ConfigPage = () => {
|
||||||
const [devices, setDevices] = useState([]);
|
const [devices, setDevices] = useState([]);
|
||||||
const [selectedDevice, setSelectedDevice] = useState('');
|
const [selectedDevice, setSelectedDevice] = useState('');
|
||||||
|
const [selectedDeviceConfig, setSelectedDeviceConfig] = useState('');
|
||||||
const [inputText, setInputText] = useState('');
|
const [inputText, setInputText] = useState('');
|
||||||
const [parsedConfig, setParsedConfig] = useState('');
|
const [parsedConfig, setParsedConfig] = useState('');
|
||||||
const [editableConfig, setEditableConfig] = useState('');
|
const [editableConfig, setEditableConfig] = useState('');
|
||||||
@ -112,9 +113,26 @@ const ConfigPage = () => {
|
|||||||
setApplying(true);
|
setApplying(true);
|
||||||
setIsApplying(true);
|
setIsApplying(true);
|
||||||
try {
|
try {
|
||||||
const applyOperation = testMode
|
const applyOperation = async () => {
|
||||||
? Common.sleep(1000).then(() => ({ success: true }))
|
if (testMode) {
|
||||||
: await api.applyConfig(selectedDevice, JSON.parse(editableConfig)?.config?.commands);
|
Common.sleep(1000).then(() => ({ success: true }));
|
||||||
|
} else {
|
||||||
|
let commands = JSON.parse(editableConfig)?.config?.commands;
|
||||||
|
console.log(`commands:${JSON.stringify(commands)}`);
|
||||||
|
const deviceConfig = JSON.parse(selectedDeviceConfig);
|
||||||
|
console.log(`deviceConfig:${JSON.stringify(deviceConfig)}`);
|
||||||
|
if (!deviceConfig.username || !deviceConfig.password) {
|
||||||
|
Notification.warn({
|
||||||
|
title: '所选交换机暂未配置用户名和密码',
|
||||||
|
description: '请前往交换机设备处配置username和password',
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
commands.push(`username=${deviceConfig.username.toString()}`);
|
||||||
|
commands.push(`password=${deviceConfig.password.toString()}`);
|
||||||
|
await api.applyConfig(selectedDevice, commands);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
await Notification.promise({
|
await Notification.promise({
|
||||||
promise: applyOperation,
|
promise: applyOperation,
|
||||||
@ -152,7 +170,12 @@ const ConfigPage = () => {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
collection={deviceCollection}
|
collection={deviceCollection}
|
||||||
value={selectedDevice ? [selectedDevice] : []}
|
value={selectedDevice ? [selectedDevice] : []}
|
||||||
onValueChange={({ value }) => setSelectedDevice(value[0] ?? '')}
|
onValueChange={({ value }) => {
|
||||||
|
const selectedIp = value[0] ?? '';
|
||||||
|
setSelectedDevice(selectedIp);
|
||||||
|
const fullDeviceConfig = devices.find((device) => device.ip === selectedIp);
|
||||||
|
setSelectedDeviceConfig(JSON.stringify(fullDeviceConfig));
|
||||||
|
}}
|
||||||
placeholder={'请选择交换机设备'}
|
placeholder={'请选择交换机设备'}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
colorPalette={'teal'}
|
colorPalette={'teal'}
|
||||||
|
@ -27,7 +27,7 @@ const Dashboard = () => {
|
|||||||
const checkBackend = useCallback(async () => {
|
const checkBackend = useCallback(async () => {
|
||||||
setNetworkStatus('loading');
|
setNetworkStatus('loading');
|
||||||
try {
|
try {
|
||||||
const res = await api.test();
|
const res = true;//await api.test();
|
||||||
if (res) {
|
if (res) {
|
||||||
setNetworkStatus('ok');
|
setNetworkStatus('ok');
|
||||||
console.log(JSON.stringify(res));
|
console.log(JSON.stringify(res));
|
||||||
|
@ -50,7 +50,7 @@ export const api = {
|
|||||||
* @returns {Promise<axios.AxiosResponse<any>>}
|
* @returns {Promise<axios.AxiosResponse<any>>}
|
||||||
*/
|
*/
|
||||||
applyConfig: (switch_ip, commands) =>
|
applyConfig: (switch_ip, commands) =>
|
||||||
axios.post(buildUrl('/api/execute_cli_commands'), { switch_ip, commands }),
|
axios.post(buildUrl('/api/execute_cli_commands'), { switch_ip: switch_ip, commands: commands }),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新基础URL
|
* 更新基础URL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user