[virt-tools-list] [virt-manager PATCH] osinfo: warn when using deprecated osinfo IDs

Cole Robinson crobinso at redhat.com
Tue Oct 2 15:23:29 UTC 2018


On 10/02/2018 07:53 AM, Pino Toscano wrote:
> At some point in the future it could be a good idea to drop the _aliases
> mapping altogether; it will be hard to do so, in case the users are not
> informed that they are using a deprecated ID.
>

I had a similar thought just a few days ago!

> Signed-off-by: Pino Toscano <ptoscano at redhat.com>
> ---
>   virtinst/osdict.py | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/virtinst/osdict.py b/virtinst/osdict.py
> index 39422233..b78bcedd 100644
> --- a/virtinst/osdict.py
> +++ b/virtinst/osdict.py
> @@ -192,7 +192,14 @@ class _OSDB(object):
>                   return osobj
>   
>       def lookup_os(self, key):
> -        key = self._aliases.get(key) or key
> +        try:
> +            mapped_key = self._aliases[key]
> +            logging.warning(_("Using a deprecated Guest osinfo %s, "
> +                              "%s will be used instead"),
> +                            key, mapped_key)
> +            key = mapped_key
> +        except KeyError:
> +            pass

I kinda hate the EAFP pattern for this type of stuff so I tweaked it. I 
also tweaked the message to indicate the alias will be removed some day. 
Pushed now

Thanks,
Cole




More information about the virt-tools-list mailing list