54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Proxmox SSH Helper - serviceslab (192.168.2.100)
|
||
|
|
Uses paramiko for native Python SSH (no sshpass needed).
|
||
|
|
Usage: python proxmox_ssh.py "command to run"
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import paramiko
|
||
|
|
|
||
|
|
PROXMOX_HOST = "192.168.2.100"
|
||
|
|
PROXMOX_USER = "root"
|
||
|
|
PROXMOX_PASS = "Nbkx4mdmay1)"
|
||
|
|
PROXMOX_PORT = 22
|
||
|
|
TIMEOUT = 15
|
||
|
|
|
||
|
|
|
||
|
|
def run_command(command: str) -> tuple:
|
||
|
|
"""Execute a command on the Proxmox server via SSH.
|
||
|
|
Returns (stdout, stderr, exit_code).
|
||
|
|
"""
|
||
|
|
client = paramiko.SSHClient()
|
||
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
|
|
try:
|
||
|
|
client.connect(
|
||
|
|
hostname=PROXMOX_HOST,
|
||
|
|
port=PROXMOX_PORT,
|
||
|
|
username=PROXMOX_USER,
|
||
|
|
password=PROXMOX_PASS,
|
||
|
|
timeout=TIMEOUT,
|
||
|
|
look_for_keys=False,
|
||
|
|
allow_agent=False,
|
||
|
|
)
|
||
|
|
stdin, stdout, stderr = client.exec_command(command, timeout=TIMEOUT)
|
||
|
|
exit_code = stdout.channel.recv_exit_status()
|
||
|
|
out = stdout.read().decode("utf-8", errors="replace")
|
||
|
|
err = stderr.read().decode("utf-8", errors="replace")
|
||
|
|
return out, err, exit_code
|
||
|
|
finally:
|
||
|
|
client.close()
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
if len(sys.argv) < 2:
|
||
|
|
print("Usage: python proxmox_ssh.py \"command\"")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
cmd = sys.argv[1]
|
||
|
|
out, err, code = run_command(cmd)
|
||
|
|
if out:
|
||
|
|
print(out, end="")
|
||
|
|
if err:
|
||
|
|
print(err, end="", file=sys.stderr)
|
||
|
|
sys.exit(code)
|