5
5
6
6
7
7
def get_albs (session : boto3 .Session ):
8
- return list (filter (lambda lb : lb ['Type' ] == 'application' , session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ]))
8
+ return list (
9
+ filter (
10
+ lambda lb : lb ['Type' ] == 'application' ,
11
+ session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ],
12
+ )
13
+ )
9
14
10
15
11
16
def get_nlbs (session : boto3 .Session ):
12
- return list (filter (lambda lb : lb ['Type' ] == 'network' , session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ]))
17
+ return list (
18
+ filter (
19
+ lambda lb : lb ['Type' ] == 'network' ,
20
+ session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ],
21
+ )
22
+ )
13
23
14
24
15
25
class ClassicLoadBalancerCountCheck (QuotaCheck ):
@@ -21,7 +31,9 @@ class ClassicLoadBalancerCountCheck(QuotaCheck):
21
31
22
32
@property
23
33
def current (self ):
24
- return len (self .boto_session .client ('elb' ).describe_load_balancers ()['LoadBalancerDescriptions' ])
34
+ return len (
35
+ self .boto_session .client ('elb' ).describe_load_balancers ()['LoadBalancerDescriptions' ]
36
+ )
25
37
26
38
27
39
class ListenerPerClassicLoadBalancerCountCheck (InstanceQuotaCheck ):
@@ -33,14 +45,19 @@ class ListenerPerClassicLoadBalancerCountCheck(InstanceQuotaCheck):
33
45
34
46
@staticmethod
35
47
def get_all_identifiers (session : boto3 .Session ) -> typing .List [str ]:
36
- return [lb ['LoadBalancerName' ] for lb in session .client ('elb' ).describe_load_balancers ()['LoadBalancerDescriptions' ]]
48
+ return [
49
+ lb ['LoadBalancerName' ]
50
+ for lb in session .client ('elb' ).describe_load_balancers ()['LoadBalancerDescriptions' ]
51
+ ]
37
52
38
53
@property
39
54
def current (self ):
40
55
try :
41
- return len (self .boto_session .client ('elb' ).describe_load_balancers (
42
- LoadBalancerNames = [self .instance_id ]
43
- )['LoadBalancerDescriptions' ][0 ]['ListenerDescriptions' ])
56
+ return len (
57
+ self .boto_session .client ('elb' ).describe_load_balancers (
58
+ LoadBalancerNames = [self .instance_id ]
59
+ )['LoadBalancerDescriptions' ][0 ]['ListenerDescriptions' ]
60
+ )
44
61
except self .boto_session .client ('elb' ).exceptions .AccessPointNotFoundException as e :
45
62
raise InstanceWithIdentifierNotFound (self ) from e
46
63
@@ -54,7 +71,14 @@ class NetworkLoadBalancerCountCheck(QuotaCheck):
54
71
55
72
@property
56
73
def current (self ):
57
- return len (list (filter (lambda lb : lb ['Type' ] == 'network' , self .boto_session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ])))
74
+ return len (
75
+ list (
76
+ filter (
77
+ lambda lb : lb ['Type' ] == 'network' ,
78
+ self .boto_session .client ('elbv2' ).describe_load_balancers ()['LoadBalancers' ],
79
+ )
80
+ )
81
+ )
58
82
59
83
60
84
class ListenerPerNetworkLoadBalancerCountCheck (InstanceQuotaCheck ):
@@ -66,14 +90,16 @@ class ListenerPerNetworkLoadBalancerCountCheck(InstanceQuotaCheck):
66
90
67
91
@staticmethod
68
92
def get_all_identifiers (session : boto3 .Session ) -> typing .List [str ]:
69
- return [alb ['LoadBalancerArn' ]
70
- for alb in get_nlbs (session )]
93
+ return [alb ['LoadBalancerArn' ] for alb in get_nlbs (session )]
71
94
72
95
@property
73
96
def current (self ):
74
97
try :
75
- return len (self .boto_session .client ('elbv2' ).describe_listeners (
76
- LoadBalancerArn = self .instance_id )['Listeners' ])
98
+ return len (
99
+ self .boto_session .client ('elbv2' ).describe_listeners (
100
+ LoadBalancerArn = self .instance_id
101
+ )['Listeners' ]
102
+ )
77
103
except self .boto_session .client ('elbv2' ).exceptions .LoadBalancerNotFoundException as e :
78
104
raise InstanceWithIdentifierNotFound (self ) from e
79
105
@@ -99,14 +125,16 @@ class ListenerPerApplicationLoadBalancerCountCheck(InstanceQuotaCheck):
99
125
100
126
@staticmethod
101
127
def get_all_identifiers (session : boto3 .Session ) -> typing .List [str ]:
102
- return [alb ['LoadBalancerArn' ]
103
- for alb in get_albs (session )]
128
+ return [alb ['LoadBalancerArn' ] for alb in get_albs (session )]
104
129
105
130
@property
106
131
def current (self ) -> int :
107
132
try :
108
- return len (self .boto_session .client ('elbv2' ).describe_listeners (
109
- LoadBalancerArn = self .instance_id )['Listeners' ])
133
+ return len (
134
+ self .boto_session .client ('elbv2' ).describe_listeners (
135
+ LoadBalancerArn = self .instance_id
136
+ )['Listeners' ]
137
+ )
110
138
except self .boto_session .client ('elbv2' ).exceptions .LoadBalancerNotFoundException as e :
111
139
raise InstanceWithIdentifierNotFound (self ) from e
112
140
@@ -121,3 +149,26 @@ class TargetGroupCountCheck(QuotaCheck):
121
149
@property
122
150
def current (self ):
123
151
return len (self .boto_session .client ('elbv2' ).describe_target_groups ()['TargetGroups' ])
152
+
153
+
154
+ class TargetGroupsPerApplicationLoadBalancerCountCheck (InstanceQuotaCheck ):
155
+ key = "elb_target_groups_per_alb"
156
+ description = "Target groups per Application Load Balancer"
157
+ service_code = 'elasticloadbalancing'
158
+ quota_code = 'L-822D1B1B'
159
+ instance_id = 'Load Balancer ARN'
160
+
161
+ @staticmethod
162
+ def get_all_identifiers (session : boto3 .Session ) -> typing .List [str ]:
163
+ return [alb ['LoadBalancerArn' ] for alb in get_albs (session )]
164
+
165
+ @property
166
+ def current (self ) -> int :
167
+ try :
168
+ return len (
169
+ self .boto_session .client ('elbv2' ).describe_target_groups (
170
+ LoadBalancerArn = self .instance_id
171
+ )['TargetGroups' ]
172
+ )
173
+ except self .boto_session .client ('elbv2' ).exceptions .LoadBalancerNotFoundException as e :
174
+ raise InstanceWithIdentifierNotFound (self ) from e
0 commit comments