X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPCUs.py;h=298094c205192d041faa37a8e7a9b1e1454ae3db;hb=e795c7325c38c212ed525e567fe028e8ed0c8e90;hp=28d50d6f152a029b35ceaa0869887ff6ccb92386;hpb=c292f0b768fcaa05218cf5ffdda5672e6ea9ffe6;p=plcapi.git diff --git a/PLC/Methods/GetPCUs.py b/PLC/Methods/GetPCUs.py index 28d50d6..298094c 100644 --- a/PLC/Methods/GetPCUs.py +++ b/PLC/Methods/GetPCUs.py @@ -1,3 +1,5 @@ +# $Id$ +# $URL$ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed @@ -32,7 +34,7 @@ class GetPCUs(Method): returns = [PCU.fields] def call(self, auth, pcu_filter = None, return_fields = None): - # If we are not admin + # If we are not admin if not (isinstance(self.caller, Person) and 'admin' in self.caller['roles']): # Return only the PCUs at our site valid_pcu_ids = [] @@ -51,10 +53,23 @@ class GetPCUs(Method): if pcu_filter is None: pcu_filter = valid_pcu_ids + # Must query at least slice_id (see below) + if return_fields is not None and 'pcu_id' not in return_fields: + return_fields.append('pcu_id') + added_fields = True + else: + added_fields = False + pcus = PCUs(self.api, pcu_filter, return_fields) # Filter out PCUs that are not viewable if not (isinstance(self.caller, Person) and 'admin' in self.caller['roles']): pcus = filter(lambda pcu: pcu['pcu_id'] in valid_pcu_ids, pcus) + # Remove pcu_id if not specified + if added_fields: + for pcu in pcus: + if 'pcu_id' in pcu: + del pcu['pcu_id'] + return pcus