+++ /dev/null
-#
-# 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)
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):
"""
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"),
--- /dev/null
+#
+# 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)
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
# 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:
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) ????
# 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
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.
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']
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
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.
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
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.
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)
# 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
+++ /dev/null
-#
-# 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
--- /dev/null
+#
+# 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
----------------------------------------
-- ilinks
----------------------------------------
-CREATE TABLE ilink_types ...
+CREATE TABLE link_types ...
CREATE TABLE ilink ...
CREATE OR REPLACE VIEW ilinks AS ...
--------------------------------------------------------------------------------
-- 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
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