Add node deletion functionality to FARMQ Admin
- Add DELETE API endpoint for node deletion via Headscale CLI - Add delete buttons to both table and card views in machine list - Implement confirmation dialog with clear warning message - Add proper error handling and user feedback with toast messages - Auto-refresh page after successful deletion - Match Headplane functionality for complete node management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ from utils.database_new import (
|
||||
get_machine_detail, get_pharmacy_detail, get_active_alerts,
|
||||
sync_machines_from_headscale, sync_users_from_headscale
|
||||
)
|
||||
import subprocess
|
||||
from utils.proxmox_client import ProxmoxClient
|
||||
|
||||
def create_app(config_name=None):
|
||||
@@ -400,6 +401,42 @@ def create_app(config_name=None):
|
||||
print(f"❌ VM 정지 오류: {e}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
# 노드 삭제 API
|
||||
@app.route('/api/nodes/<int:node_id>/delete', methods=['DELETE'])
|
||||
def api_delete_node(node_id):
|
||||
"""노드 삭제 API"""
|
||||
try:
|
||||
# Headscale CLI를 통해 노드 삭제
|
||||
result = subprocess.run(
|
||||
['docker', 'exec', 'headscale', 'headscale', 'nodes', 'delete', '-i', str(node_id), '--force'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
# 삭제 성공
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': f'노드 {node_id}가 성공적으로 삭제되었습니다.',
|
||||
'output': result.stdout
|
||||
})
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
# Headscale CLI 오류
|
||||
error_msg = e.stderr if e.stderr else e.stdout
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'노드 삭제 실패: {error_msg}'
|
||||
}), 400
|
||||
|
||||
except Exception as e:
|
||||
# 기타 오류
|
||||
print(f"❌ 노드 삭제 오류: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'서버 오류: {str(e)}'
|
||||
}), 500
|
||||
|
||||
# 에러 핸들러
|
||||
@app.errorhandler(404)
|
||||
def not_found_error(error):
|
||||
|
||||
Reference in New Issue
Block a user