Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support waiting until VM is network-accessible.
With the new flag ``downburst create --wait``, we add a final step into cloud-init user-data, that ejects the ``cidata`` CD-ROM. Outside the vm, we then poll for the CD-ROM tray position, waiting for it to be open. When using a reactive DNS updating mechanism (such as https://github.com/ceph/propernoun ) that updates DNS after seeing the VM creation and the DHCP lease, the DNS name won't exist until after the VM has requested a DHCP lease. This combined with caching DNS resolvers that enforce a multi-minute lower bound on DNS negative-cache entries means that if you ask for the IP address of the new VM too early, you won't see the correct answer for several minutes. This is frustrating. With ``--wait``, downburst waits for the cloud-init run to complete. And we know that the DHCP lease completes before the cloud-init run starts. This does not completely eliminate the above issue (there's still a race if the DNS updating is significantly delayed), but in practice ``--wait`` is enough to make things work.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#cloud-config-archive | ||
|
||
# eject the cdrom (containing the cloud-init metadata) | ||
# as a signal that we've reached full functionality; | ||
# you can poll this via libvirt with | ||
# | ||
# virsh qemu-monitor-command DOMAIN --cmd '{"execute": "query-block"}' | ||
# | ||
- | | ||
#!/bin/sh | ||
exec eject /dev/cdrom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import json | ||
import libvirt_qemu | ||
import time | ||
|
||
from . import exc | ||
|
||
|
||
def is_cdrom_tray_open(domain): | ||
""" | ||
Returns True if even one CD-ROM tray is open. | ||
""" | ||
res = libvirt_qemu.qemuMonitorCommand( | ||
domain, | ||
json.dumps( | ||
{'execute': 'query-block'}, | ||
), | ||
# TODO should force this to be qmp, but python-libvirt 0.9.8 | ||
# doesn't seem to be able to do that | ||
libvirt_qemu.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT, | ||
) | ||
res = json.loads(res) | ||
if 'error' in res: | ||
raise exc.DownburstError( | ||
'Cannot query QEmu for block device state', | ||
res['error'].get('desc'), | ||
) | ||
|
||
cdroms = [dev for dev in res['return'] if 'tray_open' in dev] | ||
if not cdroms: | ||
raise exc.DownburstError( | ||
'VM must have at least one CD-ROM to check tray status', | ||
res['error'].get('desc'), | ||
) | ||
|
||
for dev in cdroms: | ||
if dev['tray_open']: | ||
return True | ||
|
||
return False | ||
|
||
|
||
def wait_for_cdrom_eject(domain): | ||
cd_ejected = False | ||
while not cd_ejected: | ||
cd_ejected = is_cdrom_tray_open(domain) | ||
|
||
if not cd_ejected: | ||
time.sleep(1) |