3 # Thierry Parmentelat - INRIA
7 from PLC.Faults import *
8 from PLC.Parameter import Parameter
9 from PLC.Filter import Filter
10 from PLC.Table import Row, Table
11 from PLC.TagTypes import TagType, TagTypes
12 from PLC.Interfaces import Interface
14 class InterfaceTag(Row):
16 Representation of a row in the interface_tag.
17 To use, instantiate with a dict of values.
20 table_name = 'interface_tag'
21 primary_key = 'interface_tag_id'
23 'interface_tag_id': Parameter(int, "Interface setting identifier"),
24 'interface_id': Interface.fields['interface_id'],
25 'ip': Interface.fields['ip'],
26 'tag_type_id': TagType.fields['tag_type_id'],
27 'tagname': TagType.fields['tagname'],
28 'description': TagType.fields['description'],
29 'category': TagType.fields['category'],
30 'min_role_id': TagType.fields['min_role_id'],
31 'value': Parameter(str, "Interface setting value"),
36 class InterfaceTags(Table):
38 Representation of row(s) from the interface_tag table in the
42 def __init__(self, api, interface_tag_filter = None, columns = None):
43 Table.__init__(self, api, InterfaceTag, columns)
45 sql = "SELECT %s FROM view_interface_tags WHERE True" % \
46 ", ".join(self.columns)
48 if interface_tag_filter is not None:
49 if isinstance(interface_tag_filter, (list, tuple, set)):
50 interface_tag_filter = Filter(InterfaceTag.fields, {'interface_tag_id': interface_tag_filter})
51 elif isinstance(interface_tag_filter, dict):
52 interface_tag_filter = Filter(InterfaceTag.fields, interface_tag_filter)
53 elif isinstance(interface_tag_filter, int):
54 interface_tag_filter = Filter(InterfaceTag.fields, {'interface_tag_id': [interface_tag_filter]})
56 raise PLCInvalidArgument, "Wrong interface setting filter %r"%interface_tag_filter
57 sql += " AND (%s) %s" % interface_tag_filter.sql(api)