From 359db6ef33d687c864778e9e23fddc94dc7c479a Mon Sep 17 00:00:00 2001 From: aaraj Date: Mon, 29 Jul 2024 11:09:59 +0530 Subject: [PATCH] OCM-9228 | test: Get instances by nodepool id --- pkg/aws/aws_client/instance.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/aws/aws_client/instance.go b/pkg/aws/aws_client/instance.go index 25575e90..f6d2fab1 100644 --- a/pkg/aws/aws_client/instance.go +++ b/pkg/aws/aws_client/instance.go @@ -289,6 +289,37 @@ func (client *AWSClient) GetInstancesByInfraID(infraID string) ([]types.Instance return instances, err } +// GetInstancesByNodePoolID will return the instances with tag tag:api.openshift.com/nodepool-ocm: +func (client *AWSClient) GetInstancesByNodePoolID(nodePoolID string, clusterID string) ([]types.Instance, error) { + filter1 := types.Filter{ + Name: aws.String("tag:api.openshift.com/nodepool-ocm"), + Values: []string{ + nodePoolID, + }, + } + filter2 := types.Filter{ + Name: aws.String("tag:api.openshift.com/id"), + Values: []string{ + clusterID, + }, + } + output, err := client.Ec2Client.DescribeInstances(context.TODO(), &ec2.DescribeInstancesInput{ + Filters: []types.Filter{ + filter1, + filter2, + }, + MaxResults: aws.Int32(100), + }) + if err != nil { + return nil, err + } + var instances []types.Instance + for _, reservation := range output.Reservations { + instances = append(instances, reservation.Instances...) + } + return instances, err +} + func (client *AWSClient) ListAvaliableRegionsFromAWS() ([]types.Region, error) { optInStatus := "opt-in-status" optInNotRequired := "opt-in-not-required"