The key of instance status metadata which was generated from notification source is "state", but the key is "status" when the meter data was generated from polling. Because the meter data generated from notification or polling update the resource information in cycles, the show resource API will return the same type metadata with different key:
Sometimes it return:
{……
metadata :{'state':'active',……}
……}
But at other times, it return:
{……
metadata :{'status':'active',……}
……}
In some situations, this problems may confuse us. (e.g. Recently we develop a billing component for openstack, and we call the show resource API of ceilometer to retrieve the resource information, and get the current status of instance via code 'metadata['state']', but sometimes the above code will cause 'key error' issue due to this problem)
Reviewed: https:/ /review. openstack. org/219552 /git.openstack. org/cgit/ openstack/ ceilometer/ commit/ ?id=d054c7c7407 f5f20e6b01f1515 29bf44fe8ef577
Committed: https:/
Submitter: Jenkins
Branch: master
commit d054c7c7407f5f2 0e6b01f151529bf 44fe8ef577
Author: xiangjun li <email address hidden>
Date: Mon Sep 14 13:14:07 2015 +0800
Add attribute 'state' to meter metadata when source is polling
For now, instance attribute 'state' is stored to
metadata of meter which was generated from
notifications. But when meter was generated from
instance polling, 'state' is not stored to
metadata of meter even this attribute could be
retrieved from polling action. Because the meter
generated from notifications or polling update
the resource information in database in cycles,
the resource show API may return the instance
metadata with different style(sometimes the
returned metadata contains 'state', but at other
times, the 'state' is disappeared in it), which
may confuse us in some situations. In this patch,
'state' has been added to the meter metadata if
the meter was generated from polling source.
Closes-Bug: #1491224
Change-Id: Ie869672901b1d1 3f9444d0ca0e7d8 49f5e4ffc4b