A toolbox for OpenStack (Infomaniak hosting)
Project description
OpenStack Toolbox ๐งฐ
A suite of tools to optimize and manage your OpenStack resources, with multilingual support (FR/EN).
Version 1.6.0 - Enhanced security (encrypted SMTP passwords), improved logging with rotation, complete type hints, and better error handling!
โจ What's New in v1.6.0
- ๐ 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
๐ Features
Core Tools
- ๐ 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
New in v1.6.0
- ๐ 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
๐ ๏ธ Installation
๐ฆ PyPI (recommended for CLI tools)
pip install openstack-toolbox
๐ณ Docker (recommended for metrics collector)
For running the Prometheus metrics collector as a service:
# 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 collector
docker-compose up -d
๐ See README-DOCKER.md for complete Docker documentation
๐ป From source
git clone https://github.com/your-username/openstack-toolbox.git
cd openstack-toolbox
pip install .
Dependencies will be automatically managed through pyproject.toml.
โ๏ธ Configuration
OpenStack Environment Variables
The 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-region
Choose the method that best suits your workflow. The toolbox will automatically detect and use the credentials from either source.
SMTP Configuration (for notifications)
SMTP configuration is interactive. Run:
weekly-notification
The script will guide you to configure:
- SMTP Server
- Port
- Credentials
- Email addresses
๐ Usage
Metrics Collector
openstack-metrics-collector
The collector implements a passive Prometheus exporter that starts a server on port 8000. Metrics are stored in a custom directory and served on demand when Prometheus scrapes them.
Available metrics:
openstack_identity_metricsopenstack_compute_metricsopenstack_block_storage_metricsopenstack_network_metricsopenstack_gnocchi_metric
All metrics are stored in /var/lib/openstack-metrics-collector/ by default. You can customize this path in the configuration.
Prometheus Configuration
Add this job to your prometheus.yml:
scrape_configs:
- job_name: 'openstack'
static_configs:
- targets: ['localhost:8000']
metrics_path: /metrics
scrape_interval: 30s
This will collect OpenStack metrics every 30 seconds. Adjust the scrape_interval and targets according to your needs.
Alerting Rules
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.
Resource Summary
openstack-summary
Displays a complete summary of your OpenStack resources:
- Instances (CPU, RAM, disk)
- Volumes and snapshots
- Images and containers
- Estimated costs (specific to Infomaniak hosting provider, in EUR and CHF)
Administration
openstack-admin
Enter the project ID to view:
- Project details
- Resource list
- Usage metrics
Weekly Notifications
weekly-notification
Configures and sends weekly reports via email.
๐ Internationalization
The project supports French (default) and English. To change the language, use:
openstack-toolbox --config
This 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-toolbox
๐ Function Documentation
Utils (utils.py)
format_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
Config (config.py)
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
Metrics (openstack_metrics_collector.py)
- Class
GnocchiAPI: Client for Gnocchi APIget_resources()get_metrics_for_resource()get_measures()
collect_resource_metrics(): Per-resource collectioncollect_gnocchi_metrics_parallel(): Parallel collection
Admin (openstack_admin.py)
process_resource_parallel(): Parallel processinglist_all_resources(): Lists all resources- Specialized listing functions for each type
Notifications (weekly_notification_optimization.py)
generate_report(): Generates the reportsend_email(): Sends via SMTPsetup_cron(): Configures cron task
๐ Project Structure
openstack-toolbox/
โโโ src/ # Python source code (12 modules)
โโโ .github/ # GitHub Actions CI/CD
Source Code (src/)
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
๏ฟฝ Migration from v1.5.0
Automatic Migration
- โ 100% backward compatible - No action required
- โ Existing SMTP configurations continue to work
- โ System will prompt to re-encrypt passwords on next use
Recommended Actions
# Reconfigure SMTP to enable encryption
weekly-notification
New Dependencies
# Install the new security dependency
pip install cryptography>=41.0.0
Security Improvements
Configuration files now have restricted permissions:
~/.config/openstack-toolbox/smtp_config.ini: 600 (rw-------)~/.config/openstack-toolbox/.encryption_key: 600 (rw-------)
Troubleshooting
If you encounter decryption errors:
# Remove old configuration
rm ~/.config/openstack-toolbox/smtp_config.ini
rm ~/.config/openstack-toolbox/.encryption_key
# Reconfigure
weekly-notification
๐ Changelog
[1.6.0] - 2024-11-21
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
๐ค Contributing
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.
โจ Credits
Special thanks to Kevin Allioli, Cloud Architect & SysAdmin, for his valuable contributions and expertise in OpenStack development.
๐ License
This project is under Apache License 2.0. See LICENSE.TXT file for more details.
โจ Author
Developed by Loutre
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openstack_toolbox-1.6.0.tar.gz.
File metadata
- Download URL: openstack_toolbox-1.6.0.tar.gz
- Upload date:
- Size: 42.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99c772063e04428093dde5a6f1481c28ca47008d3d69af3290b07d5d57476d5a
|
|
| MD5 |
b869859a13ba3ac86f22a4dd54d9e590
|
|
| BLAKE2b-256 |
778f598c0ec9d7fc01f400cb1931e4d5df185b2366b52d5473ca02fca5eaaff2
|
File details
Details for the file openstack_toolbox-1.6.0-py3-none-any.whl.
File metadata
- Download URL: openstack_toolbox-1.6.0-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cdbf82ed0476cc52f053e9aae49781eec54b0bffd40dc71c88fdf18b432e14c
|
|
| MD5 |
a72addbfee04050dd7e44a645fd35d12
|
|
| BLAKE2b-256 |
1ce3754458db63378dd973a2efee1beb720c0d5dcf5027e11ef9a42b267e6ab9
|