- 55 CLI files: handlers/, aitbc_cli/commands/, cli/core/, cli/utils/, top-level scripts
- Click-based files: print() -> click.echo()
- Library modules: print() -> logger.info/error/warning
- Fixed pre-existing indentation bugs in monitor.py dashboard function
- Fixed bare print() -> logger.info('') in chain_manager.py
- 0 remaining print() in production CLI code
- All files compile cleanly
88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
"""Resource command handlers for AITBC CLI."""
|
|
|
|
import json
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def handle_resource_status(args, output_format, render_mapping):
|
|
"""Handle resource status command."""
|
|
status_data = {
|
|
"cpu": {"usage": 45, "available": 55},
|
|
"memory": {"usage": 62, "available": 38},
|
|
"disk": {"usage": 30, "available": 70},
|
|
"gpu": {"usage": 0, "available": 100},
|
|
"timestamp": __import__('datetime').datetime.now().isoformat()
|
|
}
|
|
|
|
if output_format(args) == "json":
|
|
logger.info(json.dumps(status_data, indent=2))
|
|
else:
|
|
render_mapping("Resource Status:", status_data)
|
|
|
|
|
|
def handle_resource_allocate(args, render_mapping):
|
|
"""Handle resource allocate command."""
|
|
agent_id = getattr(args, "agent_id", None)
|
|
cpu = getattr(args, "cpu", 2)
|
|
memory = getattr(args, "memory", 4096)
|
|
|
|
allocation_data = {
|
|
"agent_id": agent_id,
|
|
"cpu_allocated": cpu,
|
|
"memory_allocated_mb": memory,
|
|
"status": "allocated",
|
|
"timestamp": __import__('datetime').datetime.now().isoformat()
|
|
}
|
|
|
|
logger.info(f"Resources allocated to {agent_id}")
|
|
render_mapping("Allocation:", allocation_data)
|
|
|
|
|
|
def handle_resource_monitor(args, render_mapping):
|
|
"""Handle resource monitor command."""
|
|
interval = getattr(args, "interval", 5)
|
|
duration = getattr(args, "duration", 10)
|
|
|
|
monitor_data = {
|
|
"monitoring_active": True,
|
|
"interval_seconds": interval,
|
|
"duration_seconds": duration,
|
|
"metrics_collected": 0,
|
|
"timestamp": __import__('datetime').datetime.now().isoformat()
|
|
}
|
|
|
|
logger.info(f"Resource monitoring started (interval: {interval}s, duration: {duration}s)")
|
|
render_mapping("Monitor:", monitor_data)
|
|
|
|
|
|
def handle_resource_optimize(args, render_mapping):
|
|
"""Handle resource optimize command."""
|
|
target = getattr(args, "target", "cpu")
|
|
|
|
optimization_data = {
|
|
"target": target,
|
|
"optimization_applied": True,
|
|
"efficiency_gain": "12%",
|
|
"timestamp": __import__('datetime').datetime.now().isoformat()
|
|
}
|
|
|
|
logger.info(f"Resource optimization applied for {target}")
|
|
render_mapping("Optimization:", optimization_data)
|
|
|
|
|
|
def handle_resource_benchmark(args, render_mapping):
|
|
"""Handle resource benchmark command."""
|
|
benchmark_type = getattr(args, "type", "cpu")
|
|
|
|
benchmark_data = {
|
|
"type": benchmark_type,
|
|
"score": 850,
|
|
"units": "operations/sec",
|
|
"timestamp": __import__('datetime').datetime.now().isoformat()
|
|
}
|
|
|
|
logger.info(f"Resource benchmark completed for {benchmark_type}")
|
|
render_mapping("Benchmark:", benchmark_data)
|