virt-install: Add --tpm /dev/tpm convenience option

This commit is contained in:
Cole Robinson 2013-09-28 10:28:04 -04:00
parent b3719f25ac
commit 5329a9afc9
3 changed files with 17 additions and 6 deletions

View File

@ -1219,6 +1219,10 @@ An example invocation:
Make the host's TPM accessible to a single guest.
=item B<--tpm /dev/tpm>
Convenience option for passing through the hosts TPM.
=back
See C<http://libvirt.org/formatdomain.html#elementsTpm> for complete

View File

@ -493,7 +493,7 @@ c.add_compare("""--hvm --pxe \
--network bridge=foobar,model=virtio \
--channel spicevmc \
--smartcard passthrough,type=spicevmc \
--tpm passthrough,model=tpm-tis,path=/dev/tpm0 \
--tpm /dev/tpm0 \
--security type=static,label='system_u:object_r:svirt_image_t:s0:c100,c200',relabel=yes \
--numatune \\"1-3,5\\",mode=preferred \
--boot loader=/foo/bar \

View File

@ -893,7 +893,7 @@ def add_device_options(devg):
"--memballoon model=virtio"))
devg.add_option("--tpm", dest="tpm", action="append",
help=_("Configure a guest TPM device. Ex:\n"
"--tpm type=passthrough"))
"--tpm /dev/tpm"))
devg.add_option("--rng", dest="rng", action="append",
help=_("Configure a guest RNG device. Ex:\n"
"--rng /dev/random\n"
@ -989,6 +989,9 @@ def _build_set_param(inst, opts, support_cb=None):
if type(paramname) is not str:
paramname(val)
else:
if not hasattr(inst, paramname):
raise RuntimeError("programming error: obj=%s does not have "
"member=%s" % (inst, paramname))
setattr(inst, paramname, val)
return _set_param
@ -1596,9 +1599,14 @@ def parse_tpm(guest, optstr, dev=None):
opts = parse_optstr(optstr, remove_first="type")
set_param = _build_set_param(dev, opts)
set_param("type", "type")
# Allow --tpm /dev/tpm
if opts.get("type", "").startswith("/"):
dev.device_path = opts.pop("type")
else:
set_param("type", "type")
set_param("model", "model")
set_param("path", "path")
set_param("device_path", "path")
_check_leftover_opts(opts)
return dev
@ -1618,9 +1626,8 @@ def parse_rng(guest, optstr, dev):
opts = parse_optstr(optstr, remove_first="type")
set_param = _build_set_param(dev, opts)
# Allow --rng /dev/random
if opts.get("type", "").startswith("/"):
# if the provided type begins with '/' then assume it is the name of
# the RNG device and that its type is "random".
dev.device = opts.pop("type")
dev.type = "random"
else: