runbooks 1.1.3__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.
- runbooks/__init__.py +31 -2
- runbooks/__init___optimized.py +18 -4
- runbooks/_platform/__init__.py +1 -5
- runbooks/_platform/core/runbooks_wrapper.py +141 -138
- runbooks/aws2/accuracy_validator.py +812 -0
- runbooks/base.py +7 -0
- runbooks/cfat/WEIGHT_CONFIG_README.md +1 -1
- runbooks/cfat/assessment/compliance.py +8 -8
- runbooks/cfat/assessment/runner.py +1 -0
- runbooks/cfat/cloud_foundations_assessment.py +227 -239
- runbooks/cfat/models.py +6 -2
- runbooks/cfat/tests/__init__.py +6 -1
- runbooks/cli/__init__.py +13 -0
- runbooks/cli/commands/cfat.py +274 -0
- runbooks/cli/commands/finops.py +1164 -0
- runbooks/cli/commands/inventory.py +379 -0
- runbooks/cli/commands/operate.py +239 -0
- runbooks/cli/commands/security.py +248 -0
- runbooks/cli/commands/validation.py +825 -0
- runbooks/cli/commands/vpc.py +310 -0
- runbooks/cli/registry.py +107 -0
- runbooks/cloudops/__init__.py +23 -30
- runbooks/cloudops/base.py +96 -107
- runbooks/cloudops/cost_optimizer.py +549 -547
- runbooks/cloudops/infrastructure_optimizer.py +5 -4
- runbooks/cloudops/interfaces.py +226 -227
- runbooks/cloudops/lifecycle_manager.py +5 -4
- runbooks/cloudops/mcp_cost_validation.py +252 -235
- runbooks/cloudops/models.py +78 -53
- runbooks/cloudops/monitoring_automation.py +5 -4
- runbooks/cloudops/notebook_framework.py +179 -215
- runbooks/cloudops/security_enforcer.py +125 -159
- runbooks/common/accuracy_validator.py +11 -0
- runbooks/common/aws_pricing.py +349 -326
- runbooks/common/aws_pricing_api.py +211 -212
- runbooks/common/aws_profile_manager.py +341 -0
- runbooks/common/aws_utils.py +75 -80
- runbooks/common/business_logic.py +127 -105
- runbooks/common/cli_decorators.py +36 -60
- runbooks/common/comprehensive_cost_explorer_integration.py +456 -464
- runbooks/common/cross_account_manager.py +198 -205
- runbooks/common/date_utils.py +27 -39
- runbooks/common/decorators.py +235 -0
- runbooks/common/dry_run_examples.py +173 -208
- runbooks/common/dry_run_framework.py +157 -155
- runbooks/common/enhanced_exception_handler.py +15 -4
- runbooks/common/enhanced_logging_example.py +50 -64
- runbooks/common/enhanced_logging_integration_example.py +65 -37
- runbooks/common/env_utils.py +16 -16
- runbooks/common/error_handling.py +40 -38
- runbooks/common/lazy_loader.py +41 -23
- runbooks/common/logging_integration_helper.py +79 -86
- runbooks/common/mcp_cost_explorer_integration.py +478 -495
- runbooks/common/mcp_integration.py +63 -74
- runbooks/common/memory_optimization.py +140 -118
- runbooks/common/module_cli_base.py +37 -58
- runbooks/common/organizations_client.py +176 -194
- runbooks/common/patterns.py +204 -0
- runbooks/common/performance_monitoring.py +67 -71
- runbooks/common/performance_optimization_engine.py +283 -274
- runbooks/common/profile_utils.py +248 -39
- runbooks/common/rich_utils.py +643 -92
- runbooks/common/sre_performance_suite.py +177 -186
- runbooks/enterprise/__init__.py +1 -1
- runbooks/enterprise/logging.py +144 -106
- runbooks/enterprise/security.py +187 -204
- runbooks/enterprise/validation.py +43 -56
- runbooks/finops/__init__.py +29 -33
- runbooks/finops/account_resolver.py +1 -1
- runbooks/finops/advanced_optimization_engine.py +980 -0
- runbooks/finops/automation_core.py +268 -231
- runbooks/finops/business_case_config.py +184 -179
- runbooks/finops/cli.py +660 -139
- runbooks/finops/commvault_ec2_analysis.py +157 -164
- runbooks/finops/compute_cost_optimizer.py +336 -320
- runbooks/finops/config.py +20 -20
- runbooks/finops/cost_optimizer.py +488 -622
- runbooks/finops/cost_processor.py +332 -214
- runbooks/finops/dashboard_runner.py +1006 -172
- runbooks/finops/ebs_cost_optimizer.py +991 -657
- runbooks/finops/elastic_ip_optimizer.py +317 -257
- runbooks/finops/enhanced_mcp_integration.py +340 -0
- runbooks/finops/enhanced_progress.py +40 -37
- runbooks/finops/enhanced_trend_visualization.py +3 -2
- runbooks/finops/enterprise_wrappers.py +230 -292
- runbooks/finops/executive_export.py +203 -160
- runbooks/finops/helpers.py +130 -288
- runbooks/finops/iam_guidance.py +1 -1
- runbooks/finops/infrastructure/__init__.py +80 -0
- runbooks/finops/infrastructure/commands.py +506 -0
- runbooks/finops/infrastructure/load_balancer_optimizer.py +866 -0
- runbooks/finops/infrastructure/vpc_endpoint_optimizer.py +832 -0
- runbooks/finops/markdown_exporter.py +338 -175
- runbooks/finops/mcp_validator.py +1952 -0
- runbooks/finops/nat_gateway_optimizer.py +1513 -482
- runbooks/finops/network_cost_optimizer.py +657 -587
- runbooks/finops/notebook_utils.py +226 -188
- runbooks/finops/optimization_engine.py +1136 -0
- runbooks/finops/optimizer.py +25 -29
- runbooks/finops/rds_snapshot_optimizer.py +367 -411
- runbooks/finops/reservation_optimizer.py +427 -363
- runbooks/finops/scenario_cli_integration.py +77 -78
- runbooks/finops/scenarios.py +1278 -439
- runbooks/finops/schemas.py +218 -182
- runbooks/finops/snapshot_manager.py +2289 -0
- runbooks/finops/tests/test_finops_dashboard.py +3 -3
- runbooks/finops/tests/test_reference_images_validation.py +2 -2
- runbooks/finops/tests/test_single_account_features.py +17 -17
- runbooks/finops/tests/validate_test_suite.py +1 -1
- runbooks/finops/types.py +3 -3
- runbooks/finops/validation_framework.py +263 -269
- runbooks/finops/vpc_cleanup_exporter.py +191 -146
- runbooks/finops/vpc_cleanup_optimizer.py +593 -575
- runbooks/finops/workspaces_analyzer.py +171 -182
- runbooks/hitl/enhanced_workflow_engine.py +1 -1
- runbooks/integration/__init__.py +89 -0
- runbooks/integration/mcp_integration.py +1920 -0
- runbooks/inventory/CLAUDE.md +816 -0
- runbooks/inventory/README.md +3 -3
- runbooks/inventory/Tests/common_test_data.py +30 -30
- runbooks/inventory/__init__.py +2 -2
- runbooks/inventory/cloud_foundations_integration.py +144 -149
- runbooks/inventory/collectors/aws_comprehensive.py +28 -11
- runbooks/inventory/collectors/aws_networking.py +111 -101
- runbooks/inventory/collectors/base.py +4 -0
- runbooks/inventory/core/collector.py +495 -313
- runbooks/inventory/discovery.md +2 -2
- runbooks/inventory/drift_detection_cli.py +69 -96
- runbooks/inventory/find_ec2_security_groups.py +1 -1
- runbooks/inventory/inventory_mcp_cli.py +48 -46
- runbooks/inventory/list_rds_snapshots_aggregator.py +192 -208
- runbooks/inventory/mcp_inventory_validator.py +549 -465
- runbooks/inventory/mcp_vpc_validator.py +359 -442
- runbooks/inventory/organizations_discovery.py +56 -52
- runbooks/inventory/rich_inventory_display.py +33 -32
- runbooks/inventory/unified_validation_engine.py +278 -251
- runbooks/inventory/vpc_analyzer.py +733 -696
- runbooks/inventory/vpc_architecture_validator.py +293 -348
- runbooks/inventory/vpc_dependency_analyzer.py +382 -378
- runbooks/inventory/vpc_flow_analyzer.py +3 -3
- runbooks/main.py +152 -9147
- runbooks/main_final.py +91 -60
- runbooks/main_minimal.py +22 -10
- runbooks/main_optimized.py +131 -100
- runbooks/main_ultra_minimal.py +7 -2
- runbooks/mcp/__init__.py +36 -0
- runbooks/mcp/integration.py +679 -0
- runbooks/metrics/dora_metrics_engine.py +2 -2
- runbooks/monitoring/performance_monitor.py +9 -4
- runbooks/operate/dynamodb_operations.py +3 -1
- runbooks/operate/ec2_operations.py +145 -137
- runbooks/operate/iam_operations.py +146 -152
- runbooks/operate/mcp_integration.py +1 -1
- runbooks/operate/networking_cost_heatmap.py +33 -10
- runbooks/operate/privatelink_operations.py +1 -1
- runbooks/operate/rds_operations.py +223 -254
- runbooks/operate/s3_operations.py +107 -118
- runbooks/operate/vpc_endpoints.py +1 -1
- runbooks/operate/vpc_operations.py +648 -618
- runbooks/remediation/base.py +1 -1
- runbooks/remediation/commons.py +10 -7
- runbooks/remediation/commvault_ec2_analysis.py +71 -67
- runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
- runbooks/remediation/multi_account.py +24 -21
- runbooks/remediation/rds_snapshot_list.py +91 -65
- runbooks/remediation/remediation_cli.py +92 -146
- runbooks/remediation/universal_account_discovery.py +83 -79
- runbooks/remediation/workspaces_list.py +49 -44
- runbooks/security/__init__.py +19 -0
- runbooks/security/assessment_runner.py +1150 -0
- runbooks/security/baseline_checker.py +812 -0
- runbooks/security/cloudops_automation_security_validator.py +509 -535
- runbooks/security/compliance_automation_engine.py +17 -17
- runbooks/security/config/__init__.py +2 -2
- runbooks/security/config/compliance_config.py +50 -50
- runbooks/security/config_template_generator.py +63 -76
- runbooks/security/enterprise_security_framework.py +1 -1
- runbooks/security/executive_security_dashboard.py +519 -508
- runbooks/security/integration_test_enterprise_security.py +5 -3
- runbooks/security/multi_account_security_controls.py +959 -1210
- runbooks/security/real_time_security_monitor.py +422 -444
- runbooks/security/run_script.py +1 -1
- runbooks/security/security_baseline_tester.py +1 -1
- runbooks/security/security_cli.py +143 -112
- runbooks/security/test_2way_validation.py +439 -0
- runbooks/security/two_way_validation_framework.py +852 -0
- runbooks/sre/mcp_reliability_engine.py +6 -6
- runbooks/sre/production_monitoring_framework.py +167 -177
- runbooks/tdd/__init__.py +15 -0
- runbooks/tdd/cli.py +1071 -0
- runbooks/utils/__init__.py +14 -17
- runbooks/utils/logger.py +7 -2
- runbooks/utils/version_validator.py +51 -48
- runbooks/validation/__init__.py +6 -6
- runbooks/validation/cli.py +9 -3
- runbooks/validation/comprehensive_2way_validator.py +754 -708
- runbooks/validation/mcp_validator.py +906 -228
- runbooks/validation/terraform_citations_validator.py +104 -115
- runbooks/validation/terraform_drift_detector.py +447 -451
- runbooks/vpc/README.md +617 -0
- runbooks/vpc/__init__.py +8 -1
- runbooks/vpc/analyzer.py +577 -0
- runbooks/vpc/cleanup_wrapper.py +476 -413
- runbooks/vpc/cli_cloudtrail_commands.py +339 -0
- runbooks/vpc/cli_mcp_validation_commands.py +480 -0
- runbooks/vpc/cloudtrail_audit_integration.py +717 -0
- runbooks/vpc/config.py +92 -97
- runbooks/vpc/cost_engine.py +411 -148
- runbooks/vpc/cost_explorer_integration.py +553 -0
- runbooks/vpc/cross_account_session.py +101 -106
- runbooks/vpc/enhanced_mcp_validation.py +917 -0
- runbooks/vpc/eni_gate_validator.py +961 -0
- runbooks/vpc/heatmap_engine.py +190 -162
- runbooks/vpc/mcp_no_eni_validator.py +681 -640
- runbooks/vpc/nat_gateway_optimizer.py +358 -0
- runbooks/vpc/networking_wrapper.py +15 -8
- runbooks/vpc/pdca_remediation_planner.py +528 -0
- runbooks/vpc/performance_optimized_analyzer.py +219 -231
- runbooks/vpc/runbooks_adapter.py +1167 -241
- runbooks/vpc/tdd_red_phase_stubs.py +601 -0
- runbooks/vpc/test_data_loader.py +358 -0
- runbooks/vpc/tests/conftest.py +314 -4
- runbooks/vpc/tests/test_cleanup_framework.py +1022 -0
- runbooks/vpc/tests/test_cost_engine.py +0 -2
- runbooks/vpc/topology_generator.py +326 -0
- runbooks/vpc/unified_scenarios.py +1302 -1129
- runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
- runbooks-1.1.5.dist-info/METADATA +328 -0
- {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/RECORD +233 -200
- runbooks/finops/README.md +0 -414
- runbooks/finops/accuracy_cross_validator.py +0 -647
- runbooks/finops/business_cases.py +0 -950
- runbooks/finops/dashboard_router.py +0 -922
- runbooks/finops/ebs_optimizer.py +0 -956
- runbooks/finops/embedded_mcp_validator.py +0 -1629
- runbooks/finops/enhanced_dashboard_runner.py +0 -527
- runbooks/finops/finops_dashboard.py +0 -584
- runbooks/finops/finops_scenarios.py +0 -1218
- runbooks/finops/legacy_migration.py +0 -730
- runbooks/finops/multi_dashboard.py +0 -1519
- runbooks/finops/single_dashboard.py +0 -1113
- runbooks/finops/unlimited_scenarios.py +0 -393
- runbooks-1.1.3.dist-info/METADATA +0 -799
- {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
- {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
- {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
- {runbooks-1.1.3.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,358 @@
|
|
1
|
+
"""
|
2
|
+
NAT Gateway Optimizer - Cost optimization for NAT Gateway infrastructure
|
3
|
+
|
4
|
+
Reuses existing VPC infrastructure (cost_engine.py, networking_wrapper.py)
|
5
|
+
following KISS/DRY/LEAN principles for efficient NAT Gateway optimization.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import logging
|
9
|
+
from dataclasses import dataclass
|
10
|
+
from datetime import datetime
|
11
|
+
from typing import Any, Dict, List, Optional
|
12
|
+
|
13
|
+
from runbooks.common.rich_utils import (
|
14
|
+
console,
|
15
|
+
print_header,
|
16
|
+
print_success,
|
17
|
+
print_error,
|
18
|
+
print_warning,
|
19
|
+
create_table,
|
20
|
+
format_cost,
|
21
|
+
STATUS_INDICATORS,
|
22
|
+
)
|
23
|
+
|
24
|
+
from .cost_engine import NetworkingCostEngine
|
25
|
+
from .networking_wrapper import VPCNetworkingWrapper
|
26
|
+
|
27
|
+
logger = logging.getLogger(__name__)
|
28
|
+
|
29
|
+
|
30
|
+
@dataclass
|
31
|
+
class NATOptimizationResult:
|
32
|
+
"""NAT Gateway optimization analysis result"""
|
33
|
+
|
34
|
+
nat_gateway_id: str
|
35
|
+
current_monthly_cost: float
|
36
|
+
projected_savings: float
|
37
|
+
optimization_type: str
|
38
|
+
confidence_score: float
|
39
|
+
recommendations: List[str]
|
40
|
+
|
41
|
+
|
42
|
+
class NATGatewayOptimizer:
|
43
|
+
"""
|
44
|
+
NAT Gateway cost optimization module
|
45
|
+
|
46
|
+
Leverages existing VPC infrastructure for efficient cost analysis
|
47
|
+
and optimization recommendations targeting 30% cost reduction.
|
48
|
+
"""
|
49
|
+
|
50
|
+
def __init__(
|
51
|
+
self,
|
52
|
+
profile: str,
|
53
|
+
region: str = "us-east-1",
|
54
|
+
analyze: bool = False,
|
55
|
+
optimize: bool = False,
|
56
|
+
savings_target: float = 0.3,
|
57
|
+
include_alternatives: bool = False,
|
58
|
+
export_format: Optional[str] = None,
|
59
|
+
**kwargs,
|
60
|
+
):
|
61
|
+
"""
|
62
|
+
Initialize NAT Gateway Optimizer
|
63
|
+
|
64
|
+
Args:
|
65
|
+
profile: AWS profile for operations
|
66
|
+
region: AWS region to analyze
|
67
|
+
analyze: Run analysis mode
|
68
|
+
optimize: Run optimization mode
|
69
|
+
savings_target: Target savings percentage (default 30%)
|
70
|
+
include_alternatives: Include alternative solutions
|
71
|
+
export_format: Export format for results
|
72
|
+
"""
|
73
|
+
self.profile = profile
|
74
|
+
self.region = region
|
75
|
+
self.analyze = analyze
|
76
|
+
self.optimize = optimize
|
77
|
+
self.savings_target = savings_target
|
78
|
+
self.include_alternatives = include_alternatives
|
79
|
+
self.export_format = export_format
|
80
|
+
|
81
|
+
# Initialize existing VPC infrastructure (DRY principle)
|
82
|
+
self.networking_wrapper = VPCNetworkingWrapper(profile=profile, region=region, output_format="rich")
|
83
|
+
|
84
|
+
# Initialize cost engine if session available
|
85
|
+
self.cost_engine = None
|
86
|
+
if self.networking_wrapper.session:
|
87
|
+
self.cost_engine = NetworkingCostEngine(
|
88
|
+
session=self.networking_wrapper.session, enable_parallel=True, enable_caching=True
|
89
|
+
)
|
90
|
+
|
91
|
+
# Results storage
|
92
|
+
self.optimization_results = []
|
93
|
+
self.total_potential_savings = 0.0
|
94
|
+
|
95
|
+
def run_nat_gateway_optimization(self) -> Dict[str, Any]:
|
96
|
+
"""
|
97
|
+
Main optimization method called by CLI
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
Dictionary containing optimization results and recommendations
|
101
|
+
"""
|
102
|
+
print_header("NAT Gateway Cost Optimizer", "1.0.0")
|
103
|
+
|
104
|
+
results = {
|
105
|
+
"timestamp": datetime.now().isoformat(),
|
106
|
+
"profile": self.profile,
|
107
|
+
"region": self.region,
|
108
|
+
"savings_target": self.savings_target,
|
109
|
+
"total_analyzed": 0,
|
110
|
+
"total_potential_savings": 0.0,
|
111
|
+
"optimization_opportunities": [],
|
112
|
+
"recommendations": [],
|
113
|
+
"alternatives": [] if self.include_alternatives else None,
|
114
|
+
}
|
115
|
+
|
116
|
+
if not self.networking_wrapper.session:
|
117
|
+
print_error("❌ No AWS session available")
|
118
|
+
return results
|
119
|
+
|
120
|
+
if not self.cost_engine:
|
121
|
+
print_error("❌ Cost engine initialization failed")
|
122
|
+
return results
|
123
|
+
|
124
|
+
try:
|
125
|
+
# Leverage existing NAT Gateway analysis from networking_wrapper
|
126
|
+
nat_analysis = self.networking_wrapper.analyze_nat_gateways(days=30)
|
127
|
+
|
128
|
+
if not nat_analysis.get("nat_gateways"):
|
129
|
+
print_warning("⚠️ No NAT Gateways found in region")
|
130
|
+
return results
|
131
|
+
|
132
|
+
results["total_analyzed"] = len(nat_analysis["nat_gateways"])
|
133
|
+
|
134
|
+
# Analyze each NAT Gateway for optimization opportunities
|
135
|
+
for ng_data in nat_analysis["nat_gateways"]:
|
136
|
+
optimization = self._analyze_nat_gateway_optimization(ng_data)
|
137
|
+
if optimization:
|
138
|
+
self.optimization_results.append(optimization)
|
139
|
+
results["optimization_opportunities"].append(
|
140
|
+
{
|
141
|
+
"nat_gateway_id": optimization.nat_gateway_id,
|
142
|
+
"current_cost": optimization.current_monthly_cost,
|
143
|
+
"potential_savings": optimization.projected_savings,
|
144
|
+
"optimization_type": optimization.optimization_type,
|
145
|
+
"confidence": optimization.confidence_score,
|
146
|
+
}
|
147
|
+
)
|
148
|
+
|
149
|
+
# Calculate total potential savings
|
150
|
+
results["total_potential_savings"] = sum(opt.projected_savings for opt in self.optimization_results)
|
151
|
+
|
152
|
+
# Generate comprehensive recommendations
|
153
|
+
results["recommendations"] = self._generate_optimization_recommendations()
|
154
|
+
|
155
|
+
# Add alternative solutions if requested
|
156
|
+
if self.include_alternatives:
|
157
|
+
results["alternatives"] = self._generate_alternative_solutions()
|
158
|
+
|
159
|
+
# Display results using Rich formatting
|
160
|
+
self._display_optimization_results(results)
|
161
|
+
|
162
|
+
return results
|
163
|
+
|
164
|
+
except Exception as e:
|
165
|
+
print_error(f"❌ NAT Gateway optimization failed: {str(e)}")
|
166
|
+
logger.error(f"NAT Gateway optimization error: {e}")
|
167
|
+
return results
|
168
|
+
|
169
|
+
def _analyze_nat_gateway_optimization(self, nat_data: Dict[str, Any]) -> Optional[NATOptimizationResult]:
|
170
|
+
"""
|
171
|
+
Analyze individual NAT Gateway for optimization opportunities
|
172
|
+
|
173
|
+
Args:
|
174
|
+
nat_data: NAT Gateway data from networking analysis
|
175
|
+
|
176
|
+
Returns:
|
177
|
+
Optimization result if opportunities found
|
178
|
+
"""
|
179
|
+
nat_id = nat_data.get("nat_gateway_id", "unknown")
|
180
|
+
monthly_cost = nat_data.get("monthly_cost", 0.0)
|
181
|
+
|
182
|
+
# Skip if cost is negligible
|
183
|
+
if monthly_cost < 10.0:
|
184
|
+
return None
|
185
|
+
|
186
|
+
# Calculate optimization based on usage patterns
|
187
|
+
bytes_processed = nat_data.get("bytes_processed_gb", 0.0)
|
188
|
+
confidence_score = 0.8 # Base confidence
|
189
|
+
|
190
|
+
# Determine optimization type and potential savings
|
191
|
+
if bytes_processed < 1.0: # Low usage
|
192
|
+
optimization_type = "low_usage_replacement"
|
193
|
+
projected_savings = monthly_cost * 0.8 # 80% savings via VPC Endpoints
|
194
|
+
confidence_score = 0.9
|
195
|
+
recommendations = [
|
196
|
+
"Replace with VPC Endpoints for AWS services",
|
197
|
+
"Consider NAT Instance for minimal traffic",
|
198
|
+
"Evaluate subnet routing optimization",
|
199
|
+
]
|
200
|
+
|
201
|
+
elif bytes_processed < 10.0: # Medium usage
|
202
|
+
optimization_type = "nat_instance_replacement"
|
203
|
+
projected_savings = monthly_cost * 0.4 # 40% savings via NAT Instance
|
204
|
+
confidence_score = 0.7
|
205
|
+
recommendations = [
|
206
|
+
"Replace with cost-optimized NAT Instance",
|
207
|
+
"Implement VPC Endpoints for AWS services",
|
208
|
+
"Optimize routing for efficiency",
|
209
|
+
]
|
210
|
+
|
211
|
+
elif monthly_cost > 100.0: # High cost
|
212
|
+
optimization_type = "architecture_optimization"
|
213
|
+
projected_savings = monthly_cost * self.savings_target
|
214
|
+
confidence_score = 0.6
|
215
|
+
recommendations = [
|
216
|
+
"Implement multi-AZ NAT Instance cluster",
|
217
|
+
"Add VPC Endpoints for high-traffic AWS services",
|
218
|
+
"Consider Transit Gateway for complex routing",
|
219
|
+
]
|
220
|
+
|
221
|
+
else:
|
222
|
+
# No significant optimization opportunity
|
223
|
+
return None
|
224
|
+
|
225
|
+
return NATOptimizationResult(
|
226
|
+
nat_gateway_id=nat_id,
|
227
|
+
current_monthly_cost=monthly_cost,
|
228
|
+
projected_savings=projected_savings,
|
229
|
+
optimization_type=optimization_type,
|
230
|
+
confidence_score=confidence_score,
|
231
|
+
recommendations=recommendations,
|
232
|
+
)
|
233
|
+
|
234
|
+
def _generate_optimization_recommendations(self) -> List[str]:
|
235
|
+
"""Generate comprehensive optimization recommendations"""
|
236
|
+
recommendations = []
|
237
|
+
|
238
|
+
if not self.optimization_results:
|
239
|
+
return ["No optimization opportunities identified"]
|
240
|
+
|
241
|
+
total_savings = sum(opt.projected_savings for opt in self.optimization_results)
|
242
|
+
|
243
|
+
recommendations.extend(
|
244
|
+
[
|
245
|
+
f"💰 Potential annual savings: {format_cost(total_savings * 12)}",
|
246
|
+
f"🎯 Target savings rate: {self.savings_target * 100:.0f}%",
|
247
|
+
"🔧 Recommended actions:",
|
248
|
+
]
|
249
|
+
)
|
250
|
+
|
251
|
+
# Group recommendations by optimization type
|
252
|
+
optimization_types = set(opt.optimization_type for opt in self.optimization_results)
|
253
|
+
|
254
|
+
for opt_type in optimization_types:
|
255
|
+
count = sum(1 for opt in self.optimization_results if opt.optimization_type == opt_type)
|
256
|
+
if opt_type == "low_usage_replacement":
|
257
|
+
recommendations.append(f" • Replace {count} low-usage NAT Gateway(s) with VPC Endpoints")
|
258
|
+
elif opt_type == "nat_instance_replacement":
|
259
|
+
recommendations.append(f" • Replace {count} medium-usage NAT Gateway(s) with NAT Instances")
|
260
|
+
elif opt_type == "architecture_optimization":
|
261
|
+
recommendations.append(f" • Optimize {count} high-cost NAT Gateway(s) architecture")
|
262
|
+
|
263
|
+
return recommendations
|
264
|
+
|
265
|
+
def _generate_alternative_solutions(self) -> List[Dict[str, Any]]:
|
266
|
+
"""Generate alternative networking solutions"""
|
267
|
+
alternatives = []
|
268
|
+
|
269
|
+
alternatives.extend(
|
270
|
+
[
|
271
|
+
{
|
272
|
+
"solution": "VPC Endpoints",
|
273
|
+
"use_case": "AWS service traffic",
|
274
|
+
"cost_impact": "80-90% reduction for AWS service calls",
|
275
|
+
"complexity": "Low",
|
276
|
+
"implementation_time": "1-2 days",
|
277
|
+
},
|
278
|
+
{
|
279
|
+
"solution": "NAT Instance",
|
280
|
+
"use_case": "Medium traffic volumes",
|
281
|
+
"cost_impact": "40-60% cost reduction",
|
282
|
+
"complexity": "Medium",
|
283
|
+
"implementation_time": "3-5 days",
|
284
|
+
},
|
285
|
+
{
|
286
|
+
"solution": "Transit Gateway",
|
287
|
+
"use_case": "Complex multi-VPC scenarios",
|
288
|
+
"cost_impact": "20-40% cost optimization",
|
289
|
+
"complexity": "High",
|
290
|
+
"implementation_time": "1-2 weeks",
|
291
|
+
},
|
292
|
+
]
|
293
|
+
)
|
294
|
+
|
295
|
+
return alternatives
|
296
|
+
|
297
|
+
def _display_optimization_results(self, results: Dict[str, Any]) -> None:
|
298
|
+
"""Display optimization results using Rich formatting"""
|
299
|
+
|
300
|
+
# Summary panel
|
301
|
+
console.print()
|
302
|
+
console.print("🚀 [bold green]NAT Gateway Optimization Summary[/bold green]")
|
303
|
+
console.print(f" • Analyzed: {results['total_analyzed']} NAT Gateway(s)")
|
304
|
+
console.print(f" • Opportunities: {len(results['optimization_opportunities'])}")
|
305
|
+
console.print(
|
306
|
+
f" • Potential Savings: [green]{format_cost(results['total_potential_savings'] * 12)} annually[/green]"
|
307
|
+
)
|
308
|
+
|
309
|
+
# Optimization opportunities table
|
310
|
+
if results["optimization_opportunities"]:
|
311
|
+
console.print()
|
312
|
+
table = create_table("NAT Gateway Optimization Opportunities")
|
313
|
+
table.add_column("NAT Gateway ID", style="cyan")
|
314
|
+
table.add_column("Current Cost", style="yellow")
|
315
|
+
table.add_column("Potential Savings", style="green")
|
316
|
+
table.add_column("Optimization Type", style="blue")
|
317
|
+
table.add_column("Confidence", style="magenta")
|
318
|
+
|
319
|
+
for opp in results["optimization_opportunities"]:
|
320
|
+
table.add_row(
|
321
|
+
opp["nat_gateway_id"],
|
322
|
+
format_cost(opp["current_cost"]),
|
323
|
+
format_cost(opp["potential_savings"]),
|
324
|
+
opp["optimization_type"].replace("_", " ").title(),
|
325
|
+
f"{opp['confidence'] * 100:.0f}%",
|
326
|
+
)
|
327
|
+
|
328
|
+
console.print(table)
|
329
|
+
|
330
|
+
# Recommendations
|
331
|
+
if results["recommendations"]:
|
332
|
+
console.print()
|
333
|
+
console.print("📋 [bold blue]Optimization Recommendations[/bold blue]")
|
334
|
+
for rec in results["recommendations"]:
|
335
|
+
console.print(f" {rec}")
|
336
|
+
|
337
|
+
# Alternative solutions (if requested)
|
338
|
+
if results.get("alternatives"):
|
339
|
+
console.print()
|
340
|
+
console.print("🔄 [bold purple]Alternative Solutions[/bold purple]")
|
341
|
+
alt_table = create_table("Alternative Networking Solutions")
|
342
|
+
alt_table.add_column("Solution", style="cyan")
|
343
|
+
alt_table.add_column("Use Case", style="yellow")
|
344
|
+
alt_table.add_column("Cost Impact", style="green")
|
345
|
+
alt_table.add_column("Complexity", style="blue")
|
346
|
+
|
347
|
+
for alt in results["alternatives"]:
|
348
|
+
alt_table.add_row(alt["solution"], alt["use_case"], alt["cost_impact"], alt["complexity"])
|
349
|
+
|
350
|
+
console.print(alt_table)
|
351
|
+
|
352
|
+
# Success message
|
353
|
+
if results["total_potential_savings"] > 0:
|
354
|
+
print_success(
|
355
|
+
f"✅ NAT Gateway optimization complete - {format_cost(results['total_potential_savings'] * 12)} annual savings identified"
|
356
|
+
)
|
357
|
+
else:
|
358
|
+
print_warning("⚠️ No significant optimization opportunities found")
|
@@ -21,8 +21,16 @@ from rich.table import Table
|
|
21
21
|
|
22
22
|
from runbooks.common.profile_utils import create_operational_session, create_cost_session, create_management_session
|
23
23
|
from runbooks.common.rich_utils import (
|
24
|
-
console,
|
25
|
-
|
24
|
+
console,
|
25
|
+
print_header,
|
26
|
+
print_success,
|
27
|
+
print_error,
|
28
|
+
print_warning,
|
29
|
+
print_info,
|
30
|
+
create_table,
|
31
|
+
create_progress_bar,
|
32
|
+
format_cost,
|
33
|
+
STATUS_INDICATORS,
|
26
34
|
)
|
27
35
|
from runbooks.common.env_utils import get_required_env_float
|
28
36
|
|
@@ -78,7 +86,7 @@ class VPCNetworkingWrapper:
|
|
78
86
|
if profile:
|
79
87
|
try:
|
80
88
|
# Use operational profile for VPC operations
|
81
|
-
self.session = create_operational_session(
|
89
|
+
self.session = create_operational_session(profile_name=profile)
|
82
90
|
print_success(f"Connected to AWS profile: {profile}")
|
83
91
|
except Exception as e:
|
84
92
|
print_warning(f"Failed to connect to AWS: {e}")
|
@@ -90,7 +98,6 @@ class VPCNetworkingWrapper:
|
|
90
98
|
# Results storage
|
91
99
|
self.last_results = {}
|
92
100
|
|
93
|
-
|
94
101
|
def analyze_nat_gateways(self, days: int = 30) -> Dict[str, Any]:
|
95
102
|
"""
|
96
103
|
Analyze NAT Gateway usage and costs
|
@@ -138,10 +145,10 @@ class VPCNetworkingWrapper:
|
|
138
145
|
usage_data = self._analyze_nat_gateway_usage(cloudwatch, ng_id, days)
|
139
146
|
|
140
147
|
# Calculate costs with dynamic pricing - NO hardcoded defaults
|
141
|
-
base_nat_cost = get_required_env_float(
|
148
|
+
base_nat_cost = get_required_env_float("NAT_GATEWAY_MONTHLY_COST")
|
142
149
|
monthly_cost = base_nat_cost
|
143
150
|
if usage_data["bytes_processed_gb"] > 0:
|
144
|
-
processing_rate = get_required_env_float(
|
151
|
+
processing_rate = get_required_env_float("NAT_GATEWAY_DATA_PROCESSING_RATE")
|
145
152
|
monthly_cost += usage_data["bytes_processed_gb"] * processing_rate
|
146
153
|
|
147
154
|
ng_analysis = {
|
@@ -486,7 +493,7 @@ class VPCNetworkingWrapper:
|
|
486
493
|
# Enhanced enterprise cost modeling for multi-account environment
|
487
494
|
# Base TGW hourly cost: Dynamic from environment or AWS Pricing API
|
488
495
|
# NO hardcoded defaults allowed for enterprise compliance
|
489
|
-
tgw_hourly_rate = get_required_env_float(
|
496
|
+
tgw_hourly_rate = get_required_env_float("TGW_HOURLY_RATE")
|
490
497
|
tgw_base_cost = len(tgws) * tgw_hourly_rate * 24 * 30 # Monthly cost
|
491
498
|
|
492
499
|
# Attachment costs with enterprise multipliers for 60-account environment
|
@@ -923,7 +930,7 @@ class VPCNetworkingWrapper:
|
|
923
930
|
try:
|
924
931
|
# Discovery phase
|
925
932
|
progress.update(discovery_task, description=f"🔍 Discovering {account_profile}")
|
926
|
-
account_session = create_operational_session(
|
933
|
+
account_session = create_operational_session(profile_name=account_profile)
|
927
934
|
|
928
935
|
# Cost analysis phase
|
929
936
|
progress.update(cost_task, description=f"💰 Analyzing costs for {account_profile}")
|