Diagnostic CLI tool for OCN (Open Control Network) servers
Project description
OCN CLI - Diagnostic Tool for OCN Servers
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) |
onboard |
Onboard OCN server to OCN-cloud (remove OpenVPN, set hostname, join Tailscale, reboot) |
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
Onboard to OCN-Cloud
# Onboard server to OCN-cloud (Debian/Ubuntu only)
onboard --auth-key tskey-auth-xxx --hostname ocn-server-01
# Process:
# 1. Removes OpenVPN/openvpn3/connexa and disables openvpn* services
# 2. Sets hostname via hostnamectl
# 3. Installs Tailscale (if needed) and joins with auth key
# 4. Reboots the server (session will disconnect)
# Requires: sudo password when connecting, Debian/Ubuntu
See: OCN_CLOUD_ONBOARD.md for a complete step-by-step guide from installing Python to running the onboard command.
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 commandCtrl+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_keyson the OCN server contains your public key - Verify file permissions:
chmod 600 ~/.ssh/your_key - Try using a different key with
--keyoption
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:
- GitHub Issues: https://github.com/your-org/ocn/issues
- Documentation: https://github.com/your-org/ocn/tree/main/cli
Version
Current version: 1.0.0
See CHANGELOG.md for version history and changes.
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 ocn_cli-1.2.0.tar.gz.
File metadata
- Download URL: ocn_cli-1.2.0.tar.gz
- Upload date:
- Size: 72.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9b44f2b5ffa1286bce7e52a932c7eb02423326312dd34bc9443bed129936930
|
|
| MD5 |
c9230ef46b60450a73ebca97170f1386
|
|
| BLAKE2b-256 |
65c5daeb3d8da3cb643c22c7a87dc8cb51bde50ed29cc42f8dde3b8ffaf6e4bd
|
Provenance
The following attestation bundles were made for ocn_cli-1.2.0.tar.gz:
Publisher:
publish-ocn-cli.yml on stratoautomation/ocn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocn_cli-1.2.0.tar.gz -
Subject digest:
d9b44f2b5ffa1286bce7e52a932c7eb02423326312dd34bc9443bed129936930 - Sigstore transparency entry: 1004096362
- Sigstore integration time:
-
Permalink:
stratoautomation/ocn@7fe6f3cca9ebb7f6a9ce4956fba53450a842078a -
Branch / Tag:
refs/tags/ocn-cli-v1.2.0 - Owner: https://github.com/stratoautomation
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-ocn-cli.yml@7fe6f3cca9ebb7f6a9ce4956fba53450a842078a -
Trigger Event:
release
-
Statement type:
File details
Details for the file ocn_cli-1.2.0-py3-none-any.whl.
File metadata
- Download URL: ocn_cli-1.2.0-py3-none-any.whl
- Upload date:
- Size: 72.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f477188b45a62c63afe97a74f69ae5f471be6c0246ccb13107edfa7ef64967a
|
|
| MD5 |
9512648b019e5325c0e64c623681a70e
|
|
| BLAKE2b-256 |
db1a75df67dbd9e362b78e0d9237befa0e0f32f5170e37a6a2a86e5085750402
|
Provenance
The following attestation bundles were made for ocn_cli-1.2.0-py3-none-any.whl:
Publisher:
publish-ocn-cli.yml on stratoautomation/ocn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocn_cli-1.2.0-py3-none-any.whl -
Subject digest:
3f477188b45a62c63afe97a74f69ae5f471be6c0246ccb13107edfa7ef64967a - Sigstore transparency entry: 1004096363
- Sigstore integration time:
-
Permalink:
stratoautomation/ocn@7fe6f3cca9ebb7f6a9ce4956fba53450a842078a -
Branch / Tag:
refs/tags/ocn-cli-v1.2.0 - Owner: https://github.com/stratoautomation
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-ocn-cli.yml@7fe6f3cca9ebb7f6a9ce4956fba53450a842078a -
Trigger Event:
release
-
Statement type: