@@ -171,16 +171,24 @@ def parse_args():
171171 return parser .parse_args ()
172172
173173
174- def wait_vm_not_running (domain ):
174+ def virsh_cmd (libvirt , * args ):
175+ return ["virsh" , f"--connect={ libvirt } " , * args ]
176+
177+
178+ def wait_vm_not_running (libvirt , domain ):
175179 timeout = 300
176180
177181 print (f'Waiting for { domain } VM to shutdown (max. { timeout } s)' )
178182 end_time = time .time () + timeout
179183 try :
180184 while True :
181185 time .sleep (5 )
182- cmd = ["virsh" , "domstate" , domain ]
183- if subprocess .getoutput (cmd ).rstrip () != "running" :
186+ result = subprocess .run (
187+ virsh_cmd (libvirt , "domstate" , domain ),
188+ capture_output = True ,
189+ text = True ,
190+ )
191+ if result .stdout .rstrip () != "running" :
184192 return
185193 if time .time () < end_time :
186194 continue
@@ -303,7 +311,7 @@ def get_virt_install_command(data):
303311 f'--initrd-inject={ data .kickstart } ' ,
304312 '--serial=pty' ,
305313 '--noautoconsole' ,
306- '--rng=/dev/random ' ,
314+ '--rng=/dev/urandom ' ,
307315 f'--wait={ data .wait_opt } ' ,
308316 f'--location={ data .url } ' ,
309317 ]
@@ -317,7 +325,7 @@ def get_virt_install_command(data):
317325 # names. For more details see:
318326 # https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
319327 'net.ifnames=0' ,
320- 'console=ttyS0,115200 ' ,
328+ 'console=ttyS0' ,
321329 ]
322330
323331 features_opts = []
@@ -343,8 +351,8 @@ def get_virt_install_command(data):
343351 command .append (f'--osinfo={ data .osinfo } ' )
344352 else :
345353 if data .distro in UNRELEASED_DISTROS_AND_OSINFO .keys ():
346- command . append ( "--osinfo={}" . format (
347- UNRELEASED_DISTROS_AND_OSINFO . get ( data . distro , "rhel9-unknown" )) )
354+ osinfo = UNRELEASED_DISTROS_AND_OSINFO . get ( data . distro , "rhel9-unknown" )
355+ command . append ( f"--osinfo= { osinfo } " )
348356
349357 command .extend (join_extented_opt ("--boot" , "," , boot_opts ))
350358 command .extend (join_extented_opt ("--extra-args" , " " , extra_args_opts ))
@@ -362,25 +370,19 @@ def run_virt_install(data, command):
362370
363371 subprocess .call (command )
364372 if data .console :
365- subprocess .call (["unbuffer" , "virsh" , "console" , data .domain ])
366- wait_vm_not_running (data .domain )
367- subprocess .call ([ "virsh" , "start" , data .domain ] )
373+ subprocess .call (["unbuffer" , * virsh_cmd ( data . libvirt , "console" , data .domain ) ])
374+ wait_vm_not_running (data .libvirt , data . domain )
375+ subprocess .call (virsh_cmd ( data . libvirt , "start" , data .domain ) )
368376
369377 give_info (data )
370378
371379
372380def give_info (data ):
373- if data .libvirt == "qemu:///system" :
374- ip_cmd = f'sudo virsh domifaddr { data .domain } '
375- else :
376- # command evaluation in fish shell is simply surrounded by
377- # parenthesis for example: (echo foo). In other shells you
378- # need to prepend the $ symbol as: $(echo foo)
379- from os import environ
380-
381- cmd_eval = "" if environ ["SHELL" ][- 4 :] == "fish" else "$"
382-
383- ip_cmd = f"arp -n | grep { cmd_eval } (virsh -q domiflist { data .domain } | awk '{{print $5}}')"
381+ sudo = "sudo " if data .libvirt == "qemu:///system" else ""
382+ ip_cmd = (
383+ f"{ sudo } virsh --connect={ data .libvirt } -q domifaddr --source arp "
384+ f"{ data .domain } | awk '{{print $4}}' | sed 's|/.*||'"
385+ )
384386
385387 print (f"""
386388To determine the IP address of the { data .domain } VM use:
@@ -390,7 +392,7 @@ def give_info(data):
390392 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@IP
391393
392394To connect to the VM serial console, use:
393- virsh console { data .domain } """ )
395+ virsh --connect= { data . libvirt } console { data .domain } """ )
394396
395397 if data .ssh_pubkey_used :
396398 print (f"""
0 commit comments