35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
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 |