A suite of tools to optimize and manage your OpenStack resources, with multilingual support (FR/EN).
Version 1.6.1 - Code quality improvements, security enhancements, and better reliability!
- π HTTP timeout protection - All HTTP requests now have 30s timeout to prevent indefinite hangs
- π§Ή Code quality - Formatted with Black and isort, cleaned unused imports
- π§ Bug fixes - Fixed relative imports and credential loading issues
- β Security audit - Passed Bandit security scan with 0 critical issues
- π Type safety - Corrected type hints for better IDE support
- π Encrypted SMTP passwords - Passwords are now encrypted using Fernet (AES-128)
- π Professional logging - Colored console output, automatic rotation, JSON support
- π Complete type hints - Better IDE support and code quality
- π§ Specific exceptions - 12 custom exceptions for better error handling
- π Organized structure - Clean separation of code and documentation
- π Metrics Collector - Real-time Gnocchi metrics with Prometheus export
- π Resource Summary - Complete overview of instances, volumes, snapshots, and costs
- π¨βπΌ Administration - Multi-project management and resource overview
- π§ Weekly Notifications - Automated email reports with secure SMTP
- π Optimization - Identify underutilized resources
- π Security Module (
src/security.py) - Encryption/decryption for sensitive data - π Logger Module (
src/logger.py) - Professional logging with rotation and colors - π§ Exceptions Module (
src/exceptions.py) - 12 specific exceptions for better error handling - π Type Hints - Complete type annotations for better IDE support
Docker deployment includes all features: Prometheus metrics collector + automated cron tasks (weekly reports, daily summaries, optimization).
# Clone the repository
git clone https://github.com/your-username/openstack-toolbox.git
cd openstack-toolbox
# Configure credentials
cp .env.example .env
nano .env
# Start the complete suite
docker-compose up -d- β Prometheus metrics on port 8000 (real-time)
- β
Automated cron tasks:
- Weekly report (Monday 8:00 AM)
- Daily summary (9:00 AM)
- Optimization analysis (10:00 AM)
- β Email notifications (if SMTP configured)
- β
Centralized logs in
./logs/ - β Auto-restart on failure
Edit .env file with your credentials:
# OpenStack (required)
OS_AUTH_URL=https://api.pub1.infomaniak.cloud:5000/v3
OS_PROJECT_NAME=your-project
OS_USERNAME=your-username
OS_PASSWORD=your-password
OS_USER_DOMAIN_NAME=default
OS_PROJECT_DOMAIN_NAME=default
OS_REGION_NAME=RegionOne
# SMTP (optional, for email notifications)
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_FROM_EMAIL=your-email@gmail.com
SMTP_TO_EMAIL=recipient@example.com
# Timezone
TZ=Europe/ParisNote for Gmail: Use an app password, not your regular password.
# View logs
docker-compose logs -f
# Check status
docker-compose ps
# Restart
docker-compose restart
# Stop
docker-compose down
# Rebuild after code changes
docker-compose up -d --build
# Execute commands manually
docker exec openstack-toolbox python -m src.openstack_summary
docker exec openstack-toolbox python -m src.openstack_optimization
# View cron jobs
docker exec openstack-toolbox crontab -l
# View specific logs
docker exec openstack-toolbox tail -f /var/log/openstack-toolbox/weekly-notification.logYou can easily customize when tasks run by setting environment variables in your .env file:
# Cron format: minute hour day month weekday
CRON_WEEKLY_REPORT=0 8 * * 1 # Monday at 8:00 AM (default)
CRON_DAILY_SUMMARY=0 9 * * * # Every day at 9:00 AM (default)
CRON_OPTIMIZATION=0 10 * * * # Every day at 10:00 AM (default)Common examples:
# Weekly report on Friday at 5:00 PM
CRON_WEEKLY_REPORT=0 17 * * 5
# Daily summary at 6:00 AM
CRON_DAILY_SUMMARY=0 6 * * *
# Optimization every 6 hours
CRON_OPTIMIZATION=0 */6 * * *
# Run every 30 minutes
CRON_OPTIMIZATION=*/30 * * * *
# Multiple times per day (8 AM and 8 PM)
CRON_DAILY_SUMMARY=0 8,20 * * *Cron format reference:
*= every*/N= every N unitsN,M= at N and MN-M= from N to M
| Field | Values | Examples |
|---|---|---|
| Minute | 0-59 | 0, */15, 30 |
| Hour | 0-23 | 8, */6, 9,17 |
| Day | 1-31 | 1, 15, */2 |
| Month | 1-12 | *, 1,6,12 |
| Weekday | 0-7 (0=Sunday) | 1 (Monday), 1-5 (weekdays) |
After changing schedules, restart the container:
docker-compose restartAdd to your prometheus.yml:
scrape_configs:
- job_name: 'openstack-toolbox'
static_configs:
- targets: ['openstack-toolbox:8000']
scrape_interval: 60s
scrape_timeout: 30sCreate docker-compose.override.yml:
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./docker/prometheus.yml.example:/etc/prometheus/prometheus.yml:ro
- prometheus-data:/prometheus
networks:
- monitoring
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana-data:/var/lib/grafana
networks:
- monitoring
volumes:
prometheus-data:
grafana-data:Start everything: docker-compose up -d
Container won't start:
docker-compose logs
docker-compose down -v
docker-compose build --no-cache
docker-compose up -dMetrics not available:
curl http://localhost:8000/metrics
docker-compose logs | grep -i errorCron tasks not running:
docker exec openstack-toolbox ps aux | grep cron
docker exec openstack-toolbox crontab -l
docker exec openstack-toolbox service cron statusEmail not sent:
docker exec openstack-toolbox env | grep SMTP
docker exec openstack-toolbox tail -f /var/log/openstack-toolbox/weekly-notification.loggit clone https://github.com/your-username/openstack-toolbox.git
cd openstack-toolbox
# Install in development mode
pip install -e .
# Or use directly with Docker
docker-compose up -dThe toolbox supports two methods for configuring OpenStack credentials:
- Using environment variables directly:
export OS_AUTH_URL=https://your-auth-url
export OS_PROJECT_NAME=your-project
export OS_USERNAME=your-username
export OS_PASSWORD=your-password
export OS_USER_DOMAIN_NAME=your-domain
export OS_PROJECT_DOMAIN_NAME=your-project-domain
export OS_REGION_NAME=your-region- Using a
.envfile at the project root:
OS_AUTH_URL=https://your-auth-url
OS_PROJECT_NAME=your-project
OS_USERNAME=your-username
OS_PASSWORD=your-password
OS_USER_DOMAIN_NAME=your-domain
OS_PROJECT_DOMAIN_NAME=your-project-domain
OS_REGION_NAME=your-regionChoose the method that best suits your workflow. The toolbox will automatically detect and use the credentials from either source.
SMTP configuration is interactive. Run:
weekly-notificationThe script will guide you to configure:
- SMTP Server
- Port
- Credentials
- Email addresses
Once the container is running with docker-compose up -d, everything runs automatically:
- Metrics Collector runs continuously on port 8000
- Cron tasks execute automatically:
- Weekly report: Monday 8:00 AM
- Daily summary: Every day 9:00 AM
- Optimization: Every day 10:00 AM
# Resource summary
docker exec openstack-toolbox python -m src.openstack_summary
# Optimization analysis
docker exec openstack-toolbox python -m src.openstack_optimization
# Send weekly notification
docker exec openstack-toolbox python -m src.weekly_notification_optimization
# View metrics
curl http://localhost:8000/metricsIf you installed from source:
# Metrics collector
openstack-metrics-collector
# Resource summary
openstack-summary
# Administration
openstack-admin
# Weekly notifications
weekly-notificationThe collector exposes these metrics on port 8000:
openstack_identity_metrics- Identity service metricsopenstack_compute_metrics- Compute (instances) metricsopenstack_block_storage_metrics- Block storage (volumes) metricsopenstack_network_metrics- Network metricsopenstack_gnocchi_metric- Gnocchi telemetry metrics
Create an alert.yml file with these example rules:
groups:
- name: openstack_alerts
rules:
- alert: OpenStackInstanceDown
expr: openstack_instance_status == 0
for: 5m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance_name }} is down"
description: "Instance {{ $labels.instance_name }} in project {{ $labels.project_name }} has been down for more than 5 minutes"
- alert: OpenStackHighCPUUsage
expr: openstack_instance_cpu_usage > 90
for: 15m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance_name }}"
description: "Instance {{ $labels.instance_name }} has had CPU usage above 90% for 15 minutes"
- alert: OpenStackLowDiskSpace
expr: openstack_volume_free_space / openstack_volume_total_space * 100 < 10
for: 10m
labels:
severity: warning
annotations:
summary: "Low disk space on volume {{ $labels.volume_name }}"
description: "Volume {{ $labels.volume_name }} has less than 10% free space"Add this file to your Prometheus configuration to enable alerting on common OpenStack issues.
The project supports French (default) and English. To change the language, use:
openstack-toolbox --configThis will display an interactive menu to select your preferred language. The choice will be saved and used across all tools in the suite.
You can also view all available commands in your preferred language with:
openstack-toolboxformat_size(size_bytes): Formats a size in bytesparse_flavor_name(name): Parses an OpenStack flavor nameisoformat(dt): Converts a date to ISO 8601print_header(header): Displays a formatted header
get_language_preference(): Gets the configured languageset_language_preference(lang): Sets the languagecreate_smtp_config_interactive(): Configures SMTPload_smtp_config(): Loads SMTP configload_openstack_credentials(): Loads OpenStack credentials
- Class
GnocchiAPI: Client for Gnocchi APIget_resources()get_metrics_for_resource()get_measures()
collect_resource_metrics(): Per-resource collectioncollect_gnocchi_metrics_parallel(): Parallel collection
process_resource_parallel(): Parallel processinglist_all_resources(): Lists all resources- Specialized listing functions for each type
generate_report(): Generates the reportsend_email(): Sends via SMTPsetup_cron(): Configures cron task
openstack-toolbox/
βββ src/ # Python source code (12 modules)
βββ .github/ # GitHub Actions CI/CD
Core Modules:
openstack_toolbox.py- Main CLIopenstack_summary.py- Resource summaryopenstack_admin.py- Administration toolsopenstack_metrics_collector.py- Prometheus exporteropenstack_optimization.py- Resource optimizationweekly_notification_optimization.py- Email notifications
Utility Modules (v1.6.0):
config.py- Configuration managementsecurity.py- Encryption/decryption β¨ NEWlogger.py- Logging system β¨ NEWexceptions.py- Custom exceptions β¨ NEWutils.py- Helper functions
- β 100% backward compatible - No action required
- β Existing SMTP configurations continue to work
- β System will prompt to re-encrypt passwords on next use
# Reconfigure SMTP to enable encryption
weekly-notification# Install the new security dependency
pip install cryptography>=41.0.0Configuration files now have restricted permissions:
~/.config/openstack-toolbox/smtp_config.ini: 600 (rw-------)~/.config/openstack-toolbox/.encryption_key: 600 (rw-------)
If you encounter decryption errors:
# Remove old configuration
rm ~/.config/openstack-toolbox/smtp_config.ini
rm ~/.config/openstack-toolbox/.encryption_key
# Reconfigure
weekly-notificationFixed:
- π§ Fixed relative imports in all modules (from
src.to.) - π§ Fixed credential loading to properly handle tuple return values
- π§ Corrected type hint
anytoAnyin config.py
Improved:
- π Added 30-second timeout to all HTTP requests (prevents hanging)
- π§Ή Removed unused imports and variables
- π§Ή Cleaned whitespace in blank lines
- β¨ Code formatted with Black (line-length=120)
- β¨ Imports sorted with isort (profile=black)
Security:
- β Passed Bandit security audit with 0 medium/high severity issues
- π All HTTP requests now protected against indefinite hangs
No breaking changes - Full backward compatibility maintained
Added:
- π Encrypted SMTP passwords using Fernet (AES-128)
- π Professional logging with rotation and colors
- π§ 12 custom exceptions for better error handling
- π Complete type hints on all core modules
- π Organized project structure
Security:
- Encrypted password storage
- Restricted file permissions (600)
- Unique encryption key per installation
No breaking changes - Full backward compatibility maintained
Contributions are welcome! Feel free to:
- Fork the project
- Create a branch (
git checkout -b feature/improvement) - Commit (
git commit -am 'Add feature') - Push (
git push origin feature/improvement) - Open a Pull Request
See docs/IMPROVEMENTS.md for technical details.
Special thanks to Kevin Allioli, Cloud Architect & SysAdmin, for his valuable contributions and expertise in OpenStack development.
This project is under Apache License 2.0. See LICENSE.TXT file for more details.
Developed by Loutre