def create_vlan(self, request, system_id): """Create a VLAN interface on a machine. :param tags: Tags for the interface. :param vlan: Tagged VLAN the interface is connected to. :param parent: Parent interface for this VLAN interface. 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, NODE_PERMISSION.ADMIN) raise_error_for_invalid_state_on_allocated_operations( machine, request.user, "create VLAN") # 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'] form = VLANInterfaceForm(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)
def create_vlan(self, params): """Create VLAN interface.""" node = self._get_node_or_permission_error(params) params['parents'] = [params.pop('parent')] form = VLANInterfaceForm(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)
def create_vlan(self, request, system_id): """@description-title Create a VLAN interface @description Create a VLAN interface on a machine. @param (string) "{system_id}" [required=true] A system_id. @param (string) "tags" [required=false] Tags for the interface. @param (string) "vlan" [required=true] Tagged VLAN the interface is connected to. @param (int) "parent" [required=true] Parent interface id for this VLAN interface. @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 VLAN interface object. @success-example "success-json" [exkey=interfaces-placeholder] 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 VLAN") # 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'] form = VLANInterfaceForm(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)
def create_vlan(self, params): """Create VLAN interface.""" # Only admin users can perform create. if not reload_object(self.user).is_superuser: raise HandlerPermissionError() node = self.get_object(params) params['parents'] = [params.pop('parent')] form = VLANInterfaceForm(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)