runbooks 1.1.4__py3-none-any.whl → 1.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. runbooks/__init__.py +31 -2
  2. runbooks/__init___optimized.py +18 -4
  3. runbooks/_platform/__init__.py +1 -5
  4. runbooks/_platform/core/runbooks_wrapper.py +141 -138
  5. runbooks/aws2/accuracy_validator.py +812 -0
  6. runbooks/base.py +7 -0
  7. runbooks/cfat/assessment/compliance.py +1 -1
  8. runbooks/cfat/assessment/runner.py +1 -0
  9. runbooks/cfat/cloud_foundations_assessment.py +227 -239
  10. runbooks/cli/__init__.py +1 -1
  11. runbooks/cli/commands/cfat.py +64 -23
  12. runbooks/cli/commands/finops.py +1005 -54
  13. runbooks/cli/commands/inventory.py +138 -35
  14. runbooks/cli/commands/operate.py +9 -36
  15. runbooks/cli/commands/security.py +42 -18
  16. runbooks/cli/commands/validation.py +432 -18
  17. runbooks/cli/commands/vpc.py +81 -17
  18. runbooks/cli/registry.py +22 -10
  19. runbooks/cloudops/__init__.py +20 -27
  20. runbooks/cloudops/base.py +96 -107
  21. runbooks/cloudops/cost_optimizer.py +544 -542
  22. runbooks/cloudops/infrastructure_optimizer.py +5 -4
  23. runbooks/cloudops/interfaces.py +224 -225
  24. runbooks/cloudops/lifecycle_manager.py +5 -4
  25. runbooks/cloudops/mcp_cost_validation.py +252 -235
  26. runbooks/cloudops/models.py +78 -53
  27. runbooks/cloudops/monitoring_automation.py +5 -4
  28. runbooks/cloudops/notebook_framework.py +177 -213
  29. runbooks/cloudops/security_enforcer.py +125 -159
  30. runbooks/common/accuracy_validator.py +11 -0
  31. runbooks/common/aws_pricing.py +349 -326
  32. runbooks/common/aws_pricing_api.py +211 -212
  33. runbooks/common/aws_profile_manager.py +40 -36
  34. runbooks/common/aws_utils.py +74 -79
  35. runbooks/common/business_logic.py +126 -104
  36. runbooks/common/cli_decorators.py +36 -60
  37. runbooks/common/comprehensive_cost_explorer_integration.py +455 -463
  38. runbooks/common/cross_account_manager.py +197 -204
  39. runbooks/common/date_utils.py +27 -39
  40. runbooks/common/decorators.py +29 -19
  41. runbooks/common/dry_run_examples.py +173 -208
  42. runbooks/common/dry_run_framework.py +157 -155
  43. runbooks/common/enhanced_exception_handler.py +15 -4
  44. runbooks/common/enhanced_logging_example.py +50 -64
  45. runbooks/common/enhanced_logging_integration_example.py +65 -37
  46. runbooks/common/env_utils.py +16 -16
  47. runbooks/common/error_handling.py +40 -38
  48. runbooks/common/lazy_loader.py +41 -23
  49. runbooks/common/logging_integration_helper.py +79 -86
  50. runbooks/common/mcp_cost_explorer_integration.py +476 -493
  51. runbooks/common/mcp_integration.py +63 -74
  52. runbooks/common/memory_optimization.py +140 -118
  53. runbooks/common/module_cli_base.py +37 -58
  54. runbooks/common/organizations_client.py +175 -193
  55. runbooks/common/patterns.py +23 -25
  56. runbooks/common/performance_monitoring.py +67 -71
  57. runbooks/common/performance_optimization_engine.py +283 -274
  58. runbooks/common/profile_utils.py +111 -37
  59. runbooks/common/rich_utils.py +201 -141
  60. runbooks/common/sre_performance_suite.py +177 -186
  61. runbooks/enterprise/__init__.py +1 -1
  62. runbooks/enterprise/logging.py +144 -106
  63. runbooks/enterprise/security.py +187 -204
  64. runbooks/enterprise/validation.py +43 -56
  65. runbooks/finops/__init__.py +26 -30
  66. runbooks/finops/account_resolver.py +1 -1
  67. runbooks/finops/advanced_optimization_engine.py +980 -0
  68. runbooks/finops/automation_core.py +268 -231
  69. runbooks/finops/business_case_config.py +184 -179
  70. runbooks/finops/cli.py +660 -139
  71. runbooks/finops/commvault_ec2_analysis.py +157 -164
  72. runbooks/finops/compute_cost_optimizer.py +336 -320
  73. runbooks/finops/config.py +20 -20
  74. runbooks/finops/cost_optimizer.py +484 -618
  75. runbooks/finops/cost_processor.py +332 -214
  76. runbooks/finops/dashboard_runner.py +1006 -172
  77. runbooks/finops/ebs_cost_optimizer.py +991 -657
  78. runbooks/finops/elastic_ip_optimizer.py +317 -257
  79. runbooks/finops/enhanced_mcp_integration.py +340 -0
  80. runbooks/finops/enhanced_progress.py +32 -29
  81. runbooks/finops/enhanced_trend_visualization.py +3 -2
  82. runbooks/finops/enterprise_wrappers.py +223 -285
  83. runbooks/finops/executive_export.py +203 -160
  84. runbooks/finops/helpers.py +130 -288
  85. runbooks/finops/iam_guidance.py +1 -1
  86. runbooks/finops/infrastructure/__init__.py +80 -0
  87. runbooks/finops/infrastructure/commands.py +506 -0
  88. runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
  89. runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
  90. runbooks/finops/markdown_exporter.py +337 -174
  91. runbooks/finops/mcp_validator.py +1952 -0
  92. runbooks/finops/nat_gateway_optimizer.py +1512 -481
  93. runbooks/finops/network_cost_optimizer.py +657 -587
  94. runbooks/finops/notebook_utils.py +226 -188
  95. runbooks/finops/optimization_engine.py +1136 -0
  96. runbooks/finops/optimizer.py +19 -23
  97. runbooks/finops/rds_snapshot_optimizer.py +367 -411
  98. runbooks/finops/reservation_optimizer.py +427 -363
  99. runbooks/finops/scenario_cli_integration.py +64 -65
  100. runbooks/finops/scenarios.py +1277 -438
  101. runbooks/finops/schemas.py +218 -182
  102. runbooks/finops/snapshot_manager.py +2289 -0
  103. runbooks/finops/types.py +3 -3
  104. runbooks/finops/validation_framework.py +259 -265
  105. runbooks/finops/vpc_cleanup_exporter.py +189 -144
  106. runbooks/finops/vpc_cleanup_optimizer.py +591 -573
  107. runbooks/finops/workspaces_analyzer.py +171 -182
  108. runbooks/integration/__init__.py +89 -0
  109. runbooks/integration/mcp_integration.py +1920 -0
  110. runbooks/inventory/CLAUDE.md +816 -0
  111. runbooks/inventory/__init__.py +2 -2
  112. runbooks/inventory/cloud_foundations_integration.py +144 -149
  113. runbooks/inventory/collectors/aws_comprehensive.py +1 -1
  114. runbooks/inventory/collectors/aws_networking.py +109 -99
  115. runbooks/inventory/collectors/base.py +4 -0
  116. runbooks/inventory/core/collector.py +495 -313
  117. runbooks/inventory/drift_detection_cli.py +69 -96
  118. runbooks/inventory/inventory_mcp_cli.py +48 -46
  119. runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
  120. runbooks/inventory/mcp_inventory_validator.py +549 -465
  121. runbooks/inventory/mcp_vpc_validator.py +359 -442
  122. runbooks/inventory/organizations_discovery.py +55 -51
  123. runbooks/inventory/rich_inventory_display.py +33 -32
  124. runbooks/inventory/unified_validation_engine.py +278 -251
  125. runbooks/inventory/vpc_analyzer.py +732 -695
  126. runbooks/inventory/vpc_architecture_validator.py +293 -348
  127. runbooks/inventory/vpc_dependency_analyzer.py +382 -378
  128. runbooks/inventory/vpc_flow_analyzer.py +1 -1
  129. runbooks/main.py +49 -34
  130. runbooks/main_final.py +91 -60
  131. runbooks/main_minimal.py +22 -10
  132. runbooks/main_optimized.py +131 -100
  133. runbooks/main_ultra_minimal.py +7 -2
  134. runbooks/mcp/__init__.py +36 -0
  135. runbooks/mcp/integration.py +679 -0
  136. runbooks/monitoring/performance_monitor.py +9 -4
  137. runbooks/operate/dynamodb_operations.py +3 -1
  138. runbooks/operate/ec2_operations.py +145 -137
  139. runbooks/operate/iam_operations.py +146 -152
  140. runbooks/operate/networking_cost_heatmap.py +29 -8
  141. runbooks/operate/rds_operations.py +223 -254
  142. runbooks/operate/s3_operations.py +107 -118
  143. runbooks/operate/vpc_operations.py +646 -616
  144. runbooks/remediation/base.py +1 -1
  145. runbooks/remediation/commons.py +10 -7
  146. runbooks/remediation/commvault_ec2_analysis.py +70 -66
  147. runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
  148. runbooks/remediation/multi_account.py +24 -21
  149. runbooks/remediation/rds_snapshot_list.py +86 -60
  150. runbooks/remediation/remediation_cli.py +92 -146
  151. runbooks/remediation/universal_account_discovery.py +83 -79
  152. runbooks/remediation/workspaces_list.py +46 -41
  153. runbooks/security/__init__.py +19 -0
  154. runbooks/security/assessment_runner.py +1150 -0
  155. runbooks/security/baseline_checker.py +812 -0
  156. runbooks/security/cloudops_automation_security_validator.py +509 -535
  157. runbooks/security/compliance_automation_engine.py +17 -17
  158. runbooks/security/config/__init__.py +2 -2
  159. runbooks/security/config/compliance_config.py +50 -50
  160. runbooks/security/config_template_generator.py +63 -76
  161. runbooks/security/enterprise_security_framework.py +1 -1
  162. runbooks/security/executive_security_dashboard.py +519 -508
  163. runbooks/security/multi_account_security_controls.py +959 -1210
  164. runbooks/security/real_time_security_monitor.py +422 -444
  165. runbooks/security/security_baseline_tester.py +1 -1
  166. runbooks/security/security_cli.py +143 -112
  167. runbooks/security/test_2way_validation.py +439 -0
  168. runbooks/security/two_way_validation_framework.py +852 -0
  169. runbooks/sre/production_monitoring_framework.py +167 -177
  170. runbooks/tdd/__init__.py +15 -0
  171. runbooks/tdd/cli.py +1071 -0
  172. runbooks/utils/__init__.py +14 -17
  173. runbooks/utils/logger.py +7 -2
  174. runbooks/utils/version_validator.py +50 -47
  175. runbooks/validation/__init__.py +6 -6
  176. runbooks/validation/cli.py +9 -3
  177. runbooks/validation/comprehensive_2way_validator.py +745 -704
  178. runbooks/validation/mcp_validator.py +906 -228
  179. runbooks/validation/terraform_citations_validator.py +104 -115
  180. runbooks/validation/terraform_drift_detector.py +447 -451
  181. runbooks/vpc/README.md +617 -0
  182. runbooks/vpc/__init__.py +8 -1
  183. runbooks/vpc/analyzer.py +577 -0
  184. runbooks/vpc/cleanup_wrapper.py +476 -413
  185. runbooks/vpc/cli_cloudtrail_commands.py +339 -0
  186. runbooks/vpc/cli_mcp_validation_commands.py +480 -0
  187. runbooks/vpc/cloudtrail_audit_integration.py +717 -0
  188. runbooks/vpc/config.py +92 -97
  189. runbooks/vpc/cost_engine.py +411 -148
  190. runbooks/vpc/cost_explorer_integration.py +553 -0
  191. runbooks/vpc/cross_account_session.py +101 -106
  192. runbooks/vpc/enhanced_mcp_validation.py +917 -0
  193. runbooks/vpc/eni_gate_validator.py +961 -0
  194. runbooks/vpc/heatmap_engine.py +185 -160
  195. runbooks/vpc/mcp_no_eni_validator.py +680 -639
  196. runbooks/vpc/nat_gateway_optimizer.py +358 -0
  197. runbooks/vpc/networking_wrapper.py +15 -8
  198. runbooks/vpc/pdca_remediation_planner.py +528 -0
  199. runbooks/vpc/performance_optimized_analyzer.py +219 -231
  200. runbooks/vpc/runbooks_adapter.py +1167 -241
  201. runbooks/vpc/tdd_red_phase_stubs.py +601 -0
  202. runbooks/vpc/test_data_loader.py +358 -0
  203. runbooks/vpc/tests/conftest.py +314 -4
  204. runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
  205. runbooks/vpc/tests/test_cost_engine.py +0 -2
  206. runbooks/vpc/topology_generator.py +326 -0
  207. runbooks/vpc/unified_scenarios.py +1297 -1124
  208. runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
  209. runbooks-1.1.5.dist-info/METADATA +328 -0
  210. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/RECORD +214 -193
  211. runbooks/finops/README.md +0 -414
  212. runbooks/finops/accuracy_cross_validator.py +0 -647
  213. runbooks/finops/business_cases.py +0 -950
  214. runbooks/finops/dashboard_router.py +0 -922
  215. runbooks/finops/ebs_optimizer.py +0 -973
  216. runbooks/finops/embedded_mcp_validator.py +0 -1629
  217. runbooks/finops/enhanced_dashboard_runner.py +0 -527
  218. runbooks/finops/finops_dashboard.py +0 -584
  219. runbooks/finops/finops_scenarios.py +0 -1218
  220. runbooks/finops/legacy_migration.py +0 -730
  221. runbooks/finops/multi_dashboard.py +0 -1519
  222. runbooks/finops/single_dashboard.py +0 -1113
  223. runbooks/finops/unlimited_scenarios.py +0 -393
  224. runbooks-1.1.4.dist-info/METADATA +0 -800
  225. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
  226. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
  227. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
  228. {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
3
  Performance-Optimized VPC Analysis Engine
4
-
4
+
5
5
  🎯 SRE Automation Specialist Implementation
6
6
  Following proven systematic delegation patterns for VPC network operation optimization.
7
7
 
@@ -35,7 +35,7 @@ from rich.progress import (
35
35
  BarColumn,
36
36
  TimeElapsedColumn,
37
37
  TaskProgressColumn,
38
- MofNCompleteColumn
38
+ MofNCompleteColumn,
39
39
  )
40
40
  from rich.panel import Panel
41
41
  from rich.table import Table
@@ -48,7 +48,7 @@ from runbooks.common.rich_utils import (
48
48
  print_warning,
49
49
  print_error,
50
50
  create_table,
51
- STATUS_INDICATORS
51
+ STATUS_INDICATORS,
52
52
  )
53
53
  from runbooks.common.performance_optimization_engine import get_optimization_engine
54
54
 
@@ -58,6 +58,7 @@ logger = logging.getLogger(__name__)
58
58
  @dataclass
59
59
  class VPCAnalysisResult:
60
60
  """VPC analysis result container"""
61
+
61
62
  vpc_id: str
62
63
  region: str
63
64
  analysis_data: Dict[str, Any] = field(default_factory=dict)
@@ -72,9 +73,10 @@ class VPCAnalysisResult:
72
73
  success: bool = True
73
74
 
74
75
 
75
- @dataclass
76
+ @dataclass
76
77
  class RegionalAnalysisMetrics:
77
78
  """Metrics for regional analysis performance"""
79
+
78
80
  region: str
79
81
  start_time: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
80
82
  end_time: Optional[datetime] = None
@@ -89,31 +91,44 @@ class RegionalAnalysisMetrics:
89
91
  class PerformanceOptimizedVPCAnalyzer:
90
92
  """
91
93
  Performance-optimized VPC analysis engine with SRE automation patterns
92
-
94
+
93
95
  Addresses VPC analysis timeout issues through:
94
96
  - Parallel regional processing with intelligent load balancing
95
- - Connection pooling and optimized AWS client configuration
97
+ - Connection pooling and optimized AWS client configuration
96
98
  - Configurable timeouts with graceful degradation
97
99
  - Memory-efficient batch processing for large VPC environments
98
100
  - Real-time progress monitoring with Rich CLI indicators
99
101
  """
100
-
102
+
101
103
  # AWS regions for global VPC analysis
102
104
  DEFAULT_REGIONS = [
103
- 'us-east-1', 'us-west-2', 'us-east-2', 'us-west-1',
104
- 'eu-west-1', 'eu-west-2', 'eu-central-1', 'eu-north-1',
105
- 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'ap-northeast-2',
106
- 'ap-south-1', 'ca-central-1', 'sa-east-1'
105
+ "us-east-1",
106
+ "us-west-2",
107
+ "us-east-2",
108
+ "us-west-1",
109
+ "eu-west-1",
110
+ "eu-west-2",
111
+ "eu-central-1",
112
+ "eu-north-1",
113
+ "ap-southeast-1",
114
+ "ap-southeast-2",
115
+ "ap-northeast-1",
116
+ "ap-northeast-2",
117
+ "ap-south-1",
118
+ "ca-central-1",
119
+ "sa-east-1",
107
120
  ]
108
-
109
- def __init__(self,
110
- operational_profile: str,
111
- max_workers: int = 15,
112
- region_timeout_seconds: int = 45,
113
- overall_timeout_seconds: int = 300):
121
+
122
+ def __init__(
123
+ self,
124
+ operational_profile: str,
125
+ max_workers: int = 15,
126
+ region_timeout_seconds: int = 45,
127
+ overall_timeout_seconds: int = 300,
128
+ ):
114
129
  """
115
130
  Initialize performance-optimized VPC analyzer
116
-
131
+
117
132
  Args:
118
133
  operational_profile: AWS profile for VPC operations
119
134
  max_workers: Maximum concurrent workers for parallel analysis
@@ -124,44 +139,47 @@ class PerformanceOptimizedVPCAnalyzer:
124
139
  self.max_workers = max_workers
125
140
  self.region_timeout_seconds = region_timeout_seconds
126
141
  self.overall_timeout_seconds = overall_timeout_seconds
127
-
142
+
128
143
  # Performance optimization engine
129
144
  self.optimization_engine = get_optimization_engine(
130
145
  max_workers=max_workers,
131
146
  cache_ttl_minutes=60, # Longer cache for VPC data
132
- memory_limit_mb=3072 # Higher limit for VPC analysis
147
+ memory_limit_mb=3072, # Higher limit for VPC analysis
133
148
  )
134
-
149
+
135
150
  # Analysis tracking
136
151
  self.regional_metrics: Dict[str, RegionalAnalysisMetrics] = {}
137
152
  self.vpc_results: Dict[str, List[VPCAnalysisResult]] = {}
138
153
 
139
- async def analyze_vpcs_globally(self,
140
- regions: Optional[List[str]] = None,
141
- include_detailed_analysis: bool = True) -> Dict[str, Any]:
154
+ async def analyze_vpcs_globally(
155
+ self, regions: Optional[List[str]] = None, include_detailed_analysis: bool = True
156
+ ) -> Dict[str, Any]:
142
157
  """
143
158
  Perform global VPC analysis with performance optimization
144
-
159
+
145
160
  Args:
146
161
  regions: List of regions to analyze (defaults to all major regions)
147
162
  include_detailed_analysis: Whether to include detailed network component analysis
148
-
163
+
149
164
  Returns:
150
165
  Comprehensive VPC analysis results with performance metrics
151
166
  """
152
167
  if regions is None:
153
168
  regions = self.DEFAULT_REGIONS
154
-
169
+
155
170
  print_header("Performance-Optimized VPC Analysis", "SRE Automation Engine")
156
-
171
+
157
172
  # Start optimized analysis
158
173
  with self.optimization_engine.optimize_operation("global_vpc_analysis", 180.0):
159
-
160
- console.print(f"[cyan]🌐 Analyzing VPCs across {len(regions)} regions with SRE optimization patterns[/cyan]")
161
- console.print(f"[dim]Timeout per region: {self.region_timeout_seconds}s, Overall timeout: {self.overall_timeout_seconds}s[/dim]")
162
-
174
+ console.print(
175
+ f"[cyan]🌐 Analyzing VPCs across {len(regions)} regions with SRE optimization patterns[/cyan]"
176
+ )
177
+ console.print(
178
+ f"[dim]Timeout per region: {self.region_timeout_seconds}s, Overall timeout: {self.overall_timeout_seconds}s[/dim]"
179
+ )
180
+
163
181
  start_time = time.time()
164
-
182
+
165
183
  # Parallel regional analysis with progress tracking
166
184
  with Progress(
167
185
  SpinnerColumn(),
@@ -170,171 +188,150 @@ class PerformanceOptimizedVPCAnalyzer:
170
188
  TaskProgressColumn(),
171
189
  MofNCompleteColumn(),
172
190
  TimeElapsedColumn(),
173
- console=console
191
+ console=console,
174
192
  ) as progress:
175
-
176
- analysis_task = progress.add_task(
177
- "Analyzing VPCs globally...",
178
- total=len(regions)
179
- )
180
-
193
+ analysis_task = progress.add_task("Analyzing VPCs globally...", total=len(regions))
194
+
181
195
  # Execute parallel regional analysis
182
196
  analysis_results = await self._analyze_regions_parallel(
183
- regions,
184
- include_detailed_analysis,
185
- progress,
186
- analysis_task
197
+ regions, include_detailed_analysis, progress, analysis_task
187
198
  )
188
-
199
+
189
200
  # Aggregate results
190
201
  total_duration = time.time() - start_time
191
202
  summary = self._create_analysis_summary(analysis_results, total_duration)
192
-
203
+
193
204
  # Display performance summary
194
205
  self._display_performance_summary(summary)
195
-
206
+
196
207
  return summary
197
208
 
198
- async def _analyze_regions_parallel(self,
199
- regions: List[str],
200
- include_detailed: bool,
201
- progress: Progress,
202
- task_id) -> Dict[str, Any]:
209
+ async def _analyze_regions_parallel(
210
+ self, regions: List[str], include_detailed: bool, progress: Progress, task_id
211
+ ) -> Dict[str, Any]:
203
212
  """Execute parallel regional VPC analysis with timeout handling"""
204
-
213
+
205
214
  # Initialize regional metrics
206
215
  for region in regions:
207
216
  self.regional_metrics[region] = RegionalAnalysisMetrics(region=region)
208
-
217
+
209
218
  analysis_results = {}
210
219
  successful_regions = 0
211
220
  failed_regions = 0
212
-
221
+
213
222
  # Use ThreadPoolExecutor for parallel regional analysis
214
223
  with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
215
-
216
224
  # Submit regional analysis tasks
217
225
  future_to_region = {
218
- executor.submit(
219
- self._analyze_vpc_region_optimized,
220
- region,
221
- include_detailed
222
- ): region for region in regions
226
+ executor.submit(self._analyze_vpc_region_optimized, region, include_detailed): region
227
+ for region in regions
223
228
  }
224
-
229
+
225
230
  # Process completed tasks
226
231
  for future in as_completed(future_to_region, timeout=self.overall_timeout_seconds):
227
232
  region = future_to_region[future]
228
-
233
+
229
234
  try:
230
235
  # Get result with per-region timeout
231
236
  region_result = future.result(timeout=self.region_timeout_seconds)
232
237
  analysis_results[region] = region_result
233
-
238
+
234
239
  # Update metrics
235
240
  metrics = self.regional_metrics[region]
236
241
  metrics.end_time = datetime.now(timezone.utc)
237
242
  metrics.duration_seconds = (metrics.end_time - metrics.start_time).total_seconds()
238
- metrics.vpcs_analyzed = len(region_result.get('vpcs', []))
239
-
243
+ metrics.vpcs_analyzed = len(region_result.get("vpcs", []))
244
+
240
245
  successful_regions += 1
241
-
246
+
242
247
  progress.update(
243
- task_id,
248
+ task_id,
244
249
  advance=1,
245
- description=f"Completed {region} ({metrics.vpcs_analyzed} VPCs, {metrics.duration_seconds:.1f}s)"
250
+ description=f"Completed {region} ({metrics.vpcs_analyzed} VPCs, {metrics.duration_seconds:.1f}s)",
246
251
  )
247
-
252
+
248
253
  except TimeoutError:
249
254
  logger.warning(f"VPC analysis timeout for region {region} after {self.region_timeout_seconds}s")
250
255
  analysis_results[region] = {
251
- 'error': f'Analysis timeout after {self.region_timeout_seconds}s',
252
- 'vpcs': [],
253
- 'timeout': True
256
+ "error": f"Analysis timeout after {self.region_timeout_seconds}s",
257
+ "vpcs": [],
258
+ "timeout": True,
254
259
  }
255
-
260
+
256
261
  # Update timeout metrics
257
- metrics = self.regional_metrics[region]
262
+ metrics = self.regional_metrics[region]
258
263
  metrics.timeout_occurred = True
259
264
  metrics.end_time = datetime.now(timezone.utc)
260
265
  metrics.duration_seconds = self.region_timeout_seconds
261
-
266
+
262
267
  failed_regions += 1
263
268
  progress.advance(task_id)
264
-
269
+
265
270
  except Exception as e:
266
271
  logger.error(f"VPC analysis failed for region {region}: {e}")
267
- analysis_results[region] = {
268
- 'error': str(e),
269
- 'vpcs': [],
270
- 'failed': True
271
- }
272
-
272
+ analysis_results[region] = {"error": str(e), "vpcs": [], "failed": True}
273
+
273
274
  # Update error metrics
274
275
  metrics = self.regional_metrics[region]
275
276
  metrics.errors_encountered += 1
276
- metrics.end_time = datetime.now(timezone.utc)
277
+ metrics.end_time = datetime.now(timezone.utc)
277
278
  metrics.duration_seconds = (metrics.end_time - metrics.start_time).total_seconds()
278
-
279
+
279
280
  failed_regions += 1
280
281
  progress.advance(task_id)
281
-
282
+
282
283
  return {
283
- 'regional_results': analysis_results,
284
- 'successful_regions': successful_regions,
285
- 'failed_regions': failed_regions,
286
- 'total_regions': len(regions)
284
+ "regional_results": analysis_results,
285
+ "successful_regions": successful_regions,
286
+ "failed_regions": failed_regions,
287
+ "total_regions": len(regions),
287
288
  }
288
289
 
289
- def _analyze_vpc_region_optimized(self,
290
- region: str,
291
- include_detailed: bool) -> Dict[str, Any]:
290
+ def _analyze_vpc_region_optimized(self, region: str, include_detailed: bool) -> Dict[str, Any]:
292
291
  """Optimized VPC analysis for a specific region with performance enhancements"""
293
-
292
+
294
293
  metrics = self.regional_metrics[region]
295
-
294
+
296
295
  try:
297
296
  # Get optimized VPC analyzer from performance engine
298
297
  optimized_vpc_analysis = self.optimization_engine.optimize_vpc_analysis(
299
298
  operational_profile=self.operational_profile
300
299
  )
301
-
300
+
302
301
  # Execute regional analysis
303
302
  regional_data = optimized_vpc_analysis([region])
304
- region_vpcs = regional_data.get('vpc_data_by_region', {}).get(region, {})
305
-
306
- if 'error' in region_vpcs:
307
- raise Exception(region_vpcs['error'])
308
-
309
- vpcs = region_vpcs.get('vpcs', [])
303
+ region_vpcs = regional_data.get("vpc_data_by_region", {}).get(region, {})
304
+
305
+ if "error" in region_vpcs:
306
+ raise Exception(region_vpcs["error"])
307
+
308
+ vpcs = region_vpcs.get("vpcs", [])
310
309
  metrics.vpcs_analyzed = len(vpcs)
311
- metrics.api_calls_made = region_vpcs.get('api_calls', 0)
312
-
310
+ metrics.api_calls_made = region_vpcs.get("api_calls", 0)
311
+
313
312
  # Enhanced VPC analysis if requested
314
313
  if include_detailed and vpcs:
315
314
  vpcs = self._enrich_vpcs_with_details(vpcs, region)
316
315
  metrics.optimizations_applied.append("detailed_enrichment")
317
-
316
+
318
317
  # Apply additional performance optimizations
319
318
  if len(vpcs) > 10:
320
319
  metrics.optimizations_applied.append("batch_processing")
321
-
322
- metrics.optimizations_applied.extend([
323
- "connection_pooling",
324
- "intelligent_caching",
325
- "parallel_regional_processing"
326
- ])
327
-
320
+
321
+ metrics.optimizations_applied.extend(
322
+ ["connection_pooling", "intelligent_caching", "parallel_regional_processing"]
323
+ )
324
+
328
325
  return {
329
- 'vpcs': vpcs,
330
- 'region': region,
331
- 'metrics': {
332
- 'vpcs_analyzed': metrics.vpcs_analyzed,
333
- 'api_calls_made': metrics.api_calls_made,
334
- 'optimizations_applied': metrics.optimizations_applied
335
- }
326
+ "vpcs": vpcs,
327
+ "region": region,
328
+ "metrics": {
329
+ "vpcs_analyzed": metrics.vpcs_analyzed,
330
+ "api_calls_made": metrics.api_calls_made,
331
+ "optimizations_applied": metrics.optimizations_applied,
332
+ },
336
333
  }
337
-
334
+
338
335
  except Exception as e:
339
336
  metrics.errors_encountered += 1
340
337
  logger.error(f"Optimized VPC analysis failed for region {region}: {e}")
@@ -342,155 +339,152 @@ class PerformanceOptimizedVPCAnalyzer:
342
339
 
343
340
  def _enrich_vpcs_with_details(self, vpcs: List[Dict], region: str) -> List[Dict]:
344
341
  """Enrich VPC data with detailed network component analysis"""
345
-
342
+
346
343
  try:
347
344
  # Use cached client from optimization engine
348
- ec2_client = self.optimization_engine.client_pool.get_client('ec2', self.operational_profile, region)
349
-
345
+ ec2_client = self.optimization_engine.client_pool.get_client("ec2", self.operational_profile, region)
346
+
350
347
  for vpc in vpcs:
351
- vpc_id = vpc['VpcId']
352
-
348
+ vpc_id = vpc["VpcId"]
349
+
353
350
  # Get additional VPC components in parallel where possible
354
351
  try:
355
352
  # Route tables
356
- rt_response = ec2_client.describe_route_tables(
357
- Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
358
- )
359
- vpc['RouteTables'] = rt_response['RouteTables']
360
-
353
+ rt_response = ec2_client.describe_route_tables(Filters=[{"Name": "vpc-id", "Values": [vpc_id]}])
354
+ vpc["RouteTables"] = rt_response["RouteTables"]
355
+
361
356
  # Security groups
362
- sg_response = ec2_client.describe_security_groups(
363
- Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
364
- )
365
- vpc['SecurityGroups'] = sg_response['SecurityGroups']
366
-
357
+ sg_response = ec2_client.describe_security_groups(Filters=[{"Name": "vpc-id", "Values": [vpc_id]}])
358
+ vpc["SecurityGroups"] = sg_response["SecurityGroups"]
359
+
367
360
  # NAT Gateways
368
- nat_response = ec2_client.describe_nat_gateways(
369
- Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
370
- )
371
- vpc['NatGateways'] = nat_response['NatGateways']
372
-
373
- # Internet Gateways
361
+ nat_response = ec2_client.describe_nat_gateways(Filters=[{"Name": "vpc-id", "Values": [vpc_id]}])
362
+ vpc["NatGateways"] = nat_response["NatGateways"]
363
+
364
+ # Internet Gateways
374
365
  igw_response = ec2_client.describe_internet_gateways(
375
- Filters=[{'Name': 'attachment.vpc-id', 'Values': [vpc_id]}]
366
+ Filters=[{"Name": "attachment.vpc-id", "Values": [vpc_id]}]
376
367
  )
377
- vpc['InternetGateways'] = igw_response['InternetGateways']
378
-
368
+ vpc["InternetGateways"] = igw_response["InternetGateways"]
369
+
379
370
  except Exception as detail_error:
380
371
  logger.debug(f"Failed to get detailed info for VPC {vpc_id}: {detail_error}")
381
372
  # Continue with basic VPC data
382
-
373
+
383
374
  except Exception as e:
384
375
  logger.warning(f"VPC enrichment failed for region {region}: {e}")
385
-
376
+
386
377
  return vpcs
387
378
 
388
379
  def _create_analysis_summary(self, analysis_results: Dict, total_duration: float) -> Dict[str, Any]:
389
380
  """Create comprehensive analysis summary with performance metrics"""
390
-
391
- regional_results = analysis_results.get('regional_results', {})
392
- successful_regions = analysis_results.get('successful_regions', 0)
393
- failed_regions = analysis_results.get('failed_regions', 0)
394
-
381
+
382
+ regional_results = analysis_results.get("regional_results", {})
383
+ successful_regions = analysis_results.get("successful_regions", 0)
384
+ failed_regions = analysis_results.get("failed_regions", 0)
385
+
395
386
  # Aggregate VPC data
396
387
  total_vpcs = 0
397
388
  total_api_calls = 0
398
389
  regions_with_vpcs = 0
399
390
  all_optimizations = set()
400
-
391
+
401
392
  vpc_summary_by_region = {}
402
-
393
+
403
394
  for region, result in regional_results.items():
404
- if 'error' not in result and not result.get('failed', False):
405
- vpcs = result.get('vpcs', [])
395
+ if "error" not in result and not result.get("failed", False):
396
+ vpcs = result.get("vpcs", [])
406
397
  total_vpcs += len(vpcs)
407
-
398
+
408
399
  if vpcs:
409
400
  regions_with_vpcs += 1
410
-
401
+
411
402
  # Collect metrics
412
- region_metrics = result.get('metrics', {})
413
- total_api_calls += region_metrics.get('api_calls_made', 0)
414
- all_optimizations.update(region_metrics.get('optimizations_applied', []))
415
-
403
+ region_metrics = result.get("metrics", {})
404
+ total_api_calls += region_metrics.get("api_calls_made", 0)
405
+ all_optimizations.update(region_metrics.get("optimizations_applied", []))
406
+
416
407
  vpc_summary_by_region[region] = {
417
- 'vpc_count': len(vpcs),
418
- 'analysis_duration': self.regional_metrics[region].duration_seconds,
419
- 'optimizations_applied': region_metrics.get('optimizations_applied', [])
408
+ "vpc_count": len(vpcs),
409
+ "analysis_duration": self.regional_metrics[region].duration_seconds,
410
+ "optimizations_applied": region_metrics.get("optimizations_applied", []),
420
411
  }
421
-
412
+
422
413
  # Performance analysis
423
414
  avg_duration_per_region = total_duration / len(regional_results) if regional_results else 0
424
415
  performance_grade = "A" if total_duration < 120 else "B" if total_duration < 180 else "C"
425
-
416
+
426
417
  return {
427
- 'analysis_summary': {
428
- 'total_regions_analyzed': len(regional_results),
429
- 'successful_regions': successful_regions,
430
- 'failed_regions': failed_regions,
431
- 'regions_with_vpcs': regions_with_vpcs,
432
- 'total_vpcs_discovered': total_vpcs,
433
- 'total_duration_seconds': total_duration,
434
- 'average_duration_per_region': avg_duration_per_region,
435
- 'performance_grade': performance_grade
418
+ "analysis_summary": {
419
+ "total_regions_analyzed": len(regional_results),
420
+ "successful_regions": successful_regions,
421
+ "failed_regions": failed_regions,
422
+ "regions_with_vpcs": regions_with_vpcs,
423
+ "total_vpcs_discovered": total_vpcs,
424
+ "total_duration_seconds": total_duration,
425
+ "average_duration_per_region": avg_duration_per_region,
426
+ "performance_grade": performance_grade,
436
427
  },
437
- 'vpc_summary_by_region': vpc_summary_by_region,
438
- 'regional_results': regional_results,
439
- 'performance_metrics': {
440
- 'total_api_calls': total_api_calls,
441
- 'optimizations_applied': list(all_optimizations),
442
- 'regional_metrics': {
428
+ "vpc_summary_by_region": vpc_summary_by_region,
429
+ "regional_results": regional_results,
430
+ "performance_metrics": {
431
+ "total_api_calls": total_api_calls,
432
+ "optimizations_applied": list(all_optimizations),
433
+ "regional_metrics": {
443
434
  region: {
444
- 'duration_seconds': metrics.duration_seconds,
445
- 'vpcs_analyzed': metrics.vpcs_analyzed,
446
- 'api_calls_made': metrics.api_calls_made,
447
- 'timeout_occurred': metrics.timeout_occurred,
448
- 'errors_encountered': metrics.errors_encountered
449
- } for region, metrics in self.regional_metrics.items()
450
- }
435
+ "duration_seconds": metrics.duration_seconds,
436
+ "vpcs_analyzed": metrics.vpcs_analyzed,
437
+ "api_calls_made": metrics.api_calls_made,
438
+ "timeout_occurred": metrics.timeout_occurred,
439
+ "errors_encountered": metrics.errors_encountered,
440
+ }
441
+ for region, metrics in self.regional_metrics.items()
442
+ },
451
443
  },
452
- 'timestamp': datetime.now(timezone.utc).isoformat()
444
+ "timestamp": datetime.now(timezone.utc).isoformat(),
453
445
  }
454
446
 
455
447
  def _display_performance_summary(self, summary: Dict[str, Any]):
456
448
  """Display comprehensive performance summary with Rich formatting"""
457
-
458
- analysis_summary = summary['analysis_summary']
459
- performance_metrics = summary['performance_metrics']
460
-
449
+
450
+ analysis_summary = summary["analysis_summary"]
451
+ performance_metrics = summary["performance_metrics"]
452
+
461
453
  # Performance overview panel
462
454
  performance_text = f"""
463
455
  [bold cyan]📊 VPC Analysis Performance Summary[/bold cyan]
464
456
 
465
- [green]✅ Regions Successful:[/green] {analysis_summary['successful_regions']}/{analysis_summary['total_regions_analyzed']}
466
- [yellow]🌐 VPCs Discovered:[/yellow] {analysis_summary['total_vpcs_discovered']} across {analysis_summary['regions_with_vpcs']} regions
467
- [blue]⏱️ Total Duration:[/blue] {analysis_summary['total_duration_seconds']:.1f}s (avg: {analysis_summary['average_duration_per_region']:.1f}s/region)
468
- [magenta]📈 Performance Grade:[/magenta] {analysis_summary['performance_grade']}
469
- [dim]🔧 Optimizations Applied:[/dim] {', '.join(performance_metrics['optimizations_applied'])}
457
+ [green]✅ Regions Successful:[/green] {analysis_summary["successful_regions"]}/{analysis_summary["total_regions_analyzed"]}
458
+ [yellow]🌐 VPCs Discovered:[/yellow] {analysis_summary["total_vpcs_discovered"]} across {analysis_summary["regions_with_vpcs"]} regions
459
+ [blue]⏱️ Total Duration:[/blue] {analysis_summary["total_duration_seconds"]:.1f}s (avg: {analysis_summary["average_duration_per_region"]:.1f}s/region)
460
+ [magenta]📈 Performance Grade:[/magenta] {analysis_summary["performance_grade"]}
461
+ [dim]🔧 Optimizations Applied:[/dim] {", ".join(performance_metrics["optimizations_applied"])}
470
462
  """
471
-
472
- console.print(Panel(
473
- performance_text.strip(),
474
- title="[bold green]🚀 SRE Optimization Results[/bold green]",
475
- border_style="green" if analysis_summary['performance_grade'] in ['A', 'B'] else "yellow"
476
- ))
477
-
463
+
464
+ console.print(
465
+ Panel(
466
+ performance_text.strip(),
467
+ title="[bold green]🚀 SRE Optimization Results[/bold green]",
468
+ border_style="green" if analysis_summary["performance_grade"] in ["A", "B"] else "yellow",
469
+ )
470
+ )
471
+
478
472
  # Regional performance table
479
- if summary['vpc_summary_by_region']:
473
+ if summary["vpc_summary_by_region"]:
480
474
  table = create_table(
481
475
  title="Regional VPC Analysis Performance",
482
476
  columns=[
483
477
  {"name": "Region", "style": "cyan", "justify": "left"},
484
478
  {"name": "VPCs", "style": "yellow", "justify": "center"},
485
- {"name": "Duration", "style": "white", "justify": "right"},
486
- {"name": "Status", "style": "white", "justify": "center"}
487
- ]
479
+ {"name": "Duration", "style": "white", "justify": "right"},
480
+ {"name": "Status", "style": "white", "justify": "center"},
481
+ ],
488
482
  )
489
-
490
- for region, data in summary['vpc_summary_by_region'].items():
491
- duration = data['analysis_duration']
492
- vpc_count = data['vpc_count']
493
-
483
+
484
+ for region, data in summary["vpc_summary_by_region"].items():
485
+ duration = data["analysis_duration"]
486
+ vpc_count = data["vpc_count"]
487
+
494
488
  # Determine status
495
489
  if duration <= 30:
496
490
  status_icon = f"[green]{STATUS_INDICATORS['success']}[/green]"
@@ -498,14 +492,9 @@ class PerformanceOptimizedVPCAnalyzer:
498
492
  status_icon = f"[yellow]{STATUS_INDICATORS['warning']}[/yellow]"
499
493
  else:
500
494
  status_icon = f"[red]{STATUS_INDICATORS['error']}[/red]"
501
-
502
- table.add_row(
503
- region,
504
- str(vpc_count),
505
- f"{duration:.1f}s",
506
- status_icon
507
- )
508
-
495
+
496
+ table.add_row(region, str(vpc_count), f"{duration:.1f}s", status_icon)
497
+
509
498
  console.print(table)
510
499
 
511
500
  def clear_analysis_cache(self):
@@ -517,20 +506,19 @@ class PerformanceOptimizedVPCAnalyzer:
517
506
 
518
507
 
519
508
  # Convenience functions
520
- def create_optimized_vpc_analyzer(operational_profile: str,
521
- max_workers: int = 15) -> PerformanceOptimizedVPCAnalyzer:
509
+ def create_optimized_vpc_analyzer(operational_profile: str, max_workers: int = 15) -> PerformanceOptimizedVPCAnalyzer:
522
510
  """Create performance-optimized VPC analyzer instance"""
523
511
  return PerformanceOptimizedVPCAnalyzer(
524
512
  operational_profile=operational_profile,
525
513
  max_workers=max_workers,
526
514
  region_timeout_seconds=45,
527
- overall_timeout_seconds=300
515
+ overall_timeout_seconds=300,
528
516
  )
529
517
 
530
518
 
531
- async def run_optimized_global_vpc_analysis(operational_profile: str,
532
- regions: Optional[List[str]] = None,
533
- include_detailed: bool = True) -> Dict[str, Any]:
519
+ async def run_optimized_global_vpc_analysis(
520
+ operational_profile: str, regions: Optional[List[str]] = None, include_detailed: bool = True
521
+ ) -> Dict[str, Any]:
534
522
  """Run optimized global VPC analysis"""
535
523
  analyzer = create_optimized_vpc_analyzer(operational_profile)
536
524
  return await analyzer.analyze_vpcs_globally(regions, include_detailed)
@@ -540,7 +528,7 @@ async def run_optimized_global_vpc_analysis(operational_profile: str,
540
528
  __all__ = [
541
529
  "PerformanceOptimizedVPCAnalyzer",
542
530
  "VPCAnalysisResult",
543
- "RegionalAnalysisMetrics",
531
+ "RegionalAnalysisMetrics",
544
532
  "create_optimized_vpc_analyzer",
545
- "run_optimized_global_vpc_analysis"
546
- ]
533
+ "run_optimized_global_vpc_analysis",
534
+ ]