Skip to main content

A toolbox for OpenStack (Infomaniak hosting)

Project description

OpenStack Toolbox ๐Ÿงฐ

Build Python PyPi Infomaniak OpenStack Prometheus Docker

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:

  1. 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
  1. Using a .env file 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_metrics
  • openstack_compute_metrics
  • openstack_block_storage_metrics
  • openstack_network_metrics
  • openstack_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 bytes
  • parse_flavor_name(name): Parses an OpenStack flavor name
  • isoformat(dt): Converts a date to ISO 8601
  • print_header(header): Displays a formatted header

Config (config.py)

  • get_language_preference(): Gets the configured language
  • set_language_preference(lang): Sets the language
  • create_smtp_config_interactive(): Configures SMTP
  • load_smtp_config(): Loads SMTP config
  • load_openstack_credentials(): Loads OpenStack credentials

Metrics (openstack_metrics_collector.py)

  • Class GnocchiAPI: Client for Gnocchi API
    • get_resources()
    • get_metrics_for_resource()
    • get_measures()
  • collect_resource_metrics(): Per-resource collection
  • collect_gnocchi_metrics_parallel(): Parallel collection

Admin (openstack_admin.py)

  • process_resource_parallel(): Parallel processing
  • list_all_resources(): Lists all resources
  • Specialized listing functions for each type

Notifications (weekly_notification_optimization.py)

  • generate_report(): Generates the report
  • send_email(): Sends via SMTP
  • setup_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 CLI
  • openstack_summary.py - Resource summary
  • openstack_admin.py - Administration tools
  • openstack_metrics_collector.py - Prometheus exporter
  • openstack_optimization.py - Resource optimization
  • weekly_notification_optimization.py - Email notifications

Utility Modules (v1.6.0):

  • config.py - Configuration management
  • security.py - Encryption/decryption โœจ NEW
  • logger.py - Logging system โœจ NEW
  • exceptions.py - Custom exceptions โœจ NEW
  • utils.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:

  1. Fork the project
  2. Create a branch (git checkout -b feature/improvement)
  3. Commit (git commit -am 'Add feature')
  4. Push (git push origin feature/improvement)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openstack_toolbox-1.6.0.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openstack_toolbox-1.6.0-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

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

Hashes for openstack_toolbox-1.6.0.tar.gz
Algorithm Hash digest
SHA256 99c772063e04428093dde5a6f1481c28ca47008d3d69af3290b07d5d57476d5a
MD5 b869859a13ba3ac86f22a4dd54d9e590
BLAKE2b-256 778f598c0ec9d7fc01f400cb1931e4d5df185b2366b52d5473ca02fca5eaaff2

See more details on using hashes here.

File details

Details for the file openstack_toolbox-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openstack_toolbox-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cdbf82ed0476cc52f053e9aae49781eec54b0bffd40dc71c88fdf18b432e14c
MD5 a72addbfee04050dd7e44a645fd35d12
BLAKE2b-256 1ce3754458db63378dd973a2efee1beb720c0d5dcf5027e11ef9a42b267e6ab9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page