3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Events import Event, Events
7 from PLC.Auth import Auth
9 class GetEvents(Method):
11 Return an array of dictionaries containing details about the
14 if object_ids is specified, and object_types must be specified
15 with only 1 object type
18 roles = ['admin', 'pi', 'user', 'tech']
22 [Event.fields['event_id']],
23 [Event.fields['person_id']],
24 Event.fields['object_ids'],
25 [Event.fields['event_type']],
26 [Event.fields['object_type']],
27 [Event.fields['fault_code']]
30 returns = [Event.fields]
32 def __init__(self, *args, **kwds):
33 Method.__init__(self, *args, **kwds)
34 # Update documentation with list of default fields returned
35 self.__doc__ += os.linesep.join(Event.fields.keys())
37 def call(self, auth, event_id_list = None, person_id_list = None, event_type_list = None, object_type_list = None, object_id_list = None, fault_code_list = None):
39 # Authenticated function
40 assert self.caller is not None
42 # filter out invalid event types
44 valid_event_types = ['Add', 'AddTo', 'Get', 'Update', 'Delete', \
45 'DeleteFrom', 'Unknown']
46 if filter(lambda field: field not in valid_event_types, event_type_list):
47 raise PLCInvalidArgument, "Invalid event type. Must be in %s" % \
50 # filter out invalid object types
52 valid_object_types = ['AddreessType', 'Address', 'BootState', 'ConfFile', \
53 'KeyType', 'Key', 'NetworkType', 'NodeGroup',\
54 'NodeNetwork', 'Node', 'PCU', 'Perons', 'Site', \
55 'SliceAttributeType', 'SliceAttribute', 'Slice', 'Unknown']
56 if filter(lambda field: field not in valid_object_types, object_type_list):
57 raise PLCInvalidArgument, "Invalid object type. Must be in %s" % \
60 # if object ids are specified only 1 object type can be specified
62 if not object_type_list:
63 raise PLCInvalidArgument, "Object type must be specified"
64 elif len(object_type_list) > 1:
65 raise PLCInvalidArgument, "Cannot specify multiple object types when object_ids are specified"
67 # Get node information
68 return Events(self.api, event_id_list, person_id_list, event_type_list, \
69 object_type_list, object_id_list, fault_code_list).values()