mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-25 06:03:55 +03:00
cli: --rng: use predictable cli subarg names
To match the XML schema, rename these subarguments and add aliases to preserve compatibility: * backend_connect_host -> backend.source.connect_host * backend_connect_service -> backend.source.connect_service * backend_host -> backend.source.host * backend_mode -> backend.source.mode * backend_service -> backend.source.service * backend_type -> backend.type * rate_bytes -> rate.bytes * rate_period -> rate.period 'type', and 'device' are kept as advertised options, due to them being commonly specified and documented
This commit is contained in:
parent
fae52f4784
commit
354dc4df4a
@ -1475,7 +1475,7 @@ be specified:
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<backend_device>
|
||||
=item B<backend>
|
||||
|
||||
The device to use as a source of entropy.
|
||||
|
||||
@ -1485,29 +1485,29 @@ Whereas, when the type is B<egd>, these values must be provided:
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<backend_host>
|
||||
=item B<backend.source.host>
|
||||
|
||||
Specify the host of the Entropy Gathering Daemon to connect to.
|
||||
|
||||
=item B<backend_service>
|
||||
=item B<backend.source.service>
|
||||
|
||||
Specify the port of the Entropy Gathering Daemon to connect to.
|
||||
|
||||
=item B<backend_type>
|
||||
=item B<backend.type>
|
||||
|
||||
Specify the type of the connection: B<tcp> or B<udp>.
|
||||
|
||||
=item B<backend_mode>
|
||||
=item B<backend.source.mode>
|
||||
|
||||
Specify the mode of the connection. It is either 'bind' (wait for
|
||||
connections on HOST:PORT) or 'connect' (send output to HOST:PORT).
|
||||
|
||||
=item B<backend_connect_host>
|
||||
=item B<backend.connect_host>
|
||||
|
||||
Specify the remote host to connect to when the specified backend_type is B<udp>
|
||||
and backend_mode is B<bind>.
|
||||
|
||||
=item B<backend_connect_service>
|
||||
=item B<backend.connect_service>
|
||||
|
||||
Specify the remote service to connect to when the specified backend_type is
|
||||
B<udp> and backend_mode is B<bind>.
|
||||
@ -1518,7 +1518,7 @@ An example invocation:
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<--rng egd,backend_host=localhost,backend_service=8000,backend_type=tcp>
|
||||
=item B<--rng egd,backend.source.host=localhost,backend.source.service=8000,backend.type=tcp>
|
||||
|
||||
Connect to localhost to the TCP port 8000 to get entropy data.
|
||||
|
||||
|
@ -411,7 +411,7 @@
|
||||
<redirdev bus="usb" type="spicevmc"/>
|
||||
<rng model="virtio">
|
||||
<backend model="egd" type="tcp">
|
||||
<source mode="connect" host="127.0.0.1" service="8000"/>
|
||||
<source host="127.0.0.1" service="8000"/>
|
||||
</backend>
|
||||
</rng>
|
||||
<panic model="isa">
|
||||
|
@ -3135,73 +3135,67 @@ class ParserTPM(VirtCLIParser):
|
||||
class ParserRNG(VirtCLIParser):
|
||||
cli_arg_name = "rng"
|
||||
guest_propname = "devices.rng"
|
||||
remove_first = "type"
|
||||
remove_first = "backend.model"
|
||||
stub_none = False
|
||||
aliases = {
|
||||
"backend.type": "backend_type",
|
||||
"backend.source.mode": "backend_mode",
|
||||
"backend.source.host": "backend_host",
|
||||
"backend.source.service": "backend_service",
|
||||
"backend.source.connect_host": "backend_connect_host",
|
||||
"backend.source.connect_service": "backend_connect_service",
|
||||
"rate.bytes": "rate_bytes",
|
||||
"rate.period": "rate_period",
|
||||
}
|
||||
|
||||
def set_hosts_cb(self, inst, val, virtarg):
|
||||
namemap = {}
|
||||
inst.backend_type = inst.cli_backend_type
|
||||
|
||||
if inst.cli_backend_mode == "connect":
|
||||
namemap["backend_host"] = "source.connect_host"
|
||||
namemap["backend_service"] = "source.connect_service"
|
||||
|
||||
if inst.cli_backend_mode == "bind":
|
||||
namemap["backend_host"] = "source.bind_host"
|
||||
namemap["backend_service"] = "source.bind_service"
|
||||
|
||||
if inst.cli_backend_type == "udp":
|
||||
namemap["backend_connect_host"] = "source.connect_host"
|
||||
namemap["backend_connect_service"] = "source.connect_service"
|
||||
|
||||
if virtarg.cliname in namemap:
|
||||
util.set_prop_path(inst, namemap[virtarg.cliname], val)
|
||||
|
||||
def set_backend_cb(self, inst, val, virtarg):
|
||||
if virtarg.cliname == "backend_mode":
|
||||
inst.cli_backend_mode = val
|
||||
elif virtarg.cliname == "backend_type":
|
||||
inst.cli_backend_type = val
|
||||
def _add_advertised_aliases(self):
|
||||
# These are essentially aliases for new style options, but we still
|
||||
# want to advertise them in --rng=help output because they are
|
||||
# historically commonly used. This should rarely, if ever, be extended
|
||||
if "type" in self.optdict:
|
||||
self.optdict["backend.model"] = self.optdict.pop("type")
|
||||
if "device" in self.optdict:
|
||||
self.optdict["backend"] = self.optdict.pop("device")
|
||||
|
||||
def _parse(self, inst):
|
||||
if self.optstr == "none":
|
||||
self.guest.skip_default_rng = True
|
||||
return
|
||||
|
||||
inst.cli_backend_mode = "connect"
|
||||
inst.cli_backend_type = "udp"
|
||||
|
||||
if self.optdict.get("type", "").startswith("/"):
|
||||
# Allow --rng /dev/random
|
||||
self.optdict["device"] = self.optdict.pop("type")
|
||||
self.optdict["type"] = "random"
|
||||
self._add_advertised_aliases()
|
||||
if self.optdict.get("backend.model", "").startswith("/"):
|
||||
# Handle --rng /path/to/dev
|
||||
self.optdict["backend"] = self.optdict.pop("backend.model")
|
||||
self.optdict["backend.model"] = "random"
|
||||
|
||||
return super()._parse(inst)
|
||||
|
||||
|
||||
###################
|
||||
# Option handling #
|
||||
###################
|
||||
|
||||
@classmethod
|
||||
def _init_class(cls, **kwargs):
|
||||
VirtCLIParser._init_class(**kwargs)
|
||||
_add_device_address_args(cls)
|
||||
cls.add_arg("type", "backend_model")
|
||||
# These are handled in _add_advertised_aliases
|
||||
cls.add_arg("type", "backend_model", cb=cls.noset_cb)
|
||||
cls.add_arg("device", "device", cb=cls.noset_cb)
|
||||
|
||||
cls.add_arg("backend_mode", None, lookup_cb=None,
|
||||
cb=cls.set_backend_cb)
|
||||
cls.add_arg("backend_type", None, lookup_cb=None,
|
||||
cb=cls.set_backend_cb)
|
||||
|
||||
cls.add_arg("backend_host", None, lookup_cb=None,
|
||||
cb=cls.set_hosts_cb)
|
||||
cls.add_arg("backend_service", None, lookup_cb=None,
|
||||
cb=cls.set_hosts_cb)
|
||||
cls.add_arg("backend_connect_host", None, lookup_cb=None,
|
||||
cb=cls.set_hosts_cb)
|
||||
cls.add_arg("backend_connect_service", None, lookup_cb=None,
|
||||
cb=cls.set_hosts_cb)
|
||||
|
||||
cls.add_arg("device", "device")
|
||||
cls.add_arg("model", "model")
|
||||
cls.add_arg("rate_bytes", "rate_bytes")
|
||||
cls.add_arg("rate_period", "rate_period")
|
||||
cls.add_arg("backend", "device")
|
||||
cls.add_arg("backend.model", "backend_model")
|
||||
cls.add_arg("backend.type", "backend_type")
|
||||
|
||||
cls.add_arg("backend.source.mode", "source.mode")
|
||||
cls.add_arg("backend.source.host", "source.host")
|
||||
cls.add_arg("backend.source.service", "source.service")
|
||||
cls.add_arg("backend.source.connect_host", "source.connect_host")
|
||||
cls.add_arg("backend.source.connect_service", "source.connect_service")
|
||||
|
||||
cls.add_arg("rate.bytes", "rate_bytes")
|
||||
cls.add_arg("rate.period", "rate_period")
|
||||
|
||||
|
||||
######################
|
||||
|
Loading…
x
Reference in New Issue
Block a user