mirror of
				https://github.com/oSoWoSo/DistroHopper.git
				synced 2024-08-14 22:46:53 +00:00 
			
		
		
		
	find free port for spice (#29)
allows to run more VMs in parallel Co-authored-by: Marian Gasparovic <marian.gasparovic@canonical.com>
This commit is contained in:
		
							parent
							
								
									df51b17d71
								
							
						
					
					
						commit
						7f408e59cf
					
				
					 1 changed files with 11 additions and 5 deletions
				
			
		
							
								
								
									
										16
									
								
								quickemu
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								quickemu
									
										
									
									
									
								
							|  | @ -92,8 +92,8 @@ function snapshot_info() { | |||
| } | ||||
| 
 | ||||
| function get_port() { | ||||
|     local PORT_START=22220 | ||||
|     local PORT_RANGE=9 | ||||
|     local PORT_START=$1 | ||||
|     local PORT_RANGE=$2 | ||||
|     while true; do | ||||
|         local CANDIDATE=$[${PORT_START} + (${RANDOM} % ${PORT_RANGE})] | ||||
|         (echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1 | ||||
|  | @ -362,7 +362,7 @@ function vm_boot() { | |||
|   fi | ||||
| 
 | ||||
|   # Find a free port to expose ssh to the guest | ||||
|   local PORT=$(get_port) | ||||
|   local PORT=$(get_port 22220 9) | ||||
|   if [ -n "${PORT}" ]; then | ||||
|     NET="${NET},hostfwd=tcp::${PORT}-:22" | ||||
|     echo " - ssh:      ${PORT}/tcp is connected. Login via 'ssh user@localhost -p ${PORT}'" | ||||
|  | @ -370,6 +370,12 @@ function vm_boot() { | |||
|     echo " - ssh:      All ports for exposing ssh have been exhausted." | ||||
|   fi | ||||
| 
 | ||||
|   # Find a free port for spice | ||||
|   local SPICE_PORT=$(get_port 5930 9) | ||||
|   if [ ! -n "${SPICE_PORT}" ]; then | ||||
|     echo " - spice:      All spice ports have been exhausted." | ||||
|   fi | ||||
| 
 | ||||
|   enable_usb_passthrough | ||||
| 
 | ||||
|   # Boot the iso image | ||||
|  | @ -438,7 +444,7 @@ function vm_boot() { | |||
|         -rtc base=localtime,clock=host \ | ||||
|         -object rng-random,id=rng0,filename=/dev/urandom \ | ||||
|         -device virtio-rng-pci,rng=rng0 \ | ||||
|         -spice port=5930,disable-ticketing \ | ||||
|         -spice port=${SPICE_PORT},disable-ticketing \ | ||||
|         -device virtio-serial-pci \ | ||||
|         -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ | ||||
|         -chardev spicevmc,id=spicechannel0,name=vdagent \ | ||||
|  | @ -463,7 +469,7 @@ function vm_boot() { | |||
|       -rtc base=localtime,clock=host \ | ||||
|       -object rng-random,id=rng0,filename=/dev/urandom \ | ||||
|       -device virtio-rng-pci,rng=rng0 \ | ||||
|       -spice port=5930,disable-ticketing \ | ||||
|       -spice port=${SPICE_PORT},disable-ticketing \ | ||||
|       -device virtio-serial-pci \ | ||||
|       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ | ||||
|       -chardev spicevmc,id=spicechannel0,name=vdagent \ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue