Skip to content

Commit 873ef46

Browse files
committed
Merge pull request cloudbase#13 from petrutlucian94/master
Provide a reference to the previous instance in case of events
2 parents 4c6d70c + a08bab5 commit 873ef46

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

PyMI/src/wmi/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,21 @@ def _indication_result(self, instance, bookmark, machine_id, more_results,
320320
conn = self._conn_ref()
321321
if conn:
322322
if instance:
323-
event = instance[u"TargetInstance"]
324-
self._events_queue.append(
325-
_Instance(conn, event.clone(), use_conn_weak_ref=True))
323+
event = _Instance(conn,
324+
instance[u"TargetInstance"].clone(),
325+
use_conn_weak_ref=True)
326+
try:
327+
previous_inst = _Instance(
328+
conn, instance[u'PreviousInstance'].clone(),
329+
use_conn_weak_ref=True)
330+
object.__setattr__(event, 'previous', previous_inst)
331+
except (mi.error, AttributeError):
332+
# The 'PreviousInstance' attribute may be missing, for
333+
# example in case of a creation event or simply
334+
# because this field was not requested.
335+
pass
336+
337+
self._events_queue.append(event)
326338
if error_details:
327339
self._error = (
328340
result_code, error_string,

0 commit comments

Comments
 (0)