From: Thierry Parmentelat Date: Mon, 2 Jun 2008 18:59:30 +0000 (+0000) Subject: a single tag type for slice attributes, iterface settings, node tags and ilinks X-Git-Tag: PLCAPI-4.3-1~36 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=eafc0194bc0dde66e31315a72f2cb05775c9800b a single tag type for slice attributes, iterface settings, node tags and ilinks --- diff --git a/PLC/Ilinks.py b/PLC/Ilinks.py index 0267702..28c95e2 100644 --- a/PLC/Ilinks.py +++ b/PLC/Ilinks.py @@ -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.LinkTypes import LinkType, LinkTypes +from PLC.TagTypes import TagType, TagTypes class Ilink(Row): """ @@ -20,7 +20,7 @@ class Ilink(Row): primary_key = 'ilink_id' fields = { 'ilink_id': Parameter(int, "ilink identifier"), - 'link_type_id': LinkType.fields['link_type_id'], + 'tag_type_id': TagType.fields['tag_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/InterfaceSettingTypes.py b/PLC/InterfaceSettingTypes.py deleted file mode 100644 index 27f5987..0000000 --- a/PLC/InterfaceSettingTypes.py +++ /dev/null @@ -1,78 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision$ -# -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 InterfaceSettingType (Row): - - """ - Representation of a row in the interface_setting_types table. - """ - - table_name = 'interface_setting_types' - primary_key = 'interface_setting_type_id' - join_tables = ['interface_setting'] - fields = { - 'interface_setting_type_id': Parameter(int, "Interface setting type identifier"), - 'name': Parameter(str, "Interface setting type name", max = 100), - 'description': Parameter(str, "Interface setting type description", max = 254), - 'category' : Parameter (str, "Interface setting category", max=64, optional=True), - '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, "interface setting type name must be set" - - conflicts = InterfaceSettingTypes(self.api, [name]) - for setting_type in conflicts: - if 'interface_setting_type_id' not in self or \ - self['interface_setting_type_id'] != setting_type['interface_setting_type_id']: - raise PLCInvalidArgument, "interface setting 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 InterfaceSettingTypes(Table): - """ - Representation of row(s) from the interface_setting_types table - in the database. - """ - - def __init__(self, api, interface_setting_type_filter = None, columns = None): - Table.__init__(self, api, InterfaceSettingType, columns) - - sql = "SELECT %s FROM interface_setting_types WHERE True" % \ - ", ".join(self.columns) - - if interface_setting_type_filter is not None: - if isinstance(interface_setting_type_filter, (list, tuple, set)): - # Separate the list into integers and strings - ints = filter(lambda x: isinstance(x, (int, long)), interface_setting_type_filter) - strs = filter(lambda x: isinstance(x, StringTypes), interface_setting_type_filter) - interface_setting_type_filter = Filter(InterfaceSettingType.fields, {'interface_setting_type_id': ints, 'name': strs}) - sql += " AND (%s) %s" % interface_setting_type_filter.sql(api, "OR") - elif isinstance(interface_setting_type_filter, dict): - interface_setting_type_filter = Filter(InterfaceSettingType.fields, interface_setting_type_filter) - sql += " AND (%s) %s" % interface_setting_type_filter.sql(api, "AND") - elif isinstance (interface_setting_type_filter, StringTypes): - interface_setting_type_filter = Filter(InterfaceSettingType.fields, {'name':[interface_setting_type_filter]}) - sql += " AND (%s) %s" % interface_setting_type_filter.sql(api, "AND") - else: - raise PLCInvalidArgument, "Wrong interface setting type filter %r"%interface_setting_type_filter - - self.selectall(sql) diff --git a/PLC/InterfaceSettings.py b/PLC/InterfaceSettings.py index 63442f1..c7b0af8 100644 --- a/PLC/InterfaceSettings.py +++ b/PLC/InterfaceSettings.py @@ -7,7 +7,7 @@ from PLC.Faults import * from PLC.Parameter import Parameter from PLC.Filter import Filter from PLC.Table import Row, Table -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes +from PLC.TagTypes import TagType, TagTypes class InterfaceSetting(Row): """ @@ -20,11 +20,11 @@ class InterfaceSetting(Row): fields = { 'interface_setting_id': Parameter(int, "Interface setting identifier"), 'interface_id': Parameter(int, "Interface identifier"), - 'interface_setting_type_id': InterfaceSettingType.fields['interface_setting_type_id'], - 'name': InterfaceSettingType.fields['name'], - 'description': InterfaceSettingType.fields['description'], - 'category': InterfaceSettingType.fields['category'], - 'min_role_id': InterfaceSettingType.fields['min_role_id'], + 'tag_type_id': TagType.fields['tag_type_id'], + 'tagname': TagType.fields['tagname'], + 'description': TagType.fields['description'], + 'category': TagType.fields['category'], + 'min_role_id': TagType.fields['min_role_id'], 'value': Parameter(str, "Interface setting value"), ### relations diff --git a/PLC/LinkTypes.py b/PLC/LinkTypes.py deleted file mode 100644 index 3b8651c..0000000 --- a/PLC/LinkTypes.py +++ /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 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) diff --git a/PLC/Methods/AddIlink.py b/PLC/Methods/AddIlink.py index 6e554f0..d7c1c7f 100644 --- a/PLC/Methods/AddIlink.py +++ b/PLC/Methods/AddIlink.py @@ -8,7 +8,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth -from PLC.LinkTypes import LinkType, LinkTypes +from PLC.TagTypes import TagType, TagTypes from PLC.Ilinks import Ilink, Ilinks from PLC.Interfaces import Interface, Interfaces @@ -17,7 +17,7 @@ from PLC.Sites import Sites class AddIlink(Method): """ Create a link between two interfaces - The link has a type, that needs be created beforehand + The link has a tag type, that needs be created beforehand and an optional value. Returns the new ilink_id (> 0) if successful, faults @@ -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(LinkType.fields['link_type_id'], - LinkType.fields['name']), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), Ilink.fields['value'], ] returns = Parameter(int, 'New ilink_id (> 0) if successful') - def call(self, auth, src_if_id, dst_if_id, link_type_id_or_name, value): + def call(self, auth, src_if_id, dst_if_id, tag_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 - 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] + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: + raise PLCInvalidArgument, "AddIlink: No such tag type %r"%tag_type_id_or_name + tag_type = tag_types[0] # checks for existence - with the same type conflicts = Ilinks(self.api, - {'link_type_id':link_type['link_type_id'], + {'tag_type_id':tag_type['tag_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"\ - %(link_type['name'],src_if_id,dst_if_id,ilink['value']) + %(tag_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 = link_type ['min_role_id'] + required_min_role = tag_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['link_type_id'] = link_type['link_type_id'] + ilink['tag_type_id'] = tag_type['tag_type_id'] ilink['src_interface_id'] = src_if_id ilink['dst_interface_id'] = dst_if_id ilink['value'] = value diff --git a/PLC/Methods/AddInterfaceSetting.py b/PLC/Methods/AddInterfaceSetting.py index bc2c621..c9e99f6 100644 --- a/PLC/Methods/AddInterfaceSetting.py +++ b/PLC/Methods/AddInterfaceSetting.py @@ -8,7 +8,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes +from PLC.TagTypes import TagType, TagTypes from PLC.InterfaceSettings import InterfaceSetting, InterfaceSettings from PLC.Interfaces import Interface, Interfaces @@ -21,7 +21,7 @@ class AddInterfaceSetting(Method): to the specified value. In general only tech(s), PI(s) and of course admin(s) are allowed to - do the change, but this is defined in the interface setting type object. + do the change, but this is defined in the tag type object. Returns the new interface_setting_id (> 0) if successful, faults otherwise. @@ -33,8 +33,8 @@ class AddInterfaceSetting(Method): Auth(), # no other way to refer to a interface InterfaceSetting.fields['interface_id'], - Mixed(InterfaceSettingType.fields['interface_setting_type_id'], - InterfaceSettingType.fields['name']), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), InterfaceSetting.fields['value'], ] @@ -43,25 +43,25 @@ class AddInterfaceSetting(Method): object_type = 'Interface' - def call(self, auth, interface_id, interface_setting_type_id_or_name, value): + def call(self, auth, interface_id, tag_type_id_or_name, value): interfaces = Interfaces(self.api, [interface_id]) if not interfaces: raise PLCInvalidArgument, "No such interface %r"%interface_id interface = interfaces[0] - interface_setting_types = InterfaceSettingTypes(self.api, [interface_setting_type_id_or_name]) - if not interface_setting_types: - raise PLCInvalidArgument, "No such interface setting type %r"%interface_setting_type_id_or_name - interface_setting_type = interface_setting_types[0] + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: + raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_name + tag_type = tag_types[0] # checks for existence - does not allow several different settings conflicts = InterfaceSettings(self.api, {'interface_id':interface['interface_id'], - 'interface_setting_type_id':interface_setting_type['interface_setting_type_id']}) + 'tag_type_id':tag_type['tag_type_id']}) if len(conflicts) : raise PLCInvalidArgument, "Interface %d already has setting %d"%(interface['interface_id'], - interface_setting_type['interface_setting_type_id']) + tag_type['tag_type_id']) # check permission : it not admin, is the user affiliated with the right site if 'admin' not in self.caller['roles']: @@ -73,14 +73,14 @@ class AddInterfaceSetting(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 = interface_setting_type ['min_role_id'] + required_min_role = tag_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 interface setting, requires role %d",required_min_role interface_setting = InterfaceSetting(self.api) interface_setting['interface_id'] = interface['interface_id'] - interface_setting['interface_setting_type_id'] = interface_setting_type['interface_setting_type_id'] + interface_setting['tag_type_id'] = tag_type['tag_type_id'] interface_setting['value'] = value interface_setting.sync() diff --git a/PLC/Methods/AddInterfaceSettingType.py b/PLC/Methods/AddInterfaceSettingType.py deleted file mode 100644 index 29141c2..0000000 --- a/PLC/Methods/AddInterfaceSettingType.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision$ -# - - -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes -from PLC.Auth import Auth - -can_update = lambda (field, value): field in \ - ['name', 'description', 'category', 'min_role_id'] - -class AddInterfaceSettingType(Method): - """ - Adds a new type of interface setting. - Any fields specified are used, otherwise defaults are used. - - Returns the new interface_setting_id (> 0) if successful, - faults otherwise. - """ - - roles = ['admin'] - - interface_setting_type_fields = dict(filter(can_update, InterfaceSettingType.fields.items())) - - accepts = [ - Auth(), - interface_setting_type_fields - ] - - returns = Parameter(int, 'New interface_setting_id (> 0) if successful') - - - def call(self, auth, interface_setting_type_fields): - interface_setting_type_fields = dict(filter(can_update, interface_setting_type_fields.items())) - interface_setting_type = InterfaceSettingType(self.api, interface_setting_type_fields) - interface_setting_type.sync() - - self.object_ids = [interface_setting_type['interface_setting_type_id']] - - return interface_setting_type['interface_setting_type_id'] diff --git a/PLC/Methods/AddLinkType.py b/PLC/Methods/AddLinkType.py deleted file mode 100644 index c02743a..0000000 --- a/PLC/Methods/AddLinkType.py +++ /dev/null @@ -1,45 +0,0 @@ -# -# 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 AddLinkType(Method): - """ - Adds a new type of ilink. - Any fields specified are used, otherwise defaults are used. - - Returns the new ilink_id (> 0) if successful, - faults otherwise. - """ - - roles = ['admin'] - - link_type_fields = dict(filter(can_update, LinkType.fields.items())) - - accepts = [ - Auth(), - link_type_fields - ] - - returns = Parameter(int, 'New ilink_id (> 0) if successful') - - - 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 = [link_type['link_type_id']] - - return link_type['link_type_id'] diff --git a/PLC/Methods/AddNodeGroup.py b/PLC/Methods/AddNodeGroup.py index e22b9a3..404fb81 100644 --- a/PLC/Methods/AddNodeGroup.py +++ b/PLC/Methods/AddNodeGroup.py @@ -4,7 +4,7 @@ from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth from PLC.NodeGroups import NodeGroup, NodeGroups -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.TagTypes import TagType, TagTypes from PLC.NodeTags import NodeTag, NodeTags can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field @@ -24,23 +24,23 @@ class AddNodeGroup(Method): accepts = [ Auth(), NodeGroup.fields['groupname'], - Mixed(NodeTagType.fields['node_tag_type_id'], - NodeTagType.fields['tagname']), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), NodeTag.fields['tagvalue'], ] returns = Parameter(int, 'New nodegroup_id (> 0) if successful') - def call(self, auth, groupname, node_tag_type_id_or_tagname, tagvalue): + def call(self, auth, groupname, tag_type_id_or_tagname, tagvalue): # locate tag type - tag_types = NodeTagTypes (self.api,[node_tag_type_id_or_tagname]) + tag_types = TagTypes (self.api,[tag_type_id_or_tagname]) if not(tag_types): - raise PLCInvalidArgument, "No such tag type %r"%node_tag_type_id_or_tagname + raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_tagname tag_type=tag_types[0] nodegroup_fields = { 'groupname' : groupname, - 'node_tag_type_id' : tag_type['node_tag_type_id'], + 'tag_type_id' : tag_type['tag_type_id'], 'tagvalue' : tagvalue } nodegroup = NodeGroup(self.api, nodegroup_fields) nodegroup.sync() diff --git a/PLC/Methods/AddNodeTag.py b/PLC/Methods/AddNodeTag.py index 1584e02..62e166c 100644 --- a/PLC/Methods/AddNodeTag.py +++ b/PLC/Methods/AddNodeTag.py @@ -8,7 +8,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.TagTypes import TagType, TagTypes from PLC.NodeTags import NodeTag, NodeTags from PLC.Nodes import Node, Nodes @@ -33,8 +33,8 @@ class AddNodeTag(Method): # no other way to refer to a node Mixed(Node.fields['node_id'], Node.fields['hostname']), - Mixed(NodeTagType.fields['node_tag_type_id'], - NodeTagType.fields['tagname']), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), NodeTag.fields['tagvalue'], ] @@ -43,25 +43,25 @@ class AddNodeTag(Method): object_type = 'Node' - def call(self, auth, node_id, node_tag_type_id_or_name, value): + def call(self, auth, node_id, tag_type_id_or_name, value): nodes = Nodes(self.api, [node_id]) if not nodes: raise PLCInvalidArgument, "No such node %r"%node_id node = nodes[0] - node_tag_types = NodeTagTypes(self.api, [node_tag_type_id_or_name]) - if not node_tag_types: - raise PLCInvalidArgument, "No such node tag type %r"%node_tag_type_id_or_name - node_tag_type = node_tag_types[0] + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: + raise PLCInvalidArgument, "No such node tag type %r"%tag_type_id_or_name + tag_type = tag_types[0] # checks for existence - does not allow several different tags conflicts = NodeTags(self.api, {'node_id':node['node_id'], - 'node_tag_type_id':node_tag_type['node_tag_type_id']}) + 'tag_type_id':tag_type['tag_type_id']}) if len(conflicts) : raise PLCInvalidArgument, "Node %d already has tag %d"%(node['node_id'], - node_tag_type['node_tag_type_id']) + tag_type['tag_type_id']) # check permission : it not admin, is the user affiliated with the right site if 'admin' not in self.caller['roles']: @@ -73,14 +73,14 @@ class AddNodeTag(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 = node_tag_type ['min_role_id'] + required_min_role = tag_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 node tag, requires role %d",required_min_role node_tag = NodeTag(self.api) node_tag['node_id'] = node['node_id'] - node_tag['node_tag_type_id'] = node_tag_type['node_tag_type_id'] + node_tag['tag_type_id'] = tag_type['tag_type_id'] node_tag['tagvalue'] = value node_tag.sync() diff --git a/PLC/Methods/AddSliceAttribute.py b/PLC/Methods/AddSliceAttribute.py index 8102fe1..692dce0 100644 --- a/PLC/Methods/AddSliceAttribute.py +++ b/PLC/Methods/AddSliceAttribute.py @@ -1,7 +1,7 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes +from PLC.TagTypes import TagType, TagTypes from PLC.Slices import Slice, Slices from PLC.Nodes import Node, Nodes from PLC.SliceAttributes import SliceAttribute, SliceAttributes @@ -28,10 +28,10 @@ class AddSliceAttribute(Method): accepts = [ Auth(), - Mixed(SliceAttribute.fields['slice_id'], - SliceAttribute.fields['name']), - Mixed(SliceAttribute.fields['attribute_type_id'], - SliceAttribute.fields['name']), + Mixed(Slice.fields['slice_id'], + Slice.fields['name']), + Mixed(SliceAttribute.fields['tag_type_id'], + SliceAttribute.fields['tagname']), Mixed(SliceAttribute.fields['value'], InitScript.fields['name']), Mixed(Node.fields['node_id'], @@ -43,16 +43,16 @@ class AddSliceAttribute(Method): returns = Parameter(int, 'New slice_attribute_id (> 0) if successful') - def call(self, auth, slice_id_or_name, attribute_type_id_or_name, value, node_id_or_hostname = None, nodegroup_id_or_name = None): + def call(self, auth, slice_id_or_name, tag_type_id_or_name, value, node_id_or_hostname = None, nodegroup_id_or_name = None): slices = Slices(self.api, [slice_id_or_name]) if not slices: - raise PLCInvalidArgument, "No such slice" + raise PLCInvalidArgument, "No such slice %r"%slice_id_or_name slice = slices[0] - attribute_types = SliceAttributeTypes(self.api, [attribute_type_id_or_name]) - if not attribute_types: - raise PLCInvalidArgument, "No such slice attribute type" - attribute_type = attribute_types[0] + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: + raise PLCInvalidArgument, "No such tag type %r"%tag_type_id_or_name + tag_type = tag_types[0] if 'admin' not in self.caller['roles']: if self.caller['person_id'] in slice['person_ids']: @@ -62,19 +62,19 @@ class AddSliceAttribute(Method): elif slice['site_id'] not in self.caller['site_ids']: raise PLCPermissionDenied, "Specified slice not associated with any of your sites" - if attribute_type['min_role_id'] is not None and \ - min(self.caller['role_ids']) > attribute_type['min_role_id']: + if tag_type['min_role_id'] is not None and \ + min(self.caller['role_ids']) > tag_type['min_role_id']: raise PLCPermissionDenied, "Not allowed to set the specified slice attribute" # if initscript is specified, validate value - if attribute_type['name'] in ['initscript']: + if tag_type['tagname'] in ['initscript']: initscripts = InitScripts(self.api, {'enabled': True, 'name': value}) if not initscripts: - raise PLCInvalidArgument, "No such plc initscript" + raise PLCInvalidArgument, "No such plc initscript %r"%value slice_attribute = SliceAttribute(self.api) slice_attribute['slice_id'] = slice['slice_id'] - slice_attribute['attribute_type_id'] = attribute_type['attribute_type_id'] + slice_attribute['tag_type_id'] = tag_type['tag_type_id'] slice_attribute['value'] = unicode(value) # Sliver attribute if node is specified @@ -92,13 +92,15 @@ class AddSliceAttribute(Method): if nodegroup_id_or_name is not None: nodegroups = NodeGroups(self.api, [nodegroup_id_or_name]) if not nodegroups: - raise PLCInvalidArgument, "No such nodegroup" + raise PLCInvalidArgument, "No such nodegroup %r"%nodegroup_id_or_name nodegroup = nodegroups[0] slice_attribute['nodegroup_id'] = nodegroup['nodegroup_id'] # Check if slice attribute alreay exists - slice_attributes_check = SliceAttributes(self.api, {'slice_id': slice['slice_id'], 'name': attribute_type['name'], 'value': value}) + slice_attributes_check = SliceAttributes(self.api, {'slice_id': slice['slice_id'], + 'tagname': tag_type['tagname'], + 'value': value}) for slice_attribute_check in slice_attributes_check: if 'node_id' in slice_attribute and slice_attribute['node_id'] == slice_attribute_check['node_id']: raise PLCInvalidArgument, "Sliver attribute already exists" diff --git a/PLC/Methods/AddSliceAttributeType.py b/PLC/Methods/AddSliceAttributeType.py deleted file mode 100644 index 095ae83..0000000 --- a/PLC/Methods/AddSliceAttributeType.py +++ /dev/null @@ -1,38 +0,0 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes -from PLC.Auth import Auth - -can_update = lambda (field, value): field in \ - ['name', 'description', 'min_role_id'] - -class AddSliceAttributeType(Method): - """ - Adds a new type of slice attribute. Any fields specified in - attribute_type_fields are used, otherwise defaults are used. - - Returns the new attribute_type_id (> 0) if successful, faults - otherwise. - """ - - roles = ['admin'] - - attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items())) - - accepts = [ - Auth(), - attribute_type_fields - ] - - returns = Parameter(int, 'New attribute_id (> 0) if successful') - - - def call(self, auth, attribute_type_fields): - attribute_type_fields = dict(filter(can_update, attribute_type_fields.items())) - attribute_type = SliceAttributeType(self.api, attribute_type_fields) - attribute_type.sync() - - self.event_objects = {'AttributeType': [attribute_type['attribute_type_id']]} - - return attribute_type['attribute_type_id'] diff --git a/PLC/Methods/AddNodeTagType.py b/PLC/Methods/AddTagType.py similarity index 54% rename from PLC/Methods/AddNodeTagType.py rename to PLC/Methods/AddTagType.py index a542bd1..978af37 100644 --- a/PLC/Methods/AddNodeTagType.py +++ b/PLC/Methods/AddTagType.py @@ -8,13 +8,13 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.TagTypes import TagType, TagTypes from PLC.Auth import Auth can_update = lambda (field, value): field in \ ['tagname', 'description', 'category', 'min_role_id'] -class AddNodeTagType(Method): +class AddTagType(Method): """ Adds a new type of node tag. Any fields specified are used, otherwise defaults are used. @@ -25,21 +25,21 @@ class AddNodeTagType(Method): roles = ['admin'] - node_tag_type_fields = dict(filter(can_update, NodeTagType.fields.items())) + tag_type_fields = dict(filter(can_update, TagType.fields.items())) accepts = [ Auth(), - node_tag_type_fields + tag_type_fields ] returns = Parameter(int, 'New node_tag_id (> 0) if successful') - def call(self, auth, node_tag_type_fields): - node_tag_type_fields = dict(filter(can_update, node_tag_type_fields.items())) - node_tag_type = NodeTagType(self.api, node_tag_type_fields) - node_tag_type.sync() + def call(self, auth, tag_type_fields): + tag_type_fields = dict(filter(can_update, tag_type_fields.items())) + tag_type = TagType(self.api, tag_type_fields) + tag_type.sync() - self.object_ids = [node_tag_type['node_tag_type_id']] + self.object_ids = [tag_type['tag_type_id']] - return node_tag_type['node_tag_type_id'] + return tag_type['tag_type_id'] diff --git a/PLC/Methods/DeleteIlink.py b/PLC/Methods/DeleteIlink.py index 6e223d5..b6e05b2 100644 --- a/PLC/Methods/DeleteIlink.py +++ b/PLC/Methods/DeleteIlink.py @@ -19,8 +19,8 @@ class DeleteIlink(Method): """ Deletes the specified ilink - Attributes may require the caller to have a particular role in order - to be deleted, depending on the related ilink type. + Attributes may require the caller to have a particular + role in order to be deleted, depending on the related tag type. Admins may delete attributes of any slice or sliver. Returns 1 if successful, faults otherwise. @@ -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 = link_type ['min_role_id'] + required_min_role = tag_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/DeleteInterfaceSetting.py b/PLC/Methods/DeleteInterfaceSetting.py index 7037bc3..8ea1b77 100644 --- a/PLC/Methods/DeleteInterfaceSetting.py +++ b/PLC/Methods/DeleteInterfaceSetting.py @@ -20,7 +20,7 @@ class DeleteInterfaceSetting(Method): Deletes the specified interface setting Attributes may require the caller to have a particular role in order - to be deleted, depending on the related interface setting type. + to be deleted, depending on the related tag type. Admins may delete attributes of any slice or sliver. Returns 1 if successful, faults otherwise. @@ -62,7 +62,7 @@ class DeleteInterfaceSetting(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 = interface_setting_type ['min_role_id'] + required_min_role = tag_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 interface setting, requires role %d",required_min_role diff --git a/PLC/Methods/DeleteInterfaceSettingType.py b/PLC/Methods/DeleteInterfaceSettingType.py deleted file mode 100644 index 48af8cc..0000000 --- a/PLC/Methods/DeleteInterfaceSettingType.py +++ /dev/null @@ -1,39 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision$ -# -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes -from PLC.Auth import Auth - -class DeleteInterfaceSettingType(Method): - """ - Deletes the specified interface setting type. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - accepts = [ - Auth(), - Mixed(InterfaceSettingType.fields['interface_setting_type_id'], - InterfaceSettingType.fields['name']), - ] - - returns = Parameter(int, '1 if successful') - - - def call(self, auth, interface_setting_type_id_or_name): - interface_setting_types = InterfaceSettingTypes(self.api, [interface_setting_type_id_or_name]) - if not interface_setting_types: - raise PLCInvalidArgument, "No such interface setting type" - interface_setting_type = interface_setting_types[0] - - interface_setting_type.delete() - self.object_ids = [interface_setting_type['interface_setting_type_id']] - - return 1 diff --git a/PLC/Methods/DeleteLinkType.py b/PLC/Methods/DeleteLinkType.py deleted file mode 100644 index 91d3145..0000000 --- a/PLC/Methods/DeleteLinkType.py +++ /dev/null @@ -1,39 +0,0 @@ -# -# 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 - -class DeleteLinkType(Method): - """ - Deletes the specified ilink type. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - accepts = [ - Auth(), - Mixed(LinkType.fields['link_type_id'], - LinkType.fields['name']), - ] - - returns = Parameter(int, '1 if successful') - - - 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" - link_type = link_types[0] - - link_type.delete() - self.object_ids = [link_type['link_type_id']] - - return 1 diff --git a/PLC/Methods/DeleteNodeTag.py b/PLC/Methods/DeleteNodeTag.py index b7bfd3f..e76849c 100644 --- a/PLC/Methods/DeleteNodeTag.py +++ b/PLC/Methods/DeleteNodeTag.py @@ -62,7 +62,7 @@ class DeleteNodeTag(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 = node_tag_type ['min_role_id'] + required_min_role = tag_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 node tag, requires role %d",required_min_role diff --git a/PLC/Methods/DeleteSliceAttributeType.py b/PLC/Methods/DeleteSliceAttributeType.py deleted file mode 100644 index e6c1a8a..0000000 --- a/PLC/Methods/DeleteSliceAttributeType.py +++ /dev/null @@ -1,34 +0,0 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes -from PLC.Auth import Auth - -class DeleteSliceAttributeType(Method): - """ - Deletes the specified slice attribute. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - accepts = [ - Auth(), - Mixed(SliceAttributeType.fields['attribute_type_id'], - SliceAttributeType.fields['name']), - ] - - returns = Parameter(int, '1 if successful') - - - def call(self, auth, attribute_type_id_or_name): - attribute_types = SliceAttributeTypes(self.api, [attribute_type_id_or_name]) - if not attribute_types: - raise PLCInvalidArgument, "No such slice attribute type" - attribute_type = attribute_types[0] - - attribute_type.delete() - self.event_objects = {'AttributeType': [attribute_type['attribute_type_id']]} - - return 1 diff --git a/PLC/Methods/DeleteNodeTagType.py b/PLC/Methods/DeleteTagType.py similarity index 50% rename from PLC/Methods/DeleteNodeTagType.py rename to PLC/Methods/DeleteTagType.py index 3e6694c..6a485e0 100644 --- a/PLC/Methods/DeleteNodeTagType.py +++ b/PLC/Methods/DeleteTagType.py @@ -6,10 +6,10 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.TagTypes import TagType, TagTypes from PLC.Auth import Auth -class DeleteNodeTagType(Method): +class DeleteTagType(Method): """ Deletes the specified node tag type. @@ -20,20 +20,20 @@ class DeleteNodeTagType(Method): accepts = [ Auth(), - Mixed(NodeTagType.fields['node_tag_type_id'], - NodeTagType.fields['tagname']), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), ] returns = Parameter(int, '1 if successful') - def call(self, auth, node_tag_type_id_or_name): - node_tag_types = NodeTagTypes(self.api, [node_tag_type_id_or_name]) - if not node_tag_types: + def call(self, auth, tag_type_id_or_name): + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: raise PLCInvalidArgument, "No such node tag type" - node_tag_type = node_tag_types[0] + tag_type = tag_types[0] - node_tag_type.delete() - self.object_ids = [node_tag_type['node_tag_type_id']] + tag_type.delete() + self.object_ids = [tag_type['tag_type_id']] return 1 diff --git a/PLC/Methods/GetInterfaceSettingTypes.py b/PLC/Methods/GetInterfaceSettingTypes.py deleted file mode 100644 index 236d8ce..0000000 --- a/PLC/Methods/GetInterfaceSettingTypes.py +++ /dev/null @@ -1,33 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision$ -# -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Filter import Filter -from PLC.Auth import Auth -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes - -class GetInterfaceSettingTypes(Method): - """ - Returns an array of structs containing details about - interface setting types. - - The usual filtering scheme applies on this method. - """ - - roles = ['admin', 'pi', 'user', 'tech', 'node'] - - accepts = [ - Auth(), - Mixed([Mixed(InterfaceSettingType.fields['interface_setting_type_id'], - InterfaceSettingType.fields['name'])], - Filter(InterfaceSettingType.fields)), - Parameter([str], "List of fields to return", nullok = True) - ] - - returns = [InterfaceSettingType.fields] - - def call(self, auth, interface_setting_type_filter = None, return_fields = None): - return InterfaceSettingTypes(self.api, interface_setting_type_filter, return_fields) diff --git a/PLC/Methods/GetNodeTagTypes.py b/PLC/Methods/GetNodeTagTypes.py deleted file mode 100644 index 137e721..0000000 --- a/PLC/Methods/GetNodeTagTypes.py +++ /dev/null @@ -1,33 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision: 9423 $ -# -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Filter import Filter -from PLC.Auth import Auth -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes - -class GetNodeTagTypes(Method): - """ - Returns an array of structs containing details about - node tag types. - - The usual filtering scheme applies on this method. - """ - - roles = ['admin', 'pi', 'user', 'tech', 'node'] - - accepts = [ - Auth(), - Mixed([Mixed(NodeTagType.fields['node_tag_type_id'], - NodeTagType.fields['tagname'])], - Filter(NodeTagType.fields)), - Parameter([str], "List of fields to return", nullok = True) - ] - - returns = [NodeTagType.fields] - - def call(self, auth, node_tag_type_filter = None, return_fields = None): - return NodeTagTypes(self.api, node_tag_type_filter, return_fields) diff --git a/PLC/Methods/GetSliceAttributeTypes.py b/PLC/Methods/GetSliceAttributeTypes.py deleted file mode 100644 index bc8f1ed..0000000 --- a/PLC/Methods/GetSliceAttributeTypes.py +++ /dev/null @@ -1,30 +0,0 @@ -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.Filter import Filter -from PLC.Auth import Auth -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes - -class GetSliceAttributeTypes(Method): - """ - Returns an array of structs containing details about slice - attribute types. If attribute_type_filter is specified and - is an array of slice attribute type identifiers, or a - struct of slice attribute type attributes, only slice attribute - types matching the filter will be returned. If return_fields is - specified, only the specified details will be returned. - """ - - roles = ['admin', 'pi', 'user', 'tech', 'node'] - - accepts = [ - Auth(), - Mixed([Mixed(SliceAttributeType.fields['attribute_type_id'], - SliceAttributeType.fields['name'])], - Filter(SliceAttributeType.fields)), - Parameter([str], "List of fields to return", nullok = True) - ] - - returns = [SliceAttributeType.fields] - - def call(self, auth, attribute_type_filter = None, return_fields = None): - return SliceAttributeTypes(self.api, attribute_type_filter, return_fields) diff --git a/PLC/Methods/GetSlivers.py b/PLC/Methods/GetSlivers.py index 9123e46..39dd97c 100644 --- a/PLC/Methods/GetSlivers.py +++ b/PLC/Methods/GetSlivers.py @@ -140,7 +140,7 @@ class GetSlivers(Method): 'key': Key.fields['key'] }], 'attributes': [{ - 'name': SliceAttribute.fields['name'], + 'tagname': SliceAttribute.fields['tagname'], 'value': SliceAttribute.fields['value'] }] }] diff --git a/PLC/Methods/GetLinkTypes.py b/PLC/Methods/GetTagTypes.py similarity index 54% rename from PLC/Methods/GetLinkTypes.py rename to PLC/Methods/GetTagTypes.py index 3182fa8..ebcff1e 100644 --- a/PLC/Methods/GetLinkTypes.py +++ b/PLC/Methods/GetTagTypes.py @@ -7,12 +7,12 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Filter import Filter from PLC.Auth import Auth -from PLC.LinkTypes import LinkType, LinkTypes +from PLC.TagTypes import TagType, TagTypes -class GetLinkTypes(Method): +class GetTagTypes(Method): """ Returns an array of structs containing details about - ilink types. + node tag types. The usual filtering scheme applies on this method. """ @@ -21,13 +21,13 @@ class GetLinkTypes(Method): accepts = [ Auth(), - Mixed([Mixed(LinkType.fields['link_type_id'], - LinkType.fields['name'])], - Filter(LinkType.fields)), + Mixed([Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname'])], + Filter(TagType.fields)), Parameter([str], "List of fields to return", nullok = True) ] - returns = [LinkType.fields] + returns = [TagType.fields] - def call(self, auth, link_type_filter = None, return_fields = None): - return LinkTypes(self.api, link_type_filter, return_fields) + def call(self, auth, tag_type_filter = None, return_fields = None): + return TagTypes(self.api, tag_type_filter, return_fields) diff --git a/PLC/Methods/SliceGetTicket.py b/PLC/Methods/SliceGetTicket.py index 64413c9..7cdb167 100644 --- a/PLC/Methods/SliceGetTicket.py +++ b/PLC/Methods/SliceGetTicket.py @@ -186,7 +186,7 @@ class SliceGetTicket(GetSliceTicket): attribute_name = value_name = name type = "string" - # + # xml.startElement('resource', {'name': unicode(attribute_name)}) # diff --git a/PLC/Methods/UpdateIlink.py b/PLC/Methods/UpdateIlink.py index c2bf751..ef6e80e 100644 --- a/PLC/Methods/UpdateIlink.py +++ b/PLC/Methods/UpdateIlink.py @@ -18,7 +18,7 @@ class UpdateIlink(Method): """ Updates the value of an existing ilink - Access rights depend on the ilink type. + Access rights depend on the tag type. Returns 1 if successful, faults otherwise. """ @@ -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 = link_type ['min_role_id'] + required_min_role = tag_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/UpdateInterfaceSetting.py b/PLC/Methods/UpdateInterfaceSetting.py index b62c93b..cdc4dc5 100644 --- a/PLC/Methods/UpdateInterfaceSetting.py +++ b/PLC/Methods/UpdateInterfaceSetting.py @@ -19,7 +19,7 @@ class UpdateInterfaceSetting(Method): """ Updates the value of an existing interface setting - Access rights depend on the interface setting type. + Access rights depend on the tag type. Returns 1 if successful, faults otherwise. """ @@ -60,7 +60,7 @@ class UpdateInterfaceSetting(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 = interface_setting_type ['min_role_id'] + required_min_role = tag_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 interface setting, requires role %d",required_min_role diff --git a/PLC/Methods/UpdateInterfaceSettingType.py b/PLC/Methods/UpdateInterfaceSettingType.py deleted file mode 100644 index b16a750..0000000 --- a/PLC/Methods/UpdateInterfaceSettingType.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# Thierry Parmentelat - INRIA -# -# $Revision$ -# -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.InterfaceSettingTypes import InterfaceSettingType, InterfaceSettingTypes -from PLC.Auth import Auth - -can_update = lambda (field, value): field in \ - ['name', 'description', 'category', 'min_role_id'] - -class UpdateInterfaceSettingType(Method): - """ - Updates the parameters of an existing setting type - with the values in interface_setting_type_fields. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - interface_setting_type_fields = dict(filter(can_update, InterfaceSettingType.fields.items())) - - accepts = [ - Auth(), - Mixed(InterfaceSettingType.fields['interface_setting_type_id'], - InterfaceSettingType.fields['name']), - interface_setting_type_fields - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, interface_setting_type_id_or_name, interface_setting_type_fields): - interface_setting_type_fields = dict(filter(can_update, interface_setting_type_fields.items())) - - interface_setting_types = InterfaceSettingTypes(self.api, [interface_setting_type_id_or_name]) - if not interface_setting_types: - raise PLCInvalidArgument, "No such setting type" - interface_setting_type = interface_setting_types[0] - - interface_setting_type.update(interface_setting_type_fields) - interface_setting_type.sync() - self.object_ids = [interface_setting_type['interface_setting_type_id']] - - return 1 diff --git a/PLC/Methods/UpdateLinkType.py b/PLC/Methods/UpdateLinkType.py deleted file mode 100644 index f1ee43a..0000000 --- a/PLC/Methods/UpdateLinkType.py +++ /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.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 diff --git a/PLC/Methods/UpdateNodeTag.py b/PLC/Methods/UpdateNodeTag.py index 563e62b..2d39e19 100644 --- a/PLC/Methods/UpdateNodeTag.py +++ b/PLC/Methods/UpdateNodeTag.py @@ -60,7 +60,7 @@ class UpdateNodeTag(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 = node_tag_type ['min_role_id'] + required_min_role = tag_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 node tag, requires role %d",required_min_role diff --git a/PLC/Methods/UpdateNodeTagType.py b/PLC/Methods/UpdateNodeTagType.py deleted file mode 100644 index b0831ba..0000000 --- a/PLC/Methods/UpdateNodeTagType.py +++ /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.NodeTagTypes import NodeTagType, NodeTagTypes -from PLC.Auth import Auth - -can_update = lambda (field, value): field in \ - ['tagname', 'description', 'category', 'min_role_id'] - -class UpdateNodeTagType(Method): - """ - Updates the parameters of an existing tag type - with the values in node_tag_type_fields. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - node_tag_type_fields = dict(filter(can_update, NodeTagType.fields.items())) - - accepts = [ - Auth(), - Mixed(NodeTagType.fields['node_tag_type_id'], - NodeTagType.fields['tagname']), - node_tag_type_fields - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, node_tag_type_id_or_name, node_tag_type_fields): - node_tag_type_fields = dict(filter(can_update, node_tag_type_fields.items())) - - node_tag_types = NodeTagTypes(self.api, [node_tag_type_id_or_name]) - if not node_tag_types: - raise PLCInvalidArgument, "No such tag type" - node_tag_type = node_tag_types[0] - - node_tag_type.update(node_tag_type_fields) - node_tag_type.sync() - self.object_ids = [node_tag_type['node_tag_type_id']] - - return 1 diff --git a/PLC/Methods/UpdateSliceAttribute.py b/PLC/Methods/UpdateSliceAttribute.py index 9451291..3c21403 100644 --- a/PLC/Methods/UpdateSliceAttribute.py +++ b/PLC/Methods/UpdateSliceAttribute.py @@ -54,7 +54,7 @@ class UpdateSliceAttribute(Method): min(self.caller['role_ids']) > slice_attribute['min_role_id']: raise PLCPermissionDenied, "Not allowed to update the specified attribute" - if slice_attribute['name'] in ['initscript']: + if slice_attribute['tagname'] in ['initscript']: initscripts = InitScripts(self.api, {'enabled': True, 'name': value}) if not initscripts: raise PLCInvalidArgument, "No such plc initscript" diff --git a/PLC/Methods/UpdateSliceAttributeType.py b/PLC/Methods/UpdateSliceAttributeType.py deleted file mode 100644 index 145a51d..0000000 --- a/PLC/Methods/UpdateSliceAttributeType.py +++ /dev/null @@ -1,43 +0,0 @@ -from PLC.Faults import * -from PLC.Method import Method -from PLC.Parameter import Parameter, Mixed -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes -from PLC.Auth import Auth - -can_update = lambda (field, value): field in \ - ['name', 'description', 'min_role_id'] - -class UpdateSliceAttributeType(Method): - """ - Updates the parameters of an existing attribute with the values in - attribute_type_fields. - - Returns 1 if successful, faults otherwise. - """ - - roles = ['admin'] - - attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items())) - - accepts = [ - Auth(), - Mixed(SliceAttributeType.fields['attribute_type_id'], - SliceAttributeType.fields['name']), - attribute_type_fields - ] - - returns = Parameter(int, '1 if successful') - - def call(self, auth, attribute_type_id_or_name, attribute_type_fields): - attribute_type_fields = dict(filter(can_update, attribute_type_fields.items())) - - attribute_types = SliceAttributeTypes(self.api, [attribute_type_id_or_name]) - if not attribute_types: - raise PLCInvalidArgument, "No such attribute" - attribute_type = attribute_types[0] - - attribute_type.update(attribute_type_fields) - attribute_type.sync() - self.event_objects = {'AttributeType': [attribute_type['attribute_type_id']]} - - return 1 diff --git a/PLC/Methods/UpdateTagType.py b/PLC/Methods/UpdateTagType.py new file mode 100644 index 0000000..7067917 --- /dev/null +++ b/PLC/Methods/UpdateTagType.py @@ -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.TagTypes import TagType, TagTypes +from PLC.Auth import Auth + +can_update = lambda (field, value): field in \ + ['tagname', 'description', 'category', 'min_role_id'] + +class UpdateTagType(Method): + """ + Updates the parameters of an existing tag type + with the values in tag_type_fields. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin'] + + tag_type_fields = dict(filter(can_update, TagType.fields.items())) + + accepts = [ + Auth(), + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), + tag_type_fields + ] + + returns = Parameter(int, '1 if successful') + + def call(self, auth, tag_type_id_or_name, tag_type_fields): + tag_type_fields = dict(filter(can_update, tag_type_fields.items())) + + tag_types = TagTypes(self.api, [tag_type_id_or_name]) + if not tag_types: + raise PLCInvalidArgument, "No such tag type" + tag_type = tag_types[0] + + tag_type.update(tag_type_fields) + tag_type.sync() + self.object_ids = [tag_type['tag_type_id']] + + return 1 diff --git a/PLC/Methods/__init__.py b/PLC/Methods/__init__.py index 7bc0ea1..08d9f1f 100644 --- a/PLC/Methods/__init__.py +++ b/PLC/Methods/__init__.py @@ -9,16 +9,13 @@ AddIlink AddInitScript AddInterface AddInterfaceSetting -AddInterfaceSettingType AddKeyType -AddLinkType AddMessage AddNetworkMethod AddNetworkType AddNode AddNodeGroup AddNodeTag -AddNodeTagType AddNodeToPCU AddPCU AddPCUProtocolType @@ -35,10 +32,10 @@ AddSite AddSiteAddress AddSlice AddSliceAttribute -AddSliceAttributeType AddSliceInstantiation AddSliceToNodes AddSliceToNodesWhitelist +AddTagType AuthCheck BlacklistKey BootCheckAuthentication @@ -56,10 +53,8 @@ DeleteIlink DeleteInitScript DeleteInterface DeleteInterfaceSetting -DeleteInterfaceSettingType DeleteKey DeleteKeyType -DeleteLinkType DeleteMessage DeleteNetworkMethod DeleteNetworkType @@ -67,7 +62,6 @@ DeleteNode DeleteNodeFromPCU DeleteNodeGroup DeleteNodeTag -DeleteNodeTagType DeletePCU DeletePCUProtocolType DeletePCUType @@ -81,10 +75,10 @@ DeleteSession DeleteSite DeleteSlice DeleteSliceAttribute -DeleteSliceAttributeType DeleteSliceFromNodes DeleteSliceFromNodesWhitelist DeleteSliceInstantiation +DeleteTagType GenerateNodeConfFile GetAddressTypes GetAddresses @@ -95,17 +89,14 @@ GetEventObjects GetEvents GetIlinks GetInitScripts -GetInterfaceSettingTypes GetInterfaceSettings GetInterfaces GetKeyTypes GetKeys -GetLinkTypes GetMessages GetNetworkMethods GetNetworkTypes GetNodeGroups -GetNodeTagTypes GetNodeTags GetNodes GetPCUProtocolTypes @@ -120,7 +111,6 @@ GetRoles GetSession GetSessions GetSites -GetSliceAttributeTypes GetSliceAttributes GetSliceInstantiations GetSliceKeys @@ -128,6 +118,7 @@ GetSliceTicket GetSlices GetSlicesMD5 GetSlivers +GetTagTypes GetWhitelist NotifyPersons NotifySupport @@ -158,14 +149,11 @@ UpdateIlink UpdateInitScript UpdateInterface UpdateInterfaceSetting -UpdateInterfaceSettingType UpdateKey -UpdateLinkType UpdateMessage UpdateNode UpdateNodeGroup UpdateNodeTag -UpdateNodeTagType UpdatePCU UpdatePCUProtocolType UpdatePCUType @@ -174,7 +162,7 @@ UpdatePerson UpdateSite UpdateSlice UpdateSliceAttribute -UpdateSliceAttributeType +UpdateTagType VerifyPerson system.listMethods system.methodHelp diff --git a/PLC/NodeGroups.py b/PLC/NodeGroups.py index bf624ef..9292467 100644 --- a/PLC/NodeGroups.py +++ b/PLC/NodeGroups.py @@ -30,7 +30,7 @@ class NodeGroup(Row): fields = { 'nodegroup_id': Parameter(int, "Node group identifier"), 'groupname': Parameter(str, "Node group name", max = 50), - 'node_tag_type_id': Parameter (int, "Node tag type id"), + 'tag_type_id': Parameter (int, "Node tag type id"), 'tagvalue' : Parameter(str, "value that the nodegroup definition is based upon"), 'tagname' : Parameter(str, "Tag name that the nodegroup definition is based upon"), 'conf_file_ids': Parameter([int], "List of configuration files specific to this node group"), diff --git a/PLC/NodeTagTypes.py b/PLC/NodeTagTypes.py deleted file mode 100644 index 92d96d2..0000000 --- a/PLC/NodeTagTypes.py +++ /dev/null @@ -1,78 +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 NodeTagType (Row): - - """ - Representation of a row in the node_tag_types table. - """ - - table_name = 'node_tag_types' - primary_key = 'node_tag_type_id' - join_tables = ['node_tag'] - fields = { - 'node_tag_type_id': Parameter(int, "Node tag type identifier"), - 'tagname': Parameter(str, "Node tag type name", max = 100), - 'description': Parameter(str, "Node tag type description", max = 254), - 'category' : Parameter (str, "Node tag category", max=64, optional=True), - '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, "node tag type name must be set" - - conflicts = NodeTagTypes(self.api, [name]) - for tag_type in conflicts: - if 'node_tag_type_id' not in self or \ - self['node_tag_type_id'] != tag_type['node_tag_type_id']: - raise PLCInvalidArgument, "node tag 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 NodeTagTypes(Table): - """ - Representation of row(s) from the node_tag_types table - in the database. - """ - - def __init__(self, api, node_tag_type_filter = None, columns = None): - Table.__init__(self, api, NodeTagType, columns) - - sql = "SELECT %s FROM node_tag_types WHERE True" % \ - ", ".join(self.columns) - - if node_tag_type_filter is not None: - if isinstance(node_tag_type_filter, (list, tuple, set)): - # Separate the list into integers and strings - ints = filter(lambda x: isinstance(x, (int, long)), node_tag_type_filter) - strs = filter(lambda x: isinstance(x, StringTypes), node_tag_type_filter) - node_tag_type_filter = Filter(NodeTagType.fields, {'node_tag_type_id': ints, 'tagname': strs}) - sql += " AND (%s) %s" % node_tag_type_filter.sql(api, "OR") - elif isinstance(node_tag_type_filter, dict): - node_tag_type_filter = Filter(NodeTagType.fields, node_tag_type_filter) - sql += " AND (%s) %s" % node_tag_type_filter.sql(api, "AND") - elif isinstance (node_tag_type_filter, StringTypes): - node_tag_type_filter = Filter(NodeTagType.fields, {'tagname':[node_tag_type_filter]}) - sql += " AND (%s) %s" % node_tag_type_filter.sql(api, "AND") - else: - raise PLCInvalidArgument, "Wrong node tag type filter %r"%node_tag_type_filter - - self.selectall(sql) diff --git a/PLC/NodeTags.py b/PLC/NodeTags.py index 8690a8a..4949e8c 100644 --- a/PLC/NodeTags.py +++ b/PLC/NodeTags.py @@ -8,7 +8,7 @@ from PLC.Parameter import Parameter from PLC.Filter import Filter from PLC.Table import Row, Table from PLC.Nodes import Node, Nodes -from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.TagTypes import TagType, TagTypes class NodeTag(Row): """ @@ -22,12 +22,12 @@ class NodeTag(Row): 'node_tag_id': Parameter(int, "Node tag identifier"), 'node_id': Node.fields['node_id'], 'hostname' : Node.fields['hostname'], - 'node_tag_type_id': NodeTagType.fields['node_tag_type_id'], + 'tag_type_id': TagType.fields['tag_type_id'], 'tagvalue': Parameter(str, "Node tag value"), - 'tagname': NodeTagType.fields['tagname'], - 'description': NodeTagType.fields['description'], - 'category': NodeTagType.fields['category'], - 'min_role_id': NodeTagType.fields['min_role_id'], + 'tagname': TagType.fields['tagname'], + 'description': TagType.fields['description'], + 'category': TagType.fields['category'], + 'min_role_id': TagType.fields['min_role_id'], } class NodeTags(Table): diff --git a/PLC/Nodes.py b/PLC/Nodes.py index 73a8223..cc7bbcc 100644 --- a/PLC/Nodes.py +++ b/PLC/Nodes.py @@ -128,12 +128,12 @@ class Node(Row): def associate_interfaces(self, auth, field, value): """ - Delete interfaces not found in value list (using DeleteNodeNetwor)k + Delete interfaces not found in value list (using DeleteInterface) Add interfaces found in value list (using AddInterface) Updates interfaces found w/ interface_id in value list (using UpdateInterface) """ - assert 'interfacep_ids' in self + assert 'interface_ids' in self assert 'node_id' in self assert isinstance(value, list) diff --git a/PLC/Peers.py b/PLC/Peers.py index 0973c3d..582cdb0 100644 --- a/PLC/Peers.py +++ b/PLC/Peers.py @@ -16,7 +16,7 @@ from PLC.Sites import Site, Sites from PLC.Persons import Person, Persons from PLC.Keys import Key, Keys from PLC.Nodes import Node, Nodes -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes +from PLC.TagTypes import TagType, TagTypes from PLC.SliceAttributes import SliceAttribute, SliceAttributes from PLC.Slices import Slice, Slices @@ -28,8 +28,7 @@ class Peer(Row): table_name = 'peers' primary_key = 'peer_id' - join_tables = ['peer_site', 'peer_person', 'peer_key', 'peer_node', - 'peer_slice_attribute_type', 'peer_slice_attribute', 'peer_slice'] + join_tables = ['peer_site', 'peer_person', 'peer_key', 'peer_node', 'peer_slice'] fields = { 'peer_id': Parameter (int, "Peer identifier"), 'peername': Parameter (str, "Peer name"), diff --git a/PLC/Roles.py b/PLC/Roles.py index 400b344..ddb33af 100644 --- a/PLC/Roles.py +++ b/PLC/Roles.py @@ -21,7 +21,7 @@ class Role(Row): table_name = 'roles' primary_key = 'role_id' - join_tables = ['person_role', ('slice_attribute_types', 'min_role_id')] + join_tables = ['person_role', ('tag_types', 'min_role_id')] fields = { 'role_id': Parameter(int, "Role identifier"), 'name': Parameter(str, "Role", max = 100), diff --git a/PLC/SliceAttributeTypes.py b/PLC/SliceAttributeTypes.py deleted file mode 100644 index 030bcde..0000000 --- a/PLC/SliceAttributeTypes.py +++ /dev/null @@ -1,67 +0,0 @@ -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 SliceAttributeType(Row): - """ - Representation of a row in the slice_attribute_types table. To - use, instantiate with a dict of values. - """ - - 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), - 'description': Parameter(str, "Slice attribute 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, "Slice attribute type name must be set" - - conflicts = SliceAttributeTypes(self.api, [name]) - for attribute in conflicts: - if 'attribute_type_id' not in self or \ - self['attribute_type_id'] != attribute['attribute_type_id']: - raise PLCInvalidArgument, "Slice attribute 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 SliceAttributeTypes(Table): - """ - Representation of row(s) from the slice_attribute_types table in the - database. - """ - - def __init__(self, api, attribute_type_filter = None, columns = None): - Table.__init__(self, api, SliceAttributeType, columns) - - sql = "SELECT %s FROM slice_attribute_types WHERE True" % \ - ", ".join(self.columns) - - if attribute_type_filter is not None: - if isinstance(attribute_type_filter, (list, tuple, set)): - # Separate the list into integers and strings - ints = filter(lambda x: isinstance(x, (int, long)), attribute_type_filter) - strs = filter(lambda x: isinstance(x, StringTypes), attribute_type_filter) - attribute_type_filter = Filter(SliceAttributeType.fields, {'attribute_type_id': ints, 'name': strs}) - sql += " AND (%s) %s" % attribute_type_filter.sql(api, "OR") - elif isinstance(attribute_type_filter, dict): - attribute_type_filter = Filter(SliceAttributeType.fields, attribute_type_filter) - sql += " AND (%s) %s" % attribute_type_filter.sql(api, "AND") - - self.selectall(sql) diff --git a/PLC/SliceAttributes.py b/PLC/SliceAttributes.py index 9f0b1fb..eafebc4 100644 --- a/PLC/SliceAttributes.py +++ b/PLC/SliceAttributes.py @@ -2,7 +2,7 @@ from PLC.Faults import * from PLC.Parameter import Parameter from PLC.Filter import Filter from PLC.Table import Row, Table -from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes +from PLC.TagTypes import TagType, TagTypes class SliceAttribute(Row): """ @@ -17,10 +17,11 @@ class SliceAttribute(Row): 'slice_id': Parameter(int, "Slice identifier"), 'node_id': Parameter(int, "Node identifier, if a sliver attribute"), 'nodegroup_id': Parameter(int, "Nodegroup identifier, if a sliver attribute"), - 'attribute_type_id': SliceAttributeType.fields['attribute_type_id'], - 'name': SliceAttributeType.fields['name'], - 'description': SliceAttributeType.fields['description'], - 'min_role_id': SliceAttributeType.fields['min_role_id'], + 'tag_type_id': TagType.fields['tag_type_id'], + 'tagname': TagType.fields['tagname'], + 'description': TagType.fields['description'], + 'category': TagType.fields['category'], + 'min_role_id': TagType.fields['min_role_id'], 'value': Parameter(str, "Slice attribute value"), } diff --git a/PLC/Slices.py b/PLC/Slices.py index 5c670b7..5dcde46 100644 --- a/PLC/Slices.py +++ b/PLC/Slices.py @@ -183,12 +183,12 @@ class Slice(Row): updated_attributes = filter(lambda x: 'slice_attribute_id' in x, attributes) for added_attribute in added_attributes: - if 'attribute_type' in added_attribute: - type = added_attribute['attribute_type'] - elif 'attribute_type_id' in added_attribute: - type = added_attribute['attribute_type_id'] + if 'tag_type' in added_attribute: + type = added_attribute['tag_type'] + elif 'tag_type_id' in added_attribute: + type = added_attribute['tag_type_id'] else: - raise PLCInvalidArgument, "Must specify attribute_type or attribute_type_id" + raise PLCInvalidArgument, "Must specify tag_type or tag_type_id" if 'value' in added_attribute: value = added_attribute['value'] diff --git a/PLC/TagTypes.py b/PLC/TagTypes.py new file mode 100644 index 0000000..f15cbfe --- /dev/null +++ b/PLC/TagTypes.py @@ -0,0 +1,80 @@ +# +# 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 + +# xxx todo : deleting a tag type should delete the related nodegroup(s) + +class TagType (Row): + + """ + Representation of a row in the tag_types table. + """ + + table_name = 'tag_types' + primary_key = 'tag_type_id' + join_tables = ['node_tag'] + fields = { + 'tag_type_id': Parameter(int, "Node tag type identifier"), + 'tagname': Parameter(str, "Node tag type name", max = 100), + 'description': Parameter(str, "Node tag type description", max = 254), + 'category' : Parameter (str, "Node tag category", max=64, optional=True), + '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, "node tag type name must be set" + + conflicts = TagTypes(self.api, [name]) + for tag_type in conflicts: + if 'tag_type_id' not in self or \ + self['tag_type_id'] != tag_type['tag_type_id']: + raise PLCInvalidArgument, "node tag 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 TagTypes(Table): + """ + Representation of row(s) from the tag_types table + in the database. + """ + + def __init__(self, api, tag_type_filter = None, columns = None): + Table.__init__(self, api, TagType, columns) + + sql = "SELECT %s FROM tag_types WHERE True" % \ + ", ".join(self.columns) + + if tag_type_filter is not None: + if isinstance(tag_type_filter, (list, tuple, set)): + # Separate the list into integers and strings + ints = filter(lambda x: isinstance(x, (int, long)), tag_type_filter) + strs = filter(lambda x: isinstance(x, StringTypes), tag_type_filter) + tag_type_filter = Filter(TagType.fields, {'tag_type_id': ints, 'tagname': strs}) + sql += " AND (%s) %s" % tag_type_filter.sql(api, "OR") + elif isinstance(tag_type_filter, dict): + tag_type_filter = Filter(TagType.fields, tag_type_filter) + sql += " AND (%s) %s" % tag_type_filter.sql(api, "AND") + elif isinstance (tag_type_filter, StringTypes): + tag_type_filter = Filter(TagType.fields, {'tagname':[tag_type_filter]}) + sql += " AND (%s) %s" % tag_type_filter.sql(api, "AND") + else: + raise PLCInvalidArgument, "Wrong node tag type filter %r"%tag_type_filter + + self.selectall(sql) diff --git a/PLC/__init__.py b/PLC/__init__.py index 9f3415c..22f8b24 100644 --- a/PLC/__init__.py +++ b/PLC/__init__.py @@ -15,18 +15,15 @@ Filter GPG Ilinks InitScripts -InterfaceSettingTypes InterfaceSettings Interfaces KeyTypes Keys -LinkTypes Messages Method NetworkMethods NetworkTypes NodeGroups -NodeTagTypes NodeTags Nodes PCUProtocolTypes @@ -42,11 +39,10 @@ Roles Sessions Shell Sites -SliceAttributeTypes SliceAttributes SliceInstantiations Slices Table -Test +TagTypes sendmail """.split() diff --git a/migrations/migrate-v4-to-v5.sql b/migrations/migrate-v4-to-v5.sql index 86f4db9..31027b2 100644 --- a/migrations/migrate-v4-to-v5.sql +++ b/migrations/migrate-v4-to-v5.sql @@ -12,8 +12,9 @@ ALTER TABLE interfaces RENAME COLUMN nodenetwork_id TO interface_id; ALTER INDEX nodenetworks_node_id_idx RENAME TO interfaces_node_id_idx; -ALTER TABLE nodenetwork_setting_types RENAME TO interface_setting_types; -ALTER TABLE interface_setting_types RENAME COLUMN nodenetwork_setting_type_id TO interface_setting_type_id; +-- xxx need manual merge -> turn into tag_type +--ALTER TABLE nodenetwork_setting_types RENAME TO interface_setting_types; +--ALTER TABLE interface_setting_types RENAME COLUMN nodenetwork_setting_type_id TO interface_setting_type_id; ALTER TABLE nodenetwork_setting RENAME TO interface_setting; @@ -31,7 +32,8 @@ ALTER TABLE interface_settings RENAME COLUMN nodenetwork_setting_ids TO interfac ALTER TABLE view_nodenetwork_settings RENAME TO view_interface_settings; ALTER TABLE view_interface_settings RENAME COLUMN nodenetwork_setting_id TO interface_setting_id; ALTER TABLE view_interface_settings RENAME COLUMN nodenetwork_id TO interface_id; -ALTER TABLE view_interface_settings RENAME COLUMN nodenetwork_setting_type_id TO interface_setting_type_id; +-- xxx need manual merge -> turn into tag_type +--ALTER TABLE view_interface_settings RENAME COLUMN nodenetwork_setting_type_id TO interface_setting_type_id; ALTER TABLE view_nodenetworks RENAME TO view_interfaces; ALTER TABLE view_interfaces RENAME COLUMN nodenetwork_id TO interface_id; @@ -42,7 +44,7 @@ ALTER TABLE view_nodes RENAME COLUMN nodenetwork_ids TO interface_ids; ---------------------------------------- -- node tags ---------------------------------------- -CREATE TABLE node_tag_types ... +CREATE TABLE tag_types ... CREATE TABLE node_tag ... ---------- related views @@ -72,7 +74,7 @@ CREATE OR REPLACE VIEW view_nodes AS ... ---------------------------------------- -- ilinks ---------------------------------------- -CREATE TABLE link_types ... +--CREATE TABLE link_types ... CREATE TABLE ilink ... CREATE OR REPLACE VIEW ilinks AS ... diff --git a/planetlab5.sql b/planetlab5.sql index fe4e562..7219d9b 100644 --- a/planetlab5.sql +++ b/planetlab5.sql @@ -290,9 +290,9 @@ GROUP BY site_id; -------------------------------------------------------------------------------- -- node tags -------------------------------------------------------------------------------- -CREATE TABLE node_tag_types ( +CREATE TABLE tag_types ( - node_tag_type_id serial PRIMARY KEY, -- ID + tag_type_id serial PRIMARY KEY, -- ID tagname text UNIQUE NOT NULL, -- Tag Name description text, -- Optional Description category text NOT NULL DEFAULT 'general', -- Free text for grouping tags together @@ -302,7 +302,7 @@ CREATE TABLE node_tag_types ( CREATE TABLE node_tag ( node_tag_id serial PRIMARY KEY, -- ID node_id integer REFERENCES nodes NOT NULL, -- node id - node_tag_type_id integer REFERENCES node_tag_types, -- tag type id + tag_type_id integer REFERENCES tag_types, -- tag type id tagvalue text -- value attached ) WITH OIDS; @@ -317,14 +317,14 @@ SELECT node_tag.node_tag_id, node_tag.node_id, nodes.hostname, -node_tag_types.node_tag_type_id, -node_tag_types.tagname, -node_tag_types.description, -node_tag_types.category, -node_tag_types.min_role_id, +tag_types.tag_type_id, +tag_types.tagname, +tag_types.description, +tag_types.category, +tag_types.min_role_id, node_tag.tagvalue FROM node_tag -INNER JOIN node_tag_types USING (node_tag_type_id) +INNER JOIN tag_types USING (tag_type_id) INNER JOIN nodes USING (node_id); -------------------------------------------------------------------------------- @@ -381,22 +381,13 @@ FROM interfaces_ordered GROUP BY node_id; -------------------------------------------------------------------------------- --- Interface setting types and interfaces settings +-- Interface settings -------------------------------------------------------------------------------- -CREATE TABLE interface_setting_types ( - interface_setting_type_id serial PRIMARY KEY, -- Setting Type Identifier - name text UNIQUE NOT NULL, -- Setting Name - description text, -- Optional Description - category text NOT NULL DEFAULT 'general', -- Free text for grouping, e.g. Wifi, or whatever - min_role_id integer REFERENCES roles DEFAULT 10 -- minimal role required -) WITH OIDS; - CREATE TABLE interface_setting ( interface_setting_id serial PRIMARY KEY, -- Interface Setting Identifier interface_id integer REFERENCES interfaces NOT NULL,-- the interface this applies to - interface_setting_type_id integer - REFERENCES interface_setting_types NOT NULL, -- the setting type + tag_type_id integer REFERENCES tag_types NOT NULL, -- the setting type value text -- value attached ) WITH OIDS; @@ -410,14 +401,14 @@ CREATE OR REPLACE VIEW view_interface_settings AS SELECT interface_setting.interface_setting_id, interface_setting.interface_id, -interface_setting_types.interface_setting_type_id, -interface_setting_types.name, -interface_setting_types.description, -interface_setting_types.category, -interface_setting_types.min_role_id, +tag_types.tag_type_id, +tag_types.tagname, +tag_types.description, +tag_types.category, +tag_types.min_role_id, interface_setting.value FROM interface_setting -INNER JOIN interface_setting_types USING (interface_setting_type_id); +INNER JOIN tag_types USING (tag_type_id); CREATE OR REPLACE VIEW view_interfaces AS SELECT @@ -442,30 +433,23 @@ FROM interfaces; -------------------------------------------------------------------------------- -- ilinks : links between interfaces -------------------------------------------------------------------------------- -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 -) WITH OIDS; - CREATE TABLE ilink ( ilink_id serial PRIMARY KEY, -- id - link_type_id integer REFERENCES link_types, -- id of the ilink type + tag_type_id integer REFERENCES tag_types, -- id of the tag 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 link_types -INNER JOIN ilink USING (link_type_id); +SELECT * FROM tag_types +INNER JOIN ilink USING (tag_type_id); -- expose node_ids ??? -- -- cannot mention the same table twice in a join ? -- -- CREATE OR REPLACE VIEW ilink_src_node AS -- SELECT --- ilink.link_type_id, +-- ilink.tag_type_id, -- ilink.src_interface_id, -- interfaces.node_id AS src_node_id, -- ilink.dst_interface_id @@ -485,20 +469,20 @@ INNER JOIN ilink USING (link_type_id); -- Node groups CREATE TABLE nodegroups ( - nodegroup_id serial PRIMARY KEY, -- Group identifier - groupname text UNIQUE NOT NULL, -- Group name - node_tag_type_id integer REFERENCES node_tag_types, -- node is in nodegroup if it has this tag defined - tagvalue text NOT NULL -- with this value attached + nodegroup_id serial PRIMARY KEY, -- Group identifier + groupname text UNIQUE NOT NULL, -- Group name + tag_type_id integer REFERENCES tag_types, -- node is in nodegroup if it has this tag defined + tagvalue text NOT NULL -- with this value attached ) WITH OIDS; -- xxx - first rough implem. similar to former semantics but might be slow CREATE OR REPLACE VIEW nodegroup_node AS SELECT nodegroup_id, node_id -FROM node_tag_types +FROM tag_types JOIN node_tag -USING (node_tag_type_id) +USING (tag_type_id) JOIN nodegroups -USING (node_tag_type_id,tagvalue); +USING (tag_type_id,tagvalue); CREATE OR REPLACE VIEW nodegroup_nodes AS SELECT nodegroup_id, @@ -746,23 +730,13 @@ GROUP BY node_id; -- Slice attributes -------------------------------------------------------------------------------- --- Slice attribute types -CREATE TABLE slice_attribute_types ( - attribute_type_id serial PRIMARY KEY, -- Attribute type identifier - name text UNIQUE NOT NULL, -- Attribute name - description text, -- Attribute description - min_role_id integer REFERENCES roles DEFAULT 10 -- If set, minimum (least powerful) role that can - -- set or change this attribute -) WITH OIDS; - -- Slice/sliver attributes CREATE TABLE slice_attribute ( slice_attribute_id serial PRIMARY KEY, -- Slice attribute identifier slice_id integer REFERENCES slices NOT NULL, -- Slice identifier node_id integer REFERENCES nodes, -- Sliver attribute if set nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set - attribute_type_id integer -- Attribute type identifier - REFERENCES slice_attribute_types NOT NULL, + tag_type_id integer REFERENCES tag_types NOT NULL, -- Attribute type identifier value text ) WITH OIDS; CREATE INDEX slice_attribute_slice_id_idx ON slice_attribute (slice_id); @@ -1116,14 +1090,14 @@ LEFT JOIN node_session USING (node_id); CREATE OR REPLACE VIEW view_nodegroups AS SELECT nodegroups.*, -node_tag_types.tagname, +tag_types.tagname, COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}') AS conf_file_ids, COALESCE((SELECT node_ids FROM nodegroup_nodes WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}') AS node_ids -FROM nodegroups INNER JOIN node_tag_types USING (node_tag_type_id); +FROM nodegroups INNER JOIN tag_types USING (tag_type_id); CREATE OR REPLACE VIEW view_conf_files AS SELECT @@ -1214,13 +1188,14 @@ slice_attribute.slice_attribute_id, slice_attribute.slice_id, slice_attribute.node_id, slice_attribute.nodegroup_id, -slice_attribute_types.attribute_type_id, -slice_attribute_types.name, -slice_attribute_types.description, -slice_attribute_types.min_role_id, +tag_types.tag_type_id, +tag_types.tagname, +tag_types.description, +tag_types.category, +tag_types.min_role_id, slice_attribute.value FROM slice_attribute -INNER JOIN slice_attribute_types USING (attribute_type_id); +INNER JOIN tag_types USING (tag_type_id); CREATE OR REPLACE VIEW view_sessions AS SELECT