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