Skip to content

Commit 795ba1f

Browse files
committed
OCM-15901 | feat: adding capacity reservations capability
1 parent da72de1 commit 795ba1f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package aws_client
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/aws/aws-sdk-go-v2/aws"
8+
"github.com/aws/aws-sdk-go-v2/service/ec2"
9+
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
10+
"github.com/openshift-online/ocm-common/pkg/log"
11+
)
12+
13+
func (client *AWSClient) CreateCapacityReservation(crInput *ec2.CreateCapacityReservationInput, endDate time.Time, creator string) (*ec2.CreateCapacityReservationOutput, error) {
14+
crInput.EndDateType = types.EndDateTypeLimited
15+
crInput.EndDate = aws.Time(endDate)
16+
crInput.TagSpecifications = []types.TagSpecification{
17+
{
18+
ResourceType: types.ResourceTypeCapacityReservation,
19+
Tags: []types.Tag{
20+
{
21+
Key: aws.String("Creator"),
22+
Value: aws.String(creator),
23+
},
24+
{
25+
Key: aws.String("Timestamp"),
26+
Value: aws.String(time.Now().Format(time.RFC3339)),
27+
},
28+
},
29+
},
30+
}
31+
output, err := client.Ec2Client.CreateCapacityReservation(context.Background(), crInput)
32+
if err != nil {
33+
log.LogError("Got error creating capacity reservation: %s", err)
34+
}
35+
return output, err
36+
}
37+
38+
func (client *AWSClient) CancelCapacityReservation(crId string) (*ec2.CancelCapacityReservationOutput, error) {
39+
output, err := client.Ec2Client.CancelCapacityReservation(context.Background(), &ec2.CancelCapacityReservationInput{
40+
CapacityReservationId: aws.String(crId),
41+
})
42+
if err != nil {
43+
log.LogError("Delete capacity reservation failed with error: %s", err)
44+
}
45+
return output, err
46+
}

0 commit comments

Comments
 (0)