forked from Juniper/contrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
77 lines (68 loc) · 2.98 KB
/
errors.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package logic
import (
"encoding/json"
"fmt"
)
type errorType string
// ErrorFields neutron error fields.
type errorFields map[string]interface{}
// Error structure.
type Error struct {
fields errorFields
}
func (e *Error) Error() string {
bytes, err := json.Marshal(e)
if err != nil {
return fmt.Sprintf("failed to marshall error description: %v", err)
}
return string(bytes)
}
// MarshalJSON custom marshalling code.
func (e *Error) MarshalJSON() ([]byte, error) {
return json.Marshal(e.fields)
}
func newNeutronError(name errorType, fields errorFields) *Error {
e := &Error{
fields: fields,
}
if fields == nil {
e.fields = errorFields{}
}
e.fields["exception"] = name
return e
}
func isNeutronError(err error) bool {
_, ok := err.(*Error)
return ok
}
// constants for Neutron API exception names
// https://docs.openstack.org/neutron-lib/queens/reference/modules/neutron_lib.exceptions.html
const (
internalServerError errorType = "InternalServerError"
badRequest errorType = "BadRequest"
overQuota errorType = "OverQuota"
portNotFound errorType = "PortNotFound"
l3PortInUse errorType = "L3PortInUse"
macAddressInUse errorType = "MacAddressInUse"
ipAddressGenerationFailure errorType = "IpAddressGenerationFailure"
ipAddressInUse errorType = "ipAddressInUse"
networkNotFound errorType = "NetworkNotFound"
routerNotFound errorType = "RouterNotFound"
routerInUse errorType = "RouterInUse"
subnetNotFound errorType = "SubnetNotFound"
subnetMismatchForPort errorType = "SubnetMismatchForPort"
securityGroupNotFound errorType = "SecurityGroupNotFound"
securityGroupAlreadyExists errorType = "SecurityGroupAlreadyExists"
securityGroupRemoteGroupAndRemoteIPPrefix errorType = "SecurityGroupRemoteGroupAndRemoteIpPrefix"
securityGroupCannotRemoveDefault errorType = "SecurityGroupCannotRemoveDefault"
securityGroupInUse errorType = "SecurityGroupInUse"
securityGroupRuleParameterConflict errorType = "SecurityGroupRuleParameterConflict"
securityGroupRuleInvalidProtocol errorType = "SecurityGroupRuleInvalidProtocol"
securityGroupRuleExists errorType = "SecurityGroupRuleExists"
securityGroupRuleNotFound errorType = "SecurityGroupRuleNotFound"
networkInUse errorType = "NetworkInUse"
invalidSharedSetting errorType = "InvalidSharedSetting"
routerInterfaceNotFound errorType = "RouterInterfaceNotFound"
routerInterfaceNotFoundForSubnet errorType = "RouterInterfaceNotFoundForSubnet"
floatingIPNotFound errorType = "FloatingIPNotFound"
)