X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddNode.py;h=485667b23fbd9c25a781436a803dc267755ab2da;hb=9538a99a4190a75414c5d3ad37b8ed928bb03e21;hp=086f5e0dd20914f0c1304d892fd12910f0c04dea;hpb=f34d2986c1897c30ebbac1344f3d289b935382ea;p=plcapi.git diff --git a/PLC/Methods/AddNode.py b/PLC/Methods/AddNode.py index 086f5e0..485667b 100644 --- a/PLC/Methods/AddNode.py +++ b/PLC/Methods/AddNode.py @@ -4,10 +4,10 @@ from PLC.Parameter import Parameter, Mixed from PLC.Nodes import Node, Nodes from PLC.NodeGroups import NodeGroup, NodeGroups from PLC.Sites import Site, Sites -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth can_update = lambda (field, value): field in \ - ['boot_state', 'model', 'version'] + ['hostname', 'boot_state', 'model', 'version'] class AddNode(Method): """ @@ -22,27 +22,27 @@ class AddNode(Method): roles = ['admin', 'pi', 'tech'] - update_fields = dict(filter(can_update, Node.fields.items())) + node_fields = dict(filter(can_update, Node.fields.items())) accepts = [ - PasswordAuth(), + Auth(), Mixed(Site.fields['site_id'], Site.fields['login_base']), - Node.fields['hostname'], - update_fields + node_fields ] returns = Parameter(int, 'New node_id (> 0) if successful') - def call(self, auth, site_id_or_login_base, hostname, node_fields = {}): + + def call(self, auth, site_id_or_login_base, node_fields): node_fields = dict(filter(can_update, node_fields.items())) - + # Get site information sites = Sites(self.api, [site_id_or_login_base]) if not sites: raise PLCInvalidArgument, "No such site" - site = sites.values()[0] + site = sites[0] # Authenticated function assert self.caller is not None @@ -57,8 +57,10 @@ class AddNode(Method): assert self.caller['person_id'] in site['person_ids'] node = Node(self.api, node_fields) - node['hostname'] = hostname node['site_id'] = site['site_id'] node.sync() + self.object_ids = [site['site_id'], node['node_id']] + self.message = "Node %s created" % node['node_id'] + return node['node_id']