import paramiko import config ssh_user = config.PVE_SSH_USER ssh_password = config.PVE_SSH_PASS vmid = '210' node_ip = config.PVE_NODE_2 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('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)