X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FUpdateNodeNetwork.py;h=dc1e65ad1c760373afbd136f817965756b225d17;hb=refs%2Fheads%2Fplanetlab-4_0-branch;hp=393b6e4a577ab5eb9179d0413fe9e9c2b557b435;hpb=da289170c5514b97929a271ed1fe4fb082959c7c;p=plcapi.git diff --git a/PLC/Methods/UpdateNodeNetwork.py b/PLC/Methods/UpdateNodeNetwork.py index 393b6e4..dc1e65a 100644 --- a/PLC/Methods/UpdateNodeNetwork.py +++ b/PLC/Methods/UpdateNodeNetwork.py @@ -1,48 +1,45 @@ - from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Nodes import Node, Nodes from PLC.NodeNetworks import NodeNetwork, NodeNetworks -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth + +can_update = lambda (field, value): field not in \ + ['nodenetwork_id','node_id'] class UpdateNodeNetwork(Method): """ - Updates an existing node network. Any values specified in update_fields - are used, otherwise defaults are used. Acceptable values for method are - dhcp and static. If type is static, the parameter update_fields must - be present and ip, gateway, network, broadcast, netmask, and dns1 must - all be specified. If type is dhcp, these parameters, even if - specified, are ignored. + Updates an existing node network. Any values specified in + nodenetwork_fields are used, otherwise defaults are + used. Acceptable values for method are dhcp and static. If type is + static, then ip, gateway, network, broadcast, netmask, and dns1 + must all be specified in nodenetwork_fields. If type is dhcp, + these parameters, even if specified, are ignored. PIs and techs may only update networks associated with their own - nodes. ins may update any node network. + nodes. Admins may update any node network. Returns 1 if successful, faults otherwise. """ roles = ['admin', 'pi', 'tech'] - can_update = lambda (field, value): field not in \ - ['nodenetwork_id'] - update_fields = dict(filter(can_update, NodeNetwork.fields.items())) + nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items())) accepts = [ - PasswordAuth(), - Mixed(NodeNetwork.fields['nodenetwork_id'], - NodeNetwork.fields['hostname']), - update_fields + Auth(), + NodeNetwork.fields['nodenetwork_id'], + nodenetwork_fields ] returns = Parameter(int, '1 if successful') - def call(self, auth, nodenetwork_id_or_hostname, update_fields): - # Check for invalid fields - if filter(lambda field: field not in self.update_fields, update_fields): - raise PLCInvalidArgument, "Invalid fields specified" + def call(self, auth, nodenetwork_id, nodenetwork_fields): + nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items())) # Get node network information - nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values() + nodenetworks = NodeNetworks(self.api, [nodenetwork_id]) if not nodenetworks: raise PLCInvalidArgument, "No such node network" @@ -54,7 +51,7 @@ class UpdateNodeNetwork(Method): # If we are not an admin, make sure that the caller is a # member of the site where the node exists. if 'admin' not in self.caller['roles']: - nodes = Nodes(self.api, [nodenetwork['node_id']]).values() + nodes = Nodes(self.api, [nodenetwork['node_id']]) if not nodes: raise PLCPermissionDenied, "Node network is not associated with a node" node = nodes[0] @@ -62,7 +59,11 @@ class UpdateNodeNetwork(Method): raise PLCPermissionDenied, "Not allowed to update node network" # Update node network - nodenetwork.update(update_fields) + nodenetwork.update(nodenetwork_fields) nodenetwork.sync() + self.event_objects = {'NodeNetwork': [nodenetwork['nodenetwork_id']]} + self.message = "Node network %d updated: %s " % \ + (nodenetwork['nodenetwork_id'], ", ".join(nodenetwork_fields.keys())) + return 1