It appears these lines of code and the methods they call are miscalculating availableTotalSlaves when using multiple "Amazon EC2" cloud configurations with the ec2 plugin.
We have multiple "Amazon EC2" clouds configured with one AMI config each instead of using a single "Amazon EC2" configuration with multiple AMI configs. This is due to using Jenkins Configuration as Code and wanting to be able to put each AMI config in a separate YAML file (one per "customer").
When we use the global instance cap (instanceCapStr) on one of these configurations, it seems to apply to ALL ec2 instances launched by the Jenkins master, not just the instances launched by that specific "Amazon EC2" cloud. It doesn't seem to use "cloudName" in the filter.
We have worked around this temporarily by using the AMI-specific instanceCap.