From: Mark Huang Date: Wed, 20 Sep 2006 20:17:28 +0000 (+0000) Subject: - fix allowed update_fields X-Git-Tag: pycurl-7_13_1~723 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=432c25cdba91732f8c08cb9ebb86c68817c99bba;p=plcapi.git - fix allowed update_fields - update_fields (nee optional_vals) are not optional - prevent non-null fields from being unset - whitespace nits --- diff --git a/PLC/Methods/AdmUpdateNodeNetwork.py b/PLC/Methods/AdmUpdateNodeNetwork.py index ebaddc34..8977cbe2 100644 --- a/PLC/Methods/AdmUpdateNodeNetwork.py +++ b/PLC/Methods/AdmUpdateNodeNetwork.py @@ -8,24 +8,24 @@ from PLC.Auth import PasswordAuth class AdmUpdateNodeNetwork(Method): """ - Updates an existing node network. Any values specified in optional_vals + 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 optional_vals must + 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. - PIs and techs may only add networks to their own nodes. Admins may - add networks to any node. + PIs and techs may only update networks associated with their own + nodes. Admins may update any node network. Returns 1 if successful, faults otherwise. """ roles = ['admin', 'pi', 'tech'] - cant_update = lambda (field, value): field not in \ + can_update = lambda (field, value): field not in \ ['nodenetwork_id'] - update_fields = dict(filter(cant_update, NodeNetwork.all_fields.items())) + update_fields = dict(filter(can_update, NodeNetwork.fields.items())) accepts = [ PasswordAuth(), @@ -36,31 +36,41 @@ class AdmUpdateNodeNetwork(Method): returns = Parameter(int, '1 if successful') - def call(self, auth, nodenetwork_id_or_hostname, optional_vals=None): - if filter(lambda field: field not in self.update_fields, optional_vals): - raise PLCInvalidArgument, "Invalid fields specified" + 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" - # Authenticated function - assert self.caller is not None + # XML-RPC cannot marshal None, so we need special values to + # represent "unset". + for key, value in update_fields.iteritems(): + if value == -1 or value == "null": + if key in ['method', 'type', 'mac', 'ip', 'bwlimit']: + raise PLCInvalidArgument, "%s cannot be unset" % key + update_fields[key] = None - # Get nodenetwork information + # Get node network information nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values() if not nodenetworks: - raise PLCInvalidArgument, "No such node network" + raise PLCInvalidArgument, "No such node network" + nodenetwork = nodenetworks[0] + # Authenticated function + assert self.caller is not None + # 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() - if not nodes: - raise PLCPermissionDenied, "Node network is not associated with a node" - node = nodes[0] - if node['site_id'] not in self.caller['site_ids']: - raise PLCPermissionDenied, "Not allowed to update node network" - + nodes = Nodes(self.api, [nodenetwork['node_id']]).values() + if not nodes: + raise PLCPermissionDenied, "Node network is not associated with a node" + node = nodes[0] + if node['site_id'] not in self.caller['site_ids']: + raise PLCPermissionDenied, "Not allowed to update node network" + # Update node network - nodenetwork.update(optional_vals) + nodenetwork.update(update_fields) nodenetwork.flush() return 1