| 
									
										
										
										
											2025-08-26 23:55:54 +02:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											2017-10-13 18:49:39 +02:00
										 |  |  | # Restart all running libvirt domains | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import libvirt | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2018-02-12 17:14:39 +01:00
										 |  |  | import time | 
					
						
							| 
									
										
										
										
											2017-10-13 18:49:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | conn = libvirt.open('qemu:///system') | 
					
						
							|  |  |  | if not conn: | 
					
						
							|  |  |  |     print('Failed to open connection to the hypervisor!') | 
					
						
							|  |  |  |     sys.exit(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for domain in conn.listAllDomains(): | 
					
						
							|  |  |  |     name = domain.name() | 
					
						
							|  |  |  |     if domain.isActive(): | 
					
						
							| 
									
										
										
										
											2018-02-12 17:14:39 +01:00
										 |  |  |         print('Restarting {}'.format(name), end='', flush=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         domain.shutdown() | 
					
						
							|  |  |  |         while domain.isActive(): | 
					
						
							|  |  |  |             print('.', end='', flush=True) | 
					
						
							|  |  |  |             time.sleep(1) | 
					
						
							|  |  |  |         print() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-13 18:49:39 +02:00
										 |  |  |         domain.create() |