add pve ssh

This commit is contained in:
crate 2024-10-09 15:03:43 +00:00
parent 298a689545
commit d617e8f225

29
pve_ssh.py Normal file
View File

@ -0,0 +1,29 @@
import paramiko
import config
ssh_user = config.SSH_USER
ssh_password = config.SSH_PASS
vmid = '101'
node_ip = '192.168.1.101'
pci_device = 'hostpci0'
def unmount_pci_and_shutdown(node_ip, vmid, pci_device):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(node_ip, username=ssh_user, password=ssh_password)
# unmount_command = f'qm set {vmid} -delete {pci_device}'
# stdin, stdout, stderr = ssh.exec_command(unmount_command)
# print(stdout.read().decode())
# print(stderr.read().decode())
print(f"Unmounted {pci_device} from VM {vmid}, shutting down node {node_ip}...")
ssh.exec_command('sudo shutdown -h now')
ssh.close()
except Exception as e:
print(f"Error: {e}")
# Call the function to unmount PCI and shutdown
unmount_pci_and_shutdown(node_ip, vmid, pci_device)