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() { | function get_port() { | ||||||
|     local PORT_START=22220 |     local PORT_START=$1 | ||||||
|     local PORT_RANGE=9 |     local PORT_RANGE=$2 | ||||||
|     while true; do |     while true; do | ||||||
|         local CANDIDATE=$[${PORT_START} + (${RANDOM} % ${PORT_RANGE})] |         local CANDIDATE=$[${PORT_START} + (${RANDOM} % ${PORT_RANGE})] | ||||||
|         (echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1 |         (echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1 | ||||||
|  | @ -362,7 +362,7 @@ function vm_boot() { | ||||||
|   fi |   fi | ||||||
| 
 | 
 | ||||||
|   # Find a free port to expose ssh to the guest |   # Find a free port to expose ssh to the guest | ||||||
|   local PORT=$(get_port) |   local PORT=$(get_port 22220 9) | ||||||
|   if [ -n "${PORT}" ]; then |   if [ -n "${PORT}" ]; then | ||||||
|     NET="${NET},hostfwd=tcp::${PORT}-:22" |     NET="${NET},hostfwd=tcp::${PORT}-:22" | ||||||
|     echo " - ssh:      ${PORT}/tcp is connected. Login via 'ssh user@localhost -p ${PORT}'" |     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." |     echo " - ssh:      All ports for exposing ssh have been exhausted." | ||||||
|   fi |   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 |   enable_usb_passthrough | ||||||
| 
 | 
 | ||||||
|   # Boot the iso image |   # Boot the iso image | ||||||
|  | @ -438,7 +444,7 @@ function vm_boot() { | ||||||
|         -rtc base=localtime,clock=host \ |         -rtc base=localtime,clock=host \ | ||||||
|         -object rng-random,id=rng0,filename=/dev/urandom \ |         -object rng-random,id=rng0,filename=/dev/urandom \ | ||||||
|         -device virtio-rng-pci,rng=rng0 \ |         -device virtio-rng-pci,rng=rng0 \ | ||||||
|         -spice port=5930,disable-ticketing \ |         -spice port=${SPICE_PORT},disable-ticketing \ | ||||||
|         -device virtio-serial-pci \ |         -device virtio-serial-pci \ | ||||||
|         -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ |         -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ | ||||||
|         -chardev spicevmc,id=spicechannel0,name=vdagent \ |         -chardev spicevmc,id=spicechannel0,name=vdagent \ | ||||||
|  | @ -463,7 +469,7 @@ function vm_boot() { | ||||||
|       -rtc base=localtime,clock=host \ |       -rtc base=localtime,clock=host \ | ||||||
|       -object rng-random,id=rng0,filename=/dev/urandom \ |       -object rng-random,id=rng0,filename=/dev/urandom \ | ||||||
|       -device virtio-rng-pci,rng=rng0 \ |       -device virtio-rng-pci,rng=rng0 \ | ||||||
|       -spice port=5930,disable-ticketing \ |       -spice port=${SPICE_PORT},disable-ticketing \ | ||||||
|       -device virtio-serial-pci \ |       -device virtio-serial-pci \ | ||||||
|       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ |       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \ | ||||||
|       -chardev spicevmc,id=spicechannel0,name=vdagent \ |       -chardev spicevmc,id=spicechannel0,name=vdagent \ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue