sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04754
Re: [Merge] ~lloydwaltersj/maas:add-machine-count into maas:master
Diff comments:
> diff --git a/src/maasserver/websockets/handlers/bootresource.py b/src/maasserver/websockets/handlers/bootresource.py
> index fa4b17c..7337145 100644
> --- a/src/maasserver/websockets/handlers/bootresource.py
> +++ b/src/maasserver/websockets/handlers/bootresource.py
> @@ -378,6 +383,47 @@ class BootResourceHandler(Handler):
> count += 1
> return count
>
> + def get_number_of_nodes_of_node_type_deployed_for(
> + self, resource, node_type=NODE_TYPE.MACHINE
> + ):
> + """Return number of nodes of node_type='node_type' that are deploying the given
> + os, series, and architecture."""
> + if resource.rtype == BOOT_RESOURCE_TYPE.UPLOADED:
> + osystem = "custom"
> + distro_series = resource.name
> + else:
> + osystem, distro_series = resource.name.split("/")
> +
> + # Count the number of nodes with same os/release and architecture.
> + count = len(
instead of creating a list of nodes and then getting it's length, you can just sum up counting 1 for each match
e.g. `count = sum(1 for node in ... if self.node_has_...)`
> + [
> + node
> + for node in self.nodes.filter(
> + osystem=osystem,
> + distro_series=distro_series,
> + node_type=node_type,
> + )
> + if self.node_has_architecture_for_resource(node, resource)
> + ]
> + )
> +
> + # Any node that is deployed without osystem and distro_series,
> + # will be using the defaults.
> + if (
> + self.default_osystem == osystem
> + and self.default_distro_series == distro_series
> + ):
> + count += len(
> + [
> + node
> + for node in self.nodes.filter(
> + osystem="", distro_series="", node_type=node_type
> + )
> + if self.node_has_architecture_for_resource(node, resource)
> + ]
> + )
> + return count
> +
> def pick_latest_datetime(
> self, time: datetime, other_time: datetime
> ) -> datetime:
--
https://code.launchpad.net/~lloydwaltersj/maas/+git/maas/+merge/436064
Your team MAAS Committers is subscribed to branch maas:master.
References