2 # Functions for interacting with the network_methods table in the database
5 from types import StringTypes
6 from PLC.Faults import *
7 from PLC.Parameter import Parameter
8 from PLC.Storage.AlchemyObject import AlchemyObj
10 class NetworkMethod(AlchemyObj):
12 Representation of a row in the network_methods table. To use,
13 instantiate with a dict of values.
16 tablename = 'network_methods'
17 join_tables = ['interfaces']
19 'method': Parameter(str, "Network method", max = 20, primary_key=True),
22 def validate_method(self, name):
23 # Make sure name is not blank
25 raise PLCInvalidArgument, "Network method must be specified"
27 # Make sure network method does not alredy exist
28 conflicts = NetworkMethods(self.api, name)
30 raise PLCInvalidArgument, "Network method name already in use"
34 def sync(self, commit = True, validate=True):
35 AlchemyObj.sync(self, commit, validate)
36 AlchemyObj.insert(self, dict(self))
38 def delete(self, commit=True):
39 assert 'method' in self
40 AlchemyObj.delete(self, dict(self))
43 class NetworkMethods(list):
45 Representation of the network_methods table in the database.
48 def __init__(self, api, methods = None):
51 network_methods = NetworkMethod().select()
52 elif isinstance(methods, StringTypes):
53 network_methods = NetworkMethod().select(filter={'method': methods})
55 raise PLCInvalidArgument, "Wrong network method filter %r"%methods
57 self.extend(network_methods)