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
10 from PLC.Faults import *
11 from PLC.Parameter import Parameter
12 from PLC.Table import Row, Table
14 class NetworkMethod(Row):
16 Representation of a row in the network_methods table. To use,
17 instantiate with a dict of values.
20 table_name = 'network_methods'
21 primary_key = 'method'
22 join_tables = ['interfaces']
24 'method': Parameter(str, "Network method", max = 20),
27 def validate_method(self, name):
28 # Make sure name is not blank
30 raise PLCInvalidArgument, "Network method must be specified"
32 # Make sure network method does not alredy exist
33 conflicts = NetworkMethods(self.api, [name])
35 raise PLCInvalidArgument, "Network method name already in use"
39 class NetworkMethods(Table):
41 Representation of the network_methods table in the database.
44 def __init__(self, api, methods = None):
45 Table.__init__(self, api, NetworkMethod)
47 sql = "SELECT %s FROM network_methods" % \
48 ", ".join(NetworkMethod.fields)
51 sql += " WHERE method IN (%s)" % ", ".join(map(api.db.quote, methods))