rename IlinkType into LinkType as these types will be used for Nlinks as well
[plcapi.git] / PLC / Ilinks.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 # $Revision: 9423 $
5 #
6 from PLC.Faults import *
7 from PLC.Parameter import Parameter
8 from PLC.Filter import Filter
9 from PLC.Table import Row, Table
10 from PLC.Interfaces import Interface, Interfaces
11 from PLC.LinkTypes import LinkType, LinkTypes
12
13 class Ilink(Row):
14     """
15     Representation of a row in the ilink table.
16     To use, instantiate with a dict of values.
17     """
18
19     table_name = 'ilink'
20     primary_key = 'ilink_id'
21     fields = {
22         'ilink_id': Parameter(int, "ilink identifier"),
23         'link_type_id': LinkType.fields['link_type_id'],
24         'src_interface_id': Parameter(int, "source interface identifier"),
25         'dst_interface_id': Parameter(int, "destination interface identifier"),
26         'value': Parameter( str, "optional ilink value"),
27         }
28
29 class Ilinks(Table):
30     """
31     Representation of row(s) from the ilink table in the
32     database.
33     """
34
35     def __init__(self, api, ilink_filter = None, columns = None):
36         Table.__init__(self, api, Ilink, columns)
37
38         sql = "SELECT %s FROM view_ilinks WHERE True" % \
39               ", ".join(self.columns)
40
41         if ilink_filter is not None:
42             if isinstance(ilink_filter, (list, tuple, set)):
43                 ilink_filter = Filter(Ilink.fields, {'ilink_id': ilink_filter})
44             elif isinstance(ilink_filter, dict):
45                 ilink_filter = Filter(Ilink.fields, ilink_filter)
46             elif isinstance(ilink_filter, int):
47                 ilink_filter = Filter(Ilink.fields, {'ilink_id': [ilink_filter]})
48             else:
49                 raise PLCInvalidArgument, "Wrong ilink filter %r"%ilink_filter
50             sql += " AND (%s) %s" % ilink_filter.sql(api)
51
52
53         self.selectall(sql)