Skip to main content

Diagnostic CLI tool for OCN (Open Control Network) servers

Project description

OCN CLI - Diagnostic Tool for OCN Servers

PyPI version Python License: MIT

A cross-platform, Python-based command-line interface for remote troubleshooting and diagnostics of OCN (Open Control Network) server installations.

Features

  • ๐Ÿ” Secure Authentication - SSH key-based authentication
  • ๐Ÿ”Œ Interactive Shell - Persistent SSH session with command history and autocomplete
  • ๐Ÿ’ก Syntax Highlighting - Color-coded commands for better readability
  • ๐ŸŽฏ Helper Commands - Built-in diagnostic commands for common operations
  • ๐ŸŒ Cross-Platform - Works on Windows, macOS, and Linux
  • ๐Ÿ›ก๏ธ Security - Permission validation and secure key handling

Installation

Prerequisites

  • Python 3.9 or higher
  • pip package manager

Install from PyPI

pip install ocn-cli

Install from Source (Development)

git clone https://github.com/your-org/ocn.git
cd ocn/cli
pip install -e .

Usage

Basic Connection

Connect to an OCN server with your SSH key:

ocn-cli --host server.ocn.local --key ~/.ssh/id_rsa

When you connect, you'll be prompted for a sudo password (optional, needed for Docker diagnostics):

๐Ÿ”‘ Enter sudo password for remote server (optional, press Enter to skip):
Validating sudo credentials...
โœ… Sudo credentials validated

If the password is incorrect, you'll see a warning but can continue (some diagnostics may fail).

Provide Sudo Password

Some diagnostics require sudo (Docker commands, system checks). You can provide the password via:

# Recommended: Will prompt for password (masked input)
ocn-cli --host server.ocn.local --key ~/.ssh/id_rsa

# Or provide it upfront (less secure - visible in command history)
ocn-cli --host server.ocn.local --key ~/.ssh/id_rsa --sudo-password yourpassword

Note: The sudo password is validated upon connection. If invalid, you'll see a warning and can continue without sudo (some diagnostics will be skipped).

Custom User and Port

Specify a different SSH user and port:

ocn-cli --host 192.168.1.100 --key ~/.ssh/ocn_key --user admin --port 2222

Full Options

ocn-cli --help

Helper Commands

Once connected, the interactive shell provides several built-in helper commands:

Command Description
help Show available helper commands
status Display system status (uptime, CPU, memory, disk)
diagnose Run comprehensive server diagnostics (checks network, Docker, resources, services)
offline-update Upload and apply offline OCN update package (for servers without internet)
clear Clear the terminal screen
exit or quit Exit the interactive shell

Any other command is executed directly on the remote OCN server.

Examples

Check Server Status

ocn@server.ocn.local>> status

โ•ญโ”€โ”€โ”€ System Status โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                          โ”‚
โ”‚ Uptime:    5 days, 12:34:56             โ”‚
โ”‚ CPU Load:  2.5, 2.3, 2.1 (1/5/15 min)   โ”‚
โ”‚ Memory:    4.2G / 8.0G (52%)            โ”‚
โ”‚ Disk:      45G / 100G (45%)             โ”‚
โ”‚                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Run Comprehensive Diagnostics

ocn@server.ocn.local>> diagnose

โ•ญโ”€โ”€โ”€ OCN Server Diagnostic Report โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Server: ocn-server-01                                  โ”‚
โ”‚ Health Score: 85% (14/17 checks passed)                โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ”โ”โ” Network Diagnostics โ”โ”โ”
โœ… internet_connectivity       OK (3/3 endpoints reachable)
โœ… dns_resolution               OK (all 4 domains resolved)
โœ… keygen_accessibility         OK (HTTP 200)

โ”โ”โ” Docker Diagnostics โ”โ”โ”
โŒ docker_installation          FAIL - docker.io detected
   Remediation:
   โ€ข Remove docker.io: sudo apt remove docker.io
   โ€ข Install official Docker from get.docker.com
   
โœ… container_status             OK (5/5 containers running)

โ”โ”โ” Resources โ”โ”โ”
โœ… cpu_usage                    OK (15.2%)
โœ… memory_usage                 OK (RAM: 45%, Swap: 2%)
โš ๏ธ  disk_space                  HIGH (/ at 87%)
โœ… system_load                  OK (1.2, 1.5, 1.3)

โ”โ”โ” Services โ”โ”โ”
โœ… docker_daemon                Active
โœ… nginx_service                Active
โœ… firewall                     Active (ufw)

Execute Remote Commands

ocn@server.ocn.local>> docker ps
CONTAINER ID   IMAGE          COMMAND       STATUS
abc123def456   ocn-backend    "dotnet..."   Up 5 days

ocn@server.ocn.local>> journalctl -u ocn-api -n 20
-- Logs begin at Mon 2024-01-01 00:00:00 UTC --
...

Diagnose Command Options

# Run all diagnostics
diagnose

# Quick mode (critical checks only)
diagnose --quick

# Check specific category
diagnose --category docker

# Save report to file
diagnose --output report.html --format html

# Get help
diagnose --help

Offline Update (For Servers Without Internet)

# Upload and apply an offline update package
offline-update --package /local/path/to/ocn-update-2.1.10.tar.gz

# Process:
#  1. Uploads package via SFTP (with progress bar)
#  2. Validates package structure
#  3. Shows update preview
#  4. Prompts for confirmation
#  5. Applies update (stops containers, loads images, restarts)

# See OFFLINE_UPDATES.md for complete guide

Use Tab Completion

Type a partial command and press Tab to see suggestions:

ocn@server.ocn.local>> doc<TAB>
docker

Command History

Use arrow keys to navigate through previous commands:

  • โ†‘ - Previous command
  • โ†“ - Next command
  • Ctrl+R - Reverse search through history

SSH Key Setup

Generating an SSH Key

If you don't have an SSH key, generate one:

# RSA key (widely supported)
ssh-keygen -t rsa -b 4096 -f ~/.ssh/ocn_key

# Ed25519 key (modern, more secure)
ssh-keygen -t ed25519 -f ~/.ssh/ocn_key

# Set secure permissions
chmod 600 ~/.ssh/ocn_key

Authorizing Your Key on OCN Server

Add your public key to the OCN server:

# Method 1: Using ssh-copy-id
ssh-copy-id -i ~/.ssh/ocn_key.pub user@server.ocn.local

# Method 2: Manual
cat ~/.ssh/ocn_key.pub | ssh user@server.ocn.local "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Key Requirements

  • Must be a valid SSH private key (RSA, Ed25519, ECDSA, or DSA)
  • File permissions should be 600 (read/write for owner only)
  • Key must be authorized on the OCN server (~/.ssh/authorized_keys)
  • Passphrase-protected keys are not currently supported

Troubleshooting

Connection Failed

Error: Connection refused

  • Verify SSH service is running on the OCN server: systemctl status sshd
  • Check firewall rules allow SSH connections on the specified port
  • Confirm the server is reachable: ping server.ocn.local

Error: Authentication failed

  • Ensure your SSH key is authorized on the server
  • Check ~/.ssh/authorized_keys on the OCN server contains your public key
  • Verify file permissions: chmod 600 ~/.ssh/your_key
  • Try using a different key with --key option

Error: Network unreachable

  • Check network connectivity
  • Verify DNS resolution: nslookup server.ocn.local
  • Confirm VPN connection if required

Key Permission Warnings

Warning: Key file has insecure permissions

Fix with:

chmod 600 ~/.ssh/your_key

Development

Setup Development Environment

# Clone repository
git clone https://github.com/your-org/ocn.git
cd ocn/cli

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install with development dependencies
pip install -e ".[dev]"

Run Tests

pytest

Code Quality

# Type checking
mypy ocn_cli

# Linting
ruff check ocn_cli

# Formatting
black ocn_cli

Architecture

The OCN CLI follows a modular architecture:

  • CLI Layer (cli.py) - Typer-based command-line interface
  • Authentication Layer (auth/) - SSH key management
  • SSH Layer (ssh/) - Connection management, command execution
  • Shell Layer (shell/) - Interactive REPL, history, autocomplete, syntax highlighting
  • Commands Layer (commands/) - Helper command registry and implementations
  • UI Layer (ui/) - Rich-based output formatting and messages
  • Utils Layer (utils/) - Platform utilities and security helpers

Contributing

Please read AGENTS.md for guidelines on contributing to this project.

Publishing

To publish a new version of OCN CLI to PyPI, see PUBLISHING.md for detailed instructions on:

  • Setting up PyPI trusted publishing
  • Creating releases via GitHub
  • Automated publishing with GitHub Actions
  • Manual publishing workflow

Quick publish:

# 1. Update version in ocn_cli/version.py
# 2. Update CHANGELOG.md
# 3. Create GitHub release with tag cli-vX.Y.Z
# 4. GitHub Actions automatically publishes to PyPI

License

MIT License - See LICENSE file for details.

Support

For issues, questions, or feature requests:

Version

Current version: 1.0.0

See CHANGELOG.md for version history and changes.

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

ocn_cli-1.0.0.tar.gz (66.2 kB view details)

Uploaded Source

Built Distribution

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

ocn_cli-1.0.0-py3-none-any.whl (69.2 kB view details)

Uploaded Python 3

File details

Details for the file ocn_cli-1.0.0.tar.gz.

File metadata

  • Download URL: ocn_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 66.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ocn_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 23fcb3e7f3c647ffb573bef8ee24a153f64b18f3469cf95b9a0138d1a26a2b9c
MD5 a0e303245da7ef4c8a090ead8bb4ddf8
BLAKE2b-256 cc51e3dd4f91be7539b5bc4ea64b589814b4c06e1677a19796a884770bb0c997

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocn_cli-1.0.0.tar.gz:

Publisher: publish-ocn-cli.yml on stratoautomation/ocn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ocn_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ocn_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 69.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ocn_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1d6918eb530e986c9c0b6989ed2d1453a0fa9182e3cdd38234bd9f4eab6bf97
MD5 7eb682426fd35c8617082998128b5fe4
BLAKE2b-256 f8e021278d84f7c3729f1093f3c5591c6b7c26a5aa8aa12cd9521fbb8c3e3395

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocn_cli-1.0.0-py3-none-any.whl:

Publisher: publish-ocn-cli.yml on stratoautomation/ocn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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