X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FPCUs.py;h=693f8750c45da0211858e5b80ef530ad1db73498;hb=369a38089afc02f0203fb7894b2eb5d238107cdf;hp=5b69c0aa04a115a2a64498dff427d39eb719cb1a;hpb=e347fc823bbba9d88a3fddf07d5c21024dfd1e55;p=plcapi.git diff --git a/PLC/PCUs.py b/PLC/PCUs.py index 5b69c0a..693f875 100644 --- a/PLC/PCUs.py +++ b/PLC/PCUs.py @@ -4,7 +4,8 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: PCUs.py,v 1.9 2006/11/09 03:07:42 mlhuang Exp $ +# $Id$ +# $URL$ # from PLC.Faults import * @@ -12,7 +13,7 @@ from PLC.Parameter import Parameter from PLC.Filter import Filter from PLC.Debug import profile from PLC.Table import Row, Table -from PLC.NodeNetworks import valid_ip, NodeNetwork, NodeNetworks +from PLC.Interfaces import valid_ip, Interface, Interfaces from PLC.Nodes import Node, Nodes class PCU(Row): @@ -36,6 +37,7 @@ class PCU(Row): 'model': Parameter(str, "PCU model string", max = 32, nullok = True), 'node_ids': Parameter([int], "List of nodes that this PCU controls"), 'ports': Parameter([int], "List of the port numbers that each node is connected to"), + 'last_updated': Parameter(int, "Date and time when node entry was created", ro = True), } def validate_ip(self, ip): @@ -43,6 +45,23 @@ class PCU(Row): raise PLCInvalidArgument, "Invalid IP address " + ip return ip + validate_last_updated = Row.validate_timestamp + + def update_timestamp(self, col_name, commit = True): + """ + Update col_name field with current time + """ + + assert 'pcu_id' in self + assert self.table_name + + self.api.db.do("UPDATE %s SET %s = CURRENT_TIMESTAMP " % (self.table_name, col_name) + \ + " where pcu_id = %d" % (self['pcu_id']) ) + self.sync(commit) + + def update_last_updated(self, commit = True): + self.update_timestamp('last_updated', commit) + def add_node(self, node, port, commit = True): """ Add node to existing PCU. @@ -107,10 +126,12 @@ class PCUs(Table): ", ".join(self.columns) if pcu_filter is not None: - if isinstance(pcu_filter, (list, tuple, set)): + if isinstance(pcu_filter, (list, tuple, set, int, long)): pcu_filter = Filter(PCU.fields, {'pcu_id': pcu_filter}) elif isinstance(pcu_filter, dict): pcu_filter = Filter(PCU.fields, pcu_filter) - sql += " AND (%s)" % pcu_filter.sql(api) + else: + raise PLCInvalidArgument, "Wrong pcu filter %r"%pcu_filter + sql += " AND (%s) %s" % pcu_filter.sql(api) self.selectall(sql)