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 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(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 # add node to nodegroup
43 if node['node_id'] not in nodegroup['node_ids']:
44 nodegroup.add_node(node)