@@ -36,6 +36,7 @@ type ClusterLister interface {
3636 ProjectClusters (string , * store.ListOptions ) (* atlasClustersPinned.PaginatedAdvancedClusterDescription , error )
3737 ListFlexClusters (* atlasv2.ListFlexClustersApiParams ) (* atlasv2.PaginatedFlexClusters20241113 , error )
3838 LatestProjectClusters (string , * store.ListOptions ) (* atlasv2.PaginatedClusterDescription20240805 , error )
39+ GetClusterAutoScalingConfig (string , string ) (* atlasv2.ClusterDescriptionAutoScalingModeConfiguration , error )
3940}
4041
4142type ListOpts struct {
@@ -69,11 +70,15 @@ func (opts *ListOpts) Run() error {
6970
7071func (opts * ListOpts ) RunDedicatedCluster () error {
7172 listOpts := opts .NewAtlasListOptions ()
72- if opts .autoScalingMode == independentShardScalingFlag {
73+ if isIndependentShardScaling ( opts .autoScalingMode ) {
7374 r , err := opts .store .LatestProjectClusters (opts .ConfigProjectID (), listOpts )
7475 if err != nil {
7576 return err
7677 }
78+ r , err = opts .filterClustersByAutoScalingMode (r )
79+ if err != nil {
80+ return err
81+ }
7782 return opts .Print (r )
7883 }
7984
@@ -85,6 +90,22 @@ func (opts *ListOpts) RunDedicatedCluster() error {
8590 return opts .Print (r )
8691}
8792
93+ func (opts * ListOpts ) filterClustersByAutoScalingMode (clusters * atlasv2.PaginatedClusterDescription20240805 ) (* atlasv2.PaginatedClusterDescription20240805 , error ) {
94+ filteredClusters := make ([]atlasv2.ClusterDescription20240805 , 0 )
95+ for _ , cluster := range clusters .GetResults () {
96+ clusterAutoScalingConfig , err := opts .store .GetClusterAutoScalingConfig (opts .ConfigProjectID (), * cluster .Name )
97+ if err != nil {
98+ return nil , err
99+ }
100+ if isIndependentShardScaling (clusterAutoScalingConfig .GetAutoScalingMode ()) {
101+ filteredClusters = append (filteredClusters , cluster )
102+ }
103+ }
104+
105+ clusters .Results = & filteredClusters
106+ return clusters , nil
107+ }
108+
88109func (opts * ListOpts ) RunFlexCluster () error {
89110 r , err := opts .store .ListFlexClusters (opts .newListFlexClustersAPIParams ())
90111 if err != nil {
@@ -118,7 +139,11 @@ func ListBuilder() *cobra.Command {
118139 "output" : listTemplate ,
119140 },
120141 Example : ` # Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3:
121- atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --output json` ,
142+ atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --output json
143+
144+ # Return a JSON-formatted list of all clusters for the project with ID 5e2211c17a3e5a48f5497de3 and with independent shard scaling mode:
145+ atlas clusters list --projectId 5e2211c17a3e5a48f5497de3 --autoScalingMode independentShardScaling --output json
146+ ` ,
122147 PreRunE : func (cmd * cobra.Command , _ []string ) error {
123148 return opts .PreRunE (
124149 opts .ValidateProjectID ,
0 commit comments