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):
"""
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]
+ PLCCheckLocalNode (node,"AddNodeToNodeGroup")
# 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