24
24
class Event(object):
25
25
'''Class representing a Resource state change.'''
27
def __init__(self, context, stack, resource,
28
action, status, reason,
29
physical_resource_id, resource_properties,
30
timestamp=None, id=None):
27
def __init__(self, context, stack, action, status, reason,
28
physical_resource_id, resource_properties, resource_name,
29
resource_type, timestamp=None, id=None):
32
Initialise from a context, stack, resource, event information and
33
current resource data. The timestamp and database ID may also be
34
initialised if the event is already in the database.
31
Initialise from a context, stack, and event information. The timestamp
32
and database ID may also be initialised if the event is already in the
36
35
self.context = context
37
self.resource = resource
39
37
self.action = action
40
38
self.status = status
41
39
self.reason = reason
42
40
self.physical_resource_id = physical_resource_id
41
self.resource_name = resource_name
42
self.resource_type = resource_type
44
44
self.resource_properties = dict(resource_properties)
45
45
except ValueError as ex:
61
61
st = stack if stack is not None else\
62
62
parser.Stack.load(context, ev.stack_id)
63
resource = st[ev.logical_resource_id]
65
return cls(context, st, resource,
66
ev.resource_action, ev.resource_status,
67
ev.resource_status_reason,
68
ev.physical_resource_id, ev.resource_properties,
64
return cls(context, st, ev.resource_action, ev.resource_status,
65
ev.resource_status_reason, ev.physical_resource_id,
66
ev.resource_properties, ev.resource_name,
67
ev.resource_type, ev.created_at, ev.id)
72
70
'''Store the Event in the database.'''
74
'logical_resource_id': self.resource.name,
72
'resource_name': self.resource_name,
75
73
'physical_resource_id': self.physical_resource_id,
76
74
'stack_id': self.stack.id,
77
75
'resource_action': self.action,
78
76
'resource_status': self.status,
79
77
'resource_status_reason': self.reason,
80
'resource_type': self.resource.type(),
78
'resource_type': self.resource_type,
81
79
'resource_properties': self.resource_properties,
96
94
if self.id is None:
99
return identifier.EventIdentifier(event_id=str(self.id),
100
**self.resource.identifier())
97
res_id = identifier.ResourceIdentifier(
98
resource_name=self.resource_name, **self.stack.identifier())
100
return identifier.EventIdentifier(event_id=str(self.id), **res_id)