2 # Functions for interacting with the network_types 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 NetworkType(Row):
14 Representation of a row in the network_types table. To use,
15 instantiate with a dict of values.
18 table_name = 'network_types'
20 join_tables = ['interfaces']
22 'type': Parameter(str, "Network type", max = 20),
25 def validate_type(self, name):
26 # Make sure name is not blank
28 raise PLCInvalidArgument("Network type must be specified")
30 # Make sure network type does not alredy exist
31 conflicts = NetworkTypes(self.api, [name])
33 raise PLCInvalidArgument("Network type name already in use")
37 class NetworkTypes(Table):
39 Representation of the network_types table in the database.
42 def __init__(self, api, types = None):
43 Table.__init__(self, api, NetworkType)
45 sql = "SELECT %s FROM network_types" % \
46 ", ".join(NetworkType.fields)
49 sql += " WHERE type IN (%s)" % ", ".join( [ api.db.quote (t) for t in types ] )