def test__DHCP_deletes_link_with_subnet(self): interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) dhcp_subnet = factory.make_Subnet(vlan=interface.vlan) interface.link_subnet(INTERFACE_LINK_TYPE.DHCP, dhcp_subnet) interface = reload_object(interface) dhcp_ip = interface.ip_addresses.get(alloc_type=IPADDRESS_TYPE.DHCP) form = InterfaceUnlinkForm(instance=interface, data={"id": dhcp_ip.id}) self.assertTrue(form.is_valid(), form.errors) form.save() self.assertIsNone(reload_object(dhcp_ip))
def test__LINK_UP_deletes_link(self): interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) subnet = factory.make_Subnet(vlan=interface.vlan) link_ip = factory.make_StaticIPAddress( alloc_type=IPADDRESS_TYPE.STICKY, ip="", subnet=subnet, interface=interface, ) form = InterfaceUnlinkForm(instance=interface, data={"id": link_ip.id}) self.assertTrue(form.is_valid(), form.errors) form.save() self.assertIsNone(reload_object(link_ip))
def test_STATIC_deletes_link_in_subnet(self): interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL) subnet = factory.make_Subnet(vlan=interface.vlan) ip = factory.pick_ip_in_network(subnet.get_ipnetwork()) interface.link_subnet(INTERFACE_LINK_TYPE.STATIC, subnet, ip_address=ip) interface = reload_object(interface) static_ip = get_one( interface.ip_addresses.filter(alloc_type=IPADDRESS_TYPE.STICKY, ip=ip, subnet=subnet)) form = InterfaceUnlinkForm(instance=interface, data={"id": static_ip.id}) self.assertTrue(form.is_valid(), form.errors) form.save() self.assertIsNone(reload_object(static_ip))
def unlink_subnet(self, request, system_id, id): """@description-title Unlink interface from subnet @description Unlink an interface with the given system_id and interface id from a subnet. @param (string) "{system_id}" [required=true] A system_id. @param (int) "{id}" [required=true] An interface id. @param (int) "id" [required=false] ID of the subnet link on the interface to remove. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing the updated interface object. @success-example "success-json" [exkey=interfaces-unlink-subnet] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" The requested machine or interface is not found. @error-example "not-found" Not Found """ interface = Interface.objects.get_interface_or_404( system_id, id, request.user, NodePermission.admin, NodePermission.edit, ) node = interface.get_node() raise_error_if_controller(node, "link subnet") if node.node_type == NODE_TYPE.MACHINE: # This node needs to be in the correct state to modify # the interface. raise_error_for_invalid_state_on_allocated_operations( node, request.user, "unlink subnet") form = InterfaceUnlinkForm(instance=interface, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)
def unlink_subnet(self, request, system_id, id): """Unlink interface to a subnet. :param id: ID of the link on the interface to remove. Returns 404 if the node or interface is not found. """ interface = Interface.objects.get_interface_or_404( system_id, id, request.user, NODE_PERMISSION.EDIT) node = interface.get_node() raise_error_if_controller(node, "link subnet") if node.node_type == NODE_TYPE.MACHINE: # This node needs to be in the correct state to modify # the interface. raise_error_for_invalid_state_on_allocated_operations( node, request.user, "unlink subnet") form = InterfaceUnlinkForm(instance=interface, data=request.data) if form.is_valid(): return form.save() else: raise MAASAPIValidationError(form.errors)