1from moto.core.exceptions import RESTError
2
3
4class ELBClientError(RESTError):
5    code = 400
6
7
8class DuplicateTagKeysError(ELBClientError):
9    def __init__(self, cidr):
10        super(DuplicateTagKeysError, self).__init__(
11            "DuplicateTagKeys", "Tag key was specified more than once: {0}".format(cidr)
12        )
13
14
15class LoadBalancerNotFoundError(ELBClientError):
16    def __init__(self):
17        super(LoadBalancerNotFoundError, self).__init__(
18            "LoadBalancerNotFound", "The specified load balancer does not exist."
19        )
20
21
22class ListenerNotFoundError(ELBClientError):
23    def __init__(self):
24        super(ListenerNotFoundError, self).__init__(
25            "ListenerNotFound", "The specified listener does not exist."
26        )
27
28
29class SubnetNotFoundError(ELBClientError):
30    def __init__(self):
31        super(SubnetNotFoundError, self).__init__(
32            "SubnetNotFound", "The specified subnet does not exist."
33        )
34
35
36class TargetGroupNotFoundError(ELBClientError):
37    def __init__(self):
38        super(TargetGroupNotFoundError, self).__init__(
39            "TargetGroupNotFound", "The specified target group does not exist."
40        )
41
42
43class TooManyTagsError(ELBClientError):
44    def __init__(self):
45        super(TooManyTagsError, self).__init__(
46            "TooManyTagsError",
47            "The quota for the number of tags that can be assigned to a load balancer has been reached",
48        )
49
50
51class BadHealthCheckDefinition(ELBClientError):
52    def __init__(self):
53        super(BadHealthCheckDefinition, self).__init__(
54            "ValidationError",
55            "HealthCheck Target must begin with one of HTTP, TCP, HTTPS, SSL",
56        )
57
58
59class DuplicateListenerError(ELBClientError):
60    def __init__(self):
61        super(DuplicateListenerError, self).__init__(
62            "DuplicateListener", "A listener with the specified port already exists."
63        )
64
65
66class DuplicateLoadBalancerName(ELBClientError):
67    def __init__(self):
68        super(DuplicateLoadBalancerName, self).__init__(
69            "DuplicateLoadBalancerName",
70            "A load balancer with the specified name already exists.",
71        )
72
73
74class DuplicateTargetGroupName(ELBClientError):
75    def __init__(self):
76        super(DuplicateTargetGroupName, self).__init__(
77            "DuplicateTargetGroupName",
78            "A target group with the specified name already exists.",
79        )
80
81
82class InvalidTargetError(ELBClientError):
83    def __init__(self):
84        super(InvalidTargetError, self).__init__(
85            "InvalidTarget",
86            "The specified target does not exist or is not in the same VPC as the target group.",
87        )
88
89
90class EmptyListenersError(ELBClientError):
91    def __init__(self):
92        super(EmptyListenersError, self).__init__(
93            "ValidationError", "Listeners cannot be empty"
94        )
95
96
97class PriorityInUseError(ELBClientError):
98    def __init__(self):
99        super(PriorityInUseError, self).__init__(
100            "PriorityInUse", "The specified priority is in use."
101        )
102
103
104class InvalidConditionFieldError(ELBClientError):
105    VALID_FIELDS = [
106        "path-pattern",
107        "host-header",
108        "http-header",
109        "http-request-method",
110        "query-string",
111        "source-ip",
112    ]
113
114    def __init__(self, invalid_name):
115        super(InvalidConditionFieldError, self).__init__(
116            "ValidationError",
117            "Condition field '%s' must be one of '[%s]'"
118            % (invalid_name, ",".join(self.VALID_FIELDS)),
119        )
120
121
122class InvalidConditionValueError(ELBClientError):
123    def __init__(self, msg):
124        super(InvalidConditionValueError, self).__init__("ValidationError", msg)
125
126
127class InvalidActionTypeError(ELBClientError):
128    def __init__(self, invalid_name, index):
129        super(InvalidActionTypeError, self).__init__(
130            "ValidationError",
131            "1 validation error detected: Value '%s' at 'actions.%s.member.type' failed to satisfy constraint: Member must satisfy enum value set: [forward, redirect, fixed-response]"
132            % (invalid_name, index),
133        )
134
135
136class ActionTargetGroupNotFoundError(ELBClientError):
137    def __init__(self, arn):
138        super(ActionTargetGroupNotFoundError, self).__init__(
139            "TargetGroupNotFound", "Target group '%s' not found" % arn
140        )
141
142
143class ListenerOrBalancerMissingError(ELBClientError):
144    def __init__(self, arn):
145        super(ListenerOrBalancerMissingError, self).__init__(
146            "ValidationError",
147            "You must specify either listener ARNs or a load balancer ARN",
148        )
149
150
151class InvalidDescribeRulesRequest(ELBClientError):
152    def __init__(self, msg):
153        super(InvalidDescribeRulesRequest, self).__init__("ValidationError", msg)
154
155
156class ResourceInUseError(ELBClientError):
157    def __init__(self, msg="A specified resource is in use"):
158        super(ResourceInUseError, self).__init__("ResourceInUse", msg)
159
160
161class RuleNotFoundError(ELBClientError):
162    def __init__(self):
163        super(RuleNotFoundError, self).__init__(
164            "RuleNotFound", "The specified rule does not exist."
165        )
166
167
168class DuplicatePriorityError(ELBClientError):
169    def __init__(self, invalid_value):
170        super(DuplicatePriorityError, self).__init__(
171            "ValidationError",
172            "Priority '%s' was provided multiple times" % invalid_value,
173        )
174
175
176class InvalidTargetGroupNameError(ELBClientError):
177    def __init__(self, msg):
178        super(InvalidTargetGroupNameError, self).__init__("ValidationError", msg)
179
180
181class InvalidModifyRuleArgumentsError(ELBClientError):
182    def __init__(self):
183        super(InvalidModifyRuleArgumentsError, self).__init__(
184            "ValidationError", "Either conditions or actions must be specified"
185        )
186
187
188class InvalidStatusCodeActionTypeError(ELBClientError):
189    def __init__(self, msg):
190        super(InvalidStatusCodeActionTypeError, self).__init__("ValidationError", msg)
191
192
193class InvalidLoadBalancerActionException(ELBClientError):
194    def __init__(self, msg):
195        super(InvalidLoadBalancerActionException, self).__init__(
196            "InvalidLoadBalancerAction", msg
197        )
198