2024-10-09 15:03:43 +00:00
|
|
|
import paramiko
|
|
|
|
import config
|
|
|
|
|
2024-10-09 19:55:23 +00:00
|
|
|
ssh_user = config.PVE_SSH_USER
|
|
|
|
ssh_password = config.PVE_SSH_PASS
|
2024-10-09 15:03:43 +00:00
|
|
|
|
2024-10-09 19:55:23 +00:00
|
|
|
vmid = '210'
|
2024-10-09 19:56:09 +00:00
|
|
|
node_ip = config.PVE_NODE_2
|
2024-10-09 15:03:43 +00:00
|
|
|
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}...")
|
2024-10-09 19:55:23 +00:00
|
|
|
ssh.exec_command('shutdown -h now')
|
2024-10-09 15:03:43 +00:00
|
|
|
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)
|