rename IlinkType into LinkType as these types will be used for Nlinks as well
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 May 2008 04:58:00 +0000 (04:58 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Wed, 28 May 2008 04:58:00 +0000 (04:58 +0000)
13 files changed:
PLC/IlinkTypes.py [deleted file]
PLC/Ilinks.py
PLC/LinkTypes.py [new file with mode: 0644]
PLC/Methods/AddIlink.py
PLC/Methods/AddLinkType.py [moved from PLC/Methods/AddIlinkType.py with 56% similarity]
PLC/Methods/DeleteIlink.py
PLC/Methods/DeleteLinkType.py [moved from PLC/Methods/DeleteIlinkType.py with 52% similarity]
PLC/Methods/GetLinkTypes.py [moved from PLC/Methods/GetIlinkTypes.py with 55% similarity]
PLC/Methods/UpdateIlink.py
PLC/Methods/UpdateIlinkType.py [deleted file]
PLC/Methods/UpdateLinkType.py [new file with mode: 0644]
migrations/migrate-v4-to-v5.sql
planetlab5.sql

diff --git a/PLC/IlinkTypes.py b/PLC/IlinkTypes.py
deleted file mode 100644 (file)
index bb11979..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#
-# Thierry Parmentelat - INRIA
-#
-# $Revision: 9423 $
-#
-from types import StringTypes
-
-from PLC.Faults import *
-from PLC.Parameter import Parameter
-from PLC.Filter import Filter
-from PLC.Table import Row, Table
-from PLC.Roles import Role, Roles
-
-class IlinkType (Row):
-
-    """
-    Representation of a row in the ilink_types table.
-    """
-
-    table_name = 'ilink_types'
-    primary_key = 'ilink_type_id'
-    join_tables = ['ilink']
-    fields = {
-        'ilink_type_id': Parameter(int, "ilink type identifier"),
-        'name': Parameter(str, "ilink type name", max = 100),
-        'description': Parameter(str, "ilink type description", max = 254),
-        'min_role_id': Parameter(int, "Minimum (least powerful) role that can set or change this attribute"),
-        }
-
-    def validate_name(self, name):
-        if not len(name):
-            raise PLCInvalidArgument, "ilink type name must be set"
-
-        conflicts = IlinkTypes(self.api, [name])
-        for tag_type in conflicts:
-            if 'ilink_type_id' not in self or \
-                   self['ilink_type_id'] != tag_type['ilink_type_id']:
-                raise PLCInvalidArgument, "ilink type name already in use"
-
-        return name
-
-    def validate_min_role_id(self, role_id):
-        roles = [row['role_id'] for row in Roles(self.api)]
-        if role_id not in roles:
-            raise PLCInvalidArgument, "Invalid role"
-
-        return role_id
-
-class IlinkTypes(Table):
-    """
-    Representation of row(s) from the ilink_types table
-    in the database.
-    """
-
-    def __init__(self, api, ilink_type_filter = None, columns = None):
-        Table.__init__(self, api, IlinkType, columns)
-
-        sql = "SELECT %s FROM ilink_types WHERE True" % \
-              ", ".join(self.columns)
-
-        if ilink_type_filter is not None:
-            if isinstance(ilink_type_filter, (list, tuple, set)):
-                # Separate the list into integers and strings
-                ints = filter(lambda x: isinstance(x, (int, long)), ilink_type_filter)
-                strs = filter(lambda x: isinstance(x, StringTypes), ilink_type_filter)
-                ilink_type_filter = Filter(IlinkType.fields, {'ilink_type_id': ints, 'name': strs})
-                sql += " AND (%s) %s" % ilink_type_filter.sql(api, "OR")
-            elif isinstance(ilink_type_filter, dict):
-                ilink_type_filter = Filter(IlinkType.fields, ilink_type_filter)
-                sql += " AND (%s) %s" % ilink_type_filter.sql(api, "AND")
-            elif isinstance (ilink_type_filter, StringTypes):
-                ilink_type_filter = Filter(IlinkType.fields, {'name':[ilink_type_filter]})
-                sql += " AND (%s) %s" % ilink_type_filter.sql(api, "AND")
-            else:
-                raise PLCInvalidArgument, "Wrong ilink type filter %r"%ilink_type_filter
-
-        self.selectall(sql)
index f6c9586..0267702 100644 (file)
@@ -8,7 +8,7 @@ from PLC.Parameter import Parameter
 from PLC.Filter import Filter
 from PLC.Table import Row, Table
 from PLC.Interfaces import Interface, Interfaces
-from PLC.IlinkTypes import IlinkType, IlinkTypes
+from PLC.LinkTypes import LinkType, LinkTypes
 
 class Ilink(Row):
     """
@@ -20,7 +20,7 @@ class Ilink(Row):
     primary_key = 'ilink_id'
     fields = {
         'ilink_id': Parameter(int, "ilink identifier"),
-        'ilink_type_id': IlinkType.fields['ilink_type_id'],
+        'link_type_id': LinkType.fields['link_type_id'],
         'src_interface_id': Parameter(int, "source interface identifier"),
         'dst_interface_id': Parameter(int, "destination interface identifier"),
         'value': Parameter( str, "optional ilink value"),
diff --git a/PLC/LinkTypes.py b/PLC/LinkTypes.py
new file mode 100644 (file)
index 0000000..3b8651c
--- /dev/null
@@ -0,0 +1,77 @@
+#
+# Thierry Parmentelat - INRIA
+#
+# $Revision: 9423 $
+#
+from types import StringTypes
+
+from PLC.Faults import *
+from PLC.Parameter import Parameter
+from PLC.Filter import Filter
+from PLC.Table import Row, Table
+from PLC.Roles import Role, Roles
+
+class LinkType (Row):
+
+    """
+    Representation of a row in the link_types table.
+    """
+
+    table_name = 'link_types'
+    primary_key = 'link_type_id'
+    join_tables = ['ilink']
+    fields = {
+        'link_type_id': Parameter(int, "ilink type identifier"),
+        'name': Parameter(str, "ilink type name", max = 100),
+        'description': Parameter(str, "ilink type description", max = 254),
+        'min_role_id': Parameter(int, "Minimum (least powerful) role that can set or change this attribute"),
+        }
+
+    def validate_name(self, name):
+        if not len(name):
+            raise PLCInvalidArgument, "ilink type name must be set"
+
+        conflicts = LinkTypes(self.api, [name])
+        for tag_type in conflicts:
+            if 'link_type_id' not in self or \
+                   self['link_type_id'] != tag_type['link_type_id']:
+                raise PLCInvalidArgument, "ilink type name already in use"
+
+        return name
+
+    def validate_min_role_id(self, role_id):
+        roles = [row['role_id'] for row in Roles(self.api)]
+        if role_id not in roles:
+            raise PLCInvalidArgument, "Invalid role"
+
+        return role_id
+
+class LinkTypes(Table):
+    """
+    Representation of row(s) from the link_types table
+    in the database.
+    """
+
+    def __init__(self, api, link_type_filter = None, columns = None):
+        Table.__init__(self, api, LinkType, columns)
+
+        sql = "SELECT %s FROM link_types WHERE True" % \
+              ", ".join(self.columns)
+
+        if link_type_filter is not None:
+            if isinstance(link_type_filter, (list, tuple, set)):
+                # Separate the list into integers and strings
+                ints = filter(lambda x: isinstance(x, (int, long)), link_type_filter)
+                strs = filter(lambda x: isinstance(x, StringTypes), link_type_filter)
+                link_type_filter = Filter(LinkType.fields, {'link_type_id': ints, 'name': strs})
+                sql += " AND (%s) %s" % link_type_filter.sql(api, "OR")
+            elif isinstance(link_type_filter, dict):
+                link_type_filter = Filter(LinkType.fields, link_type_filter)
+                sql += " AND (%s) %s" % link_type_filter.sql(api, "AND")
+            elif isinstance (link_type_filter, StringTypes):
+                link_type_filter = Filter(LinkType.fields, {'name':[link_type_filter]})
+                sql += " AND (%s) %s" % link_type_filter.sql(api, "AND")
+            else:
+                raise PLCInvalidArgument, "Wrong ilink type filter %r"%link_type_filter
+
+        self.selectall(sql)
index c2c22c5..6e554f0 100644 (file)
@@ -8,7 +8,7 @@ from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Auth import Auth
 
-from PLC.IlinkTypes import IlinkType, IlinkTypes
+from PLC.LinkTypes import LinkType, LinkTypes
 from PLC.Ilinks import Ilink, Ilinks
 from PLC.Interfaces import Interface, Interfaces
 
@@ -31,14 +31,14 @@ class AddIlink(Method):
         # refer to either the id or the type name
         Ilink.fields['src_interface_id'],
         Ilink.fields['dst_interface_id'],
-        Mixed(IlinkType.fields['ilink_type_id'],
-              IlinkType.fields['name']),
+        Mixed(LinkType.fields['link_type_id'],
+              LinkType.fields['name']),
         Ilink.fields['value'],
         ]
 
     returns = Parameter(int, 'New ilink_id (> 0) if successful')
 
-    def call(self, auth,  src_if_id, dst_if_id, ilink_type_id_or_name, value):
+    def call(self, auth,  src_if_id, dst_if_id, link_type_id_or_name, value):
 
         src_if = Interfaces (self.api, [src_if_id],[interface_id])
         if not src_if:
@@ -47,21 +47,21 @@ class AddIlink(Method):
         if not dst_if:
             raise PLCInvalidArgument, "No such destination interface %r"%dst_if_id
 
-        ilink_types = IlinkTypes(self.api, [ilink_type_id_or_name])
-        if not ilink_types:
-            raise PLCInvalidArgument, "No such ilink type %r"%ilink_type_id_or_name
-        ilink_type = ilink_types[0]
+        link_types = LinkTypes(self.api, [link_type_id_or_name])
+        if not link_types:
+            raise PLCInvalidArgument, "No such ilink type %r"%link_type_id_or_name
+        link_type = link_types[0]
 
        # checks for existence - with the same type
         conflicts = Ilinks(self.api,
-                           {'ilink_type_id':ilink_type['ilink_type_id'],
+                           {'link_type_id':link_type['link_type_id'],
                             'src_interface_id':src_if_id,
                             'dst_interface_id':dst_if_id,})
 
         if len(conflicts) :
             ilink=conflicts[0]
             raise PLCInvalidArgument, "Ilink (%s,%d,%d) already exists and has value %r"\
-                %(ilink_type['name'],src_if_id,dst_if_id,ilink['value'])
+                %(link_type['name'],src_if_id,dst_if_id,ilink['value'])
 
        if 'admin' not in self.caller['roles']:
 #      # check permission : it not admin, is the user affiliated with the right site(s) ????
@@ -73,13 +73,13 @@ class AddIlink(Method):
 #          if self.caller['person_id'] not in site['person_ids']:
 #              raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
            
-           required_min_role = ilink_type ['min_role_id']
+           required_min_role = link_type ['min_role_id']
            if required_min_role is not None and \
                    min(self.caller['role_ids']) > required_min_role:
                raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
 
         ilink = Ilink(self.api)
-        ilink['ilink_type_id'] = ilink_type['ilink_type_id']
+        ilink['link_type_id'] = link_type['link_type_id']
         ilink['src_interface_id'] = src_if_id
         ilink['dst_interface_id'] = dst_if_id
         ilink['value'] = value
similarity index 56%
rename from PLC/Methods/AddIlinkType.py
rename to PLC/Methods/AddLinkType.py
index e4460fe..c02743a 100644 (file)
@@ -8,13 +8,13 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.IlinkTypes import IlinkType, IlinkTypes
+from PLC.LinkTypes import LinkType, LinkTypes
 from PLC.Auth import Auth
 
 can_update = lambda (field, value): field in \
              ['name', 'description', 'category', 'min_role_id']
 
-class AddIlinkType(Method):
+class AddLinkType(Method):
     """
     Adds a new type of ilink.
     Any fields specified are used, otherwise defaults are used.
@@ -25,21 +25,21 @@ class AddIlinkType(Method):
 
     roles = ['admin']
 
-    ilink_type_fields = dict(filter(can_update, IlinkType.fields.items()))
+    link_type_fields = dict(filter(can_update, LinkType.fields.items()))
 
     accepts = [
         Auth(),
-        ilink_type_fields
+        link_type_fields
         ]
 
     returns = Parameter(int, 'New ilink_id (> 0) if successful')
 
 
-    def call(self, auth, ilink_type_fields):
-        ilink_type_fields = dict(filter(can_update, ilink_type_fields.items()))
-        ilink_type = IlinkType(self.api, ilink_type_fields)
-        ilink_type.sync()
+    def call(self, auth, link_type_fields):
+        link_type_fields = dict(filter(can_update, link_type_fields.items()))
+        link_type = LinkType(self.api, link_type_fields)
+        link_type.sync()
 
-       self.object_ids = [ilink_type['ilink_type_id']]
+       self.object_ids = [link_type['link_type_id']]
 
-        return ilink_type['ilink_type_id']
+        return link_type['link_type_id']
index 685a9ae..6e223d5 100644 (file)
@@ -62,7 +62,7 @@ class DeleteIlink(Method):
            if self.caller['person_id'] not in site['person_ids']:
                raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
            
-           required_min_role = ilink_type ['min_role_id']
+           required_min_role = link_type ['min_role_id']
            if required_min_role is not None and \
                    min(self.caller['role_ids']) > required_min_role:
                raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
similarity index 52%
rename from PLC/Methods/DeleteIlinkType.py
rename to PLC/Methods/DeleteLinkType.py
index 5a533ad..91d3145 100644 (file)
@@ -6,10 +6,10 @@
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.IlinkTypes import IlinkType, IlinkTypes
+from PLC.LinkTypes import LinkType, LinkTypes
 from PLC.Auth import Auth
 
-class DeleteIlinkType(Method):
+class DeleteLinkType(Method):
     """
     Deletes the specified ilink type.
 
@@ -20,20 +20,20 @@ class DeleteIlinkType(Method):
 
     accepts = [
         Auth(),
-        Mixed(IlinkType.fields['ilink_type_id'],
-              IlinkType.fields['name']),
+        Mixed(LinkType.fields['link_type_id'],
+              LinkType.fields['name']),
         ]
 
     returns = Parameter(int, '1 if successful')
 
 
-    def call(self, auth, ilink_type_id_or_name):
-        ilink_types = IlinkTypes(self.api, [ilink_type_id_or_name])
-        if not ilink_types:
+    def call(self, auth, link_type_id_or_name):
+        link_types = LinkTypes(self.api, [link_type_id_or_name])
+        if not link_types:
             raise PLCInvalidArgument, "No such ilink type"
-        ilink_type = ilink_types[0]
+        link_type = link_types[0]
 
-        ilink_type.delete()
-       self.object_ids = [ilink_type['ilink_type_id']]
+        link_type.delete()
+       self.object_ids = [link_type['link_type_id']]
 
         return 1
similarity index 55%
rename from PLC/Methods/GetIlinkTypes.py
rename to PLC/Methods/GetLinkTypes.py
index a76807d..3182fa8 100644 (file)
@@ -7,9 +7,9 @@ from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Filter import Filter
 from PLC.Auth import Auth
-from PLC.IlinkTypes import IlinkType, IlinkTypes
+from PLC.LinkTypes import LinkType, LinkTypes
 
-class GetIlinkTypes(Method):
+class GetLinkTypes(Method):
     """
     Returns an array of structs containing details about
     ilink types.
@@ -21,13 +21,13 @@ class GetIlinkTypes(Method):
 
     accepts = [
         Auth(),
-        Mixed([Mixed(IlinkType.fields['ilink_type_id'],
-                     IlinkType.fields['name'])],
-              Filter(IlinkType.fields)),
+        Mixed([Mixed(LinkType.fields['link_type_id'],
+                     LinkType.fields['name'])],
+              Filter(LinkType.fields)),
         Parameter([str], "List of fields to return", nullok = True)
         ]
 
-    returns = [IlinkType.fields]
+    returns = [LinkType.fields]
 
-    def call(self, auth, ilink_type_filter = None, return_fields = None):
-        return IlinkTypes(self.api, ilink_type_filter, return_fields)
+    def call(self, auth, link_type_filter = None, return_fields = None):
+        return LinkTypes(self.api, link_type_filter, return_fields)
index a0578ba..c2bf751 100644 (file)
@@ -51,7 +51,7 @@ class UpdateIlink(Method):
 #          if self.caller['person_id'] not in site['person_ids']:
 #              raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
            
-           required_min_role = ilink_type ['min_role_id']
+           required_min_role = link_type ['min_role_id']
            if required_min_role is not None and \
                    min(self.caller['role_ids']) > required_min_role:
                raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
diff --git a/PLC/Methods/UpdateIlinkType.py b/PLC/Methods/UpdateIlinkType.py
deleted file mode 100644 (file)
index 38644e6..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Thierry Parmentelat - INRIA
-#
-# $Revision: 9423 $
-#
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.IlinkTypes import IlinkType, IlinkTypes
-from PLC.Auth import Auth
-
-can_update = lambda (field, value): field in \
-             ['name', 'description', 'category', 'min_role_id']
-
-class UpdateIlinkType(Method):
-    """
-    Updates the parameters of an existing tag type
-    with the values in ilink_type_fields.
-
-    Returns 1 if successful, faults otherwise.
-    """
-
-    roles = ['admin']
-
-    ilink_type_fields = dict(filter(can_update, IlinkType.fields.items()))
-
-    accepts = [
-        Auth(),
-        Mixed(IlinkType.fields['ilink_type_id'],
-              IlinkType.fields['name']),
-        ilink_type_fields
-        ]
-
-    returns = Parameter(int, '1 if successful')
-
-    def call(self, auth, ilink_type_id_or_name, ilink_type_fields):
-        ilink_type_fields = dict(filter(can_update, ilink_type_fields.items()))
-
-        ilink_types = IlinkTypes(self.api, [ilink_type_id_or_name])
-        if not ilink_types:
-            raise PLCInvalidArgument, "No such tag type"
-        ilink_type = ilink_types[0]
-
-        ilink_type.update(ilink_type_fields)
-        ilink_type.sync()
-       self.object_ids = [ilink_type['ilink_type_id']]
-
-        return 1
diff --git a/PLC/Methods/UpdateLinkType.py b/PLC/Methods/UpdateLinkType.py
new file mode 100644 (file)
index 0000000..f1ee43a
--- /dev/null
@@ -0,0 +1,48 @@
+#
+# Thierry Parmentelat - INRIA
+#
+# $Revision: 9423 $
+#
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.LinkTypes import LinkType, LinkTypes
+from PLC.Auth import Auth
+
+can_update = lambda (field, value): field in \
+             ['name', 'description', 'category', 'min_role_id']
+
+class UpdateLinkType(Method):
+    """
+    Updates the parameters of an existing link type
+    with the values in link_type_fields.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    link_type_fields = dict(filter(can_update, LinkType.fields.items()))
+
+    accepts = [
+        Auth(),
+        Mixed(LinkType.fields['link_type_id'],
+              LinkType.fields['name']),
+        link_type_fields
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    def call(self, auth, link_type_id_or_name, link_type_fields):
+        link_type_fields = dict(filter(can_update, link_type_fields.items()))
+
+        link_types = LinkTypes(self.api, [link_type_id_or_name])
+        if not link_types:
+            raise PLCInvalidArgument, "No such tag type"
+        link_type = link_types[0]
+
+        link_type.update(link_type_fields)
+        link_type.sync()
+       self.object_ids = [link_type['link_type_id']]
+
+        return 1
index 285a01f..86f4db9 100644 (file)
@@ -72,7 +72,7 @@ CREATE OR REPLACE VIEW view_nodes AS ...
 ----------------------------------------
 -- ilinks
 ----------------------------------------
-CREATE TABLE ilink_types ...
+CREATE TABLE link_types ...
 CREATE TABLE ilink ...
 
 CREATE OR REPLACE VIEW ilinks AS ...
index 828d76f..fe4e562 100644 (file)
@@ -442,8 +442,8 @@ FROM interfaces;
 --------------------------------------------------------------------------------
 -- ilinks : links between interfaces
 --------------------------------------------------------------------------------
-CREATE TABLE ilink_types (
-       ilink_type_id serial PRIMARY KEY,               -- id
+CREATE TABLE link_types (
+       link_type_id serial PRIMARY KEY,                -- id
        name text UNIQUE NOT NULL,                      -- link name
        description text,                               -- optional description
        min_role_id integer REFERENCES roles DEFAULT 10         -- minimal role required
@@ -451,21 +451,21 @@ CREATE TABLE ilink_types (
 
 CREATE TABLE ilink (
        ilink_id serial PRIMARY KEY,                            -- id
-       ilink_type_id integer REFERENCES ilink_types,           -- id of the ilink type
+       link_type_id integer REFERENCES link_types,             -- id of the ilink type
        src_interface_id integer REFERENCES interfaces not NULL,        -- id of src interface
        dst_interface_id integer REFERENCES interfaces NOT NULL, -- id of dst interface
        value text                                              -- optional value on the link
 ) WITH OIDS;
 
 CREATE OR REPLACE VIEW view_ilinks AS
-SELECT * FROM ilink_types 
-INNER JOIN ilink USING (ilink_type_id);
+SELECT * FROM link_types 
+INNER JOIN ilink USING (link_type_id);
 
 -- expose node_ids ???
 -- -- cannot mention the same table twice in a join ?
 -- -- CREATE OR REPLACE VIEW ilink_src_node AS 
 -- SELECT 
--- ilink.ilink_type_id,
+-- ilink.link_type_id,
 -- ilink.src_interface_id,
 -- interfaces.node_id AS src_node_id,
 -- ilink.dst_interface_id