[virt-tools-list] [virt-manager] [PATCH 1/4] libvirtenummap: Map state vals of agent event to libvirt enum names

Cole Robinson crobinso at redhat.com
Tue Jun 26 21:37:18 UTC 2018


On 06/24/2018 11:46 PM, Lin Ma wrote:
> Signed-off-by: Lin Ma <lma at suse.com>
> ---
>  virtManager/libvirtenummap.py | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/virtManager/libvirtenummap.py b/virtManager/libvirtenummap.py
> index eaad0374..71e4a5eb 100644
> --- a/virtManager/libvirtenummap.py
> +++ b/virtManager/libvirtenummap.py
> @@ -18,13 +18,15 @@ class _LibvirtEnumMap(object):
>      """
>      # Some values we define to distinguish between API objects
>      (DOMAIN_EVENT,
> +     DOMAIN_AGENT_EVENT,
>       NETWORK_EVENT,
>       STORAGE_EVENT,
> -     NODEDEV_EVENT) = range(1, 5)
> +     NODEDEV_EVENT) = range(1, 6)
>  
>      # Regex map for naming all event types depending on the API object
>      _EVENT_PREFIX = {
>          DOMAIN_EVENT: "VIR_DOMAIN_EVENT_ID_",
> +        DOMAIN_AGENT_EVENT: "VIR_DOMAIN_EVENT_ID_AGENT_",
>          NETWORK_EVENT: "VIR_NETWORK_EVENT_ID_",
>          STORAGE_EVENT: "VIR_STORAGE_POOL_EVENT_ID_",
>          NODEDEV_EVENT: "VIR_NODE_DEVICE_EVENT_ID_",
> @@ -33,6 +35,8 @@ class _LibvirtEnumMap(object):
>      # Regex map for 'state' values returned from lifecycle and other events
>      _DETAIL1_PREFIX = {
>          "VIR_DOMAIN_EVENT_ID_LIFECYCLE": "VIR_DOMAIN_EVENT_[^_]+$",
> +        "VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE": _("VIR_CONNECT_DOMAIN_EVENT_AGENT"
> +                                                 "_LIFECYCLE_STATE_[^_]+$"),
>          "VIR_NETWORK_EVENT_ID_LIFECYCLE": "VIR_NETWORK_EVENT_[^_]+$",
>          "VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE": "VIR_STORAGE_POOL_EVENT_[^_]+$",
>          "VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE": "VIR_NODE_DEVICE_EVENT_[^_]+$",
> @@ -161,7 +165,9 @@ class _LibvirtEnumMap(object):
>          detail2str = str(detail2)
>          eventmap = self._get_map(api, self._EVENT_PREFIX[api])
>  
> -        if event in eventmap:
> +        if eventmap:
> +            if event not in eventmap:
> +                event = next(iter(eventmap))

I can't really tell what this magic bit is doing, can you explain?

Thanks,
Cole

>              eventstr = eventmap[event]
>              detail1map = self._get_map(eventstr,
>                      self._DETAIL1_PREFIX.get(eventstr))
> @@ -187,6 +193,8 @@ class _LibvirtEnumMap(object):
>          return self._state_str(self.STORAGE_EVENT, detail1, detail2)
>      def nodedev_lifecycle_str(self, detail1, detail2):
>          return self._state_str(self.NODEDEV_EVENT, detail1, detail2)
> +    def domain_agent_lifecycle_str(self, detail1, detail2):
> +        return self._state_str(self.DOMAIN_AGENT_EVENT, detail1, detail2)
>  
>  
>  LibvirtEnumMap = _LibvirtEnumMap()
> 




More information about the virt-tools-list mailing list