2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Nodes import Node, Nodes
6 from PLC.NodeGroups import NodeGroup, NodeGroups
7 #from PLC.Sites import Site, Sites
8 from PLC.Auth import PasswordAuth
10 class AdmAddNodeGroup(Method):
12 Adds a new node group. Any values specified in optional_vals are used,
13 otherwise defaults are used.
15 Returns the new node_id (> 0) if successful, faults otherwise.
20 can_update = lambda (field, value): field in \
21 ['name', 'description', 'is_custom']
22 update_fields = dict(filter(can_update, NodeGroup.fields.items()))
26 NodeGroup.fields['name'],
27 NodeGroup.fields['description'],
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, name, description, optional_vals = {}):
34 if filter(lambda field: field not in self.update_fields, optional_vals):
35 raise PLCInvalidArgument, "Invalid fields specified"
37 # Authenticated function
38 assert self.caller is not None
40 # make sure we are 'admin'
41 if 'admin' not in self.caller['roles']:
42 raise PLCPermissionDenied, "Not allowed to add node groups"
45 node_group = NodeGroup(self.api, optional_vals)
46 node_group['name'] = name
47 node_group['description'] = description
50 return node_group['nodegroup_id']