--- /dev/null
+# NodeGroup.validate_name() changes name to null. This causes database error
+
+
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Nodes import Node, Nodes
+from PLC.NodeGroups import NodeGroup, NodeGroups
+#from PLC.Sites import Site, Sites
+from PLC.Auth import PasswordAuth
+
+class AdmAddNodeGroup(Method):
+ """
+ Adds a new node group. Any values specified in optional_vals are used,
+ otherwise defaults are used.
+
+ Returns the new node_id (> 0) if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ can_update = lambda (field, value): field in \
+ ['model', 'version']
+ update_fields = dict(filter(can_update, NodeGroup.fields.items()))
+
+ accepts = [
+ PasswordAuth(),
+ NodeGroup.fields['name'],
+ NodeGroup.fields['description'],
+ NodeGroup.fields['is_custom'],
+ update_fields
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth, name, description, optional_vals = {}):
+ if filter(lambda field: field not in self.update_fields, optional_vals):
+ raise PLCInvalidArgument, "Invalid fields specified"
+
+ # Authenticated function
+ assert self.caller is not None
+
+ # make sure we are 'admin'
+ if 'admin' not in self.caller['roles']:
+ raise PLCPermissionDenied, "Not allowed to add node groups"
+
+ #creat node group
+ node_group = NodeGroup(self.api, optional_vals)
+ node_group['name'] = name
+ node_group['description'] = description
+ node_group.flush()
+
+ return node_group['nodegroup_id']
--- /dev/null
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Auth import PasswordAuth
+from PLC.Nodes import Node, Nodes
+from PLC.NodeGroups import NodeGroup, NodeGroups
+
+class AdmDeleteNodeGroup(Method):
+ """
+ Delete an existing Node Group.
+
+ Admins my delete any node group
+
+ Returns 1 if successful, faults otherwise.
+ """
+
+ roles = ['admin']
+
+ accepts = [
+ PasswordAuth(),
+ NodeGroup.fields['nodegroup_id'],
+ ]
+
+ returns = Parameter(int, '1 if successful')
+
+ def call(self, auth, node_group_id):
+ # Get account information
+ nodegroups = NodeGroups(self.api, [node_group_id])
+ if not nodegroups:
+ raise PLCInvalidArgument, "No such node group"
+
+ nodegroup = nodegroups.values()[0]
+
+ # If we are not an admin, make sure that the caller is a
+ # member of the site at which the node is located.
+ if 'admin' not in self.caller['roles']:
+ # Authenticated function
+ raise PLCPermissionDenied, "Not allowed to delete nodes groups"
+
+ nodegroup.delete()
+
+ return 1
--- /dev/null
+import os
+
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.Sites import Site, Sites
+from PLC.Nodes import Node, Nodes
+from PLC.Auth import PasswordAuth
+from PLC.NodeGroups import NodeGroup, NodeGroups
+class AdmGetNodeGroupNodes(Method):
+ """
+ Return a list of node_ids for the node group specified.
+
+ """
+
+ roles = ['admin', 'pi', 'user', 'tech']
+
+ accepts = [
+ PasswordAuth(),
+ NodeGroup.fields['nodegroup_id']
+ ]
+
+ returns = [NodeGroup.join_fields['node_ids']]
+
+ def __init__(self, *args, **kwds):
+ Method.__init__(self, *args, **kwds)
+ # Update documentation with list of default fields returned
+ self.__doc__ += os.linesep.join(Site.default_fields.keys())
+
+ def call(self, auth, nodegroup_id):
+ # Authenticated function
+ assert self.caller is not None
+
+ # Get nodes in this nodegroup
+ nodegroup = NodeGroups(self.api, [nodegroup_id])
+
+ # make sure sites are found
+ if not nodegroup:
+ raise PLCInvalidArgument, "No such site"
+
+ #get the info for the node group specified
+ nodegroup_values = nodegroup.values()[0]
+
+ #grab the list of node ides fromt the disctioary
+ node_ids = nodegroup_values['node_ids']
+
+ return node_ids