# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: AddressTypes.py,v 1.2 2006/10/06 18:19:41 mlhuang Exp $
+# $Id: AddressTypes.py,v 1.3 2006/10/10 21:52:08 mlhuang Exp $
#
from types import StringTypes
table_name = 'address_types'
primary_key = 'address_type_id'
+ join_tables = ['address_address_type']
fields = {
'address_type_id': Parameter(int, "Address type identifier"),
'name': Parameter(str, "Address type", max = 20),
'description': Parameter(str, "Address type description", max = 254),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_name(self, name):
# Remove leading and trailing spaces
name = name.strip()
return name
- def delete(self, commit = True):
- assert 'address_type_id' in self
-
- # Clean up miscellaneous join tables
- for table in ['address_address_type', 'address_types']:
- self.api.db.do("DELETE FROM %s" \
- " WHERE address_type_id = %d" % \
- (table, self['address_type_id']), self)
-
- if commit:
- self.api.db.commit()
-
class AddressTypes(Table):
"""
Representation of the address_types table in the database.
table_name = 'addresses'
primary_key = 'address_id'
+ join_tables = ['address_address_type']
fields = {
'address_id': Parameter(int, "Address identifier"),
'line1': Parameter(str, "Address line 1", max = 254, optional = False),
'address_types': Parameter([str], "Address types", ro = True),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def add_address_type(self, address_type, commit = True):
"""
Add address type to existing address.
self['address_type_ids'].remove(address_type_id)
self['address_types'].remove(address_type['name'])
- def delete(self, commit = True):
- """
- Delete existing address from the database.
- """
-
- assert 'address_id' in self
-
- # Clean up miscellaneous join tables
- for table in ['address_address_type', 'addresses']:
- self.api.db.do("DELETE FROM %s" \
- " WHERE address_id = %d" % \
- (table, self['address_id']), self)
-
- if commit:
- self.api.db.commit()
-
class Addresses(Table):
"""
Representation of row(s) from the addresses table in the
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: BootStates.py,v 1.1 2006/10/10 20:24:06 mlhuang Exp $
+# $Id: BootStates.py,v 1.4 2006/10/10 21:54:20 mlhuang Exp $
#
from PLC.Faults import *
table_name = 'boot_states'
primary_key = 'boot_state'
+ join_tables = ['nodes']
fields = {
'boot_state': Parameter(str, "Boot state", max = 20),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_boot_state(self, name):
# Remove leading and trailing spaces
name = name.strip()
return name
- def delete(self, commit = True):
- assert 'boot_state' in self
-
- # Clean up miscellaneous join tables
- for table in ['nodes', 'boot_states']:
- self.api.db.do("DELETE FROM " + table + \
- " WHERE boot_state = %(boot_state)s",
- self)
-
- if commit:
- self.api.db.commit()
-
class BootStates(Table):
"""
Representation of the boot_states table in the database.
'object_ids': Parameter([int], "Ids of objects affected by this event")
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
-
-
class Events(Table):
"""
Representation of row(s) from the events table in the database.
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: KeyTypes.py,v 1.1 2006/10/10 20:24:06 mlhuang Exp $
+# $Id: KeyTypes.py,v 1.1 2006/10/10 22:09:31 mlhuang Exp $
#
from PLC.Faults import *
table_name = 'key_types'
primary_key = 'key_type'
+ join_tables = ['keys']
fields = {
'key_type': Parameter(str, "Key type", max = 20),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_key_type(self, name):
# Remove leading and trailing spaces
name = name.strip()
raise PLCInvalidArgument, "Key type name already in use"
return name
-
- def delete(self, commit = True):
- assert 'key_type' in self
-
- # Clean up miscellaneous join tables
- for table in ['keys', 'key_types']:
- self.api.db.do("DELETE FROM " + table + \
- " WHERE key_type = %(key_type)s",
- self)
-
- if commit:
- self.api.db.commit()
class KeyTypes(Table):
"""
table_name = 'keys'
primary_key = 'key_id'
+ join_tables = ['person_key']
fields = {
'key_id': Parameter(int, "Key identifier"),
'key_type': Parameter(str, "Key type"),
'key': Parameter(str, "Key value", max = 4096),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_key_type(self, key_type):
if key_type not in KeyTypes(self.api):
raise PLCInvalidArgument, "Invalid key type"
if commit:
self.api.db.commit()
- def delete(self, commit = True):
- """
- Delete key from the database.
- """
-
- assert 'key_id' in self
-
- for table in ['person_key', 'keys']:
- self.api.db.do("DELETE FROM %s WHERE key_id = %d" % \
- (table, self['key_id']))
-
- if commit:
- self.api.db.commit()
-
class Keys(Table):
"""
Representation of row(s) from the keys table in the
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: NetworkMethods.py,v 1.2 2006/10/06 18:19:41 mlhuang Exp $
+# $Id: NetworkMethods.py,v 1.1 2006/10/10 20:23:49 mlhuang Exp $
#
from PLC.Faults import *
table_name = 'network_methods'
primary_key = 'method'
+ join_tables = ['nodenetworks']
fields = {
'method': Parameter(str, "Network method", max = 20),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_method(self, name):
# Remove leading and trailing spaces
name = name.strip()
return name
- def delete(self, commit = True):
- assert 'method' in self
-
- # Clean up miscellaneous join tables
- for table in ['nodenetworks', 'network_methods']:
- self.api.db.do("DELETE FROM " + table + \
- " WHERE method = %(method)s",
- self)
-
- if commit:
- self.api.db.commit()
-
class NetworkMethods(Table):
"""
Representation of the network_methods table in the database.
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: NetworkTypes.py,v 1.2 2006/10/06 18:19:41 mlhuang Exp $
+# $Id: NetworkTypes.py,v 1.1 2006/10/10 20:24:06 mlhuang Exp $
#
from PLC.Faults import *
table_name = 'network_types'
primary_key = 'type'
+ join_tables = ['nodenetworks']
fields = {
'type': Parameter(str, "Network type", max = 20),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_type(self, name):
# Remove leading and trailing spaces
name = name.strip()
return name
- def delete(self, commit = True):
- assert 'type' in self
-
- # Clean up miscellaneous join tables
- for table in ['nodenetworks', 'network_types']:
- self.api.db.do("DELETE FROM " + table + \
- " WHERE type = %(type)s",
- self)
-
- if commit:
- self.api.db.commit()
-
class NetworkTypes(Table):
"""
Representation of the network_types table in the database.
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: PCUs.py,v 1.2 2006/10/11 19:54:53 mlhuang Exp $
+# $Id: PCUs.py,v 1.3 2006/10/11 20:48:58 mlhuang Exp $
#
from PLC.Faults import *
table_name = 'pcus'
primary_key = 'pcu_id'
+ join_tables = ['pcu_node']
fields = {
'pcu_id': Parameter(int, "PCU identifier"),
'site_id': Parameter(int, "Identifier of site where PCU is located"),
'ports': Parameter([int], "List of the port numbers that each node is connected to", ro = True),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_ip(self, ip):
if not valid_ip(ip):
raise PLCInvalidArgument, "Invalid IP address " + ip
self['node_ids'].remove(node_id)
self['ports'].remove(port)
- def delete(self, commit = True):
- """
- Delete existing PCU.
- """
-
- assert 'pcu_id' in self
-
- # Clean up various join tables
- for table in ['pcu_node', 'pcus']:
- self.api.db.do("DELETE FROM " + table +
- " WHERE pcu_id = %(pcu_id)d",
- self)
-
- if commit:
- self.api.db.commit()
-
class PCUs(Table):
"""
Representation of row(s) from the pcus table in the
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: Persons.py,v 1.10 2006/10/10 21:51:35 mlhuang Exp $
+# $Id: Persons.py,v 1.11 2006/10/11 15:40:25 mlhuang Exp $
#
from types import StringTypes
'slice_ids': Parameter([int], "List of slice identifiers", ro = True),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_email(self, email):
"""
Validate email address. Stolen from Mailman.
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: Roles.py,v 1.3 2006/10/10 21:54:59 mlhuang Exp $
+# $Id: Roles.py,v 1.4 2006/10/16 21:57:05 mlhuang Exp $
#
from types import StringTypes
table_name = 'roles'
primary_key = 'role_id'
+ join_tables = ['person_role', ('slice_attribute_types', 'min_role_id')]
fields = {
'role_id': Parameter(int, "Role identifier"),
'name': Parameter(str, "Role", max = 100),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_role_id(self, role_id):
# Make sure role does not already exist
conflicts = Roles(self.api, [role_id])
return name
- def delete(self, commit = True):
- assert 'role_id' in self
-
- # Clean up miscellaneous join tables
- for table in ['person_role', 'roles']:
- self.api.db.do("DELETE FROM %s" \
- " WHERE role_id = %d" % \
- (table, self['role_id']), self)
-
- self.api.db.do("DELETE FROM slice_attribute_types WHERE min_role_id = %d" % \
- self['role_id'])
-
- if commit:
- self.api.db.commit()
-
class Roles(Table):
"""
Representation of the roles table in the database.
'node_ids': Parameter([int], "List of site node identifiers", ro = True),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_name(self, name):
name = name.strip()
if not name:
table_name = 'slice_attribute_types'
primary_key = 'attribute_type_id'
+ join_tables = ['slice_attribute']
fields = {
'attribute_type_id': Parameter(int, "Slice attribute type identifier"),
'name': Parameter(str, "Slice attribute type name", max = 100),
'min_role_id': Parameter(int, "Minimum (least powerful) role that can set or change this attribute"),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_name(self, name):
name = name.strip()
return role_id
- def delete(self, commit = True):
- """
- Delete existing slice attribute type.
- """
-
- assert 'attribute_type_id' in self
-
- # Clean up miscellaneous join tables
- for table in ['slice_attribute_types', 'slice_attribute']:
- self.api.db.do("DELETE FROM %s" \
- " WHERE attribute_type_id = %d" % \
- (table, self['attribute_type_id']), self)
-
- if commit:
- self.api.db.commit()
-
class SliceAttributeTypes(Table):
"""
Representation of row(s) from the slice_attribute_types table in the
'value': Parameter(str, "Slice attribute value", max = 254),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
- def delete(self, commit = True):
- """
- Delete existing slice attribute.
- """
-
- assert 'slice_attribute_id' in self
-
- # Clean up miscellaneous join tables
- for table in 'slice_attribute',:
- self.api.db.do("DELETE FROM %s" \
- " WHERE slice_attribute_id = %d" % \
- (table, self['slice_attribute_id']), self)
-
- if commit:
- self.api.db.commit()
-
class SliceAttributes(dict):
"""
Representation of row(s) from the slice_attribute table in the
'slice_attribute_ids': Parameter([int], "List of slice attributes", ro = True),
}
- def __init__(self, api, fields = {}):
- Row.__init__(self, fields)
- self.api = api
-
def validate_name(self, name):
# N.B.: Responsibility of the caller to ensure that login_base
# portion of the slice name corresponds to a valid site, if