Ejemplo n.º 1
0
 def test__requires_id(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     form = InterfaceUnlinkForm(instance=interface, data={})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual({
         "id": ["This field is required."],
     }, form.errors)
Ejemplo n.º 2
0
 def test_must_be_valid_id(self):
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL)
     link_id = random.randint(100, 1000)
     form = InterfaceUnlinkForm(instance=interface, data={"id": link_id})
     self.assertFalse(form.is_valid(), form.errors)
     self.assertEqual(
         {
             "id":
             ["'%s' is not a valid id.  It should be one of: ." % link_id]
         },
         form.errors,
     )
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
    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)