- use base class __init__() and delete() implementations
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 20 Oct 2006 17:56:36 +0000 (17:56 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 20 Oct 2006 17:56:36 +0000 (17:56 +0000)
15 files changed:
PLC/AddressTypes.py
PLC/Addresses.py
PLC/BootStates.py
PLC/Events.py
PLC/KeyTypes.py
PLC/Keys.py
PLC/NetworkMethods.py
PLC/NetworkTypes.py
PLC/PCUs.py
PLC/Persons.py
PLC/Roles.py
PLC/Sites.py
PLC/SliceAttributeTypes.py
PLC/SliceAttributes.py
PLC/Slices.py

index 90e0b3b..dbb844a 100644 (file)
@@ -4,7 +4,7 @@
 # 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
@@ -20,16 +20,13 @@ class AddressType(Row):
 
     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()
@@ -46,18 +43,6 @@ class AddressType(Row):
 
        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.
index aca5178..84dd17c 100644 (file)
@@ -11,6 +11,7 @@ class Address(Row):
 
     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),
@@ -25,10 +26,6 @@ class Address(Row):
         '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.
@@ -80,22 +77,6 @@ class Address(Row):
             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
index fc9a578..6757ca1 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -19,14 +19,11 @@ class BootState(Row):
 
     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()
@@ -42,18 +39,6 @@ class BootState(Row):
 
        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.
index 4dd6288..a0c29dc 100644 (file)
@@ -28,12 +28,6 @@ class Event(Row):
                '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. 
index 0b0d16e..7145020 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -19,14 +19,11 @@ class KeyType(Row):
 
     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()
@@ -41,18 +38,6 @@ class KeyType(Row):
             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):
     """
index 88c7120..37fddbd 100644 (file)
@@ -15,16 +15,13 @@ class Key(Row):
 
     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"
@@ -95,20 +92,6 @@ class Key(Row):
         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
index e141429..0dbbe43 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -19,14 +19,11 @@ class NetworkMethod(Row):
 
     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()
@@ -42,18 +39,6 @@ class NetworkMethod(Row):
 
        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.
index 609b16e..06ce1b9 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -19,14 +19,11 @@ class NetworkType(Row):
 
     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()
@@ -42,18 +39,6 @@ class NetworkType(Row):
 
        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.
index 820ac00..f591ab1 100644 (file)
@@ -4,7 +4,7 @@
 # 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 *
@@ -22,6 +22,7 @@ class PCU(Row):
 
     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"),
@@ -36,10 +37,6 @@ class PCU(Row):
         '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
@@ -96,22 +93,6 @@ class PCU(Row):
             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
index 513afcf..1bc588e 100644 (file)
@@ -4,7 +4,7 @@
 # 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
@@ -51,10 +51,6 @@ class Person(Row):
         '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.
index 8896647..a7552cf 100644 (file)
@@ -4,7 +4,7 @@
 # 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
@@ -20,15 +20,12 @@ class Role(Row):
 
     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])
@@ -52,21 +49,6 @@ class Role(Row):
 
        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.
index cb9c54a..6b2d237 100644 (file)
@@ -41,10 +41,6 @@ class Site(Row):
         '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:
index e719868..ad8672c 100644 (file)
@@ -13,6 +13,7 @@ class SliceAttributeType(Row):
 
     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),
@@ -20,10 +21,6 @@ class SliceAttributeType(Row):
         '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()
 
@@ -44,22 +41,6 @@ class SliceAttributeType(Row):
 
         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
index dd91131..2494acf 100644 (file)
@@ -25,26 +25,6 @@ class SliceAttribute(Row):
         '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
index adfdd44..94b50e9 100644 (file)
@@ -36,10 +36,6 @@ class Slice(Row):
         '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