2 # Functions for interacting with the network_methods table in the database
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2006 The Trustees of Princeton University
8 from PLC.Faults import *
9 from PLC.Parameter import Parameter
10 from PLC.Table import Row, Table
12 class NetworkMethod(Row):
14 Representation of a row in the network_methods table. To use,
15 instantiate with a dict of values.
18 table_name = 'network_methods'
19 primary_key = 'method'
20 join_tables = ['interfaces']
22 'method': Parameter(str, "Network method", max = 20),
25 def validate_method(self, name):
26 # Make sure name is not blank
28 raise PLCInvalidArgument, "Network method must be specified"
30 # Make sure network method does not alredy exist
31 conflicts = NetworkMethods(self.api, [name])
33 raise PLCInvalidArgument, "Network method name already in use"
37 class NetworkMethods(Table):
39 Representation of the network_methods table in the database.
42 def __init__(self, api, methods = None):
43 Table.__init__(self, api, NetworkMethod)
45 sql = "SELECT %s FROM network_methods" % \
46 ", ".join(NetworkMethod.fields)
49 sql += " WHERE method IN (%s)" % ", ".join( [ api.db.quote (m) for m in methods ] )