1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.NodeGroups import NodeGroup, NodeGroups
5 from PLC.Auth import Auth
7 can_update = lambda (field, value): field in NodeGroup.fields.keys() and field != NodeGroup.primary_field
9 class AddNodeGroup(Method):
11 Adds a new node group. Any values specified in nodegroup_fields
12 are used, otherwise defaults are used.
14 Returns the new nodegroup_id (> 0) if successful, faults otherwise.
19 nodegroup_fields = dict(filter(can_update, NodeGroup.fields.items()))
26 returns = Parameter(int, 'New nodegroup_id (> 0) if successful')
29 def call(self, auth, nodegroup_fields):
30 nodegroup_fields = dict([f for f in nodegroup_fields.items() if can_update(f)])
31 nodegroup = NodeGroup(self.api, nodegroup_fields)
35 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']]}
36 self.message = 'Node group %d created' % nodegroup['nodegroup_id']
38 return nodegroup['nodegroup_id']