svn keywords
[plcapi.git] / PLC / Methods / GetPCUTypes.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.PCUTypes import PCUType, PCUTypes
7 from PLC.Auth import Auth
8 from PLC.Filter import Filter
9
10 class GetPCUTypes(Method):
11     """
12     Returns an array of PCU Types.
13     """
14
15     roles = ['admin', 'pi', 'user', 'tech', 'node']
16
17     accepts = [
18         Auth(),
19         Mixed([Mixed(PCUType.fields['pcu_type_id'],
20                      PCUType.fields['model'])],
21                Parameter(str, 'model'),
22                Parameter(int, 'node_id'),               
23                Filter(PCUType.fields)),
24         Parameter([str], "List of fields to return", nullok = True)
25         ]
26
27     returns = [PCUType.fields]
28     
29
30     def call(self, auth, pcu_type_filter = None, return_fields = None):
31
32         #Must query at least pcu_type_id
33         if return_fields is not None:
34             added_fields = []
35             if 'pcu_type_id' not in return_fields:
36                 return_fields.append('pcu_type_id')
37                 added_fields.append('pcu_type_id')
38             if 'pcu_protocol_types' in return_fields and \
39                'pcu_protocol_type_ids' not in return_fields:
40                 return_fields.append('pcu_protocol_type_ids')
41                 added_fields.append('pcu_protocol_type_ids') 
42         else:
43             added_fields = []
44
45         pcu_types = PCUTypes(self.api, pcu_type_filter, return_fields)
46
47         # remove added fields and protocol_types
48         for added_field in added_fields:
49             for pcu_type in pcu_types:
50                 del pcu_type[added_field]
51                 
52         return pcu_types