added refresh()
[plcapi.git] / PLC / PCUNodePorts.py
1 from types import StringTypes
2 import time
3 import re
4 import datetime
5
6 from PLC.Faults import *
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Filter import Filter
9 from PLC.Debug import profile
10 from PLC.Timestamp import Timestamp
11 from PLC.Storage.AlchemyObject import AlchemyObj
12
13 class PCUNodePort(AlchemyObj):
14     """
15     Representation of a row in the pcu_node_ports table. To use, optionally
16     instantiate with a dict of values. Update as you would a
17     dict. Commit to the database with sync().To use, instantiate
18     with a dict of values.
19     """
20
21     tablename = 'pcu_node_port'
22  
23     fields = {
24         'pcu_id': Parameter(int, "PCU identifier", primary_key=True),
25         'node_id': Parameter(int, "Node identifier", primary_key=True),
26         'port': Parameter(int, "port", indexed=True),
27         }
28
29     tags = {}
30
31     def sync(self, commit = True, validate=True):
32         """
33         Add the record
34         """
35         AlchemyObj.sync(self, commit, validate)
36         AlchemyObj.insert(self, dict(self))
37
38     def delete(self, commit = True):
39         """
40         Delete existing slice.
41         """
42         AlchemyObj.delete(self, dict(self))
43
44
45 class PCUNodePorts(list):
46     """
47     Representation of row(s) from the pcu_node_port table in the
48     database.
49     """
50
51     def __init__(self, api, filter = None, columns = None):
52          
53         # the view that we're selecting upon: start with view_slices
54         if not filter:
55             pcu_node_ports = PCUNodePort().select()
56         elif isinstance(filter, dict):
57             pcu_node_ports = PCUNodePort().select(filter=filter)
58         else:
59             raise PLCInvalidArgument, "Wrong pcu_node_port filter %r"%filter
60
61         for pcu_node_port in pcu_node_ports:
62             self.append(PCUNodePort(api, object=pcu_node_port))