refactor: flatten CLI directory structure - remove 'box in a box'
BEFORE: /opt/aitbc/cli/ ├── aitbc_cli/ # Python package (box in a box) │ ├── commands/ │ ├── main.py │ └── ... ├── setup.py AFTER: /opt/aitbc/cli/ # Flat structure ├── commands/ # Direct access ├── main.py # Direct access ├── auth/ ├── config/ ├── core/ ├── models/ ├── utils/ ├── plugins.py └── setup.py CHANGES MADE: - Moved all files from aitbc_cli/ to cli/ root - Fixed all relative imports (from . to absolute imports) - Updated setup.py entry point: aitbc_cli.main → main - Added CLI directory to Python path in entry script - Simplified deployment.py to remove dependency on deleted core.deployment - Fixed import paths in all command files - Recreated virtual environment with new structure BENEFITS: - Eliminated 'box in a box' nesting - Simpler directory structure - Direct access to all modules - Cleaner imports - Easier maintenance and development - CLI works with both 'python main.py' and 'aitbc' commands
This commit is contained in:
67
cli/commands/multi_region_load_balancer.py
Executable file
67
cli/commands/multi_region_load_balancer.py
Executable file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
Multi-Region Load Balancer CLI Commands for AITBC
|
||||
Commands for managing multi-region load balancing
|
||||
"""
|
||||
|
||||
import click
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
@click.group()
|
||||
def multi_region_load_balancer():
|
||||
"""Multi-region load balancer management commands"""
|
||||
pass
|
||||
|
||||
@multi_region_load_balancer.command()
|
||||
@click.option('--test-mode', is_flag=True, help='Run in test mode')
|
||||
def status(test_mode):
|
||||
"""Get load balancer status"""
|
||||
try:
|
||||
if test_mode:
|
||||
click.echo("⚖️ Load Balancer Status (test mode)")
|
||||
click.echo("📊 Total Rules: 5")
|
||||
click.echo("✅ Active Rules: 5")
|
||||
click.echo("🌍 Regions: 3")
|
||||
click.echo("📈 Requests/sec: 1,250")
|
||||
return
|
||||
|
||||
# Get status from service
|
||||
config = get_config()
|
||||
response = requests.get(
|
||||
f"{config.coordinator_url}/api/v1/dashboard",
|
||||
headers={"Authorization": f"Bearer {config.api_key}"},
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
status = response.json()
|
||||
dashboard = status['dashboard']
|
||||
click.echo("⚖️ Load Balancer Status")
|
||||
click.echo(f"📊 Total Rules: {dashboard.get('total_balancers', 0)}")
|
||||
click.echo(f"✅ Active Rules: {dashboard.get('active_balancers', 0)}")
|
||||
click.echo(f"🌍 Regions: {dashboard.get('regions', 0)}")
|
||||
click.echo(f"📈 Requests/sec: {dashboard.get('requests_per_second', 0)}")
|
||||
else:
|
||||
click.echo(f"❌ Failed to get status: {response.text}", err=True)
|
||||
|
||||
except Exception as e:
|
||||
click.echo(f"❌ Error getting status: {str(e)}", err=True)
|
||||
|
||||
# Helper function to get config
|
||||
def get_config():
|
||||
"""Get CLI configuration"""
|
||||
try:
|
||||
from config import get_config
|
||||
return get_config()
|
||||
except ImportError:
|
||||
# Fallback for testing
|
||||
from types import SimpleNamespace
|
||||
return SimpleNamespace(
|
||||
coordinator_url="http://localhost:8019",
|
||||
api_key="test-api-key"
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
multi_region_load_balancer()
|
||||
Reference in New Issue
Block a user