Skip to main content

Remote command execution library for SSH-based cluster operations. Execute commands on multiple servers concurrently with retry logic, error classification, and Slack notifications.

Project description

grass-remote-cli

Remote command execution library for SSH-based cluster operations.

Features

  • ClusterCmd: Execute commands on multiple servers concurrently
  • SshCmd: Single-server SSH execution with retry logic
  • StderrClassifier: Intelligent error classification (real errors vs innocent warnings)
  • Notifications: Slack integration for alerts (optional)
  • AnsibleInventory: Parse Ansible inventory files (optional)

Installation

# Core (SSH execution)
pip install grass-remote-cli

# With Ansible inventory support
pip install grass-remote-cli[inventory]

# With Slack notifications
pip install grass-remote-cli[notifications]

# Everything
pip install grass-remote-cli[all]

Quick Start

from grass_remote_cli import ClusterCmd

# Execute command on multiple servers
cluster = ClusterCmd(
    servers_ips=["<ip1>", "<ip2>", "<ip3>"],
    username="<ssh_user>",
    password="<ssh_password>",
    timeout_in_sec=300,
)
results, timed_out = cluster.execute("docker ps")

for ip, (_, stdout, stderr) in results:
    print(f"{ip}: {stdout}")

Single Server Execution

from grass_remote_cli import SshCmd

ssh = SshCmd()
ip, stdout, stderr = ssh.execute(
    host_ip="<server_ip>",
    username="<ssh_user>",
    password="<ssh_password>",
    commands="hostname && uptime"
)
print(stdout)

With Ansible Inventory

from grass_remote_cli import ClusterCmd
from grass_remote_cli.inventory import AnsibleInventory

# Load servers from Ansible inventory
inventory = AnsibleInventory("/path/to/ansible/inventories")
hosts = inventory.get_hosts_by_cluster("<cluster_name>")

# Deploy to cluster
ips = [host[1] for host in hosts]  # Extract IPs
cluster = ClusterCmd(ips, username="<ssh_user>", password="<ssh_password>")
results, _ = cluster.execute("docker pull <image>")

Error Classification

The library intelligently classifies stderr output:

from grass_remote_cli.stderr_classifier import StderrClassifier

classifier = StderrClassifier()
result = classifier.classify(stderr_output)

if result['is_error']:
    print(f"Real error: {result['summary']}")
else:
    print("Innocent warning, safe to ignore")

Slack Notifications

import os
from grass_remote_cli.notifications import post_to_slack

# Set webhook via environment variable
os.environ["SLACK_WEBHOOK_URL"] = "https://hooks.slack.com/services/..."

post_to_slack("Deployment complete!", channel="#deployments")

# Or pass webhook directly
post_to_slack(
    "Deployment complete!",
    channel="#deployments",
    webhook_url="https://hooks.slack.com/services/..."
)

Environment Variables

Variable Description
SLACK_WEBHOOK_URL Slack webhook URL for notifications
SSH_AUTH_TIMEOUT SSH authentication timeout (default: 120s)
SSH_EXEC_TIMEOUT Command execution timeout (default: 900s)
SSH_MAX_RETRIES Connection retry attempts (default: 3)
SSH_MAX_WORKERS Concurrent SSH connections (default: 50)

License

MIT

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

grass_remote_cli-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

grass_remote_cli-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file grass_remote_cli-0.1.1.tar.gz.

File metadata

  • Download URL: grass_remote_cli-0.1.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for grass_remote_cli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b4a78453c4856804454d23b843d4340d49fee4e16bf3e2885d7b84f5f7643172
MD5 75121369468739d0f59fa11def12160f
BLAKE2b-256 669550aed8045a421ff9e2436ba1170c394d0da1a5f98554cccd76cc382eac2f

See more details on using hashes here.

File details

Details for the file grass_remote_cli-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for grass_remote_cli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9f937d874b86fc216b96ce4c6a4d13827849185cf7a2445fafd052b0317a30f4
MD5 02f7f4325bf85353f84e8f1a79f98b42
BLAKE2b-256 b27ca13460778af94c8cf66948bc17471be166cfd9266de35675fa3c41b3854c

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