starlyng-ssh-connection


Namestarlyng-ssh-connection JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/starlyngapp/ssh-connection
SummaryA Python library for checking server availability and managing server configurations via SSH, with support for parallel execution using threading.
upload_time2024-12-13 02:23:55
maintainerNone
docs_urlNone
authorJustin Sherwood
requires_python>=3.7
licenseMIT
keywords server management ssh connection threading parallel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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 `Server` dataclass
- Parallel execution using threading
- Comprehensive error handling and logging
- Utility functions for server management:
  - `get_hostname`: Generate hostnames from IP/port
  - `get_host_id`: Generate host IDs
  - `get_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
```bash
pip install starlyng-ssh-connection
```

## Usage

### Creating Servers

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

1. Fork the project
2. Create your feature branch (`git checkout -b feature/YourFeature`)
3. Commit your changes (`git commit -am 'Add some YourFeature'`)
4. Push to the branch (`git push origin feature/YourFeature`)
5. Open a pull request

## Contact

If you have any questions, please contact:

- GitHub: [@justinsherwood](https://github.com/justinsherwood)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/starlyngapp/ssh-connection",
    "name": "starlyng-ssh-connection",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "server management ssh connection threading parallel",
    "author": "Justin Sherwood",
    "author_email": "justin@sherwood.fm",
    "download_url": "https://files.pythonhosted.org/packages/f7/25/1d96c40a4c1549917bf077f9cbb89bd14ad9be23340c3e85975a52936c2b/starlyng_ssh_connection-0.1.1.tar.gz",
    "platform": null,
    "description": "# Starlyng SSH Connection Library\n\nA Python library for checking server availability and managing server configurations via SSH.\n\n## Features\n\n- Check multiple servers' SSH availability in parallel using `ping_servers`\n- Execute commands across multiple servers using `run_command_on_servers` \n- Server configuration management through `Server` dataclass\n- Parallel execution using threading\n- Comprehensive error handling and logging\n- Utility functions for server management:\n  - `get_hostname`: Generate hostnames from IP/port\n  - `get_host_id`: Generate host IDs\n  - `get_ip_for_ssh`: Format IPs for SSH connections\n\n## Prerequisites\n\nBefore you begin, ensure you have:\n* Python 3.9 or higher installed\n* SSH access to target servers\n* SSH key authentication configured (optional)\n\n## Installation\n```bash\npip install starlyng-ssh-connection\n```\n\n## Usage\n\n### Creating Servers\n\n```python\nfrom ssh_connection.models import Server\n\n# Create server instances for local network\nservers = [\n    Server(\n        hostname=\"server01\",\n        ip=\"192.168.1.100\",\n        public_ip=False,\n        ssh_key_path=\"~/.ssh/id_rsa\",\n        ssh_port=22,\n        ssh_user=\"admin\",\n        ssh_vlan_id=10\n    ),\n    Server(\n        hostname=\"server02\",\n        ip=\"192.168.1.101\",\n        public_ip=False,\n        ssh_key_path=\"~/.ssh/id_rsa\",\n        ssh_port=22,\n        ssh_user=\"admin\",\n        ssh_vlan_id=10\n    )\n]\n\n# Create a public server instance\npublic_server = Server(\n    hostname=\"public-server01\",\n    ip=\"203.0.113.10\",\n    public_ip=True,\n    ssh_key_path=\"~/.ssh/id_rsa\",\n    ssh_port=12345,\n    ssh_user=\"admin\",\n    ssh_vlan_id=0  # Not used for public IPs\n)\n```\n\n### Checking Server Availability\n\n```python\nfrom ssh_connection.connections import ping_servers\n\n# Check which servers are offline\noffline_servers = ping_servers(servers)\nif offline_servers:\n    print(\"Offline servers:\", offline_servers)\nelse:\n    print(\"All servers are online!\")\n```\n\n### Running Commands on Servers\n\n```python\nfrom ssh_connection.connections import run_command_on_servers\n\n# Run a single command on all servers\nresults = run_command_on_servers(servers, \"uptime\")\nfor hostname, result in results.items():\n    if result['error']:\n        print(f\"{hostname} error: {result['error']}\")\n    else:\n        print(f\"{hostname} output: {result['output']}\")\n```\n\n### Running Multiple Commands on Servers\n\n```python\nfrom ssh_connection.connections import run_command_on_servers\n\n# Run multiple commands in sequence\ncommands = [\n    \"hostname\",\n    \"uptime\",\n    \"df -h\"\n]\nresults = run_command_on_servers(servers, commands)\nfor hostname, result in results.items():\n    if result['error']:\n        print(f\"{hostname} error: {result['error']}\")\n    else:\n        print(f\"{hostname} output: {result['output']}\")\n```\n\n### Working with Local Network Servers\n\n```python\nfrom ssh_connection.utils import get_hostname, get_ip_for_ssh\n\n# Generate hostname for a local server\nhostname = get_hostname(\"server\", \"192.168.1.20\", 22, public_ip=False)\nprint(f\"Generated hostname: {hostname}\")  # Output: server10\n\n# Get SSH IP address with VLAN\nssh_ip = get_ip_for_ssh(\"192.168.1.100\", vlan_id=10, public_ip=False)\nprint(f\"SSH IP: {ssh_ip}\")  # Output: 192.168.10.100\n```\n\n### Working with Public Servers\n\n```python\nfrom ssh_connection.utils import get_hostname, get_ip_for_ssh\n\n# Generate hostname for a public server (uses port number)\npublic_hostname = get_hostname(\"server\", \"203.0.113.10\", 12345, public_ip=True)\nprint(f\"Public server hostname: {public_hostname}\")  # Output: server45\n\n# Get SSH IP for public server\npublic_ssh_ip = get_ip_for_ssh(\"203.0.113.10\", vlan_id=0, public_ip=True)\nprint(f\"Public SSH IP: {public_ssh_ip}\")  # Output: 203.0.113.10\n```\n\n## Contributing\n\n1. Fork the project\n2. Create your feature branch (`git checkout -b feature/YourFeature`)\n3. Commit your changes (`git commit -am 'Add some YourFeature'`)\n4. Push to the branch (`git push origin feature/YourFeature`)\n5. Open a pull request\n\n## Contact\n\nIf you have any questions, please contact:\n\n- GitHub: [@justinsherwood](https://github.com/justinsherwood)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for checking server availability and managing server configurations via SSH, with support for parallel execution using threading.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/starlyngapp/ssh-connection"
    },
    "split_keywords": [
        "server",
        "management",
        "ssh",
        "connection",
        "threading",
        "parallel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4d932e342da59836f545264f5e2597ba38c33c253a761e9344d849ef1baa29a7",
                "md5": "de220f276ee332b1427800e5a4230ddb",
                "sha256": "8b6849b2647c2c2e097497d822d8049170e5a79d28b95d4b5814c61812bae37a"
            },
            "downloads": -1,
            "filename": "starlyng_ssh_connection-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "de220f276ee332b1427800e5a4230ddb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6602,
            "upload_time": "2024-12-13T02:23:53",
            "upload_time_iso_8601": "2024-12-13T02:23:53.631994Z",
            "url": "https://files.pythonhosted.org/packages/4d/93/2e342da59836f545264f5e2597ba38c33c253a761e9344d849ef1baa29a7/starlyng_ssh_connection-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7251d96c40a4c1549917bf077f9cbb89bd14ad9be23340c3e85975a52936c2b",
                "md5": "eb2abcdabb4a87b3464764ed64a9c499",
                "sha256": "749900f53139e756ef287eb19a7b5ecd05c8031e82bfe6b5bb67c152decb6855"
            },
            "downloads": -1,
            "filename": "starlyng_ssh_connection-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "eb2abcdabb4a87b3464764ed64a9c499",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6751,
            "upload_time": "2024-12-13T02:23:55",
            "upload_time_iso_8601": "2024-12-13T02:23:55.957584Z",
            "url": "https://files.pythonhosted.org/packages/f7/25/1d96c40a4c1549917bf077f9cbb89bd14ad9be23340c3e85975a52936c2b/starlyng_ssh_connection-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-13 02:23:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "starlyngapp",
    "github_project": "ssh-connection",
    "github_not_found": true,
    "lcname": "starlyng-ssh-connection"
}
        
Elapsed time: 0.35348s