From 19d3c95c7f25501d6cef72340a5c19ae1489b064 Mon Sep 17 00:00:00 2001 From: Claudio-Daniel Freire Date: Tue, 12 Jul 2011 18:21:45 +0200 Subject: [PATCH] Allow filtering attributes that do NOT have some flags (in get_attribute_list) --- src/nepi/core/attributes.py | 14 ++++++++++++-- src/nepi/core/execute.py | 2 +- src/nepi/core/testbed_impl.py | 4 ++-- src/nepi/util/proxy.py | 6 +++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/nepi/core/attributes.py b/src/nepi/core/attributes.py index 75a21166..3de13cff 100644 --- a/src/nepi/core/attributes.py +++ b/src/nepi/core/attributes.py @@ -168,12 +168,22 @@ class AttributesMap(object): def attributes(self): return self._attributes.values() - def get_attribute_list(self, filter_flags = None): + def get_attribute_list(self, filter_flags = None, exclude = False): + """ + Returns the list of attributes. + + Params: + filter_flags: if given, only attributes with (all) the specified + flags will be returned. + + exclude: if True, only attributes without (any of) the specified + flags will be returned. + """ attributes = self._attributes if filter_flags != None: def filter_attrs(attr_data): (attr_id, attr) = attr_data - return attr.has_flag(filter_flags) + return attr.has_flag(filter_flags) == (not exclude) attributes = dict(filter(filter_attrs, attributes.iteritems())) return attributes.keys() diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py index 84def93c..70df1c70 100644 --- a/src/nepi/core/execute.py +++ b/src/nepi/core/execute.py @@ -165,7 +165,7 @@ class TestbedController(object): """ raise NotImplementedError - def get_attribute_list(self, guid, filter_flags = None): + def get_attribute_list(self, guid, filter_flags = None, exclude = False): raise NotImplementedError def get_factory_id(self, guid): diff --git a/src/nepi/core/testbed_impl.py b/src/nepi/core/testbed_impl.py index 4b200565..336da507 100644 --- a/src/nepi/core/testbed_impl.py +++ b/src/nepi/core/testbed_impl.py @@ -374,10 +374,10 @@ class TestbedController(execute.TestbedController): return addresses[index][attribute_index] - def get_attribute_list(self, guid, filter_flags = None): + def get_attribute_list(self, guid, filter_flags = None, exclude = False): factory = self._get_factory(guid) attribute_list = list() - return factory.box_attributes.get_attribute_list(filter_flags) + return factory.box_attributes.get_attribute_list(filter_flags, exclude) def get_factory_id(self, guid): factory = self._get_factory(guid) diff --git a/src/nepi/util/proxy.py b/src/nepi/util/proxy.py index 45943c69..c89f1d88 100644 --- a/src/nepi/util/proxy.py +++ b/src/nepi/util/proxy.py @@ -650,10 +650,10 @@ class TestbedControllerServer(BaseServer): return self._testbed.status(guid) @Marshalling.handles(GET_ATTRIBUTE_LIST) - @Marshalling.args(int, int) + @Marshalling.args(int, int, Marshalling.bool) @Marshalling.retval( Marshalling.pickled_data ) - def get_attribute_list(self, guid, filter_flags = None): - return self._testbed.get_attribute_list(guid, filter_flags) + def get_attribute_list(self, guid, filter_flags = None, exclude = False): + return self._testbed.get_attribute_list(guid, filter_flags, exclude) @Marshalling.handles(GET_FACTORY_ID) @Marshalling.args(int) -- 2.43.0