Revision 43fcf0d3

b/lib/hypervisor/hv_kvm.py
34 34
import struct
35 35
import fcntl
36 36
import shutil
37
import urllib2
37 38

  
38 39
from ganeti import utils
39 40
from ganeti import constants
......
127 128
  return (ifname, tapfd)
128 129

  
129 130

  
131
def _CheckUrl(url):
132
  """Check if a given URL exists on the server
133

  
134
  """
135
  req = urllib2.Request(url)
136

  
137
  # XXX: ugly but true
138
  req.get_method = lambda: "HEAD"
139

  
140
  try:
141
    resp = urllib2.urlopen(req)
142
  except urllib2.URLError:
143
    return False
144

  
145
  del resp
146
  return True
147

  
148

  
130 149
class KVMHypervisor(hv_base.BaseHypervisor):
131 150
  """KVM hypervisor interface"""
132 151
  CAN_MIGRATE = True
......
568 587
    iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
569 588
    if iso_image:
570 589
      options = ',media=cdrom'
571
      if not re.match(r'(https?|ftp)://', iso_image):
590
      if re.match(r'(https?|ftp)://', iso_image):
591
        # Check that the iso image is really there
592
        # See https://bugs.launchpad.net/qemu/+bug/597575
593
        if not _CheckUrl(iso_image):
594
          raise errors.HypervisorError("ISO image %s is not accessible" %
595
                                       iso_image)
596
      else:
572 597
        options = "%s,format=raw" % options
573 598
      if boot_cdrom:
574 599
        kvm_cmd.extend(['-boot', 'd'])

Also available in: Unified diff