launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06857
[Merge] lp:~rvb/maas/maas-cobbler-node into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/maas-cobbler-node into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/maas-cobbler-node/+merge/98871
Manually check the uniqueness of the mac addresses.
--
https://code.launchpad.net/~rvb/maas/maas-cobbler-node/+merge/98871
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-cobbler-node into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-03-22 15:01:02 +0000
+++ src/maasserver/forms.py 2012-03-22 16:36:23 +0000
@@ -143,27 +143,19 @@
['One or more MAC Addresses is invalid.'])
return valid
- def add_mac(self, node, mac):
- # Add a mac address to a node. Raise a ValidationError with key
- # mac_addresses is the mac address is a duplicate.
- try:
- node.add_mac_address(mac)
- except ValidationError, e:
- is_unique_validation_error = (
- 'mac_address' in e.message_dict and
- e.message_dict['mac_address'] == [
- 'Mac address with this Mac address already exists.'])
- if is_unique_validation_error:
+ def clean_mac_addresses(self):
+ data = self.cleaned_data['mac_addresses']
+ for mac in data:
+ if MACAddress.objects.filter(mac_address=mac.lower()).count() > 0:
raise ValidationError(
{'mac_addresses': [
'Mac address %s already in use.' % mac]})
- else:
- raise
+ return data
def save(self):
node = super(NodeWithMACAddressesForm, self).save()
for mac in self.cleaned_data['mac_addresses']:
- self.add_mac(node, mac)
+ node.add_mac_address(mac)
if self.cleaned_data['hostname'] == "":
node.set_mac_based_hostname(self.cleaned_data['mac_addresses'][0])
return node