X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddNodeToNodeGroup.py;h=6829daf3ee88d4206ca4883a02fa0a8835ee1470;hb=53c0a911837538bd54044440d11354183cd93726;hp=c1e70d61dd70e5947f7687d8cbd9889399575735;hpb=f8e0c71d96dce99eff25e5bb6bdf941468e897a2;p=plcapi.git diff --git a/PLC/Methods/AddNodeToNodeGroup.py b/PLC/Methods/AddNodeToNodeGroup.py index c1e70d6..6829daf 100644 --- a/PLC/Methods/AddNodeToNodeGroup.py +++ b/PLC/Methods/AddNodeToNodeGroup.py @@ -3,7 +3,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Nodes import Node, Nodes -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class AddNodeToNodeGroup(Method): """ @@ -16,36 +16,39 @@ class AddNodeToNodeGroup(Method): roles = ['admin'] accepts = [ - PasswordAuth(), + Auth(), + Mixed(Node.fields['node_id'], + Node.fields['hostname']), Mixed(NodeGroup.fields['nodegroup_id'], NodeGroup.fields['name']), - Mixed(Node.fields['node_id'], - Node.fields['hostname']) ] returns = Parameter(int, '1 if successful') - event_type = 'AddTo' - object_type = 'NodeGroup' - object_ids = [] - def call(self, auth, nodegroup_id_or_name, node_id_or_hostname): + def call(self, auth, node_id_or_hostname, nodegroup_id_or_name): # Get node info nodes = Nodes(self.api, [node_id_or_hostname]) if not nodes: raise PLCInvalidArgument, "No such node" - node = nodes.values()[0] + node = nodes[0] + + if node['peer_id'] is not None: + raise PLCInvalidArgument, "Not a local node" # Get nodegroup info nodegroups = NodeGroups(self.api, [nodegroup_id_or_name]) if not nodegroups: raise PLCInvalidArgument, "No such nodegroup" - nodegroup = nodegroups.values()[0] + nodegroup = nodegroups[0] # add node to nodegroup if node['node_id'] not in nodegroup['node_ids']: nodegroup.add_node(node) + + # Logging variables self.object_ids = [nodegroup['nodegroup_id']] - + self.message = 'Node %d added to node group %d' % \ + (node['node_id'], nodegroup['nodegroup_id']) return 1