Fin Projet avant bonus

This commit is contained in:
2025-11-27 14:06:29 +01:00
parent 0b7d66777e
commit bd4bc7cb24
10 changed files with 1254 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
import os
from datetime import datetime
from api import app
from services.config import get_config_by_device
from flask import Flask,jsonify,request,abort, make_response
snapshot_directory = 'fastprod/snapshots'
def get_snapshot_by_name(name):
files = os.listdir()
snapshots = []
for file in files:
file_device_name = file.split('_')[0]
if name == file:
snapshots.append(dict(file=file, path=snapshot_directory, at=file.split('_')[1].split('.')[0]))
return snapshots
def create_snapshot_by_device(device=None):
nr = app.config.get('nr')
config = get_config_by_device(device)
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
file_path = os.path.join(snapshot_directory, f"{device.get('name')}_{timestamp}.conf")
with open(file_path, 'w') as file:
file.write(config.get('running'))
return file_path
def get_snapshots_by_device(device):
files = os.listdir(snapshot_directory)
snapshots = []
for file in files:
file_device_name = file.split('_')[0]
if file_device_name == device.get('name'):
snapshots.append(dict(file=file, path=snapshot_directory, at=file.split('_')[1].split('.')[0]))
return snapshots