Esempio n. 1
0
    def read(self, request, system_id):
        """@description-title List interfaces
        @description List all interfaces belonging to a machine, device, or
        rack controller.

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

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing a list of
        interface objects.
        @success-example "success-json" [exkey=interfaces-read] placeholder
        text

        @error (http-status-code) "404" 404
        @error (content) "not-found" The requested machine is not found.
        @error-example "not-found"
            Not Found
        """
        node = Node.objects.get_node_or_404(
            system_id, request.user, NodePermission.view)
        interfaces = prefetch_queryset(
            node.interface_set.all(), INTERFACES_PREFETCH)
        # Preload the node on the interface, no need for another query.
        for interface in interfaces:
            interface.node = node
        return interfaces
Esempio n. 2
0
    def read(self, request):
        """List Nodes visible to the user, optionally filtered by criteria.

        Nodes are sorted by id (i.e. most recent last) and grouped by type.

        :param hostname: An optional hostname. Only nodes relating to the node
            with the matching hostname will be returned. This can be specified
            multiple times to see multiple nodes.
        :type hostname: unicode

        :param mac_address: An optional MAC address. Only nodes relating to the
            node owning the specified MAC address will be returned. This can be
            specified multiple times to see multiple nodes.
        :type mac_address: unicode

        :param id: An optional list of system ids.  Only nodes relating to the
            nodes with matching system ids will be returned.
        :type id: unicode

        :param domain: An optional name for a dns domain. Only nodes relating
            to the nodes in the domain will be returned.
        :type domain: unicode

        :param zone: An optional name for a physical zone. Only nodes relating
            to the nodes in the zone will be returned.
        :type zone: unicode

        :param agent_name: An optional agent name.  Only nodes relating to the
            nodes with matching agent names will be returned.
        :type agent_name: unicode
        """

        if self.base_model == Node:
            # Avoid circular dependencies
            from maasserver.api.devices import DevicesHandler
            from maasserver.api.machines import MachinesHandler
            from maasserver.api.rackcontrollers import RackControllersHandler
            from maasserver.api.regioncontrollers import (
                RegionControllersHandler)
            racks = RackControllersHandler().read(request).order_by("id")
            nodes = list(
                chain(
                    DevicesHandler().read(request).order_by("id"),
                    MachinesHandler().read(request).order_by("id"),
                    racks,
                    RegionControllersHandler().read(request).exclude(
                        id__in=racks).order_by("id"),
                ))
            return nodes
        else:
            nodes = filtered_nodes_list_from_request(request, self.base_model)
            nodes = nodes.select_related(*NODES_SELECT_RELATED)
            nodes = prefetch_queryset(nodes, NODES_PREFETCH).order_by('id')
            # Set related node parents so no extra queries are needed.
            for node in nodes:
                for interface in node.interface_set.all():
                    interface.node = node
                for block_device in node.blockdevice_set.all():
                    block_device.node = node
            return nodes
Esempio n. 3
0
 def read(self, request):
     """List all fabrics."""
     fabrics = prefetch_queryset(Fabric.objects.all(), FABRIC_PREFETCH)
     # Preload the fabric on each vlan as that is already known, another
     # query is not required.
     for fabric in fabrics:
         for vlan in fabric.vlan_set.all():
             vlan.fabric = fabric
     return fabrics
Esempio n. 4
0
    def read(self, request):
        """@description-title List fabrics
        @description List all fabrics.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing a list of
        fabric objects.
        @success-example "success-json" [exkey=fabrics-read] placeholder text
        """
        return prefetch_queryset(Fabric.objects.all(), FABRIC_PREFETCH)
Esempio n. 5
0
    def read(self, request, system_id):
        """List all interfaces belonging to a machine, device, or
        rack controller.

        Returns 404 if the node is not found.
        """
        node = Node.objects.get_node_or_404(system_id, request.user,
                                            NODE_PERMISSION.VIEW)
        interfaces = prefetch_queryset(node.interface_set.all(),
                                       INTERFACES_PREFETCH)
        # Preload the node on the interface, no need for another query.
        for interface in interfaces:
            interface.node = node
        return interfaces
Esempio n. 6
0
    def read(self, request):
        """@description-title List fabrics
        @description List all fabrics.

        @success (http-status-code) "server-success" 200
        @success (json) "success-json" A JSON object containing a list of
        fabric objects.
        @success-example "success-json" [exkey=fabrics-read] placeholder text
        """
        fabrics = prefetch_queryset(Fabric.objects.all(), FABRIC_PREFETCH)
        # Preload the fabric on each vlan as that is already known, another
        # query is not required.
        for fabric in fabrics:
            for vlan in fabric.vlan_set.all():
                vlan.fabric = fabric
        return fabrics
Esempio n. 7
0
 def _get_node_type(self, model, request, name):
     # Workaround an issue where piston3 will try to use the fields from
     # this handler instead of the fields defined for the returned object.
     # This is done because this operation actually returns a list of nodes
     # and not a list of tags as this handler is defined to return.
     self.fields = None
     tag = Tag.objects.get_tag_or_404(name=name, user=request.user)
     nodes = model.objects.get_nodes(request.user,
                                     NodePermission.view,
                                     from_nodes=tag.node_set.all())
     nodes = nodes.select_related(*NODES_SELECT_RELATED)
     nodes = prefetch_queryset(nodes, NODES_PREFETCH).order_by("id")
     # Set related node parents so no extra queries are needed.
     for node in nodes:
         for interface in node.interface_set.all():
             interface.node = node
         for block_device in node.blockdevice_set.all():
             block_device.node = node
     return [node.as_self() for node in nodes]
Esempio n. 8
0
    def read(self, request):
        """@description-title List Nodes visible to the user
        @description List nodes visible to current user, optionally filtered by
        criteria.

        Nodes are sorted by id (i.e. most recent last) and grouped by type.

        @param (string) "hostname" [required=false] Only nodes relating to the
        node with the matching hostname will be returned. This can be specified
        multiple times to see multiple nodes.

        @param (int) "cpu_count" [required=false] Only nodes with the specified
        minimum number of CPUs will be included.

        @param (string) "mem" [required=false] Only nodes with the specified
        minimum amount of RAM (in MiB) will be included.

        @param (string) "mac_address" [required=false] Only nodes relating to
        the node owning the specified MAC address will be returned. This can be
        specified multiple times to see multiple nodes.

        @param (string) "id" [required=false] Only nodes relating to the nodes
        with matching system ids will be returned.

        @param (string) "domain" [required=false] Only nodes relating to the
        nodes in the domain will be returned.

        @param (string) "zone" [required=false] Only nodes relating to the
        nodes in the zone will be returned.

        @param (string) "pool" [required=false] Only nodes belonging to the
        pool will be returned.

        @param (string) "agent_name" [required=false] Only nodes relating to
        the nodes with matching agent names will be returned.

        @param (string) "fabrics" [required=false] Only nodes with interfaces
        in specified fabrics will be returned.

        @param (string) "not_fabrics" [required=false] Only nodes with
        interfaces not in specified fabrics will be returned.

        @param (string) "vlans" [required=false] Only nodes with interfaces in
        specified VLANs will be returned.

        @param (string) "not_vlans" [required=false] Only nodes with interfaces
        not in specified VLANs will be returned.

        @param (string) "subnets" [required=false] Only nodes with interfaces
        in specified subnets will be returned.

        @param (string) "not_subnets" [required=false] Only nodes with
        interfaces not in specified subnets will be returned.

        @param (string) "link_speed" [required=false] Only nodes with
        interfaces with link speeds greater than or equal to link_speed will
        be returned.

        @param (string) "status" [required=false] Only nodes with specified
        status will be returned.

        @param (string) "pod": [required=false] Only nodes that belong to a
        specified pod will be returned.

        @param (string) "not_pod": [required=false] Only nodes that don't
        belong to a specified pod will be returned.

        @param (string) "pod_type": [required=false] Only nodes that belong to
        a pod of the specified type will be returned.

        @param (string) "not_pod_type": [required=false] Only nodes that don't
        belong a pod of the specified type will be returned.

        @success (http-status-code) "200" 200

        @success (json) "success_json" A JSON object containing a list of node
        objects.
        @success-example "success_json" [exkey=read-visible-nodes] placeholder
        text

        """

        if self.base_model == Node:
            # Avoid circular dependencies
            from maasserver.api.devices import DevicesHandler
            from maasserver.api.machines import MachinesHandler
            from maasserver.api.rackcontrollers import RackControllersHandler
            from maasserver.api.regioncontrollers import (
                RegionControllersHandler, )

            racks = RackControllersHandler().read(request).order_by("id")
            nodes = list(
                chain(
                    DevicesHandler().read(request).order_by("id"),
                    MachinesHandler().read(request).order_by("id"),
                    racks,
                    RegionControllersHandler().read(request).exclude(
                        id__in=racks).order_by("id"),
                ))
            return nodes
        else:
            form = ReadNodesForm(data=request.GET)
            if not form.is_valid():
                raise MAASAPIValidationError(form.errors)
            nodes = self.base_model.objects.get_nodes(request.user,
                                                      NodePermission.view)
            nodes, _, _ = form.filter_nodes(nodes)
            nodes = nodes.select_related(*NODES_SELECT_RELATED)
            nodes = prefetch_queryset(nodes, NODES_PREFETCH).order_by("id")
            # Set related node parents so no extra queries are needed.
            for node in nodes:
                for interface in node.interface_set.all():
                    interface.node = node
                for block_device in node.blockdevice_set.all():
                    block_device.node = node
            return nodes
Esempio n. 9
0
    def read(self, request):
        """@description-title List Nodes visible to the user
        @description List nodes visible to current user, optionally filtered by
        criteria.

        Nodes are sorted by id (i.e. most recent last) and grouped by type.

        @param (string) "hostname" [required=false] Only nodes relating to the
        node with the matching hostname will be returned. This can be specified
        multiple times to see multiple nodes.

        @param (string) "mac_address" [required=false] Only nodes relating to
        the node owning the specified MAC address will be returned. This can be
        specified multiple times to see multiple nodes.

        @param (string) "id" [required=false] Only nodes relating to the nodes
        with matching system ids will be returned.

        @param (string) "domain" [required=false] Only nodes relating to the
        nodes in the domain will be returned.

        @param (string) "zone" [required=false] Only nodes relating to the
        nodes in the zone will be returned.

        @param (string) "pool" [required=false] Only nodes belonging to the
        pool will be returned.

        @param (string) "agent_name" [required=false] Only nodes relating to
        the nodes with matching agent names will be returned.

        @success (http-status-code) "200" 200

        @success (json) "success_json" A JSON object containing a list of node
        objects.
        @success-example "success_json" [exkey=read-visible-nodes] placeholder
        text
        """

        if self.base_model == Node:
            # Avoid circular dependencies
            from maasserver.api.devices import DevicesHandler
            from maasserver.api.machines import MachinesHandler
            from maasserver.api.rackcontrollers import RackControllersHandler
            from maasserver.api.regioncontrollers import (
                RegionControllersHandler
            )
            racks = RackControllersHandler().read(request).order_by("id")
            nodes = list(chain(
                DevicesHandler().read(request).order_by("id"),
                MachinesHandler().read(request).order_by("id"),
                racks,
                RegionControllersHandler().read(request).exclude(
                    id__in=racks).order_by("id"),
            ))
            return nodes
        else:
            nodes = filtered_nodes_list_from_request(request, self.base_model)
            nodes = nodes.select_related(*NODES_SELECT_RELATED)
            nodes = prefetch_queryset(
                nodes, NODES_PREFETCH).order_by('id')
            # Set related node parents so no extra queries are needed.
            for node in nodes:
                for interface in node.interface_set.all():
                    interface.node = node
                for block_device in node.blockdevice_set.all():
                    block_device.node = node
            return nodes