Skip to main content

CLI interface for managing DigitalOcean droplets with local inventory tracking.

Project description

OCEA - DigitalOcean CLI with Local Inventory

A command-line interface for managing DigitalOcean droplets with local SQLite-based inventory tracking. OCEA enables smart droplet management including automatic snapshot-based restore, reserved IP reassignment, and comprehensive audit logging.

Features

  • Local Inventory Tracking: SQLite database stores droplet metadata, snapshots, and reserved IPs locally for offline access and faster operations.

  • Smart Restore: Automatically restore terminated droplets from snapshots using stored configuration (region, size, reserved IPs).

  • Audit Logging: All operations are logged with timestamps for accountability and debugging.

  • Multi-Droplet Operations: Manage multiple droplets in a single command.

  • Reserved IP Management: Automatic reassignment of reserved (floating) IPs during restore operations.

  • In-Progress Tracking: See snapshots that are currently being created.

  • Python API: Programmatic access to all functionality.

Installation

Install from source:

pip install -e .

For development:

pip install -e ".[dev]"

Configuration

OCEA requires a DigitalOcean API token. Configure it using one of these methods (in priority order):

  1. `.env` file in the current directory:

    DO_API_TOKEN=your_token_here
  2. Environment Variable (recommended):

    export DO_API_TOKEN=your_token_here
    # or
    export DIGITALOCEAN_TOKEN=your_token_here
  3. Config file at ~/.config/ocea/token (Linux/macOS) or %APPDATA%\ocea\token (Windows)

Optional: Set a custom database path:

export OCEA_DB_PATH=/path/to/ocea.db

Quick Start

# Set your API token
export DO_API_TOKEN=your_token_here

# List all droplets
ocea list

# Check inventory status
ocea status

# Create a new droplet
ocea new my-server -r nyc1 -s s-1vcpu-1gb -i ubuntu-24-04-x64

# Create a snapshot
ocea snap create my-server

# Gracefully shut down
ocea down my-server

# Terminate with auto-snapshot (for cost savings)
ocea down my-server --terminate

# Restore from snapshot
ocea up my-server

Commands

list

List droplets and snapshots from DigitalOcean API:

ocea list                      # All droplets and snapshots
ocea list --droplets           # Only droplets
ocea list --snaps              # Only snapshots
ocea list -r nyc1              # Filter by region
ocea list -r nyc1 -r sfo3      # Filter by multiple regions
ocea list --local              # From local database only
ocea list --json               # Output as JSON

status

Show inventory summary or specific droplet details:

ocea status                    # Summary of all droplets
ocea status my-server          # Details for specific droplet
ocea status --local            # From local database only
ocea status --json             # Output as JSON

up

Power on droplets or restore from snapshots. OCEA automatically determines the correct action based on the droplet’s state:

  • If the droplet is off: powers it on

  • If the droplet is archived (terminated): restores from the most recent snapshot

ocea up my-server              # Power on or restore
ocea up server1 server2        # Multiple droplets
ocea up --no-attach-ip srv     # Skip reserved IP reassignment
ocea up --json my-server       # Output as JSON

down

Power off or terminate droplets:

ocea down my-server                        # Graceful shutdown
ocea down my-server --terminate            # Terminate with auto-snapshot
ocea down my-server --terminate --no-snapshot  # Terminate without snapshot
ocea down --json my-server                 # Output as JSON

new

Create a new droplet:

# Basic creation
ocea new my-server -r nyc1 -s s-1vcpu-1gb -i ubuntu-24-04-x64

# With SSH key and tags
ocea new my-server -r nyc1 -s s-1vcpu-1gb -i ubuntu-24-04-x64 \
    --ssh-key my-key --tag production --tag web

# With all options
ocea new my-server -r nyc1 -s s-1vcpu-1gb -i ubuntu-24-04-x64 \
    --ssh-key my-key --backups --ipv6 --monitoring

snap

Manage snapshots:

ocea snap list                 # List all snapshots
ocea snap create my-server     # Create a snapshot
ocea snap delete 123456789     # Delete by ID
ocea snap delete snap1 snap2   # Delete multiple
ocea snap list --json          # Output as JSON

reboot

Reboot active droplets:

ocea reboot my-server          # Reboot single droplet
ocea reboot srv1 srv2 srv3     # Reboot multiple droplets
ocea reboot --json my-server   # Output as JSON

Python API

OCEA provides a Python API for programmatic access:

from ocea.api import OCEA

# Initialize (uses environment config)
ocea = OCEA()

# List droplets
droplets = ocea.list_droplets()
for d in droplets:
    print(f"{d.name}: {d.status} ({d.public_ip})")

# Create a droplet
droplet = ocea.create_droplet(
    name="my-server",
    region="nyc1",
    size="s-1vcpu-1gb",
    image="ubuntu-24-04-x64"
)

# Create a snapshot
snapshot = ocea.create_snapshot("my-server", "my-server-backup")

# Terminate (creates snapshot by default)
ocea.terminate("my-server")

# Restore from snapshot
ocea.power_on("my-server")

Database Schema

OCEA maintains a local SQLite database with the following tables:

  • droplets: Stores droplet metadata (name, region, size, IPs, status)

  • snapshots: Tracks snapshots and their associated droplets

  • floating_ips: Maps reserved IPs to droplets

  • actions: Audit log of all operations

Droplet Status Values

  • active - Running

  • off - Powered off but exists in DigitalOcean

  • archive - Terminated (deleted from DigitalOcean but has snapshot for restore)

Development

Setup:

make bootstrap     # Create virtualenv and install dependencies
make precommit     # Install pre-commit hooks

Run tests:

make test          # Unit + integration tests (cached)
make test-all      # Full test suite with coverage

Run linting:

make lint          # Check with Ruff
make format        # Auto-fix with Ruff

Build:

make build         # Build wheel and sdist
make version       # Print current version

License

MIT License. See LICENSE file for details.

Author

Kevin Steptoe

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

ocea-2.0.8.dev2.tar.gz (59.4 kB view details)

Uploaded Source

Built Distribution

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

ocea-2.0.8.dev2-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file ocea-2.0.8.dev2.tar.gz.

File metadata

  • Download URL: ocea-2.0.8.dev2.tar.gz
  • Upload date:
  • Size: 59.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ocea-2.0.8.dev2.tar.gz
Algorithm Hash digest
SHA256 92a2a82501ea3f38d840d1b8143b950645a71a6f2dc7e37d939ee584a0060de5
MD5 2aea340a443011e639ae84591067e2fb
BLAKE2b-256 1fcb9862056cdbb9086861e3854316068dc66ff10325202ef9e36ed639b86635

See more details on using hashes here.

File details

Details for the file ocea-2.0.8.dev2-py3-none-any.whl.

File metadata

  • Download URL: ocea-2.0.8.dev2-py3-none-any.whl
  • Upload date:
  • Size: 42.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ocea-2.0.8.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 073653e1cf7cb032d1e93e84b90b660f65b045116ff90d27c629d5de4797c642
MD5 935abc6f91df6644949f01ffb1f44a90
BLAKE2b-256 5cd3859fd59d9b48db3fa579be62e2f325aa617983b5e3f1a7ea92c93c4e43ce

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