コード例 #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)
コード例 #2
0
 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))
コード例 #3
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,
     )
コード例 #4
0
 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))
コード例 #5
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))
コード例 #6
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)
コード例 #7
0
ファイル: interfaces.py プロジェクト: Kryndex/maas
    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)