This commit is contained in:
2025-11-27 14:57:15 +01:00
parent bd4bc7cb24
commit 2d2362815b
8 changed files with 1024 additions and 6 deletions

View File

@@ -1,10 +1,13 @@
from flask import Flask,jsonify,request,abort, make_response,send_file
from werkzeug.exceptions import HTTPException
from nornir import InitNornir
from flask_cors import CORS
import os
from werkzeug.utils import secure_filename
import json
ALLOWED_EXTENSIONS = {'conf'}
UPLOAD_FOLDER = 'fastprod/upload_files/'
@@ -20,6 +23,8 @@ def allowed_file(filename):
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
CORS(app)
from services.devices import ( get_inventory, add_device,get_device_by_name,delete_device,get_device_interfaces,get_device_interfaces_ip,get_device_technical_info)
from services.config import (get_config_by_device,run_config_from_file_by_device)
@@ -75,7 +80,7 @@ def get_technical_info(device_name):
if request.method == 'GET':
device = get_device_by_name(device_name)
technical_info = get_device_technical_info(device)
return jsonify(interfaces_ip=technical_info)
return jsonify(facts=technical_info)
@app.route("/devices/<device_name>/config", methods=['GET','POST'])
def get_config(device_name):
@@ -109,15 +114,13 @@ def snapshot(device_name):
data = get_snapshots_by_device(device)
return jsonify({
"result": True,
"data": data
"snapshots": data
})
if request.method == 'POST':
snapshot_path = create_snapshot_by_device(device)
return jsonify({
"result": True,
"data": {
"snapshot_path": snapshot_path
}
"snapshots": snapshot_path
})
@app.route("/snapshots/<path:filename>", methods=['GET'])

View File

@@ -0,0 +1,236 @@
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
no service dhcp
!
hostname ESW1-CPE-BAT-A
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
no ip routing
no ip icmp rate-limit unreachable
no ip cef
!
!
!
!
no ip domain lookup
ip domain name esw1.local
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
macro name add_vlan
end
vlan database
vlan $v
exit
@
macro name del_vlan
end
vlan database
no vlan $v
exit
@
!
vtp file nvram:vlan.dat
username cisco privilege 15 password 0 cisco
archive
log config
hidekeys
!
!
!
!
ip tcp synwait-time 5
ip ssh version 2
!
!
!
!
interface Loopback1
no ip address
!
interface FastEthernet0/0
description *** Unused for Layer2 EtherSwitch ***
no ip address
no ip route-cache
duplex auto
speed auto
!
interface FastEthernet0/1
description *** Unused for Layer2 EtherSwitch ***
no ip address
no ip route-cache
shutdown
duplex auto
speed auto
!
interface FastEthernet1/0
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/1
description "port vlan teacher"
switchport access vlan 10
duplex full
speed 100
!
interface FastEthernet1/2
description "port vlan student"
switchport access vlan 20
duplex full
speed 100
!
interface FastEthernet1/3
duplex full
speed 100
!
interface FastEthernet1/4
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/5
duplex full
speed 100
!
interface FastEthernet1/6
duplex full
speed 100
!
interface FastEthernet1/7
duplex full
speed 100
!
interface FastEthernet1/8
duplex full
speed 100
!
interface FastEthernet1/9
duplex full
speed 100
!
interface FastEthernet1/10
duplex full
speed 100
!
interface FastEthernet1/11
duplex full
speed 100
!
interface FastEthernet1/12
duplex full
speed 100
!
interface FastEthernet1/13
duplex full
speed 100
!
interface FastEthernet1/14
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/15
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet2/0
no ip address
no ip route-cache
shutdown
duplex auto
speed auto
!
interface Vlan1
no ip address
no ip route-cache
!
interface Vlan99
ip address 172.16.100.123 255.255.255.192
!
ip forward-protocol nd
!
!
no ip http server
no ip http secure-server
!
no cdp log mismatch duplex
!
!
!
!
!
!
control-plane
!
!
!
!
!
!
!
!
!
banner exec ^C
***************************************************************
This is a normal Router with a Switch module inside (NM-16ESW)
It has been pre-configured with hard-coded speed and duplex
To create vlans use the command "vlan database" in exec mode
After creating all desired vlans use "exit" to apply the config
To view existing vlans use the command "show vlan-switch brief"
Alias(exec) : vl - "show vlan-switch brief" command
Alias(configure): va X - macro to add vlan X
Alias(configure): vd X - macro to delete vlan X
***************************************************************
^C
alias configure va macro global trace add_vlan $v
alias configure vd macro global trace del_vlan $v
alias exec vl show vlan-switch brief
!
line con 0
exec-timeout 0 0
privilege level 15
logging synchronous
line aux 0
exec-timeout 0 0
privilege level 15
logging synchronous
line vty 0 4
login local
transport input ssh
!
!
end

View File

@@ -0,0 +1,236 @@
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
no service dhcp
!
hostname ESW1-CPE-BAT-A
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
no ip routing
no ip icmp rate-limit unreachable
no ip cef
!
!
!
!
no ip domain lookup
ip domain name esw1.local
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
macro name add_vlan
end
vlan database
vlan $v
exit
@
macro name del_vlan
end
vlan database
no vlan $v
exit
@
!
vtp file nvram:vlan.dat
username cisco privilege 15 password 0 cisco
archive
log config
hidekeys
!
!
!
!
ip tcp synwait-time 5
ip ssh version 2
!
!
!
!
interface Loopback1
no ip address
!
interface FastEthernet0/0
description *** Unused for Layer2 EtherSwitch ***
no ip address
no ip route-cache
duplex auto
speed auto
!
interface FastEthernet0/1
description *** Unused for Layer2 EtherSwitch ***
no ip address
no ip route-cache
shutdown
duplex auto
speed auto
!
interface FastEthernet1/0
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/1
description "port vlan teacher"
switchport access vlan 10
duplex full
speed 100
!
interface FastEthernet1/2
description "port vlan student"
switchport access vlan 20
duplex full
speed 100
!
interface FastEthernet1/3
duplex full
speed 100
!
interface FastEthernet1/4
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/5
duplex full
speed 100
!
interface FastEthernet1/6
duplex full
speed 100
!
interface FastEthernet1/7
duplex full
speed 100
!
interface FastEthernet1/8
duplex full
speed 100
!
interface FastEthernet1/9
duplex full
speed 100
!
interface FastEthernet1/10
duplex full
speed 100
!
interface FastEthernet1/11
duplex full
speed 100
!
interface FastEthernet1/12
duplex full
speed 100
!
interface FastEthernet1/13
duplex full
speed 100
!
interface FastEthernet1/14
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet1/15
switchport mode trunk
duplex full
speed 100
!
interface FastEthernet2/0
no ip address
no ip route-cache
shutdown
duplex auto
speed auto
!
interface Vlan1
no ip address
no ip route-cache
!
interface Vlan99
ip address 172.16.100.123 255.255.255.192
!
ip forward-protocol nd
!
!
no ip http server
no ip http secure-server
!
no cdp log mismatch duplex
!
!
!
!
!
!
control-plane
!
!
!
!
!
!
!
!
!
banner exec ^C
***************************************************************
This is a normal Router with a Switch module inside (NM-16ESW)
It has been pre-configured with hard-coded speed and duplex
To create vlans use the command "vlan database" in exec mode
After creating all desired vlans use "exit" to apply the config
To view existing vlans use the command "show vlan-switch brief"
Alias(exec) : vl - "show vlan-switch brief" command
Alias(configure): va X - macro to add vlan X
Alias(configure): vd X - macro to delete vlan X
***************************************************************
^C
alias configure va macro global trace add_vlan $v
alias configure vd macro global trace del_vlan $v
alias exec vl show vlan-switch brief
!
line con 0
exec-timeout 0 0
privilege level 15
logging synchronous
line aux 0
exec-timeout 0 0
privilege level 15
logging synchronous
line vty 0 4
login local
transport input ssh
!
!
end

View File

@@ -0,0 +1,168 @@
!
upgrade fpd auto
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1-CPE-BAT-A
!
boot-start-marker
boot-end-marker
!
logging message-counter syslog
!
no aaa new-model
ip source-route
no ip icmp rate-limit unreachable
ip cef
!
!
!
!
no ip domain lookup
ip domain name r1.cpe.local
no ipv6 cef
!
multilink bundle-name authenticated
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
file prompt quiet
username cisco privilege 15 password 0 cisco
archive
log config
hidekeys
!
!
!
!
!
ip tcp synwait-time 5
ip ssh version 2
ip scp server enable
!
!
!
!
interface Loopback1
description Loopback pour R1-CPE-BAT-A
ip address 1.1.1.1 255.255.255.255
!
interface Loopback2
description Loopback2 pour R1-CPE-BAT-A
ip address 1.1.1.2 255.255.255.255
!
interface Loopback10
description created from config file uploaded from postman
ip address 10.10.10.10 255.255.255.255
!
interface FastEthernet0/0
ip address 172.16.100.62 255.255.255.192
duplex half
!
interface Serial1/0
no ip address
shutdown
serial restart-delay 0
!
interface Serial1/1
ip address 10.1.1.1 255.255.255.252
shutdown
serial restart-delay 0
!
interface Serial1/2
no ip address
shutdown
serial restart-delay 0
!
interface Serial1/3
no ip address
shutdown
serial restart-delay 0
!
interface GigabitEthernet2/0
no ip address
negotiation auto
!
interface GigabitEthernet2/0.10
description "Gateway for teacher vlan"
encapsulation dot1Q 10
ip address 172.16.10.253 255.255.255.0
vrrp 10 ip 172.16.10.252
!
interface GigabitEthernet2/0.20
description "Gateway for student vlan"
encapsulation dot1Q 20
ip address 172.16.20.253 255.255.255.0
vrrp 20 ip 172.16.20.252
!
interface GigabitEthernet2/0.99
encapsulation dot1Q 99
ip address 172.16.100.125 255.255.255.192
vrrp 99 ip 172.16.100.124
!
router ospf 1
router-id 1.1.1.1
log-adjacency-changes
passive-interface FastEthernet0/0
passive-interface GigabitEthernet2/0.99
network 10.1.1.0 0.0.0.3 area 0
network 172.16.10.0 0.0.0.255 area 0
network 172.16.20.0 0.0.0.255 area 0
network 172.16.100.0 0.0.0.63 area 0
network 172.16.100.64 0.0.0.63 area 0
!
ip forward-protocol nd
no ip http server
no ip http secure-server
!
!
!
no cdp log mismatch duplex
!
!
!
!
!
!
control-plane
!
!
!
!
!
!
!
gatekeeper
shutdown
!
!
line con 0
exec-timeout 0 0
privilege level 15
logging synchronous
stopbits 1
line aux 0
exec-timeout 0 0
privilege level 15
logging synchronous
stopbits 1
line vty 0 4
login local
transport input ssh
!
end