예제 #1
0
파일: device.py 프로젝트: ocni-dtu/maas
 def update_interface(self, params):
     """Update the interface."""
     device = self.get_object(params, permission=self._meta.edit_permission)
     interface = Interface.objects.get(node=device,
                                       id=params["interface_id"])
     interface_form = InterfaceForm.get_interface_form(interface.type)
     form = interface_form(instance=interface, data=params)
     if form.is_valid():
         interface = form.save()
         self._configure_interface(interface, params)
         return self.full_dehydrate(reload_object(device))
     else:
         raise ValidationError(form.errors)
예제 #2
0
 def update_interface(self, params):
     """Update the interface."""
     node = self._get_node_or_permission_error(params)
     interface = Interface.objects.get(node=node, id=params["interface_id"])
     if node.status == NODE_STATUS.DEPLOYED:
         interface_form = DeployedInterfaceForm
     else:
         interface_form = InterfaceForm.get_interface_form(interface.type)
     form = interface_form(instance=interface, data=params)
     if form.is_valid():
         interface = form.save()
         self._update_obj_tags(interface, params)
     else:
         raise ValidationError(form.errors)
     if 'mode' in params:
         self.link_subnet(params)
     return self.full_dehydrate(node)
예제 #3
0
    def update_interface(self, params):
        """Update the interface."""
        # Only admin users can perform update.
        if not reload_object(self.user).is_superuser:
            raise HandlerPermissionError()

        device = self.get_object(params)
        interface = Interface.objects.get(node=device,
                                          id=params["interface_id"])
        interface_form = InterfaceForm.get_interface_form(interface.type)
        form = interface_form(instance=interface, data=params)
        if form.is_valid():
            interface = form.save()
            self._configure_interface(interface, params)
            return self.full_dehydrate(reload_object(device))
        else:
            raise ValidationError(form.errors)
예제 #4
0
    def update_interface(self, params):
        """Update the interface."""
        # Only admin users can perform update.
        if not reload_object(self.user).is_superuser:
            raise HandlerPermissionError()

        node = self.get_object(params)
        interface = Interface.objects.get(node=node, id=params["interface_id"])
        if node.status == NODE_STATUS.DEPLOYED:
            interface_form = DeployedInterfaceForm
        else:
            interface_form = InterfaceForm.get_interface_form(interface.type)
        form = interface_form(instance=interface, data=params)
        if form.is_valid():
            interface = form.save()
            self._update_obj_tags(interface, params)
        else:
            raise ValidationError(form.errors)
        if 'mode' in params:
            self.link_subnet(params)
        return self.full_dehydrate(node)
예제 #5
0
    def update(self, request, system_id, id):
        """@description-title Update an interface
        @description Update an interface with the given system_id and interface
        id.

        Note: machines must have a status of Ready or Broken to have access to
        all options. Machines with Deployed status can only have the name
        and/or mac_address updated for an interface. This is intented to allow
        a bad interface to be replaced while the machine remains deployed.

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

        @param (int) "{id}" [required=true] An interface id.

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

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

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

        @param (int) "vlan" [required=false] (Physical interfaces) Untagged
        VLAN id the interface is connected to.  If not set then the interface
        is considered disconnected.

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

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

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

        @param (int) "vlan" [required=false] (Bond interfaces) Untagged VLAN id
        the interface is connected to. If not set then the interface is
        considered disconnected.

        @param (int) "parents" [required=false] (Bond interfaces) Parent
        interface ids that make this bond.

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

        @param (int) "vlan" [required=false] (VLAN interfaces) Tagged VLAN id
        the interface is connected to.

        @param (int) "parent" [required=false] (VLAN interfaces) Parent
        interface ids for the VLAN interface.

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

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

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

        @param (int) "vlan" [required=false] (Bridge interfaces) VLAN id the
        interface is connected to.

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

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

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

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

        @param (int) "bond_miimon" [required=false] (Bonds) The link monitoring
        freqeuncy in milliseconds.  (Default: 100).

        @param (int) "bond_downdelay" [required=false] (Bonds) Specifies the
        time, in milliseconds, to wait before disabling a slave after a link
        failure has been detected.

        @param (int) "bond_updelay" [required=false] (Bonds) Specifies the
        time, in milliseconds, to wait before enabling a slave after a link
        recovery has been detected.

        @param (string) "bond_lacp_rate" [required=false] (Bonds) Option
        specifying the rate in which we'll ask our link partner to transmit
        LACPDU packets in 802.3ad mode.  Available options are ``fast`` or
        ``slow``.  (Default: ``slow``).

        @param (string) "bond_xmit_hash_policy" [required=false] (Bonds) The
        transmit hash policy to use for slave selection in balance-xor,
        802.3ad, and tlb modes.  Possible values are: ``layer2``, ``layer2+3``,
        ``layer3+4``, ``encap2+3``, ``encap3+4``.

        @param (string) "bond_mode" [required=false,formatting=true] (Bonds)
        The operating mode of the bond.  (Default: ``active-backup``).

        Supported bonding modes (bond-mode):

        - ``balance-rr``: Transmit packets in sequential order from the first
          available slave through the last. This mode provides load balancing
          and fault tolerance.

        - ``active-backup``: Only one slave in the bond is active. A different
          slave becomes active if, and only if, the active slave fails. The
          bond's MAC address is externally visible on only one port (network
          adapter) to avoid confusing the switch.

        - ``balance-xor``: Transmit based on the selected transmit hash policy.
          The default policy is a simple [(source MAC address XOR'd with
          destination MAC address XOR packet type ID) modulo slave count].

        - ``broadcast``: Transmits everything on all slave interfaces. This
          mode provides fault tolerance.

        - ``802.3ad``: IEEE 802.3ad Dynamic link aggregation. Creates
          aggregation groups that share the same speed and duplex settings.
          Utilizes all slaves in the active aggregator according to the 802.3ad
          specification.

        - ``balance-tlb``: Adaptive transmit load balancing: channel bonding
          that does not require any special switch support.

        - ``balance-alb``: Adaptive load balancing: includes balance-tlb plus
          receive load balancing (rlb) for IPV4 traffic, and does not require
          any special switch support. The receive load balancing is achieved by
          ARP negotiation.

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

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

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

        @param (boolean) "link_connected" [required=false]
        (Physical interfaces) Whether or not the interface is physically
        conntected to an uplink.  (Default: True).

        @param (int) "interface_speed" [required=false] (Physical interfaces)
        The speed of the interface in Mbit/s. (Default: 0).

        @param (int) "link_speed" [required=false] (Physical interfaces)
        The speed of the link in Mbit/s. (Default: 0).

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing the new
        requested interface object.
        @success-example "success-json" [exkey=interfaces-update] 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()
        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, "update interface",
                extra_states=[NODE_STATUS.DEPLOYED])
        if node.is_controller:
            if interface.type == INTERFACE_TYPE.VLAN:
                raise MAASAPIForbidden(
                    "Cannot modify VLAN interface on controller.")
            interface_form = ControllerInterfaceForm
        elif node.status == NODE_STATUS.DEPLOYED:
            interface_form = DeployedInterfaceForm
        else:
            interface_form = InterfaceForm.get_interface_form(interface.type)
        # For VLAN interface we cast parents to parent. As a VLAN can only
        # have one parent.
        if interface.type == INTERFACE_TYPE.VLAN:
            request.data = request.data.copy()
            if 'parent' in request.data:
                request.data['parents'] = request.data['parent']
        form = interface_form(instance=interface, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            # Replace parents with parent so it matches the API parameter, if
            # the interface being editted was a VLAN interface.
            if (interface.type == INTERFACE_TYPE.VLAN and
                    'parents' in form.errors):
                form.errors['parent'] = form.errors.pop('parents')
            raise MAASAPIValidationError(form.errors)
예제 #6
0
파일: interfaces.py 프로젝트: Kryndex/maas
    def update(self, request, system_id, id):
        """Update interface on node.

        Machines must have a status of Ready or Broken to have access to all
        options. Machines with Deployed status can only have the name and/or
        mac_address updated for an interface. This is intented to allow a bad
        interface to be replaced while the machine remains deployed.

        Fields for physical interface:

        :param name: Name of the interface.
        :param mac_address: MAC address of the interface.
        :param tags: Tags for the interface.
        :param vlan: Untagged VLAN the interface is connected to.  If not set
            then the interface is considered disconnected.

        Fields for bond interface:

        :param name: Name of the interface.
        :param mac_address: MAC address of the interface.
        :param tags: Tags for the interface.
        :param vlan: Untagged VLAN the interface is connected to.  If not set
            then the interface is considered disconnected.
        :param parents: Parent interfaces that make this bond.

        Fields for VLAN interface:

        :param tags: Tags for the interface.
        :param vlan: Tagged VLAN the interface is connected to.
        :param parent: Parent interface for this VLAN interface.

        Fields for bridge interface:

        :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 extra parameters that can be set on all interface types:

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

        Following are parameters specific to bonds:

        :param bond_mode: The operating mode of the bond.
            (Default: active-backup).
        :param bond_miimon: The link monitoring freqeuncy in milliseconds.
            (Default: 100).
        :param bond_downdelay: Specifies the time, in milliseconds, to wait
            before disabling a slave after a link failure has been detected.
        :param bond_updelay: Specifies the time, in milliseconds, to wait
            before enabling a slave after a link recovery has been detected.
        :param bond_lacp_rate: Option specifying the rate in which we'll ask
            our link partner to transmit LACPDU packets in 802.3ad mode.
            Available options are fast or slow. (Default: slow).
        :param bond_xmit_hash_policy: The transmit hash policy to use for
            slave selection in balance-xor, 802.3ad, and tlb modes.

        Supported bonding modes (bond-mode):

        balance-rr - Transmit packets in sequential order from the first
        available slave through the last.  This mode provides load balancing
        and fault tolerance.

        active-backup - Only one slave in the bond is active.  A different
        slave becomes active if, and only if, the active slave fails.  The
        bond's MAC address is externally visible on only one port (network
        adapter) to avoid confusing the switch.

        balance-xor - Transmit based on the selected transmit hash policy.
        The default policy is a simple [(source MAC address XOR'd with
        destination MAC address XOR packet type ID) modulo slave count].

        broadcast - Transmits everything on all slave interfaces. This mode
        provides fault tolerance.

        802.3ad - IEEE 802.3ad Dynamic link aggregation.  Creates aggregation
        groups that share the same speed and duplex settings.  Utilizes all
        slaves in the active aggregator according to the 802.3ad specification.

        balance-tlb - Adaptive transmit load balancing: channel bonding that
        does not require any special switch support.

        balance-alb - Adaptive load balancing: includes balance-tlb plus
        receive load balancing (rlb) for IPV4 traffic, and does not require any
        special switch support.  The receive load balancing is achieved by
        ARP negotiation.

        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).

        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()
        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,
                "update interface",
                extra_states=[NODE_STATUS.DEPLOYED])
        if node.is_controller:
            if interface.type == INTERFACE_TYPE.VLAN:
                raise MAASAPIForbidden(
                    "Cannot modify VLAN interface on controller.")
            interface_form = ControllerInterfaceForm
        elif node.status == NODE_STATUS.DEPLOYED:
            interface_form = DeployedInterfaceForm
        else:
            interface_form = InterfaceForm.get_interface_form(interface.type)
        # For VLAN interface we cast parents to parent. As a VLAN can only
        # have one parent.
        if interface.type == INTERFACE_TYPE.VLAN:
            request.data = request.data.copy()
            if 'parent' in request.data:
                request.data['parents'] = request.data['parent']
        form = interface_form(instance=interface, data=request.data)
        if form.is_valid():
            return form.save()
        else:
            # Replace parents with parent so it matches the API parameter, if
            # the interface being editted was a VLAN interface.
            if (interface.type == INTERFACE_TYPE.VLAN
                    and 'parents' in form.errors):
                form.errors['parent'] = form.errors.pop('parents')
            raise MAASAPIValidationError(form.errors)