public int countCurrentDockerSlaves ( final DockerSlaveTemplate template ) throws Exception { int count = 0 ; List < Container > containers = getClient ( ) . listContainersCmd ( ) . exec ( ) ; for ( Container container : containers ) { final Map < String , String > labels = container . getLabels ( ) ; if ( labels . containsKey ( DOCKER_CLOUD_LABEL ) && labels . get ( DOCKER_CLOUD_LABEL ) . equals ( getDisplayName ( ) ) ) { if ( template == null ) { // count only total cloud capacity count ++ ; } else if ( labels . containsKey ( DOCKER_TEMPLATE_LABEL ) && labels . get ( DOCKER_TEMPLATE_LABEL ) . equals ( template . getId ( ) ) ) { count ++ ; } } } return count ; }
Counts the number of instances in Docker currently running that are using the specified template .