Fix version output when missing.
[plcapi.git] / PLC / InterfaceTags.py
1 # $Id$
2 # $URL$
3 #
4 # Thierry Parmentelat - INRIA
5 #
6 # $Revision$
7 #
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Filter import Filter
11 from PLC.Table import Row, Table
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.Interfaces import Interface
14
15 class InterfaceTag(Row):
16     """
17     Representation of a row in the interface_tag.
18     To use, instantiate with a dict of values.
19     """
20
21     table_name = 'interface_tag'
22     primary_key = 'interface_tag_id'
23     fields = {
24         'interface_tag_id': Parameter(int, "Interface setting identifier"),
25         'interface_id': Interface.fields['interface_id'],
26         'ip': Interface.fields['ip'],
27         'tag_type_id': TagType.fields['tag_type_id'],
28         'tagname': TagType.fields['tagname'],
29         'description': TagType.fields['description'],
30         'category': TagType.fields['category'],
31         'min_role_id': TagType.fields['min_role_id'],
32         'value': Parameter(str, "Interface setting value"),
33         ### relations
34
35         }
36
37 class InterfaceTags(Table):
38     """
39     Representation of row(s) from the interface_tag table in the
40     database.
41     """
42
43     def __init__(self, api, interface_tag_filter = None, columns = None):
44         Table.__init__(self, api, InterfaceTag, columns)
45
46         sql = "SELECT %s FROM view_interface_tags WHERE True" % \
47               ", ".join(self.columns)
48
49         if interface_tag_filter is not None:
50             if isinstance(interface_tag_filter, (list, tuple, set, int, long)):
51                 interface_tag_filter = Filter(InterfaceTag.fields, {'interface_tag_id': interface_tag_filter})
52             elif isinstance(interface_tag_filter, dict):
53                 interface_tag_filter = Filter(InterfaceTag.fields, interface_tag_filter)
54             else:
55                 raise PLCInvalidArgument, "Wrong interface setting filter %r"%interface_tag_filter
56             sql += " AND (%s) %s" % interface_tag_filter.sql(api)
57
58
59         self.selectall(sql)