Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 package testservices | |
2 | |
3 import "fmt" | |
4 | |
5 var nameReference = map[int]string{ | |
axw
2014/04/30 21:40:00
Where do these values come from? I assume these ar
| |
6 400: "badRequest", | |
7 401: "unauthorized", | |
8 403: "forbidden", | |
9 404: "itemNotFound", | |
10 405: "badMethod", | |
11 409: "conflictingRequest", | |
12 413: "overLimit", | |
13 415: "badMediaType", | |
14 429: "overLimit", | |
15 501: "notImplemented", | |
16 503: "serviceUnavailable", | |
17 } | |
18 | |
19 type ServerError struct { | |
axw
2014/04/30 21:40:00
Does it perhaps make sense to expose more of goose
| |
20 message string | |
21 code int | |
22 } | |
23 | |
24 func (n *ServerError) Error() string { | |
25 return fmt.Sprintf("%s: %s", n.Name(), n.message) | |
26 } | |
27 | |
28 func (n *ServerError) Name() string { | |
29 name, ok := nameReference[n.code] | |
30 if !ok { | |
31 return "computeFault" | |
32 } | |
33 return name | |
34 } | |
35 | |
36 func NewNotFoundError(message string) *ServerError { | |
37 return &ServerError{ | |
38 message: message, | |
39 code: 404, | |
40 } | |
41 } | |
42 | |
43 func NewNoMoreFloatingIpsError() *ServerError { | |
44 return &ServerError{ | |
45 message: "Zero floating ips available", | |
46 code: 404, | |
47 } | |
48 } | |
49 | |
50 func NewIPLimitExceededError() *ServerError { | |
51 return &ServerError{ | |
52 message: "Maximum number of floating ips exceeded", | |
53 code: 413, | |
54 } | |
55 } | |
56 | |
57 func NewRateLimitExceededError() *ServerError { | |
58 return &ServerError{ | |
59 message: "Retry limit exceeded", | |
60 // XXX: hduran-8 I infered this from the python nova code, might be wrong | |
axw
2014/04/30 21:40:00
XXX is not typical to Juju or related projects. Us
| |
61 code: 413, | |
62 } | |
63 } | |
64 | |
65 func NewAddFlavorError(id string) *ServerError { | |
66 return &ServerError{ | |
axw
2014/04/30 21:40:00
I would suggest a minor refactoring to simplify al
| |
67 message: fmt.Sprintf("A flavor with id %q already exists", id), | |
axw
2014/04/30 21:40:00
Do these error messages come from OpenStack, or di
| |
68 code: 409, | |
69 } | |
70 } | |
71 | |
72 func NewNoSuchFlavorError(id string) *ServerError { | |
73 return &ServerError{ | |
74 message: fmt.Sprintf("No such flavor %q", id), | |
75 code: 404, | |
76 } | |
77 } | |
78 | |
79 func NewServerByIDNotFoundError(id string) *ServerError { | |
80 return &ServerError{ | |
81 message: fmt.Sprintf("No such server %q", id), | |
82 code: 404, | |
83 } | |
84 } | |
85 | |
86 func NewServerByNameNotFoundError(name string) *ServerError { | |
87 return &ServerError{ | |
88 message: fmt.Sprintf("No such server named %q", name), | |
89 code: 404, | |
90 } | |
91 } | |
92 | |
93 func NewServerAlreadyExistsError(id string) *ServerError { | |
94 return &ServerError{ | |
95 message: fmt.Sprintf("A server with id %q already exists", id), | |
96 code: 409, | |
97 } | |
98 } | |
99 | |
100 func NewSecurityGroupAlreadyExistsError(id string) *ServerError { | |
101 return &ServerError{ | |
102 message: fmt.Sprintf("A security group with id %s already exists ", id), | |
103 code: 409, | |
104 } | |
105 } | |
106 | |
107 func NewSecurityGroupByIDNotFoundError(groupId string) *ServerError { | |
108 return &ServerError{ | |
109 message: fmt.Sprintf("No such security group %s", groupId), | |
110 code: 404, | |
111 } | |
112 } | |
113 | |
114 func NewSecurityGroupByNameNotFoundError(name string) *ServerError { | |
115 return &ServerError{ | |
116 message: fmt.Sprintf("No such security group named %q", name), | |
117 code: 404, | |
118 } | |
119 } | |
120 | |
121 func NewSecurityGroupRuleAlreadyExistsError(id string) *ServerError { | |
122 return &ServerError{ | |
123 message: fmt.Sprintf("A security group rule with id %s already e xists", id), | |
124 code: 409, | |
125 } | |
126 } | |
127 | |
128 func NewCannotAddTwiceRuleToGroupError(ruleId, groupId string) *ServerError { | |
129 return &ServerError{ | |
130 message: fmt.Sprintf("Cannot add twice rule %s to security group %s", ruleId, groupId), | |
131 code: 409, | |
132 } | |
133 } | |
134 | |
135 func NewUnknownSecurityGroupError(groupId string) *ServerError { | |
136 return &ServerError{ | |
137 message: fmt.Sprintf("Unknown source security group %s", groupId ), | |
138 code: 409, | |
139 } | |
140 } | |
141 | |
142 func NewSecurityGroupRuleNotFoundError(ruleId string) *ServerError { | |
143 return &ServerError{ | |
144 message: fmt.Sprintf("No such security group rule %s", ruleId), | |
145 code: 404, | |
146 } | |
147 } | |
148 | |
149 func NewServerBelongsToGroupError(serverId, groupId string) *ServerError { | |
150 return &ServerError{ | |
151 message: fmt.Sprintf("Server %q already belongs to group %s", se rverId, groupId), | |
152 code: 409, | |
153 } | |
154 } | |
155 | |
156 func NewServerDoesNotBelongToGroupsError(serverId string) *ServerError { | |
157 return &ServerError{ | |
158 message: fmt.Sprintf("Server %q does not belong to any groups", serverId), | |
159 code: 400, | |
160 } | |
161 } | |
162 | |
163 func NewServerDoesNotBelongToGroupError(serverId, groupId string) *ServerError { | |
164 return &ServerError{ | |
165 message: fmt.Sprintf("Server %q does not belong to group %s", se rverId, groupId), | |
166 code: 400, | |
167 } | |
168 } | |
169 | |
170 func NewFloatingIPExistsError(ipID string) *ServerError { | |
171 return &ServerError{ | |
172 message: fmt.Sprintf("A floating IP with id %s already exists", ipID), | |
173 code: 409, | |
174 } | |
175 } | |
176 | |
177 func NewFloatingIPNotFoundError(address string) *ServerError { | |
178 return &ServerError{ | |
179 message: fmt.Sprintf("No such floating IP %q", address), | |
180 code: 404, | |
181 } | |
182 } | |
183 | |
184 func NewServerHasFloatingIPError(serverId, ipId string) *ServerError { | |
185 return &ServerError{ | |
186 message: fmt.Sprintf("Server %q already has floating IP %s", ser verId, ipId), | |
187 code: 409, | |
188 } | |
189 } | |
190 | |
191 func NewNoFloatingIPsToRemoveError(serverId string) *ServerError { | |
192 return &ServerError{ | |
193 message: fmt.Sprintf("Server %q does not have any floating IPs t o remove", serverId), | |
194 code: 409, | |
195 } | |
196 } | |
197 | |
198 func NewNoFloatingIPsError(serverId, ipId string) *ServerError { | |
199 return &ServerError{ | |
200 message: fmt.Sprintf("Server %q does not have floating IP %s", s erverId, ipId), | |
201 code: 404, | |
202 } | |
203 } | |
OLD | NEW |