A CLI tool for managing OpenStack cloud resources with modern Python features
Project description
NNumbers CLI - OpenStack Cloud Management Tool
A command-line interface for managing OpenStack cloud resources built with modern Python features. This tool provides comprehensive instance lifecycle management, network operations, SSH keypair management, and resource monitoring with excellent developer experience and robust error handling.
โจ Features
- ๐ Instance Management: Complete lifecycle management of OpenStack compute instances
- ๐ Network Operations: Manage networks, subnets, and floating IP addresses
- ๐ SSH Keypair Management: Create, import, and manage SSH keypairs
- ๐ Resource Monitoring: View quotas, usage statistics, and resource information
- ๐ก๏ธ Robust Error Handling: Comprehensive error handling with informative messages
- ๐ Comprehensive Logging: Structured logging with different verbosity levels
- ๐ง Modern CLI: Built with cyclopts for excellent user experience and help documentation
- ๐งช Well Tested: Comprehensive test suite with high code coverage
- ๐ Type Safe: Full type annotations using modern Python 3.11+ features
๐ง Prerequisites
- Python 3.11+ (recommended: Python 3.12)
- OpenStack credentials configured via environment variables or clouds.yaml
- Network access to your OpenStack cloud environment
๐ฆ Installation
Using PDM (Recommended)
# Clone the repository
git clone https://github.com/your-org/nnumbers-cli.git
cd nnumbers-cli
# Install with PDM
pdm install
# Activate the virtual environment
eval $(pdm venv activate)
Using pip
# Clone and install
git clone https://github.com/your-org/nnumbers-cli.git
cd nnumbers-cli
pip install -e .
# Or install from PyPI (when published)
pip install nnumbers-cli
Development Installation
# Install with development dependencies
pdm install -G dev
# Install pre-commit hooks
pdm run pre-commit-install
# Run tests to verify installation
pdm run test
โ๏ธ Configuration
Environment Variables
The most common way to configure OpenStack credentials:
# Source your OpenStack credentials file
source atlas-openrc.sh
# Or set environment variables manually
export OS_AUTH_URL=https://your-openstack.com:5000/v3
export OS_PROJECT_ID=your-project-id
export OS_PROJECT_NAME=your-project-name
export OS_USERNAME=your-username
export OS_PASSWORD=your-password
export OS_REGION_NAME=your-region
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
clouds.yaml Configuration
Alternative configuration using clouds.yaml file:
# ~/.config/openstack/clouds.yaml
clouds:
mycloud:
auth:
auth_url: https://your-openstack.com:5000/v3
username: your-username
password: your-password
project_id: your-project-id
project_name: your-project-name
user_domain_name: Default
region_name: your-region
interface: public
Then use: export OS_CLOUD=mycloud
๐ Usage
Basic Commands
# Get help for any command
nnumbers --help
nnumbers instance --help
nnumbers network --help
# Check version
nnumbers --version
Instance Management
# List all instances
nnumbers instance list
# Start an instance
nnumbers instance start web-server
# Stop an instance
nnumbers instance stop web-server
# Reboot an instance
nnumbers instance reboot web-server
# Check instance status
nnumbers instance status web-server
# Manage instance with single command
nnumbers instance manage web-server start
Network Operations
# List all networks
nnumbers network list-networks
# List floating IPs
nnumbers network list-floating-ips
# Create a floating IP
nnumbers network create-floating-ip --network public --description "Web server IP"
SSH Keypair Management
# List SSH keypairs
nnumbers ssh-keypair ssh-keypair-list
# Create new keypair (generates new key)
nnumbers ssh-keypair ssh-keypair-create my-key
# Import existing public key
nnumbers ssh-keypair ssh-keypair-create my-key --public-key-file ~/.ssh/id_rsa.pub
# Delete keypair
nnumbers ssh-keypair ssh-keypair-delete my-key
Resource Monitoring
# View quota information
nnumbers core quota
# View detailed usage statistics
nnumbers core usage
๐ Examples
Instance Lifecycle
# List all instances with status
nnumbers instance list
# Start a stopped instance
nnumbers instance start web-server-01
# Check detailed instance information
nnumbers instance status web-server-01
# Gracefully stop an instance
nnumbers instance stop web-server-01
# Reboot an instance
nnumbers instance reboot web-server-01
Network Management
# View available networks
nnumbers network list-networks
# Check current floating IP allocation
nnumbers network list-floating-ips
# Allocate a new floating IP
nnumbers network create-floating-ip --description "Load balancer IP"
Monitoring and Quotas
# Check project quotas
nnumbers core quota
# View current resource usage vs quotas
nnumbers core usage
๐ ๏ธ Development
Code Quality
This project maintains high code quality standards:
# Format code
pdm run format
# Lint code
pdm run check
# Type checking
pdm run check-typing
# Find unused code
pdm run check-vulture
# Run tests with coverage
pdm run test
# Run full quality check
pdm run full
Project Structure
src/
โโโ __init__.py # Package metadata and exports
โโโ __main__.py # CLI application entry point
โโโ core.py # Core OpenStack connection and utilities
โโโ instance.py # Instance management commands
โโโ network.py # Network management commands
โโโ ssh_keypair.py # SSH keypair management commands
tests/
โโโ conftest.py # Test configuration and fixtures
โโโ test_core.py # Core functionality tests
โโโ test_instance.py # Instance management tests
โโโ test_network.py # Network management tests
Adding New Commands
To add new commands, follow these patterns:
@app.command
def new_command(param: str) -> None:
"""Description of the new command.
Detailed explanation of what the command does, its use cases,
and any important behavior or limitations.
Parameters
----------
param : str
Description of the parameter, including valid values
and any constraints.
Raises
------
SystemExit
If the operation fails or connection cannot be established.
Examples
--------
$ nnumbers module new-command example-value
"""
conn = get_openstack_connection()
try:
# Implementation here
logger.success("Operation completed successfully")
except Exception as e:
logger.error(f"Error: {e}")
raise SystemExit(1) from e
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Install development dependencies:
pdm install -G dev - Install pre-commit hooks:
pdm run pre-commit-install - Make your changes with proper tests and documentation
- Run the full test suite:
pdm run full - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ก๏ธ Error Handling
The CLI provides comprehensive error handling:
- Connection Validation: Automatic validation of OpenStack credentials
- Resource Validation: Checks for resource existence before operations
- Informative Messages: Clear error messages with suggested solutions
- Graceful Degradation: Continues operation when possible, fails fast when necessary
- Structured Logging: Consistent logging format with appropriate log levels
๐ Logging
The CLI uses structured logging with loguru:
INFO: General information and operation progressSUCCESS: Successful completion of operationsWARNING: Non-critical issues that don't prevent operationERROR: Critical errors that prevent operation completion
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Support
- Documentation: See this README and inline help (
nnumbers --help) - Issues: Report bugs and request features via GitHub Issues
- Contributing: See the Contributing section above
๐ท๏ธ Version
Current version: 0.1.0
Check your installed version:
nnumbers --version
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 nnumbers_development-0.1.3.tar.gz.
File metadata
- Download URL: nnumbers_development-0.1.3.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.24.2 CPython/3.12.3 Linux/6.6.87.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee8d696c0cc0414c187739f1895290e2c397bacc0249d91533ae1f141cd1b15e
|
|
| MD5 |
e59d22885ff36d5bfd0da552020e49d9
|
|
| BLAKE2b-256 |
8c727402980a7d78ca00a7c17edce6759d44ad9c34b73aa8134973052cbeb4fd
|
File details
Details for the file nnumbers_development-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nnumbers_development-0.1.3-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.24.2 CPython/3.12.3 Linux/6.6.87.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb4285b25694845358d2755824fa2d02831e91bc6d503418321dd2a7df6aa805
|
|
| MD5 |
ac3e2fc30f831052b50c1205cfe9560d
|
|
| BLAKE2b-256 |
8d4dfa93ea4c65176d43a1740aac82cb158df6aff4a3827623a915494fa55356
|