check_dubbo_ports.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. import yaml
  3. from pathlib import Path
  4. repo_root = Path("d:/coding-area/devops/deploy/microservice-helm")
  5. chart_base = repo_root / "charts"
  6. # Get all service directories
  7. services = sorted([d.name for d in chart_base.iterdir() if d.is_dir() and d.name != "base"])
  8. dubbo_services = {}
  9. for service_name in services:
  10. values_path = chart_base / service_name / "values.yaml"
  11. if not values_path.exists():
  12. continue
  13. try:
  14. with open(values_path, 'r', encoding='utf-8') as f:
  15. values = yaml.safe_load(f)
  16. except Exception as e:
  17. print(f"ERROR reading {service_name}: {e}")
  18. continue
  19. # Check if service has dubbo configuration
  20. if values and 'config' in values and 'yml' in values['config']:
  21. config_yml = values['config']['yml']
  22. # Look for dubbo protocol port
  23. if 'dubbo' in config_yml and 'protocol' in config_yml['dubbo']:
  24. protocol = config_yml['dubbo']['protocol']
  25. if 'port' in protocol:
  26. dubbo_port = protocol['port']
  27. http_port = values['service']['port']
  28. dubbo_services[service_name] = {
  29. 'http_port': http_port,
  30. 'dubbo_port': dubbo_port
  31. }
  32. print(f"发现 {len(dubbo_services)} 个Dubbo服务:\n")
  33. for service_name in sorted(dubbo_services.keys()):
  34. info = dubbo_services[service_name]
  35. print(f"{service_name}:")
  36. print(f" HTTP Port: {info['http_port']}")
  37. print(f" Dubbo Port: {info['dubbo_port']}")