Starlyng SSH Connection Library
A Python library for checking server availability and managing server configurations via SSH.
Features
- Check multiple servers' SSH availability in parallel using
ping_servers - Execute commands across multiple servers using
run_command_on_servers - Server configuration management through
Serverdataclass - Parallel execution using threading
- Comprehensive error handling and logging
- Utility functions for server management:
get_hostname: Generate hostnames from IP/portget_host_id: Generate host IDsget_ip_for_ssh: Format IPs for SSH connections
Prerequisites
Before you begin, ensure you have:
- Python 3.9 or higher installed
- SSH access to target servers
- SSH key authentication configured (optional)
Installation
pip install starlyng-ssh-connection
Usage
Creating Servers
from ssh_connection.models import Server
# Create server instances for local network
servers = [
Server(
hostname="server01",
ip="192.168.1.100",
public_ip=False,
ssh_key_path="~/.ssh/id_rsa",
ssh_port=22,
ssh_user="admin",
ssh_vlan_id=10
),
Server(
hostname="server02",
ip="192.168.1.101",
public_ip=False,
ssh_key_path="~/.ssh/id_rsa",
ssh_port=22,
ssh_user="admin",
ssh_vlan_id=10
)
]
# Create a public server instance
public_server = Server(
hostname="public-server01",
ip="203.0.113.10",
public_ip=True,
ssh_key_path="~/.ssh/id_rsa",
ssh_port=12345,
ssh_user="admin",
ssh_vlan_id=0 # Not used for public IPs
)
Checking Server Availability
from ssh_connection.connections import ping_servers
# Check which servers are offline
offline_servers = ping_servers(servers)
if offline_servers:
print("Offline servers:", offline_servers)
else:
print("All servers are online!")
Running Commands on Servers
from ssh_connection.connections import run_command_on_servers
# Run a single command on all servers
results = run_command_on_servers(servers, "uptime")
for hostname, result in results.items():
if result['error']:
print(f"{hostname} error: {result['error']}")
else:
print(f"{hostname} output: {result['output']}")
Running Multiple Commands on Servers
from ssh_connection.connections import run_command_on_servers
# Run multiple commands in sequence
commands = [
"hostname",
"uptime",
"df -h"
]
results = run_command_on_servers(servers, commands)
for hostname, result in results.items():
if result['error']:
print(f"{hostname} error: {result['error']}")
else:
print(f"{hostname} output: {result['output']}")
Working with Local Network Servers
from ssh_connection.utils import get_hostname, get_ip_for_ssh
# Generate hostname for a local server
hostname = get_hostname("server", "192.168.1.20", 22, public_ip=False)
print(f"Generated hostname: {hostname}") # Output: server10
# Get SSH IP address with VLAN
ssh_ip = get_ip_for_ssh("192.168.1.100", vlan_id=10, public_ip=False)
print(f"SSH IP: {ssh_ip}") # Output: 192.168.10.100
Working with Public Servers
from ssh_connection.utils import get_hostname, get_ip_for_ssh
# Generate hostname for a public server (uses port number)
public_hostname = get_hostname("server", "203.0.113.10", 12345, public_ip=True)
print(f"Public server hostname: {public_hostname}") # Output: server45
# Get SSH IP for public server
public_ssh_ip = get_ip_for_ssh("203.0.113.10", vlan_id=0, public_ip=True)
print(f"Public SSH IP: {public_ssh_ip}") # Output: 203.0.113.10
Contributing
- Fork the project
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add some YourFeature') - Push to the branch (
git push origin feature/YourFeature) - Open a pull request
Contact
If you have any questions, please contact:
- GitHub: @justinsherwood
Metadata
Release files for starlyng-ssh-connection 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| starlyng_ssh_connection-0.1.1.tar.gz | 6.8 kB | Without provenance | Details for starlyng_ssh_connection-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| starlyng_ssh_connection-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for starlyng_ssh_connection-0.1.1-py3-none-any.whl |
Total release size: 13.4 kB
Release files / starlyng_ssh_connection-0.1.1.tar.gz
| Download URL | starlyng_ssh_connection-0.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
749900f53139e756ef287eb19a7b5ecd05c8031e82bfe6b5bb67c152decb6855
|
|
BLAKE2b-256 checksum How to use checksums |
f7251d96c40a4c1549917bf077f9cbb89bd14ad9be23340c3e85975a52936c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.20
|
Release files / starlyng_ssh_connection-0.1.1-py3-none-any.whl
| Download URL | starlyng_ssh_connection-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b6849b2647c2c2e097497d822d8049170e5a79d28b95d4b5814c61812bae37a
|
|
BLAKE2b-256 checksum How to use checksums |
4d932e342da59836f545264f5e2597ba38c33c253a761e9344d849ef1baa29a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.20
|
Security for starlyng-ssh-connection 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.