From: Thierry Parmentelat Date: Thu, 29 May 2008 15:24:14 +0000 (+0000) Subject: nodegroups work and are getting tested as part of the plcapi test X-Git-Tag: PLCAPI-4.3-1~41 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=bc7c7cb26c932a361fb82c5bb72cf2542947dbb6;p=plcapi.git nodegroups work and are getting tested as part of the plcapi test --- diff --git a/PLC/Methods/AddNodeGroup.py b/PLC/Methods/AddNodeGroup.py index 9555f73e..6b0c94d6 100644 --- a/PLC/Methods/AddNodeGroup.py +++ b/PLC/Methods/AddNodeGroup.py @@ -1,9 +1,12 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Auth import Auth +from PLC.NodeGroups import NodeGroup, NodeGroups +from PLC.NodeTagTypes import NodeTagType, NodeTagTypes +from PLC.NodeTags import NodeTag, NodeTags + can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field class AddNodeGroup(Method): @@ -20,14 +23,25 @@ class AddNodeGroup(Method): accepts = [ Auth(), - nodegroup_fields + NodeGroup.fields['groupname'], + Mixed(NodeTagType.fields['node_tag_type_id'], + NodeTagType.fields['tagname']), + NodeTag.fields['tagvalue'], ] returns = Parameter(int, 'New nodegroup_id (> 0) if successful') - def call(self, auth, nodegroup_fields): - nodegroup_fields = dict([f for f in nodegroup_fields.items() if can_update(f)]) + def call(self, auth, groupname, node_tag_type_id_or_tagname, tagvalue): + # locate tag type + tag_types = NodeTagTypes (self.api,node_tag_type_id_or_tagname) + if not(tag_types): + raise PLCInvalidArgument, "No such tag type %r"%node_tag_type_id_or_tagname + tag_type=tag_types[0] + + nodegroup_fields = { 'groupname' : groupname, + 'node_tag_type_id' : tag_type['node_tag_type_id'], + 'tagvalue' : tagvalue } nodegroup = NodeGroup(self.api, nodegroup_fields) nodegroup.sync() diff --git a/PLC/Methods/UpdateNodeGroup.py b/PLC/Methods/UpdateNodeGroup.py index d6950122..4271085a 100644 --- a/PLC/Methods/UpdateNodeGroup.py +++ b/PLC/Methods/UpdateNodeGroup.py @@ -4,10 +4,7 @@ from PLC.Parameter import Parameter, Mixed from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Auth import Auth -related_fields = NodeGroup.related_fields.keys() -can_update = lambda (field, value): field in \ - ['groupname', 'tagname','tagvalue'] + \ - related_fields +can_update = lambda (field, value): field in ['groupname','tagvalue'] class UpdateNodeGroup(Method): """ @@ -18,7 +15,7 @@ class UpdateNodeGroup(Method): roles = ['admin'] - nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items() + NodeGroup.related_fields.items())) + nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()) accepts = [ Auth(), @@ -35,15 +32,9 @@ class UpdateNodeGroup(Method): # Get nodegroup information 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] - # Make requested associations - for field in related_fields: - if field in nodegroup_fields: - nodegroup.associate(auth, field, nodegroup_fields[field]) - nodegroup_fields.pop(field) - nodegroup.update(nodegroup_fields) nodegroup.sync()