X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddNodeGroup.py;h=2beed717586decc65c007d6b6dece5e57ed45459;hb=6bef7b35eec76ff66332cb20f58eb7703c2116f9;hp=f0dd56ded8da54597c39817ee882c1a371014d2f;hpb=7e7751b60ad5379a11bb78e571bad3df9f5eb02f;p=plcapi.git diff --git a/PLC/Methods/AddNodeGroup.py b/PLC/Methods/AddNodeGroup.py index f0dd56d..2beed71 100644 --- a/PLC/Methods/AddNodeGroup.py +++ b/PLC/Methods/AddNodeGroup.py @@ -1,11 +1,13 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed +from PLC.Auth import Auth + from PLC.NodeGroups import NodeGroup, NodeGroups -from PLC.Auth import PasswordAuth +from PLC.TagTypes import TagType, TagTypes +from PLC.NodeTags import NodeTag, NodeTags -can_update = lambda (field, value): field in \ - ['name', 'description'] +can_update = lambda field_value: field_value[0] in list(NodeGroup.fields.keys()) and field_value[0] != NodeGroup.primary_field class AddNodeGroup(Method): """ @@ -17,24 +19,34 @@ class AddNodeGroup(Method): roles = ['admin'] - nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items())) + nodegroup_fields = dict(list(filter(can_update, list(NodeGroup.fields.items())))) accepts = [ - PasswordAuth(), - nodegroup_fields + Auth(), + NodeGroup.fields['groupname'], + Mixed(TagType.fields['tag_type_id'], + TagType.fields['tagname']), + NodeTag.fields['value'], ] returns = Parameter(int, 'New nodegroup_id (> 0) if successful') - event_type = 'Add' - object_type = 'NodeGroup' - object_ids = [] - def call(self, auth, nodegroup_fields): - nodegroup_fields = dict(filter(can_update, nodegroup_fields.items())) + def call(self, auth, groupname, tag_type_id_or_tagname, value): + # locate tag type + tag_types = TagTypes (self.api,[tag_type_id_or_tagname]) + if not(tag_types): + raise PLCInvalidArgument("No such tag type %r"%tag_type_id_or_tagname) + tag_type=tag_types[0] + + nodegroup_fields = { 'groupname' : groupname, + 'tag_type_id' : tag_type['tag_type_id'], + 'value' : value } nodegroup = NodeGroup(self.api, nodegroup_fields) nodegroup.sync() - self.object_ids = [nodegroup['nodegroup_id']] + # Logging variables + self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]} + self.message = 'Node group %d created' % nodegroup['nodegroup_id'] return nodegroup['nodegroup_id']