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

Lin Ma lma at suse.com
Sat Jun 30 05:22:45 UTC 2018



On 06/27/2018 05:37 AM, Cole Robinson wrote:
> 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

Due to the value of incoming parameter 'event' is always 0, So without 
the above
changes, it always search key '0' in dictionary eventmap, It's fine for 
DOMAIN_EVENT,
NETWORK_EVENT, STORAGE_EVENT and NODEDEV_EVENT because there is always 
key '0' exists.
e.g.
when a nodedev event is coming, the key/value of dictionary eventmap are:
eventmap={0: 'VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE', 1: 
'VIR_NODE_DEVICE_EVENT_ID_UPDATE'}
or
when a domain event is coming, the key/value of dictionary eventmap are:
eventmap={18: 'VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE', 13: 
'VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE', 8: 
'VIR_DOMAIN_EVENT_ID_BLOCK_JOB', 16: 'VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2', 
24: 'VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD', 7: 
'VIR_DOMAIN_EVENT_ID_CONTROL_ERROR', 19: 
'VIR_DOMAIN_EVENT_ID_DEVICE_ADDED', 22: 
'VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED', 15: 
'VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED', 9: 
'VIR_DOMAIN_EVENT_ID_DISK_CHANGE', 5: 'VIR_DOMAIN_EVENT_ID_GRAPHICS', 4: 
'VIR_DOMAIN_EVENT_ID_IO_ERROR', 6: 
'VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON', 21: 
'VIR_DOMAIN_EVENT_ID_JOB_COMPLETED', 0: 'VIR_DOMAIN_EVENT_ID_LIFECYCLE', 
23: 'VIR_DOMAIN_EVENT_ID_METADATA_CHANGE', 20: 
'VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION', 12: 
'VIR_DOMAIN_EVENT_ID_PMSUSPEND', 14: 
'VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK', 11: 
'VIR_DOMAIN_EVENT_ID_PMWAKEUP', 1: 'VIR_DOMAIN_EVENT_ID_REBOOT', 2: 
'VIR_DOMAIN_EVENT_ID_RTC_CHANGE', 10: 'VIR_DOMAIN_EVENT_ID_TRAY_CHANGE', 
17: 'VIR_DOMAIN_EVENT_ID_TUNABLE', 3: 'VIR_DOMAIN_EVENT_ID_WATCHDOG'}

But it's not ok for DOMAIN_AGENT_EVENT because there is no key '0' in 
dictionary eventmap when
a domain agent event is coming, eventmap={18: 
'VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE'}
So I made the above code chage, when eventmap not null and event not in 
eventmap, just use the next
available key in dictionary eventmap instead of key '0', This way we can 
get the available eventstr
and the detail1map.

>>               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