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.Nodes import Node, Nodes
6 from PLC.Auth import PasswordAuth
8 class AdmAddNodeToNodeGroup(Method):
10 Add a node to the specified node group. If the node is
11 already a member of the nodegroup, no errors are returned.
13 Returns 1 if successful, faults otherwise.
20 Mixed(NodeGroup.fields['nodegroup_id'],
21 NodeGroup.fields['name']),
22 Mixed(Node.fields['node_id'],
23 Node.fields['hostname'])
26 returns = Parameter(int, '1 if successful')
28 def call(self, auth, nodegroup_id_or_name, node_id_or_hostname):
30 nodes = Nodes(self.api, [node_id_or_hostname])
32 raise PLCInvalidArgument, "No such node"
33 node = nodes.values()[0]
36 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
38 raise PLCInvalidArgument, "No such nodegroup"
40 nodegroup = nodegroups.values()[0]
42 # Authenticated function
43 assert self.caller is not None
45 # make sure we are 'admin'
46 if 'admin' not in self.caller['roles']:
47 raise PLCPermissionDenied, "Not allowed to add node groups"
49 # add node to nodegroup
50 if node['node_id'] not in nodegroup['node_ids']:
51 nodegroup.add_node(node)