- view = "view_interfaces"
- # as many left joins as requested tags
- for tagname in self.tag_columns:
- view= "%s left join %s using (%s)"%(view,Interface.tagvalue_view_name(tagname),
- Interface.primary_key)
-
- sql = "SELECT %s FROM %s WHERE True" % \
- (", ".join(self.columns.keys()+self.tag_columns.keys()),view)
-
- if interface_filter is not None:
- if isinstance(interface_filter, (list, tuple, set)):
- # Separate the list into integers and strings
- ints = filter(lambda x: isinstance(x, (int, long)), interface_filter)
- strs = filter(lambda x: isinstance(x, StringTypes), interface_filter)
- interface_filter = Filter(Interface.fields, {'interface_id': ints, 'ip': strs})
- sql += " AND (%s) %s" % interface_filter.sql(api, "OR")
- elif isinstance(interface_filter, dict):
- allowed_fields=dict(Interface.fields.items()+Interface.tags.items())
- interface_filter = Filter(allowed_fields, interface_filter)
- sql += " AND (%s) %s" % interface_filter.sql(api)
- elif isinstance(interface_filter, int):
- interface_filter = Filter(Interface.fields, {'interface_id': [interface_filter]})
- sql += " AND (%s) %s" % interface_filter.sql(api)
- elif isinstance (interface_filter, StringTypes):
- interface_filter = Filter(Interface.fields, {'ip':[interface_filter]})
- sql += " AND (%s) %s" % interface_filter.sql(api, "AND")
- else:
- raise PLCInvalidArgument, "Wrong interface filter %r"%interface_filter
-
- self.selectall(sql)
+ if not interface_filter:
+ interfaces = Interface().select()
+ elif isinstance(interface_filter, (list, tuple, set)):
+ # Separate the list into integers and strings
+ ints = filter(lambda x: isinstance(x, (int, long)), interface_filter)
+ strs = filter(lambda x: isinstance(x, StringTypes), interface_filter)
+ interfaces = Interface().select(filter={'interface_id': ints, 'ip': strs})
+ elif isinstance(interface_filter, dict):
+ interfaces = Interface().select(filter=interface_filter})
+ elif isinstance(interface_filter, int):
+ interfaces = Interface().select(filter={'interface_id': interface_filter})
+ elif isinstance (interface_filter, StringTypes):
+ interfaces = Interface().select(filter={'ip': interface_filter})
+ else:
+ raise PLCInvalidArgument, "Wrong interface filter %r"%interface_filter
+
+ for interface in interfaces:
+ self.append(interface)