Merge lp:~rvb/maas/rm-cluster-interf-connexion into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 3611
Proposed branch: lp:~rvb/maas/rm-cluster-interf-connexion
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~rvb/maas/no-nodegroup-for-devices
Diff against target: 150 lines (+1/-105)
2 files modified
src/maasserver/api/devices.py (+1/-42)
src/maasserver/api/tests/test_devices.py (+0/-63)
To merge this branch: bzr merge lp:~rvb/maas/rm-cluster-interf-connexion
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+251880@code.launchpad.net

Commit message

Remove the API that gives the user the ability to link a device's MAC to a cluster interface. This isn't an API endpoint we want to have to maintain in 1.8 when networks and cluster interface will be more strictly tied together.

Description of the change

Although we still internally use the connection between a cluster interface and a MAC to figure out to which network a MAC is connected to, we don't want to expose this to the user as this will be refactored heavily in 1.8.

The ways to connect a MAC to a cluster interface are:
- set a parent for the device: the device primary MAC will be connected to the same cluster interface the parent is PXE booting from
- have the device DHCP off MAAS. Then MAAS will make the connection between the MAC and the cluster interface (this is done in a follow-up branch).
- explicitly claim a particular IP address for a MAC address: if this IP is part of a network MAAS manages, it will create the connection with the right cluster interface.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/api/devices.py'
--- src/maasserver/api/devices.py 2015-02-18 13:18:08 +0000
+++ src/maasserver/api/devices.py 2015-03-05 08:43:33 +0000
@@ -15,16 +15,12 @@
15 "DevicesHandler",15 "DevicesHandler",
16 ]16 ]
1717
18from django.shortcuts import get_object_or_404
19from maasserver.api.logger import maaslog18from maasserver.api.logger import maaslog
20from maasserver.api.support import (19from maasserver.api.support import (
21 operation,20 operation,
22 OperationsHandler,21 OperationsHandler,
23 )22 )
24from maasserver.api.utils import (23from maasserver.api.utils import get_optional_list
25 get_mandatory_param,
26 get_optional_list,
27 )
28from maasserver.dns.config import dns_update_zones24from maasserver.dns.config import dns_update_zones
29from maasserver.enum import (25from maasserver.enum import (
30 IPADDRESS_TYPE,26 IPADDRESS_TYPE,
@@ -42,8 +38,6 @@
42from maasserver.models import (38from maasserver.models import (
43 MACAddress,39 MACAddress,
44 Node,40 Node,
45 NodeGroup,
46 NodeGroupInterface,
47 )41 )
48from maasserver.models.node import Device42from maasserver.models.node import Device
49from piston.utils import rc43from piston.utils import rc
@@ -186,41 +180,6 @@
186 ', '.join(allocation.ip for allocation in sticky_ips))180 ', '.join(allocation.ip for allocation in sticky_ips))
187 return device181 return device
188182
189 @operation(idempotent=False)
190 def connect_mac_to_cluster_interface(self, request, system_id):
191 """Connect the given MAC Address to a cluster interface.
192
193 :param mac_address: MAC address to connect.
194 :param cluster_uuid: The UUID of the cluster the MAC address should
195 be connected to.
196 :param cluster_interface_name: The name of the cluster interface the
197 MAC address should be connected to.
198
199 Returns 404 if the device is not found.
200 Returns 400 if the mac_address is not found on the device.
201 """
202 device = Node.devices.get_node_or_404(
203 system_id=system_id, user=request.user, perm=NODE_PERMISSION.EDIT)
204 mac_address = get_mandatory_param(request.data, 'mac_address')
205 cluster_uuid = get_mandatory_param(request.data, 'cluster_uuid')
206 cluster_interface_name = get_mandatory_param(
207 request.data, 'cluster_interface')
208 cluster = get_object_or_404(NodeGroup, uuid=cluster_uuid)
209 nodegroupinterface = get_object_or_404(
210 NodeGroupInterface, nodegroup=cluster,
211 name=cluster_interface_name)
212 try:
213 mac = MACAddress.objects.get(
214 mac_address=mac_address, node=device)
215 except MACAddress.DoesNotExist:
216 raise MAASAPIBadRequest(
217 "mac_address %s not found on the device" % mac_address)
218 mac.cluster_interface = nodegroupinterface
219 mac.save()
220 maaslog.info(
221 "%s %s linked to cluster interface %s",
222 device.hostname, mac_address, nodegroupinterface.name)
223
224183
225class DevicesHandler(OperationsHandler):184class DevicesHandler(OperationsHandler):
226 """Manage the collection of all the devices in the MAAS."""185 """Manage the collection of all the devices in the MAAS."""
227186
=== modified file 'src/maasserver/api/tests/test_devices.py'
--- src/maasserver/api/tests/test_devices.py 2015-03-05 08:43:33 +0000
+++ src/maasserver/api/tests/test_devices.py 2015-03-05 08:43:33 +0000
@@ -23,7 +23,6 @@
23from maasserver.enum import (23from maasserver.enum import (
24 IPADDRESS_TYPE,24 IPADDRESS_TYPE,
25 NODE_STATUS,25 NODE_STATUS,
26 NODEGROUP_STATUS,
27 NODEGROUPINTERFACE_MANAGEMENT,26 NODEGROUPINTERFACE_MANAGEMENT,
28 )27 )
29from maasserver.models import (28from maasserver.models import (
@@ -287,65 +286,3 @@
287 get_device_uri(device), {'op': 'claim_sticky_ip_address'})286 get_device_uri(device), {'op': 'claim_sticky_ip_address'})
288 self.assertEqual(httplib.FORBIDDEN, response.status_code)287 self.assertEqual(httplib.FORBIDDEN, response.status_code)
289 self.assertItemsEqual([], StaticIPAddress.objects.all())288 self.assertItemsEqual([], StaticIPAddress.objects.all())
290
291 def test_connect_mac_to_cluster_interface_connects_mac(self):
292 cluster = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED)
293 interface = factory.make_NodeGroupInterface(
294 cluster, network=None,
295 management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
296 device = factory.make_Node(
297 installable=False, mac=True, disable_ipv4=False,
298 owner=self.logged_in_user)
299 mac = device.macaddress_set.all()[0]
300 response = self.client.post(
301 get_device_uri(device),
302 {
303 'op': 'connect_mac_to_cluster_interface',
304 'mac_address': (
305 mac.mac_address.get_raw()),
306 'cluster_uuid': cluster.uuid,
307 'cluster_interface': interface.name,
308 })
309 self.assertEqual(httplib.OK, response.status_code, response.content)
310 self.assertEqual(interface, reload_object(mac).cluster_interface)
311
312 def test_connect_mac_to_cluster_interface_checks_permission(self):
313 cluster = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED)
314 interface = factory.make_NodeGroupInterface(
315 cluster, network=None,
316 management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
317 device = factory.make_Node(
318 installable=False, mac=True, disable_ipv4=False,
319 owner=factory.make_User())
320 mac = device.macaddress_set.all()[0]
321 response = self.client.post(
322 get_device_uri(device),
323 {
324 'op': 'connect_mac_to_cluster_interface',
325 'mac_address': (
326 mac.mac_address.get_raw()),
327 'cluster_uuid': cluster.uuid,
328 'cluster_interface': interface.name,
329 })
330 self.assertEqual(
331 httplib.FORBIDDEN, response.status_code, response.content)
332
333 def test_connect_mac_to_cluster_interface_rejects_unknown_mac(self):
334 cluster = factory.make_NodeGroup(status=NODEGROUP_STATUS.ACCEPTED)
335 interface = factory.make_NodeGroupInterface(
336 cluster, network=None,
337 management=NODEGROUPINTERFACE_MANAGEMENT.DHCP)
338 device = factory.make_Node(
339 installable=False, mac=True, disable_ipv4=False,
340 owner=self.logged_in_user)
341 response = self.client.post(
342 get_device_uri(device),
343 {
344 'op': 'connect_mac_to_cluster_interface',
345 'mac_address': (
346 factory.make_MAC()),
347 'cluster_uuid': cluster.uuid,
348 'cluster_interface': interface.name,
349 })
350 self.assertEqual(
351 httplib.BAD_REQUEST, response.status_code, response.content)