2 # Functions for interacting with the network_types 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 NetworkType(AlchemyObj):
12 Representation of a row in the network_types table. To use,
13 instantiate with a dict of values.
16 tablename = 'network_types'
18 'type': Parameter(str, "Network type", max = 20, primary_key=True),
21 def validate_type(self, name):
22 # Make sure name is not blank
24 raise PLCInvalidArgument, "Network type must be specified"
26 # Make sure network type does not alredy exist
27 conflicts = NetworkTypes(self.api, name)
29 raise PLCInvalidArgument, "Network type name already in use"
33 class NetworkTypes(list):
35 Representation of the network_types table in the database.
38 def __init__(self, api, types = None):
40 network_types = NetworkType().select()
41 elif isinstance(types, StringTypes):
42 network_types = NetworkType().select({'type': types})
44 raise PLCInvalidArgument, "Wrong network type filter %r"%types
46 self.extend(network_types)