From: Tony Mack Date: Tue, 18 Aug 2009 22:44:13 +0000 (+0000) Subject: filter results if hrn argument is specified X-Git-Tag: sfa-0.9-1~68 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3f590bb20a8f5a396de7eff0e0b235180bda8041;p=sfa.git filter results if hrn argument is specified --- diff --git a/sfa/methods/get_aggregates.py b/sfa/methods/get_aggregates.py index c057fa02..6f5bc7fc 100644 --- a/sfa/methods/get_aggregates.py +++ b/sfa/methods/get_aggregates.py @@ -1,6 +1,6 @@ ### $Id: get_slices.py 14387 2009-07-08 18:19:11Z faiyaza $ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_aggregates.py $ - +from types import StringTypes from sfa.util.faults import * from sfa.util.misc import * from sfa.util.method import Method @@ -32,4 +32,16 @@ class get_aggregates(Method): self.api.auth.check(cred, 'list') aggregates = Aggregates(self.api) - return aggregates.interfaces + hrn_list = [] + if hrn: + if isinstance(hrn, StringTypes): + hrn_list = [hrn] + elif isinstance(hrn, list): + hrn_list = hrn + + if not hrn_list: + interfaces = aggregates.interfaces + else: + interfaces = [interface for interface in aggregates.interfaces if interface['hrn'] in hrn_list] + + return interfaces diff --git a/sfa/methods/get_registries.py b/sfa/methods/get_registries.py index ed46b5a0..69b07519 100644 --- a/sfa/methods/get_registries.py +++ b/sfa/methods/get_registries.py @@ -1,6 +1,6 @@ ### $Id: get_slices.py 14387 2009-07-08 18:19:11Z faiyaza $ ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_registries.py $ - +from types import StringTypes from sfa.util.faults import * from sfa.util.misc import * from sfa.util.method import Method @@ -32,4 +32,17 @@ class get_registries(Method): self.api.auth.check(cred, 'list') registries = Registries(self.api) + hrn_list = [] + if hrn: + if isinstance(hrn, StringTypes): + hrn_list = [hrn] + elif isinstance(hrn, list): + hrn_list = hrn + + if not hrn_list: + interfaces = registries.interfaces + else: + interfaces = [interface for interface in registries.interfaces if interface['hrn'] in hrn_list] + + return interfaces return registries.interfaces