X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddNodeToPCU.py;h=f1c19618e65a203a947b1382f1341eaa9b76d822;hb=49e875c7e14b95697e3d0c7502d8457d3ce6378c;hp=2d06f9f6b023032f256736b21340aff36270a3fe;hpb=e668028fc37124059fb008f2c4da9da20aae7b2b;p=plcapi.git diff --git a/PLC/Methods/AddNodeToPCU.py b/PLC/Methods/AddNodeToPCU.py index 2d06f9f..f1c1961 100644 --- a/PLC/Methods/AddNodeToPCU.py +++ b/PLC/Methods/AddNodeToPCU.py @@ -3,7 +3,7 @@ from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Nodes import Node, Nodes from PLC.PCUs import PCU, PCUs -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class AddNodeToPCU(Method): """ @@ -18,7 +18,7 @@ class AddNodeToPCU(Method): roles = ['admin', 'pi', 'tech'] accepts = [ - PasswordAuth(), + Auth(), Mixed(Node.fields['node_id'], Node.fields['hostname']), PCU.fields['pcu_id'], @@ -26,28 +26,28 @@ class AddNodeToPCU(Method): ] returns = Parameter(int, '1 if successful') - event_type = 'AddTo' - object_type = 'PCU' - object_ids = [] + + object_type = 'Node' def call(self, auth, node_id_or_hostname, pcu_id, port): # Get node nodes = Nodes(self.api, [node_id_or_hostname]) if not nodes: raise PLCInvalidArgument, "No such node" + node = nodes[0] - node = nodes.values()[0] + if node['peer_id'] is not None: + raise PLCInvalidArgument, "Not a local node" # Get PCU pcus = PCUs(self.api, [pcu_id]) if not pcus: raise PLCInvalidArgument, "No such PCU" - - pcu = pcus.values()[0] + pcu = pcus[0] if 'admin' not in self.caller['roles']: ok = False - sites = Sites(self.api, self.caller['site_ids']).values() + sites = Sites(self.api, self.caller['site_ids']) for site in sites: if pcu['pcu_id'] in site['pcu_ids']: ok = True @@ -67,6 +67,8 @@ class AddNodeToPCU(Method): pcu.add_node(node, port) + # Logging variables self.object_ids = [node['node_id'], pcu['pcu_id']] - + self.message = 'Node %d added to pcu %d on port %d' % \ + (node['node_id'], pcu['pcu_id'], port) return 1