1 # NodeGroup.validate_name() changes name to null. This causes database error
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Nodes import Node, Nodes
8 from PLC.NodeGroups import NodeGroup, NodeGroups
9 #from PLC.Sites import Site, Sites
10 from PLC.Auth import PasswordAuth
12 class AdmAddNodeGroup(Method):
14 Adds a new node group. Any values specified in optional_vals are used,
15 otherwise defaults are used.
17 Returns the new node_id (> 0) if successful, faults otherwise.
22 can_update = lambda (field, value): field in \
24 update_fields = dict(filter(can_update, NodeGroup.fields.items()))
28 NodeGroup.fields['name'],
29 NodeGroup.fields['description'],
30 NodeGroup.fields['is_custom'],
34 returns = Parameter(int, '1 if successful')
36 def call(self, auth, name, description, optional_vals = {}):
37 if filter(lambda field: field not in self.update_fields, optional_vals):
38 raise PLCInvalidArgument, "Invalid fields specified"
40 # Authenticated function
41 assert self.caller is not None
43 # make sure we are 'admin'
44 if 'admin' not in self.caller['roles']:
45 raise PLCPermissionDenied, "Not allowed to add node groups"
48 node_group = NodeGroup(self.api, optional_vals)
49 node_group['name'] = name
50 node_group['description'] = description
53 return node_group['nodegroup_id']