diff --git a/pve_ssh.py b/pve_ssh.py new file mode 100644 index 0000000..828e76a --- /dev/null +++ b/pve_ssh.py @@ -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)