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 AdmRemoveNodeFromNodeGroup(Method):
10 Removes a node from the specified node group.
12 Returns 1 if successful, faults otherwise.
19 Mixed(NodeGroup.fields['nodegroup_id'],
20 NodeGroup.fields['name']),
21 Mixed(Node.fields['node_id'],
22 Node.fields['hostname'])
25 returns = Parameter(int, '1 if successful')
27 def call(self, auth, nodegroup_id_or_name, node_id_or_hostname):
29 nodes = Nodes(self.api, [node_id_or_hostname])
31 raise PLCInvalidArgument, "No such node"
32 node = nodes.values()[0]
35 nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
37 raise PLCInvalidArgument, "No such nodegroup"
39 nodegroup = nodegroups.values()[0]
41 # Authenticated function
42 assert self.caller is not None
44 # make sure we are 'admin'
45 if 'admin' not in self.caller['roles']:
46 raise PLCPermissionDenied, "Not allowed to remove node from nodegroup"
48 # add node to nodegroup
49 if node['node_id'] in nodegroup['node_ids']:
50 nodegroup.remove_node(node)