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.
- 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/assessment/compliance.py +1 -1
- runbooks/cfat/assessment/runner.py +1 -0
- runbooks/cfat/cloud_foundations_assessment.py +227 -239
- runbooks/cli/__init__.py +1 -1
- runbooks/cli/commands/cfat.py +64 -23
- runbooks/cli/commands/finops.py +1005 -54
- runbooks/cli/commands/inventory.py +138 -35
- runbooks/cli/commands/operate.py +9 -36
- runbooks/cli/commands/security.py +42 -18
- runbooks/cli/commands/validation.py +432 -18
- runbooks/cli/commands/vpc.py +81 -17
- runbooks/cli/registry.py +22 -10
- runbooks/cloudops/__init__.py +20 -27
- runbooks/cloudops/base.py +96 -107
- runbooks/cloudops/cost_optimizer.py +544 -542
- runbooks/cloudops/infrastructure_optimizer.py +5 -4
- runbooks/cloudops/interfaces.py +224 -225
- 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 +177 -213
- 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 +40 -36
- runbooks/common/aws_utils.py +74 -79
- runbooks/common/business_logic.py +126 -104
- runbooks/common/cli_decorators.py +36 -60
- runbooks/common/comprehensive_cost_explorer_integration.py +455 -463
- runbooks/common/cross_account_manager.py +197 -204
- runbooks/common/date_utils.py +27 -39
- runbooks/common/decorators.py +29 -19
- 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 +476 -493
- 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 +175 -193
- runbooks/common/patterns.py +23 -25
- runbooks/common/performance_monitoring.py +67 -71
- runbooks/common/performance_optimization_engine.py +283 -274
- runbooks/common/profile_utils.py +111 -37
- runbooks/common/rich_utils.py +201 -141
- 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 +26 -30
- 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 +484 -618
- 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 +32 -29
- runbooks/finops/enhanced_trend_visualization.py +3 -2
- runbooks/finops/enterprise_wrappers.py +223 -285
- 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 +337 -174
- runbooks/finops/mcp_validator.py +1952 -0
- runbooks/finops/nat_gateway_optimizer.py +1512 -481
- 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 +19 -23
- runbooks/finops/rds_snapshot_optimizer.py +367 -411
- runbooks/finops/reservation_optimizer.py +427 -363
- runbooks/finops/scenario_cli_integration.py +64 -65
- runbooks/finops/scenarios.py +1277 -438
- runbooks/finops/schemas.py +218 -182
- runbooks/finops/snapshot_manager.py +2289 -0
- runbooks/finops/types.py +3 -3
- runbooks/finops/validation_framework.py +259 -265
- runbooks/finops/vpc_cleanup_exporter.py +189 -144
- runbooks/finops/vpc_cleanup_optimizer.py +591 -573
- runbooks/finops/workspaces_analyzer.py +171 -182
- runbooks/integration/__init__.py +89 -0
- runbooks/integration/mcp_integration.py +1920 -0
- runbooks/inventory/CLAUDE.md +816 -0
- runbooks/inventory/__init__.py +2 -2
- runbooks/inventory/cloud_foundations_integration.py +144 -149
- runbooks/inventory/collectors/aws_comprehensive.py +1 -1
- runbooks/inventory/collectors/aws_networking.py +109 -99
- runbooks/inventory/collectors/base.py +4 -0
- runbooks/inventory/core/collector.py +495 -313
- runbooks/inventory/drift_detection_cli.py +69 -96
- 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 +55 -51
- runbooks/inventory/rich_inventory_display.py +33 -32
- runbooks/inventory/unified_validation_engine.py +278 -251
- runbooks/inventory/vpc_analyzer.py +732 -695
- runbooks/inventory/vpc_architecture_validator.py +293 -348
- runbooks/inventory/vpc_dependency_analyzer.py +382 -378
- runbooks/inventory/vpc_flow_analyzer.py +1 -1
- runbooks/main.py +49 -34
- 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/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/networking_cost_heatmap.py +29 -8
- runbooks/operate/rds_operations.py +223 -254
- runbooks/operate/s3_operations.py +107 -118
- runbooks/operate/vpc_operations.py +646 -616
- runbooks/remediation/base.py +1 -1
- runbooks/remediation/commons.py +10 -7
- runbooks/remediation/commvault_ec2_analysis.py +70 -66
- runbooks/remediation/ec2_unattached_ebs_volumes.py +1 -0
- runbooks/remediation/multi_account.py +24 -21
- runbooks/remediation/rds_snapshot_list.py +86 -60
- runbooks/remediation/remediation_cli.py +92 -146
- runbooks/remediation/universal_account_discovery.py +83 -79
- runbooks/remediation/workspaces_list.py +46 -41
- 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/multi_account_security_controls.py +959 -1210
- runbooks/security/real_time_security_monitor.py +422 -444
- 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/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 +50 -47
- runbooks/validation/__init__.py +6 -6
- runbooks/validation/cli.py +9 -3
- runbooks/validation/comprehensive_2way_validator.py +745 -704
- 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 +185 -160
- runbooks/vpc/mcp_no_eni_validator.py +680 -639
- 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 +1297 -1124
- runbooks/vpc/vpc_cleanup_integration.py +1943 -1115
- runbooks-1.1.5.dist-info/METADATA +328 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/RECORD +214 -193
- 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 -973
- 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.4.dist-info/METADATA +0 -800
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/WHEEL +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/entry_points.txt +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/licenses/LICENSE +0 -0
- {runbooks-1.1.4.dist-info → runbooks-1.1.5.dist-info}/top_level.txt +0 -0
runbooks/cloudops/interfaces.py
CHANGED
@@ -45,8 +45,17 @@ from dataclasses import dataclass, asdict
|
|
45
45
|
import warnings
|
46
46
|
|
47
47
|
from runbooks.common.rich_utils import (
|
48
|
-
console,
|
49
|
-
|
48
|
+
console,
|
49
|
+
print_header,
|
50
|
+
print_success,
|
51
|
+
print_error,
|
52
|
+
print_warning,
|
53
|
+
print_info,
|
54
|
+
create_table,
|
55
|
+
create_progress_bar,
|
56
|
+
format_cost,
|
57
|
+
create_panel,
|
58
|
+
STATUS_INDICATORS,
|
50
59
|
)
|
51
60
|
|
52
61
|
from .base import CloudOpsBase
|
@@ -56,17 +65,25 @@ from .lifecycle_manager import ResourceLifecycleManager
|
|
56
65
|
from .infrastructure_optimizer import InfrastructureOptimizer
|
57
66
|
from .monitoring_automation import MonitoringAutomation
|
58
67
|
from .models import (
|
59
|
-
BusinessScenario,
|
60
|
-
|
61
|
-
|
68
|
+
BusinessScenario,
|
69
|
+
ExecutionMode,
|
70
|
+
RiskLevel,
|
71
|
+
CloudOpsExecutionResult,
|
72
|
+
CostOptimizationResult,
|
73
|
+
SecurityEnforcementResult,
|
74
|
+
BusinessMetrics,
|
75
|
+
ResourceImpact,
|
76
|
+
ComplianceMetrics,
|
62
77
|
)
|
63
78
|
|
64
79
|
# Suppress warnings for cleaner notebook output
|
65
80
|
warnings.filterwarnings("ignore", category=UserWarning)
|
66
81
|
|
82
|
+
|
67
83
|
@dataclass
|
68
84
|
class BusinessResultSummary:
|
69
85
|
"""Executive-ready result summary for business stakeholders."""
|
86
|
+
|
70
87
|
scenario_name: str
|
71
88
|
success: bool
|
72
89
|
execution_time_seconds: float
|
@@ -78,7 +95,7 @@ class BusinessResultSummary:
|
|
78
95
|
security_improvement: Optional[float] = None
|
79
96
|
roi_percentage: Optional[str] = None
|
80
97
|
risk_level: str = "medium"
|
81
|
-
|
98
|
+
|
82
99
|
@property
|
83
100
|
def executive_summary(self) -> str:
|
84
101
|
"""Generate executive summary text."""
|
@@ -88,7 +105,7 @@ class BusinessResultSummary:
|
|
88
105
|
💰 Financial Impact:
|
89
106
|
• Monthly savings: ${self.monthly_savings:,.2f}
|
90
107
|
• Annual impact: ${self.annual_impact:,.2f}
|
91
|
-
• ROI: {self.roi_percentage or
|
108
|
+
• ROI: {self.roi_percentage or "Immediate"}
|
92
109
|
|
93
110
|
📊 Operational Results:
|
94
111
|
• Resources analyzed: {self.resources_analyzed:,}
|
@@ -99,68 +116,70 @@ class BusinessResultSummary:
|
|
99
116
|
{f"🔒 Compliance: {self.compliance_score:.1f}% score" if self.compliance_score else ""}
|
100
117
|
{f"🛡️ Security: +{self.security_improvement:.1f}% improvement" if self.security_improvement else ""}
|
101
118
|
|
102
|
-
Status: {
|
119
|
+
Status: {"✅ SUCCESS" if self.success else "❌ NEEDS ATTENTION"}
|
103
120
|
""".strip()
|
104
|
-
|
121
|
+
|
105
122
|
def export_reports(self, output_dir: str = "./tmp/cloudops-reports") -> Dict[str, str]:
|
106
123
|
"""Export business reports to specified directory."""
|
107
124
|
output_path = Path(output_dir)
|
108
125
|
output_path.mkdir(parents=True, exist_ok=True)
|
109
|
-
|
126
|
+
|
110
127
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
111
128
|
scenario_slug = self.scenario_name.lower().replace(" ", "_").replace("-", "_")
|
112
|
-
|
129
|
+
|
113
130
|
exported_files = {}
|
114
|
-
|
131
|
+
|
115
132
|
try:
|
116
133
|
# Export JSON summary
|
117
134
|
json_file = output_path / f"{scenario_slug}_summary_{timestamp}.json"
|
118
|
-
with open(json_file,
|
135
|
+
with open(json_file, "w") as f:
|
119
136
|
json.dump(asdict(self), f, indent=2, default=str)
|
120
|
-
exported_files[
|
121
|
-
|
137
|
+
exported_files["json"] = str(json_file)
|
138
|
+
|
122
139
|
# Export executive markdown
|
123
140
|
md_file = output_path / f"{scenario_slug}_executive_summary_{timestamp}.md"
|
124
|
-
with open(md_file,
|
141
|
+
with open(md_file, "w") as f:
|
125
142
|
f.write(f"# {self.scenario_name}\n\n")
|
126
143
|
f.write(f"**Generated**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
|
127
144
|
f.write(self.executive_summary)
|
128
|
-
exported_files[
|
129
|
-
|
145
|
+
exported_files["markdown"] = str(md_file)
|
146
|
+
|
130
147
|
print_success(f"📊 Reports exported to: {output_dir}")
|
131
148
|
print_info(f" • JSON: {json_file.name}")
|
132
149
|
print_info(f" • Markdown: {md_file.name}")
|
133
|
-
|
150
|
+
|
134
151
|
except Exception as e:
|
135
152
|
print_warning(f"Report export will be available after directory permissions are configured: {str(e)}")
|
136
|
-
exported_files[
|
137
|
-
|
153
|
+
exported_files["error"] = str(e)
|
154
|
+
|
138
155
|
return exported_files
|
139
156
|
|
157
|
+
|
140
158
|
def _run_async_operation(coro_func, operation_name: str = "CloudOps Operation"):
|
141
159
|
"""
|
142
160
|
Run async operation with proper event loop management.
|
143
|
-
|
161
|
+
|
144
162
|
Handles both existing and new event loops for notebook compatibility.
|
145
163
|
"""
|
146
164
|
print_info(f"🚀 Executing {operation_name}...")
|
147
|
-
|
165
|
+
|
148
166
|
try:
|
149
167
|
# Try to get existing event loop (common in notebooks)
|
150
168
|
loop = asyncio.get_event_loop()
|
151
169
|
if loop.is_running():
|
152
170
|
# If loop is running (like in Jupyter), create new task
|
153
171
|
import nest_asyncio
|
172
|
+
|
154
173
|
nest_asyncio.apply()
|
155
174
|
return loop.run_until_complete(coro_func)
|
156
175
|
else:
|
157
176
|
# If loop exists but not running, use it
|
158
177
|
return loop.run_until_complete(coro_func)
|
159
|
-
|
178
|
+
|
160
179
|
except RuntimeError:
|
161
180
|
# No event loop exists, create new one
|
162
181
|
return asyncio.run(coro_func)
|
163
|
-
|
182
|
+
|
164
183
|
except ImportError:
|
165
184
|
# nest_asyncio not available, try direct approach
|
166
185
|
try:
|
@@ -170,20 +189,22 @@ def _run_async_operation(coro_func, operation_name: str = "CloudOps Operation"):
|
|
170
189
|
print_warning("💡 For notebook usage, try: pip install nest-asyncio")
|
171
190
|
raise
|
172
191
|
|
192
|
+
|
173
193
|
def _validate_business_parameters(**kwargs) -> None:
|
174
194
|
"""Validate business parameters with helpful error messages."""
|
175
|
-
profile = kwargs.get(
|
195
|
+
profile = kwargs.get("profile")
|
176
196
|
if profile and not isinstance(profile, str):
|
177
197
|
raise ValueError("Profile must be a string (e.g., 'billing', 'management', 'operations')")
|
178
|
-
|
179
|
-
cost_threshold = kwargs.get(
|
198
|
+
|
199
|
+
cost_threshold = kwargs.get("cost_spike_threshold") or kwargs.get("cost_threshold")
|
180
200
|
if cost_threshold is not None and cost_threshold <= 0:
|
181
201
|
raise ValueError("Cost threshold must be positive (e.g., 25000 for $25,000)")
|
182
|
-
|
183
|
-
savings_percent = kwargs.get(
|
202
|
+
|
203
|
+
savings_percent = kwargs.get("target_savings_percent")
|
184
204
|
if savings_percent is not None and not (0 < savings_percent <= 100):
|
185
205
|
raise ValueError("Savings percentage must be between 1-100 (e.g., 30 for 30%)")
|
186
206
|
|
207
|
+
|
187
208
|
def emergency_cost_response(
|
188
209
|
profile: str = "default",
|
189
210
|
cost_spike_threshold: float = 25000.0,
|
@@ -191,15 +212,15 @@ def emergency_cost_response(
|
|
191
212
|
analysis_days: int = 7,
|
192
213
|
max_risk_level: str = "medium",
|
193
214
|
require_approval: bool = True,
|
194
|
-
dry_run: bool = True
|
215
|
+
dry_run: bool = True,
|
195
216
|
) -> BusinessResultSummary:
|
196
217
|
"""
|
197
218
|
Execute emergency cost response for unexpected AWS cost spikes.
|
198
|
-
|
219
|
+
|
199
220
|
Business Scenario:
|
200
221
|
Rapid response to cost spikes requiring immediate executive action.
|
201
222
|
Typical triggers: Monthly bill increase >$5K, daily spending >200% budget.
|
202
|
-
|
223
|
+
|
203
224
|
Args:
|
204
225
|
profile: AWS profile name (e.g., "billing", "management")
|
205
226
|
cost_spike_threshold: Minimum cost increase ($) that triggered emergency
|
@@ -208,10 +229,10 @@ def emergency_cost_response(
|
|
208
229
|
max_risk_level: Maximum acceptable risk ("low", "medium", "high")
|
209
230
|
require_approval: Require executive approval for high-impact changes
|
210
231
|
dry_run: Safe analysis mode (recommended for business users)
|
211
|
-
|
232
|
+
|
212
233
|
Returns:
|
213
234
|
BusinessResultSummary with executive-ready results and export capabilities
|
214
|
-
|
235
|
+
|
215
236
|
Example:
|
216
237
|
```python
|
217
238
|
result = emergency_cost_response(
|
@@ -224,49 +245,43 @@ def emergency_cost_response(
|
|
224
245
|
```
|
225
246
|
"""
|
226
247
|
print_header("Emergency Cost Response - Business Analysis")
|
227
|
-
|
248
|
+
|
228
249
|
# Validate business parameters
|
229
250
|
_validate_business_parameters(
|
230
|
-
profile=profile,
|
231
|
-
cost_spike_threshold=cost_spike_threshold,
|
232
|
-
target_savings_percent=target_savings_percent
|
251
|
+
profile=profile, cost_spike_threshold=cost_spike_threshold, target_savings_percent=target_savings_percent
|
233
252
|
)
|
234
|
-
|
253
|
+
|
235
254
|
# Convert business risk to system enum
|
236
255
|
risk_mapping = {"low": RiskLevel.LOW, "medium": RiskLevel.MEDIUM, "high": RiskLevel.HIGH}
|
237
256
|
risk_level = risk_mapping.get(max_risk_level.lower(), RiskLevel.MEDIUM)
|
238
|
-
|
257
|
+
|
239
258
|
print_info(f"💰 Cost spike threshold: ${cost_spike_threshold:,.2f}")
|
240
259
|
print_info(f"🎯 Target savings: {target_savings_percent}%")
|
241
260
|
print_info(f"🛡️ Risk tolerance: {max_risk_level.title()}")
|
242
261
|
print_info(f"⏱️ Analysis window: {analysis_days} days")
|
243
|
-
|
262
|
+
|
244
263
|
start_time = time.time()
|
245
|
-
|
264
|
+
|
246
265
|
try:
|
247
266
|
# Initialize cost optimizer with business-safe settings
|
248
267
|
cost_optimizer = CostOptimizer(
|
249
268
|
profile=profile,
|
250
269
|
dry_run=dry_run,
|
251
|
-
execution_mode=ExecutionMode.VALIDATE_ONLY if require_approval else ExecutionMode.DRY_RUN
|
270
|
+
execution_mode=ExecutionMode.VALIDATE_ONLY if require_approval else ExecutionMode.DRY_RUN,
|
252
271
|
)
|
253
|
-
|
272
|
+
|
254
273
|
# Execute emergency cost analysis
|
255
274
|
async def run_emergency_analysis():
|
256
275
|
return await cost_optimizer.emergency_cost_response(
|
257
|
-
cost_spike_threshold=cost_spike_threshold,
|
258
|
-
analysis_days=analysis_days
|
276
|
+
cost_spike_threshold=cost_spike_threshold, analysis_days=analysis_days
|
259
277
|
)
|
260
|
-
|
261
|
-
result = _run_async_operation(
|
262
|
-
|
263
|
-
"Emergency Cost Spike Analysis"
|
264
|
-
)
|
265
|
-
|
278
|
+
|
279
|
+
result = _run_async_operation(run_emergency_analysis(), "Emergency Cost Spike Analysis")
|
280
|
+
|
266
281
|
# Transform to business-friendly summary
|
267
282
|
execution_time = time.time() - start_time
|
268
283
|
monthly_savings = result.business_metrics.total_monthly_savings
|
269
|
-
|
284
|
+
|
270
285
|
business_summary = BusinessResultSummary(
|
271
286
|
scenario_name="Emergency Cost Response",
|
272
287
|
success=result.success,
|
@@ -276,9 +291,9 @@ def emergency_cost_response(
|
|
276
291
|
resources_analyzed=result.resources_analyzed,
|
277
292
|
resources_impacted=len(result.resources_impacted),
|
278
293
|
roi_percentage="Immediate",
|
279
|
-
risk_level=result.business_metrics.overall_risk_level.value
|
294
|
+
risk_level=result.business_metrics.overall_risk_level.value,
|
280
295
|
)
|
281
|
-
|
296
|
+
|
282
297
|
# Display Rich CLI summary
|
283
298
|
summary_panel = create_panel(
|
284
299
|
f"""💰 Emergency Analysis Complete
|
@@ -291,21 +306,21 @@ Risk Level: {business_summary.risk_level.title()}
|
|
291
306
|
|
292
307
|
✅ Ready for Executive Review""",
|
293
308
|
title="Emergency Cost Response Results",
|
294
|
-
border_style="green" if result.success else "red"
|
309
|
+
border_style="green" if result.success else "red",
|
295
310
|
)
|
296
311
|
console.print(summary_panel)
|
297
|
-
|
312
|
+
|
298
313
|
return business_summary
|
299
|
-
|
314
|
+
|
300
315
|
except Exception as e:
|
301
316
|
print_error(f"Emergency cost analysis encountered an issue: {str(e)}")
|
302
317
|
print_info("💡 This typically indicates AWS profile or permissions setup is needed")
|
303
318
|
print_info("📞 Contact CloudOps team for AWS access configuration")
|
304
|
-
|
319
|
+
|
305
320
|
# Return demonstration result for business planning
|
306
321
|
execution_time = time.time() - start_time
|
307
322
|
demo_savings = cost_spike_threshold * (target_savings_percent / 100)
|
308
|
-
|
323
|
+
|
309
324
|
return BusinessResultSummary(
|
310
325
|
scenario_name="Emergency Cost Response (Demo Mode)",
|
311
326
|
success=False,
|
@@ -313,90 +328,87 @@ Risk Level: {business_summary.risk_level.title()}
|
|
313
328
|
monthly_savings=demo_savings,
|
314
329
|
annual_impact=demo_savings * 12,
|
315
330
|
resources_analyzed=100, # Estimated
|
316
|
-
resources_impacted=25,
|
331
|
+
resources_impacted=25, # Estimated
|
317
332
|
roi_percentage="Immediate",
|
318
|
-
risk_level=max_risk_level
|
333
|
+
risk_level=max_risk_level,
|
319
334
|
)
|
320
335
|
|
336
|
+
|
321
337
|
def optimize_unused_resources(
|
322
338
|
profile: str = "default",
|
323
339
|
resource_types: Optional[List[str]] = None,
|
324
340
|
minimum_cost_threshold: float = 50.0,
|
325
341
|
idle_days_threshold: int = 7,
|
326
|
-
dry_run: bool = True
|
342
|
+
dry_run: bool = True,
|
327
343
|
) -> BusinessResultSummary:
|
328
344
|
"""
|
329
345
|
Identify and optimize unused AWS resources for immediate cost savings.
|
330
|
-
|
346
|
+
|
331
347
|
Business Scenario:
|
332
348
|
Find unused resources (NAT Gateways, EBS volumes, idle EC2) for quick wins.
|
333
349
|
Focus on resources with clear business impact and low operational risk.
|
334
|
-
|
350
|
+
|
335
351
|
Args:
|
336
352
|
profile: AWS profile name for resource analysis
|
337
353
|
resource_types: Resource types to analyze (None = all types)
|
338
354
|
minimum_cost_threshold: Minimum monthly cost to consider ($)
|
339
355
|
idle_days_threshold: Days of inactivity to consider resource unused
|
340
356
|
dry_run: Safe analysis mode (recommended)
|
341
|
-
|
357
|
+
|
342
358
|
Returns:
|
343
359
|
BusinessResultSummary with optimization opportunities
|
344
360
|
"""
|
345
361
|
print_header("Unused Resource Optimization - Business Analysis")
|
346
|
-
|
362
|
+
|
347
363
|
_validate_business_parameters(profile=profile, cost_threshold=minimum_cost_threshold)
|
348
|
-
|
364
|
+
|
349
365
|
if resource_types is None:
|
350
366
|
resource_types = ["nat-gateway", "ebs-volume", "ec2-instance", "elastic-ip"]
|
351
|
-
|
367
|
+
|
352
368
|
print_info(f"🔍 Analyzing resource types: {', '.join(resource_types)}")
|
353
369
|
print_info(f"💰 Cost threshold: ${minimum_cost_threshold:,.2f}/month")
|
354
370
|
print_info(f"⏱️ Idle threshold: {idle_days_threshold} days")
|
355
|
-
|
371
|
+
|
356
372
|
start_time = time.time()
|
357
|
-
|
373
|
+
|
358
374
|
try:
|
359
375
|
cost_optimizer = CostOptimizer(profile=profile, dry_run=dry_run)
|
360
|
-
|
376
|
+
|
361
377
|
total_savings = 0.0
|
362
378
|
total_resources = 0
|
363
379
|
impacted_resources = 0
|
364
|
-
|
380
|
+
|
365
381
|
async def analyze_unused_resources():
|
366
382
|
nonlocal total_savings, total_resources, impacted_resources
|
367
|
-
|
383
|
+
|
368
384
|
# Analyze NAT Gateways (typically significant value range/month each)
|
369
385
|
if "nat-gateway" in resource_types:
|
370
386
|
print_info("🌐 Analyzing unused NAT Gateways...")
|
371
387
|
nat_result = await cost_optimizer.optimize_nat_gateways(
|
372
|
-
idle_threshold_days=idle_days_threshold,
|
373
|
-
cost_threshold=minimum_cost_threshold
|
388
|
+
idle_threshold_days=idle_days_threshold, cost_threshold=minimum_cost_threshold
|
374
389
|
)
|
375
390
|
total_savings += nat_result.business_metrics.total_monthly_savings
|
376
391
|
total_resources += nat_result.resources_analyzed
|
377
392
|
impacted_resources += len(nat_result.resources_impacted)
|
378
|
-
|
393
|
+
|
379
394
|
# Analyze idle EC2 instances
|
380
395
|
if "ec2-instance" in resource_types:
|
381
396
|
print_info("🖥️ Analyzing idle EC2 instances...")
|
382
397
|
ec2_result = await cost_optimizer.optimize_idle_ec2_instances(
|
383
|
-
cpu_threshold=5.0,
|
384
|
-
duration_hours=idle_days_threshold * 24,
|
385
|
-
cost_threshold=minimum_cost_threshold
|
398
|
+
cpu_threshold=5.0, duration_hours=idle_days_threshold * 24, cost_threshold=minimum_cost_threshold
|
386
399
|
)
|
387
400
|
total_savings += ec2_result.business_metrics.total_monthly_savings
|
388
401
|
total_resources += ec2_result.resources_analyzed
|
389
402
|
impacted_resources += len(ec2_result.resources_impacted)
|
390
|
-
|
403
|
+
|
391
404
|
return total_savings, total_resources, impacted_resources
|
392
|
-
|
405
|
+
|
393
406
|
total_savings, total_resources, impacted_resources = _run_async_operation(
|
394
|
-
analyze_unused_resources(),
|
395
|
-
"Unused Resource Analysis"
|
407
|
+
analyze_unused_resources(), "Unused Resource Analysis"
|
396
408
|
)
|
397
|
-
|
409
|
+
|
398
410
|
execution_time = time.time() - start_time
|
399
|
-
|
411
|
+
|
400
412
|
business_summary = BusinessResultSummary(
|
401
413
|
scenario_name="Unused Resource Optimization",
|
402
414
|
success=True,
|
@@ -406,9 +418,9 @@ def optimize_unused_resources(
|
|
406
418
|
resources_analyzed=total_resources,
|
407
419
|
resources_impacted=impacted_resources,
|
408
420
|
roi_percentage="Immediate",
|
409
|
-
risk_level="low"
|
421
|
+
risk_level="low",
|
410
422
|
)
|
411
|
-
|
423
|
+
|
412
424
|
# Display optimization results
|
413
425
|
optimization_panel = create_panel(
|
414
426
|
f"""🔍 Resource Optimization Complete
|
@@ -421,12 +433,12 @@ Annual Impact: {format_cost(total_savings * 12)}
|
|
421
433
|
|
422
434
|
💡 Optimization Focus: Low-risk unused resources""",
|
423
435
|
title="Resource Optimization Results",
|
424
|
-
border_style="green"
|
436
|
+
border_style="green",
|
425
437
|
)
|
426
438
|
console.print(optimization_panel)
|
427
|
-
|
439
|
+
|
428
440
|
return business_summary
|
429
|
-
|
441
|
+
|
430
442
|
except Exception as e:
|
431
443
|
print_error(f"Resource optimization analysis failed: {str(e)}")
|
432
444
|
return BusinessResultSummary(
|
@@ -437,9 +449,10 @@ Annual Impact: {format_cost(total_savings * 12)}
|
|
437
449
|
annual_impact=0.0,
|
438
450
|
resources_analyzed=0,
|
439
451
|
resources_impacted=0,
|
440
|
-
risk_level="unknown"
|
452
|
+
risk_level="unknown",
|
441
453
|
)
|
442
454
|
|
455
|
+
|
443
456
|
def governance_campaign(
|
444
457
|
management_profile: str = "default",
|
445
458
|
billing_profile: Optional[str] = None,
|
@@ -447,15 +460,15 @@ def governance_campaign(
|
|
447
460
|
target_compliance_score: float = 95.0,
|
448
461
|
max_concurrent_accounts: int = 15,
|
449
462
|
governance_frameworks: Optional[List[str]] = None,
|
450
|
-
dry_run: bool = True
|
463
|
+
dry_run: bool = True,
|
451
464
|
) -> BusinessResultSummary:
|
452
465
|
"""
|
453
466
|
Execute organization-wide governance campaign across multiple AWS accounts.
|
454
|
-
|
467
|
+
|
455
468
|
Business Scenario:
|
456
469
|
Enforce governance policies across AWS Organizations for compliance,
|
457
470
|
cost optimization, and operational efficiency improvements.
|
458
|
-
|
471
|
+
|
459
472
|
Args:
|
460
473
|
management_profile: AWS Organizations management account profile
|
461
474
|
billing_profile: Cost analysis profile (defaults to management_profile)
|
@@ -464,39 +477,33 @@ def governance_campaign(
|
|
464
477
|
max_concurrent_accounts: Maximum accounts to process simultaneously
|
465
478
|
governance_frameworks: Compliance frameworks to validate
|
466
479
|
dry_run: Safe analysis mode
|
467
|
-
|
480
|
+
|
468
481
|
Returns:
|
469
482
|
BusinessResultSummary with governance campaign results
|
470
483
|
"""
|
471
484
|
print_header("Multi-Account Governance Campaign - Executive Analysis")
|
472
|
-
|
485
|
+
|
473
486
|
if billing_profile is None:
|
474
487
|
billing_profile = management_profile
|
475
|
-
|
488
|
+
|
476
489
|
if governance_frameworks is None:
|
477
490
|
governance_frameworks = ["AWS-Well-Architected", "SOC2", "PCI-DSS"]
|
478
|
-
|
491
|
+
|
479
492
|
_validate_business_parameters(profile=management_profile)
|
480
|
-
|
493
|
+
|
481
494
|
print_info(f"🏛️ Governance scope: {scope.title()}")
|
482
495
|
print_info(f"📊 Target compliance: {target_compliance_score}%")
|
483
496
|
print_info(f"⚡ Max concurrent accounts: {max_concurrent_accounts}")
|
484
497
|
print_info(f"📋 Frameworks: {', '.join(governance_frameworks)}")
|
485
|
-
|
498
|
+
|
486
499
|
start_time = time.time()
|
487
|
-
|
500
|
+
|
488
501
|
try:
|
489
502
|
# Initialize governance components
|
490
|
-
lifecycle_manager = ResourceLifecycleManager(
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
security_enforcer = SecurityEnforcer(
|
496
|
-
profile=management_profile,
|
497
|
-
dry_run=dry_run
|
498
|
-
)
|
499
|
-
|
503
|
+
lifecycle_manager = ResourceLifecycleManager(profile=management_profile, dry_run=dry_run)
|
504
|
+
|
505
|
+
security_enforcer = SecurityEnforcer(profile=management_profile, dry_run=dry_run)
|
506
|
+
|
500
507
|
async def run_governance_campaign():
|
501
508
|
# Simulate governance campaign execution
|
502
509
|
# In production, this would integrate with:
|
@@ -504,68 +511,67 @@ def governance_campaign(
|
|
504
511
|
# - Tagging governance
|
505
512
|
# - Security policy enforcement
|
506
513
|
# - Cost governance
|
507
|
-
|
514
|
+
|
508
515
|
print_info("🔍 Discovering organization structure...")
|
509
516
|
await asyncio.sleep(1) # Simulate discovery
|
510
|
-
|
517
|
+
|
511
518
|
print_info("🏷️ Enforcing tagging governance...")
|
512
519
|
await asyncio.sleep(2) # Simulate tagging
|
513
|
-
|
520
|
+
|
514
521
|
print_info("🔒 Enforcing security policies...")
|
515
522
|
security_result = await security_enforcer.enforce_s3_encryption()
|
516
|
-
|
523
|
+
|
517
524
|
print_info("💰 Analyzing cost governance...")
|
518
525
|
await asyncio.sleep(1) # Simulate cost analysis
|
519
|
-
|
526
|
+
|
520
527
|
# Aggregate results
|
521
528
|
return {
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
529
|
+
"accounts_processed": min(max_concurrent_accounts, 10),
|
530
|
+
"compliance_improvement": 15.0,
|
531
|
+
"security_violations_fixed": security_result.violations_fixed
|
532
|
+
if hasattr(security_result, "violations_fixed")
|
533
|
+
else 50,
|
534
|
+
"cost_governance_savings": 18750.0, # Estimated
|
535
|
+
"resources_analyzed": 2500,
|
527
536
|
}
|
528
|
-
|
529
|
-
campaign_results = _run_async_operation(
|
530
|
-
|
531
|
-
"Multi-Account Governance Campaign"
|
532
|
-
)
|
533
|
-
|
537
|
+
|
538
|
+
campaign_results = _run_async_operation(run_governance_campaign(), "Multi-Account Governance Campaign")
|
539
|
+
|
534
540
|
execution_time = time.time() - start_time
|
535
|
-
monthly_savings = campaign_results[
|
536
|
-
|
541
|
+
monthly_savings = campaign_results["cost_governance_savings"]
|
542
|
+
|
537
543
|
business_summary = BusinessResultSummary(
|
538
544
|
scenario_name="Multi-Account Governance Campaign",
|
539
545
|
success=True,
|
540
546
|
execution_time_seconds=execution_time,
|
541
547
|
monthly_savings=monthly_savings,
|
542
548
|
annual_impact=monthly_savings * 12,
|
543
|
-
resources_analyzed=campaign_results[
|
544
|
-
resources_impacted=campaign_results[
|
549
|
+
resources_analyzed=campaign_results["resources_analyzed"],
|
550
|
+
resources_impacted=campaign_results["security_violations_fixed"],
|
545
551
|
compliance_score=target_compliance_score - 5.0, # Current vs target gap
|
546
|
-
security_improvement=campaign_results[
|
552
|
+
security_improvement=campaign_results["compliance_improvement"],
|
547
553
|
roi_percentage="Immediate",
|
548
|
-
risk_level="medium"
|
554
|
+
risk_level="medium",
|
549
555
|
)
|
550
|
-
|
556
|
+
|
551
557
|
# Display governance results
|
552
558
|
governance_panel = create_panel(
|
553
559
|
f"""🏛️ Governance Campaign Complete
|
554
560
|
|
555
|
-
Accounts Processed: {campaign_results[
|
556
|
-
Resources Analyzed: {campaign_results[
|
557
|
-
Security Improvement: +{campaign_results[
|
561
|
+
Accounts Processed: {campaign_results["accounts_processed"]}
|
562
|
+
Resources Analyzed: {campaign_results["resources_analyzed"]:,}
|
563
|
+
Security Improvement: +{campaign_results["compliance_improvement"]:.1f}%
|
558
564
|
Monthly Cost Savings: {format_cost(monthly_savings)}
|
559
|
-
Violations Remediated: {campaign_results[
|
565
|
+
Violations Remediated: {campaign_results["security_violations_fixed"]}
|
560
566
|
|
561
567
|
✅ Organization-wide governance enhanced""",
|
562
|
-
title="Governance Campaign Results",
|
563
|
-
border_style="green"
|
568
|
+
title="Governance Campaign Results",
|
569
|
+
border_style="green",
|
564
570
|
)
|
565
571
|
console.print(governance_panel)
|
566
|
-
|
572
|
+
|
567
573
|
return business_summary
|
568
|
-
|
574
|
+
|
569
575
|
except Exception as e:
|
570
576
|
print_error(f"Governance campaign encountered an issue: {str(e)}")
|
571
577
|
return BusinessResultSummary(
|
@@ -578,23 +584,24 @@ Violations Remediated: {campaign_results['security_violations_fixed']}
|
|
578
584
|
resources_impacted=200,
|
579
585
|
compliance_score=85.0,
|
580
586
|
security_improvement=10.0,
|
581
|
-
risk_level="medium"
|
587
|
+
risk_level="medium",
|
582
588
|
)
|
583
589
|
|
590
|
+
|
584
591
|
def security_incident_response(
|
585
592
|
profile: str = "default",
|
586
593
|
incident_type: str = "security_violation",
|
587
594
|
compliance_frameworks: Optional[List[str]] = None,
|
588
595
|
auto_remediate: bool = False,
|
589
|
-
notification_emails: Optional[List[str]] = None
|
596
|
+
notification_emails: Optional[List[str]] = None,
|
590
597
|
) -> BusinessResultSummary:
|
591
598
|
"""
|
592
599
|
Respond to security incidents with automated analysis and remediation.
|
593
|
-
|
600
|
+
|
594
601
|
Business Scenario:
|
595
602
|
Rapid security incident response with compliance validation and
|
596
603
|
automated remediation for common security violations.
|
597
|
-
|
604
|
+
|
598
605
|
Args:
|
599
606
|
profile: AWS profile for security operations
|
600
607
|
incident_type: Type of security incident to address
|
@@ -603,22 +610,19 @@ def security_incident_response(
|
|
603
610
|
notification_emails: Stakeholder emails for incident notifications
|
604
611
|
"""
|
605
612
|
print_header("Security Incident Response - Business Analysis")
|
606
|
-
|
613
|
+
|
607
614
|
if compliance_frameworks is None:
|
608
615
|
compliance_frameworks = ["SOC2", "PCI-DSS", "HIPAA"]
|
609
|
-
|
616
|
+
|
610
617
|
print_info(f"🚨 Incident type: {incident_type.replace('_', ' ').title()}")
|
611
618
|
print_info(f"📋 Compliance frameworks: {', '.join(compliance_frameworks)}")
|
612
619
|
print_info(f"🔧 Auto-remediation: {'Enabled' if auto_remediate else 'Disabled'}")
|
613
|
-
|
620
|
+
|
614
621
|
start_time = time.time()
|
615
|
-
|
622
|
+
|
616
623
|
try:
|
617
|
-
security_enforcer = SecurityEnforcer(
|
618
|
-
|
619
|
-
dry_run=not auto_remediate
|
620
|
-
)
|
621
|
-
|
624
|
+
security_enforcer = SecurityEnforcer(profile=profile, dry_run=not auto_remediate)
|
625
|
+
|
622
626
|
async def run_incident_response():
|
623
627
|
if incident_type == "s3_encryption":
|
624
628
|
return await security_enforcer.enforce_s3_encryption()
|
@@ -632,24 +636,21 @@ def security_incident_response(
|
|
632
636
|
print_info("🔍 Running comprehensive security assessment...")
|
633
637
|
await asyncio.sleep(3)
|
634
638
|
return None
|
635
|
-
|
636
|
-
security_result = _run_async_operation(
|
637
|
-
|
638
|
-
"Security Incident Response"
|
639
|
-
)
|
640
|
-
|
639
|
+
|
640
|
+
security_result = _run_async_operation(run_incident_response(), "Security Incident Response")
|
641
|
+
|
641
642
|
execution_time = time.time() - start_time
|
642
|
-
|
643
|
+
|
643
644
|
# Extract results or use defaults
|
644
645
|
if security_result:
|
645
|
-
violations_found = getattr(security_result,
|
646
|
-
violations_fixed = getattr(security_result,
|
646
|
+
violations_found = getattr(security_result, "violations_found", 25)
|
647
|
+
violations_fixed = getattr(security_result, "violations_fixed", 20)
|
647
648
|
security_improvement = 15.0
|
648
649
|
else:
|
649
650
|
violations_found = 25
|
650
651
|
violations_fixed = 20
|
651
652
|
security_improvement = 15.0
|
652
|
-
|
653
|
+
|
653
654
|
business_summary = BusinessResultSummary(
|
654
655
|
scenario_name="Security Incident Response",
|
655
656
|
success=True,
|
@@ -659,27 +660,27 @@ def security_incident_response(
|
|
659
660
|
resources_analyzed=violations_found + 50, # Total resources scanned
|
660
661
|
resources_impacted=violations_fixed,
|
661
662
|
security_improvement=security_improvement,
|
662
|
-
risk_level="high" # Security incidents are high priority
|
663
|
+
risk_level="high", # Security incidents are high priority
|
663
664
|
)
|
664
|
-
|
665
|
+
|
665
666
|
# Display security response results
|
666
667
|
security_panel = create_panel(
|
667
668
|
f"""🚨 Security Response Complete
|
668
669
|
|
669
|
-
Incident Type: {incident_type.replace(
|
670
|
+
Incident Type: {incident_type.replace("_", " ").title()}
|
670
671
|
Security Violations Found: {violations_found}
|
671
672
|
Violations Remediated: {violations_fixed}
|
672
673
|
Security Improvement: +{security_improvement:.1f}%
|
673
|
-
Auto-remediation: {
|
674
|
+
Auto-remediation: {"Enabled" if auto_remediate else "Analysis Only"}
|
674
675
|
|
675
676
|
🛡️ Security posture enhanced""",
|
676
677
|
title="Security Incident Response Results",
|
677
|
-
border_style="red" if violations_found > violations_fixed else "green"
|
678
|
+
border_style="red" if violations_found > violations_fixed else "green",
|
678
679
|
)
|
679
680
|
console.print(security_panel)
|
680
|
-
|
681
|
+
|
681
682
|
return business_summary
|
682
|
-
|
683
|
+
|
683
684
|
except Exception as e:
|
684
685
|
print_error(f"Security incident response failed: {str(e)}")
|
685
686
|
return BusinessResultSummary(
|
@@ -690,23 +691,24 @@ Auto-remediation: {'Enabled' if auto_remediate else 'Analysis Only'}
|
|
690
691
|
annual_impact=0.0,
|
691
692
|
resources_analyzed=0,
|
692
693
|
resources_impacted=0,
|
693
|
-
risk_level="critical"
|
694
|
+
risk_level="critical",
|
694
695
|
)
|
695
696
|
|
697
|
+
|
696
698
|
def optimize_infrastructure(
|
697
699
|
profile: str = "default",
|
698
700
|
optimization_targets: Optional[List[str]] = None,
|
699
701
|
performance_requirements: Optional[Dict[str, float]] = None,
|
700
702
|
cost_reduction_target: float = 25.0,
|
701
|
-
dry_run: bool = True
|
703
|
+
dry_run: bool = True,
|
702
704
|
) -> BusinessResultSummary:
|
703
705
|
"""
|
704
706
|
Optimize infrastructure for cost, performance, and operational efficiency.
|
705
|
-
|
707
|
+
|
706
708
|
Business Scenario:
|
707
709
|
Comprehensive infrastructure optimization covering rightsizing,
|
708
710
|
reserved instances, storage optimization, and performance tuning.
|
709
|
-
|
711
|
+
|
710
712
|
Args:
|
711
713
|
profile: AWS profile for infrastructure operations
|
712
714
|
optimization_targets: Specific areas to optimize (compute, storage, network)
|
@@ -715,63 +717,59 @@ def optimize_infrastructure(
|
|
715
717
|
dry_run: Safe analysis mode
|
716
718
|
"""
|
717
719
|
print_header("Infrastructure Optimization - Business Analysis")
|
718
|
-
|
720
|
+
|
719
721
|
if optimization_targets is None:
|
720
722
|
optimization_targets = ["compute", "storage", "network"]
|
721
|
-
|
723
|
+
|
722
724
|
if performance_requirements is None:
|
723
725
|
performance_requirements = {
|
724
726
|
"cpu_utilization_min": 20.0,
|
725
727
|
"memory_utilization_min": 30.0,
|
726
|
-
"network_utilization_min": 10.0
|
728
|
+
"network_utilization_min": 10.0,
|
727
729
|
}
|
728
|
-
|
730
|
+
|
729
731
|
print_info(f"🔧 Optimization targets: {', '.join(optimization_targets)}")
|
730
732
|
print_info(f"🎯 Cost reduction target: {cost_reduction_target}%")
|
731
733
|
print_info(f"⚡ Performance constraints maintained")
|
732
|
-
|
734
|
+
|
733
735
|
start_time = time.time()
|
734
|
-
|
736
|
+
|
735
737
|
try:
|
736
|
-
infra_optimizer = InfrastructureOptimizer(
|
737
|
-
|
738
|
-
dry_run=dry_run
|
739
|
-
)
|
740
|
-
|
738
|
+
infra_optimizer = InfrastructureOptimizer(profile=profile, dry_run=dry_run)
|
739
|
+
|
741
740
|
async def run_infrastructure_optimization():
|
742
741
|
print_info("🔍 Analyzing infrastructure utilization...")
|
743
742
|
await asyncio.sleep(2)
|
744
|
-
|
743
|
+
|
745
744
|
print_info("💻 Optimizing compute resources...")
|
746
745
|
await asyncio.sleep(2)
|
747
|
-
|
746
|
+
|
748
747
|
print_info("💾 Optimizing storage resources...")
|
749
748
|
await asyncio.sleep(1)
|
750
|
-
|
749
|
+
|
751
750
|
print_info("🌐 Optimizing network resources...")
|
752
751
|
await asyncio.sleep(1)
|
753
|
-
|
752
|
+
|
754
753
|
# Simulate optimization results
|
755
754
|
return {
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
755
|
+
"compute_savings": 8500.0,
|
756
|
+
"storage_savings": 3200.0,
|
757
|
+
"network_savings": 1800.0,
|
758
|
+
"resources_optimized": 85,
|
759
|
+
"performance_maintained": True,
|
761
760
|
}
|
762
|
-
|
763
|
-
optimization_results = _run_async_operation(
|
764
|
-
|
765
|
-
"Infrastructure Optimization"
|
766
|
-
)
|
767
|
-
|
761
|
+
|
762
|
+
optimization_results = _run_async_operation(run_infrastructure_optimization(), "Infrastructure Optimization")
|
763
|
+
|
768
764
|
execution_time = time.time() - start_time
|
769
|
-
total_savings = sum(
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
765
|
+
total_savings = sum(
|
766
|
+
[
|
767
|
+
optimization_results["compute_savings"],
|
768
|
+
optimization_results["storage_savings"],
|
769
|
+
optimization_results["network_savings"],
|
770
|
+
]
|
771
|
+
)
|
772
|
+
|
775
773
|
business_summary = BusinessResultSummary(
|
776
774
|
scenario_name="Infrastructure Optimization",
|
777
775
|
success=True,
|
@@ -779,31 +777,31 @@ def optimize_infrastructure(
|
|
779
777
|
monthly_savings=total_savings,
|
780
778
|
annual_impact=total_savings * 12,
|
781
779
|
resources_analyzed=200, # Estimated
|
782
|
-
resources_impacted=optimization_results[
|
780
|
+
resources_impacted=optimization_results["resources_optimized"],
|
783
781
|
roi_percentage="3-6 months",
|
784
|
-
risk_level="low"
|
782
|
+
risk_level="low",
|
785
783
|
)
|
786
|
-
|
784
|
+
|
787
785
|
# Display optimization results
|
788
786
|
optimization_panel = create_panel(
|
789
787
|
f"""🔧 Infrastructure Optimization Complete
|
790
788
|
|
791
|
-
Compute Savings: {format_cost(optimization_results[
|
792
|
-
Storage Savings: {format_cost(optimization_results[
|
793
|
-
Network Savings: {format_cost(optimization_results[
|
789
|
+
Compute Savings: {format_cost(optimization_results["compute_savings"])}/month
|
790
|
+
Storage Savings: {format_cost(optimization_results["storage_savings"])}/month
|
791
|
+
Network Savings: {format_cost(optimization_results["network_savings"])}/month
|
794
792
|
|
795
793
|
Total Monthly Savings: {format_cost(total_savings)}
|
796
|
-
Resources Optimized: {optimization_results[
|
797
|
-
Performance Impact: {
|
794
|
+
Resources Optimized: {optimization_results["resources_optimized"]}
|
795
|
+
Performance Impact: {"✅ Maintained" if optimization_results["performance_maintained"] else "⚠️ Review Required"}
|
798
796
|
|
799
797
|
💡 Optimization maintains all performance requirements""",
|
800
798
|
title="Infrastructure Optimization Results",
|
801
|
-
border_style="green"
|
799
|
+
border_style="green",
|
802
800
|
)
|
803
801
|
console.print(optimization_panel)
|
804
|
-
|
802
|
+
|
805
803
|
return business_summary
|
806
|
-
|
804
|
+
|
807
805
|
except Exception as e:
|
808
806
|
print_error(f"Infrastructure optimization failed: {str(e)}")
|
809
807
|
return BusinessResultSummary(
|
@@ -814,15 +812,16 @@ Performance Impact: {'✅ Maintained' if optimization_results['performance_maint
|
|
814
812
|
annual_impact=0.0,
|
815
813
|
resources_analyzed=0,
|
816
814
|
resources_impacted=0,
|
817
|
-
risk_level="medium"
|
815
|
+
risk_level="medium",
|
818
816
|
)
|
819
817
|
|
818
|
+
|
820
819
|
# Export all interface functions
|
821
820
|
__all__ = [
|
822
821
|
"BusinessResultSummary",
|
823
822
|
"emergency_cost_response",
|
824
|
-
"optimize_unused_resources",
|
823
|
+
"optimize_unused_resources",
|
825
824
|
"governance_campaign",
|
826
825
|
"security_incident_response",
|
827
|
-
"optimize_infrastructure"
|
828
|
-
]
|
826
|
+
"optimize_infrastructure",
|
827
|
+
]
|