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
7 # $Id: NetworkTypes.py,v 1.1 2006/10/10 20:24:06 mlhuang Exp $
10 from PLC.Faults import *
11 from PLC.Parameter import Parameter
12 from PLC.Table import Row, Table
14 class NetworkType(Row):
16 Representation of a row in the network_types table. To use,
17 instantiate with a dict of values.
20 table_name = 'network_types'
22 join_tables = ['nodenetworks']
24 'type': Parameter(str, "Network type", max = 20),
27 def validate_type(self, name):
28 # Remove leading and trailing spaces
31 # Make sure name is not blank after we removed the spaces
33 raise PLCInvalidArgument, "Network type must be specified"
35 # Make sure network type does not alredy exist
36 conflicts = NetworkTypes(self.api, [name])
38 raise PLCInvalidArgument, "Network type name already in use"
42 class NetworkTypes(Table):
44 Representation of the network_types table in the database.
47 def __init__(self, api, names = None):
48 sql = "SELECT %s FROM network_types" % \
49 ", ".join(NetworkType.fields)
52 # Separate the list into integers and strings
53 sql += " WHERE type IN (%s)" % ", ".join(api.db.quote(names))
55 rows = api.db.selectall(sql)
58 self[row['type']] = NetworkType(api, row)