Revision 20f5cdbd

b/lib/hypervisor/hv_kvm.py
43 43
import struct
44 44
import fcntl
45 45
import shutil
46
import urllib2
46 47
import socket
47 48
import stat
48 49
import StringIO
......
356 357
  return (ifname, tapfd)
357 358

  
358 359

  
360
def _CheckUrl(url):
361
  """Check if a given URL exists on the server
362

  
363
  """
364
  req = urllib2.Request(url)
365

  
366
  # XXX: ugly but true
367
  req.get_method = lambda: "HEAD"
368

  
369
  try:
370
    resp = urllib2.urlopen(req)
371
  except urllib2.URLError:
372
    return False
373

  
374
  del resp
375
  return True
376

  
377

  
359 378
class QmpMessage:
360 379
  """QEMU Messaging Protocol (QMP) message.
361 380

  
......
1474 1493
    iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
1475 1494
    if iso_image:
1476 1495
      options = ",media=cdrom"
1477
      if not re.match(r'(https?|ftps?)://', iso_image):
1496
      if re.match(r'(https?|ftps?)://', iso_image):
1497
        # Check that the iso image is really there
1498
        # See https://bugs.launchpad.net/qemu/+bug/597575
1499
        if not _CheckUrl(iso_image):
1500
          raise errors.HypervisorError("ISO image %s is not accessible" %
1501
                                       iso_image)
1502
      else:
1478 1503
        options = "%s,format=raw" % options
1479 1504
      # set cdrom 'if' type
1480 1505
      if boot_cdrom:

Also available in: Unified diff