Commit f15a6b03 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Allow KVM to boot from HTTP



New versions of KVM support booting from HTTP-hosted ISO images, via
libcurl. This patch adds a proper check to allow defining either a sane,
absolute path or an HTTP URL as an iso image path.

Remove "format=raw" from the cdrom device options when iso_image starts
with "(https?|ftps?)://", to allow latest KVM versions (qemu-kvm) to boot
from HTTP-hosted iso images. Added FILE_OR_URL check to allow booting
from HTTP (kvm).
Signed-off-by: default avatarApollon Oikonomopoulos <apollon@noc.grnet.gr>
Signed-off-by: default avatarChristos Stavrakakis <cstavr@grnet.gr>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent e86c427c
......@@ -83,6 +83,13 @@ def _IsMultiCpuMaskWellFormed(cpu_mask):
_FILE_CHECK = (utils.IsNormAbsPath, "must be an absolute normalized path",
os.path.isfile, "not found or not a file")
# must be a file or a URL
_FILE_OR_URL_CHECK = (utils.IsNormAbsPathOrURL,
"must be an absolute normalized path or a URL",
lambda x: os.path.isfile(x) or
re.match(r'(https?|ftps?)://', x),
"not found or not a file or URL")
# must be a directory
_DIR_CHECK = (utils.IsNormAbsPath, "must be an absolute normalized path",
os.path.isdir, "not found or not a directory")
......@@ -108,6 +115,8 @@ _NONNEGATIVE_INT_CHECK = (lambda x: x >= 0, "cannot be negative", None, None)
# nice wrappers for users
REQ_FILE_CHECK = (True, ) + _FILE_CHECK
OPT_FILE_CHECK = (False, ) + _FILE_CHECK
REQ_FILE_OR_URL_CHECK = (True, ) + _FILE_OR_URL_CHECK
OPT_FILE_OR_URL_CHECK = (False, ) + _FILE_OR_URL_CHECK
REQ_DIR_CHECK = (True, ) + _DIR_CHECK
OPT_DIR_CHECK = (False, ) + _DIR_CHECK
REQ_NET_PORT_CHECK = (True, ) + _NET_PORT_CHECK
......
......@@ -678,7 +678,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
constants.HV_KVM_SPICE_TLS_CIPHERS: hv_base.NO_CHECK,
constants.HV_KVM_SPICE_USE_VDAGENT: hv_base.NO_CHECK,
constants.HV_KVM_FLOPPY_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_CDROM_IMAGE_PATH: hv_base.OPT_FILE_OR_URL_CHECK,
constants.HV_KVM_CDROM2_IMAGE_PATH: hv_base.OPT_FILE_CHECK,
constants.HV_BOOT_ORDER:
hv_base.ParamInSet(True, constants.HT_KVM_VALID_BO_TYPES),
......@@ -1426,7 +1426,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
iso_image = hvp[constants.HV_CDROM_IMAGE_PATH]
if iso_image:
options = ",format=raw,media=cdrom"
options = ",media=cdrom"
if not re.match(r'(https?|ftps?)://', iso_image):
options = "%s,format=raw" % options
# set cdrom 'if' type
if boot_cdrom:
actual_cdrom_type = constants.HT_DISK_IDE
......
......@@ -23,6 +23,7 @@
"""
import os
import re
import logging
import shutil
import tempfile
......@@ -669,6 +670,13 @@ def IsBelowDir(root, other_path):
return os.path.commonprefix([prepared_root, norm_other]) == prepared_root
def IsNormAbsPathOrURL(path):
"""Check whether a path is absolute and normalized, or an HTTP URL.
"""
return IsNormAbsPath(path) or re.match(r'(https?|ftps?)://', path)
def PathJoin(*args):
"""Safe-join a list of path components.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment