launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06763
[Merge] lp:~andreserl/maas/set_mac_based_hostname into lp:maas
Andres Rodriguez has proposed merging lp:~andreserl/maas/set_mac_based_hostname into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~andreserl/maas/set_mac_based_hostname/+merge/98219
--
https://code.launchpad.net/~andreserl/maas/set_mac_based_hostname/+merge/98219
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~andreserl/maas/set_mac_based_hostname into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-03-15 13:58:32 +0000
+++ src/maasserver/forms.py 2012-03-19 15:45:41 +0000
@@ -124,6 +124,8 @@
node = super(NodeWithMACAddressesForm, self).save()
for mac in self.cleaned_data['mac_addresses']:
node.add_mac_address(mac)
+ if self.cleaned_data['hostname'] == "":
+ node.set_mac_based_hostname(self.cleaned_data['mac_addresses'][0])
return node
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py 2012-03-15 17:40:41 +0000
+++ src/maasserver/models.py 2012-03-19 15:45:41 +0000
@@ -407,6 +407,11 @@
if mac:
mac.delete()
+ def set_mac_based_hostname(self, mac_address):
+ mac_hostname = mac_address.replace(':', '').lower()
+ self.hostname = "node-%s" % mac_hostname
+ self.save()
+
def get_effective_power_type(self):
"""Get power-type to use for this node.
=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py 2012-03-15 17:40:41 +0000
+++ src/maasserver/tests/test_models.py 2012-03-19 15:45:41 +0000
@@ -89,6 +89,12 @@
node=node, mac_address='AA:BB:CC:DD:EE:FF').count()
self.assertEqual(0, macs)
+ def test_set_mac_based_hostname(self):
+ node = factory.make_node()
+ node.set_mac_based_hostname('AA:BB:CC:DD:EE:FF')
+ hostname = 'node-aabbccddeeff'
+ self.assertEqual(hostname, node.hostname)
+
def test_get_effective_power_type_defaults_to_config(self):
power_types = list(map_enum(POWER_TYPE).values())
power_types.remove(POWER_TYPE.DEFAULT)
Follow ups