From: Tony Mack Date: Tue, 2 Oct 2012 01:37:08 +0000 (-0400) Subject: updated parameters X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0d3b8300d26a363a5656ec3678020d7c4b06d2ca;p=plcapi.git updated parameters --- diff --git a/PLC/PCUs.py b/PLC/PCUs.py index f4eaa342..985a2511 100644 --- a/PLC/PCUs.py +++ b/PLC/PCUs.py @@ -7,9 +7,7 @@ from PLC.Faults import * from PLC.Parameter import Parameter -from PLC.Filter import Filter from PLC.Debug import profile -from PLC.Table import Row, Table from PLC.Storage.AlchemyObject import AlchemyObj from PLC.Interfaces import valid_ip, Interface, Interfaces from PLC.Nodes import Node, Nodes @@ -32,8 +30,8 @@ class PCU(AlchemyObj): 'password': Parameter(str, "PCU username", max = 254, nullok = True), 'notes': Parameter(str, "Miscellaneous notes", max = 254, nullok = True), '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", ro=True), + 'node_ids': Parameter([int], "List of nodes that this PCU controls", joined=True), + 'ports': Parameter([int], "List of the port numbers that each node is connected to", joined=True), 'last_updated': Parameter(int, "Date and time when node entry was created"), } @@ -42,19 +40,13 @@ class PCU(AlchemyObj): raise PLCInvalidArgument, "Invalid IP address " + ip return ip - validate_last_updated = Row.validate_timestamp + validate_last_updated = AlchemyObj.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) + pass def update_last_updated(self, commit = True): self.update_timestamp('last_updated', commit) @@ -110,12 +102,15 @@ class PCU(AlchemyObj): self['node_ids'].remove(node_id) self['ports'].remove(port) - def sync(self, insert=False, validate=True): - AlchemyObj.sync(self, insert, validate): - if insert == True or 'id' not in self: + def sync(self, commit, validate=True): + AlchemyObj.sync(self, commit=commit, valiate=validate): + if 'pcu_id' not in self: AlchemyObj.insert(self, dict(self)) else: - AlchemyObj.delete(self, dict(self)) + AlchemyObj.delete(self, {'pcu_id': self['pcu_id']}, dict(self)) + + def delete(self, commit=True): + AlchemyObj.delete(self, dict(self)) class PCUs(list): """ @@ -134,7 +129,6 @@ class PCUs(list): pcus= PCU().select(filter=pcu_filter) else: raise PLCInvalidArgument, "Wrong pcu filter %r"%pcu_filter - sql += " AND (%s) %s" % pcu_filter.sql(api) for pcu in pcus: self.append(pcu)