-
Notifications
You must be signed in to change notification settings - Fork 0
/
elasticache.go
40 lines (32 loc) · 1.24 KB
/
elasticache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package services
import (
"fmt"
"github.com/aws/aws-sdk-go/service/elasticache"
)
type ElastiCacheClientInterface interface {
DescribeCacheClustersPages(input *elasticache.DescribeCacheClustersInput, fn func(*elasticache.DescribeCacheClustersOutput, bool) bool) error
}
func NewElastiCacheChecker() Svcquota {
serviceCode := "elasticache"
supportedQuotas := map[string]func(ServiceChecker) (ret []AWSQuotaInfo){
"Nodes per Region": ServiceChecker.getElastiCacheNodesUsage,
}
requiredPermissions := []string{"elasticache:DescribeCacheClusters"}
return NewServiceChecker(serviceCode, supportedQuotas, requiredPermissions)
}
func (c ServiceChecker) getElastiCacheNodesUsage() (ret []AWSQuotaInfo) {
ret = []AWSQuotaInfo{}
nodeNames := []*elasticache.CacheCluster{}
err := conf.ElastiCache.DescribeCacheClustersPages(&elasticache.DescribeCacheClustersInput{}, func(p *elasticache.DescribeCacheClustersOutput, lastPage bool) bool {
nodeNames = append(nodeNames, p.CacheClusters...)
return true // continue paging
})
quotaInfo := c.GetAllAppliedQuotas()["Nodes per Region"]
if err != nil {
fmt.Printf("failed to retrieve elasticache nodes, %v", err)
return
}
quotaInfo.UsageValue = float64(len(nodeNames))
ret = append(ret, quotaInfo)
return
}