#!/usr/bin/env python3 """ Generate Proxmox documentation from within the worker container. This script tests the complete flow: collect data -> generate docs using template. """ import asyncio import logging import sys from pathlib import Path # Configure logging logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", handlers=[ logging.StreamHandler(sys.stdout), logging.FileHandler("/tmp/proxmox_docs_container.log") ] ) logger = logging.getLogger(__name__) async def main(): """Main function to generate Proxmox documentation""" try: logger.info("=" * 80) logger.info("PROXMOX DOCUMENTATION GENERATION TEST") logger.info("=" * 80) # Import after configuring logging from datacenter_docs.collectors.proxmox_collector import ProxmoxCollector from datacenter_docs.generators.template_generator import TemplateBasedGenerator # Step 1: Collect Proxmox data logger.info("\n[STEP 1] Collecting Proxmox data...") collector = ProxmoxCollector() collect_result = await collector.run() if not collect_result["success"]: logger.error(f"❌ Collection failed: {collect_result['error']}") return False logger.info("✅ Data collection successful") # Log collected data summary data = collect_result.get("data", {}) vms = data.get("data", {}).get("vms", []) containers = data.get("data", {}).get("containers", []) nodes = data.get("data", {}).get("nodes", []) logger.info(f" - VMs: {len(vms)}") logger.info(f" - Containers: {len(containers)}") logger.info(f" - Nodes: {len(nodes)}") # Step 2: Generate documentation using template logger.info("\n[STEP 2] Generating documentation using template...") template_path = "/app/templates/documentation/proxmox.yaml" if not Path(template_path).exists(): logger.error(f"❌ Template not found: {template_path}") return False logger.info(f" Using template: {template_path}") generator = TemplateBasedGenerator(template_path) # Generate and save each section individually logger.info("\n[STEP 3] Generating documentation sections...") sections_results = await generator.generate_and_save_sections( data=data, save_individually=True ) # Print results logger.info("\n" + "=" * 80) logger.info("GENERATION RESULTS") logger.info("=" * 80) success_count = 0 failed_count = 0 for i, result in enumerate(sections_results, 1): section_id = result.get("section_id", "unknown") title = result.get("title", "Unknown") success = result.get("success", False) if success: success_count += 1 file_path = result.get("file_path", "N/A") logger.info(f"✅ Section {i}: {title}") logger.info(f" File: {file_path}") else: failed_count += 1 error = result.get("error", "Unknown error") logger.info(f"❌ Section {i}: {title}") logger.info(f" Error: {error}") # Final summary logger.info("\n" + "=" * 80) logger.info("SUMMARY") logger.info("=" * 80) logger.info(f"Total sections: {len(sections_results)}") logger.info(f"Successful: {success_count}") logger.info(f"Failed: {failed_count}") logger.info(f"Success rate: {(success_count / len(sections_results) * 100):.1f}%") logger.info("=" * 80) return success_count == len(sections_results) except Exception as e: logger.error(f"❌ Unexpected error: {e}", exc_info=True) return False if __name__ == "__main__": success = asyncio.run(main()) sys.exit(0 if success else 1)