Esempio n. 1
0
 def create_bridge(self, params):
     """Create bridge interface."""
     node = self._get_node_or_permission_error(params)
     if node.status == NODE_STATUS.ALLOCATED:
         form = AcquiredBridgeInterfaceForm(node=node, data=params)
     else:
         form = BridgeInterfaceForm(node=node, data=params)
     if form.is_valid():
         interface = form.save()
         self._update_obj_tags(interface, params)
         self._create_link_on_interface(interface, params)
     else:
         raise ValidationError(form.errors)
Esempio n. 2
0
    def create_bridge(self, params):
        """Create bridge interface."""
        # Only admin users can perform create.
        if not reload_object(self.user).is_superuser:
            raise HandlerPermissionError()

        node = self.get_object(params)
        if node.status == NODE_STATUS.ALLOCATED:
            form = AcquiredBridgeInterfaceForm(node=node, data=params)
        else:
            form = BridgeInterfaceForm(node=node, data=params)
        if form.is_valid():
            interface = form.save()
            self._update_obj_tags(interface, params)
            self._create_link_on_interface(interface, params)
        else:
            raise ValidationError(form.errors)
Esempio n. 3
0
    def create_bridge(self, request, system_id):
        """Create a bridge interface on a machine.

        :param name: Name of the interface.
        :param mac_address: MAC address of the interface.
        :param tags: Tags for the interface.
        :param vlan: VLAN the interface is connected to.
        :param parent: Parent interface for this bridge interface.

        Following are parameters specific to bridges:

        :param bridge_stp: Turn spanning tree protocol on or off.
            (Default: False).
        :param bridge_fd: Set bridge forward delay to time seconds.
            (Default: 15).

        Following are extra parameters that can be set on the interface:

        :param mtu: Maximum transmission unit.
        :param accept_ra: Accept router advertisements. (IPv6 only)
        :param autoconf: Perform stateless autoconfiguration. (IPv6 only)

        Returns 404 if the node is not found.
        """
        machine = Machine.objects.get_node_or_404(
            system_id, request.user, NodePermission.admin)
        raise_error_for_invalid_state_on_allocated_operations(
            machine, request.user, "create bridge")
        # Cast parent to parents to make it easier on the user and to make it
        # work with the form.
        request.data = request.data.copy()
        if 'parent' in request.data:
            request.data['parents'] = request.data['parent']
        if machine.status == NODE_STATUS.ALLOCATED:
            form = AcquiredBridgeInterfaceForm(
                node=machine, data=request.data)
        else:
            form = BridgeInterfaceForm(node=machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            # Replace parents with parent so it matches the API parameter.
            if 'parents' in form.errors:
                form.errors['parent'] = form.errors.pop('parents')
            raise MAASAPIValidationError(form.errors)
Esempio n. 4
0
    def create_bridge(self, request, system_id):
        """@description-title Create a bridge interface
        @description Create a bridge interface on a machine.

        @param (string) "{system_id}" [required=true] A system_id.

        @param (string) "name" [required=false] Name of the interface.

        @param (string) "mac_address" [required=false] MAC address of the
        interface.

        @param (string) "tags" [required=false] Tags for the interface.

        @param (string) "vlan" [required=false] VLAN the interface is connected
        to.

        @param (int) "parent" [required=false] Parent interface id for this
        bridge interface.

        @param (string) "bridge_type" [required=false] The type of bridge
        to create. Possible values are: ``standard``, ``ovs``.

        @param (boolean) "bridge_stp" [required=false] Turn spanning tree
        protocol on or off. (Default: False).

        @param (int) "bridge_fd" [required=false] Set bridge forward delay
        to time seconds. (Default: 15).

        @param (int) "mtu" [required=false] Maximum transmission unit.

        @param (boolean) "accept_ra" [required=false] Accept router
        advertisements. (IPv6 only)

        @param (boolean) "autoconf" [required=false] Perform stateless
        autoconfiguration. (IPv6 only)

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the new
        bridge interface object.
        @success-example "success-json" [exkey=interfaces-create-bridge]
        placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested machine is not found.
        @error-example "not-found"
            Not Found
        """
        machine = Machine.objects.get_node_or_404(
            system_id, request.user, NodePermission.admin)
        raise_error_for_invalid_state_on_allocated_operations(
            machine, request.user, "create bridge")
        # Cast parent to parents to make it easier on the user and to make it
        # work with the form.
        request.data = request.data.copy()
        if 'parent' in request.data:
            request.data['parents'] = request.data['parent']
        if machine.status == NODE_STATUS.ALLOCATED:
            form = AcquiredBridgeInterfaceForm(
                node=machine, data=request.data)
        else:
            form = BridgeInterfaceForm(node=machine, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            # Replace parents with parent so it matches the API parameter.
            if 'parents' in form.errors:
                form.errors['parent'] = form.errors.pop('parents')
            raise MAASAPIValidationError(form.errors)