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 Auth
8 class AddNodeToNodeGroup(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(Node.fields['node_id'],
21 Node.fields['hostname']),
22 Mixed(NodeGroup.fields['nodegroup_id'],
23 NodeGroup.fields['name']),
26 returns = Parameter(int, '1 if successful')
29 def call(self, auth, node_id_or_hostname, nodegroup_id_or_name):
31 nodes = Nodes(self.api, [node_id_or_hostname])
33 raise PLCInvalidArgument, "No such node"
36 if node['peer_id'] is not None:
37 raise PLCInvalidArgument, "Not a local node"
40 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
42 raise PLCInvalidArgument, "No such nodegroup"
44 nodegroup = nodegroups[0]
46 # add node to nodegroup
47 if node['node_id'] not in nodegroup['node_ids']:
48 nodegroup.add_node(node)
51 self.event_objects = {'NodeGroup': [nodegroup['nodegroup_id']],
52 'Node': [node['node_id']]}
53 self.message = 'Node %d added to node group %d' % \
54 (node['node_id'], nodegroup['nodegroup_id'])