sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04875
[Merge] ~ack/maas:get-mac-addresses-cleanup into maas:master
Alberto Donato has proposed merging ~ack/maas:get-mac-addresses-cleanup into maas:master.
Commit message:
drop get_mac_addresses methods in Node and Device handlers, inline logic
This makes it easier to see how the data is gathered, since the method was
actually used only in one place for each handler (and the NodeHandler class
didn't actually use it).
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/436427
--
Your team MAAS Maintainers is requested to review the proposed merge of ~ack/maas:get-mac-addresses-cleanup into maas:master.
diff --git a/src/maasserver/websockets/handlers/device.py b/src/maasserver/websockets/handlers/device.py
index 4d98b8c..8e41c45 100644
--- a/src/maasserver/websockets/handlers/device.py
+++ b/src/maasserver/websockets/handlers/device.py
@@ -253,23 +253,16 @@ class DeviceHandler(NodeHandler):
else:
raise HandlerError("Unknown action: %s" % action)
- def get_mac_addresses(self, data):
- """Convert the given `data` into a list of mac addresses.
-
- This is used by the create method and the hydrate method.
- The `primary_mac` will always be the first entry in the list.
- """
- macs = data.get("extra_macs", [])
- if "primary_mac" in data:
- macs.insert(0, data["primary_mac"])
- return macs
-
def preprocess_form(self, action, params):
"""Process the `params` to before passing the data to the form."""
+ all_macs = list(params.get("extra_macs", []))
+ if "primary_mac" in params:
+ all_macs.insert(0, params["primary_mac"])
+
new_params = self.preprocess_node_form(action, params)
new_params.update(
{
- "mac_addresses": self.get_mac_addresses(params),
+ "mac_addresses": all_macs,
"hostname": params.get("hostname"),
"parent": params.get("parent"),
}
diff --git a/src/maasserver/websockets/handlers/machine.py b/src/maasserver/websockets/handlers/machine.py
index 861a45e..63b181f 100644
--- a/src/maasserver/websockets/handlers/machine.py
+++ b/src/maasserver/websockets/handlers/machine.py
@@ -452,10 +452,14 @@ class MachineHandler(NodeHandler):
def preprocess_form(self, action, params):
"""Process the `params` to before passing the data to the form."""
+ all_macs = list(params.get("extra_macs", []))
+ if "pxe_mac" in params:
+ all_macs.insert(0, params["pxe_mac"])
+
new_params = self.preprocess_node_form(action, params)
# Only copy the allowed fields into `new_params` to be passed into
# the form.
- new_params["mac_addresses"] = self.get_mac_addresses(params)
+ new_params["mac_addresses"] = all_macs
new_params["hostname"] = params.get("hostname")
new_params["architecture"] = params.get("architecture")
new_params["power_type"] = params.get("power_type")
diff --git a/src/maasserver/websockets/handlers/node.py b/src/maasserver/websockets/handlers/node.py
index cba41c1..5fa038d 100644
--- a/src/maasserver/websockets/handlers/node.py
+++ b/src/maasserver/websockets/handlers/node.py
@@ -1018,17 +1018,6 @@ class NodeHandler(TimestampedModelHandler):
for blockdevice in obj.current_config.blockdevice_set.all()
]
- def get_mac_addresses(self, data):
- """Convert the given `data` into a list of mac addresses.
-
- This is used by the create method and the hydrate method. The `pxe_mac`
- will always be the first entry in the list.
- """
- macs = data.get("extra_macs", [])
- if "pxe_mac" in data:
- macs.insert(0, data["pxe_mac"])
- return macs
-
def get_providing_dhcp(self, obj):
"""Return if providing DHCP using the prefetched query."""
for interface in obj.current_config.interface_set.all():
diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
index cdd2019..3b7691d 100644
--- a/src/maasserver/websockets/handlers/tests/test_machine.py
+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
@@ -566,7 +566,6 @@ class TestMachineHandler(MAASServerTestCase):
"get_blockdevices_for",
"get_form_class",
"get_grouped_storages",
- "get_mac_addresses",
"get_object",
"get_own_object",
"get_providing_dhcp",
Follow ups