-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgopowerstore_types.go
195 lines (161 loc) · 6.28 KB
/
gopowerstore_types.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
*
* Copyright © 2020-2024 Dell Inc. or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package gopowerstore
import (
"net/http"
"strings"
"github.com/dell/gopowerstore/api"
)
// RequestConfig represents options for request
type RequestConfig api.RequestConfig
// RenderRequestConfig returns internal struct with request config
func (rc RequestConfig) RenderRequestConfig() api.RequestConfig {
return api.RequestConfig(rc)
}
// CreateResponse create response
type CreateResponse struct {
// Unique identifier of the new instance created.
ID string `json:"id,omitempty"`
}
// EmptyResponse is response without content
type EmptyResponse string
// APIError represents API error
type APIError struct {
*api.ErrorMsg
}
// NewAPIError returns pointer to new APIError
func NewAPIError() *APIError {
return &APIError{&api.ErrorMsg{}}
}
// WrapErr converts internal error type to public
func WrapErr(err error) error {
errorMsg, ok := err.(*api.ErrorMsg)
if ok {
err = APIError{errorMsg}
}
return err
}
// NotFound returns true if API error indicate that volume is not exists
func (err *APIError) NotFound() bool {
return err.StatusCode == http.StatusNotFound
}
// VolumeNameIsAlreadyUse returns true if API error indicate that volume name is already in use
func (err *APIError) VolumeNameIsAlreadyUse() bool {
return err.StatusCode == http.StatusUnprocessableEntity || err.StatusCode == http.StatusInternalServerError
}
// SnapshotNameIsAlreadyUse returns true if API error indicate that snapshot name is already in use
func (err *APIError) SnapshotNameIsAlreadyUse() bool {
return err.StatusCode == http.StatusBadRequest
}
// FSNameIsAlreadyUse returns true if API error indicate that fs name is already in use
func (err *APIError) FSNameIsAlreadyUse() bool {
return err.StatusCode == http.StatusUnprocessableEntity
}
// HostIsNotAttachedToVolume returns true if API error indicate that host is not attached to volume
func (err *APIError) HostIsNotAttachedToVolume() bool {
return err.StatusCode == http.StatusBadRequest
}
// VolumeIsNotAttachedToHost returns true if API error indicate that volume is not attached to host
func (err *APIError) VolumeIsNotAttachedToHost() bool {
return err.StatusCode == http.StatusBadRequest
}
// HostIsNotExist returns true if API error indicate that host is not exists
func (err *APIError) HostIsNotExist() bool {
return err.StatusCode == http.StatusNotFound || err.StatusCode == http.StatusBadRequest
}
// BadRange returns true if API error indicate that request was submitted with invalid range
func (err *APIError) BadRange() bool {
return err.StatusCode == http.StatusRequestedRangeNotSatisfiable
}
// VolumeAttachedToHost returns true if API error indicate that operation can't be complete because
// volume is attached to host
func (err *APIError) VolumeAttachedToHost() bool {
return err.StatusCode == http.StatusUnprocessableEntity
}
// VolumeDetachedFromHost returns true if API error indicate that volume is detached from host
func (err *APIError) VolumeDetachedFromHost() bool {
return err.StatusCode == http.StatusUnprocessableEntity
}
// HostAlreadyRemovedFromNFSExport returns true if API error indicate that operation can't be complete because
// host ip already removed from nfs export access
func (err *APIError) HostAlreadyRemovedFromNFSExport() bool {
return err.StatusCode == http.StatusBadRequest
}
// HostAlreadyPresentInNFSExport returns true if API error indicate that operation can't be complete because
// host ip already present in nfs export access
func (err *APIError) HostAlreadyPresentInNFSExport() bool {
return err.StatusCode == http.StatusBadRequest
}
// UnableToFailoverFromDestination returns true if API error indicate that operation can't be complete because
// it is impossible to failover from Destination
func (err *APIError) UnableToFailoverFromDestination() bool {
return err.StatusCode == http.StatusBadRequest
}
// ReplicationSessionAlreadyCreated returns true if API error indicate that replication session has already been created
func (err *APIError) ReplicationSessionAlreadyCreated() bool {
return err.StatusCode == http.StatusBadRequest
}
// VolumeAlreadyRemovedFromVolumeGroup returns true if API error indicate that volume is not part of the volume group
func (err *APIError) VolumeAlreadyRemovedFromVolumeGroup() bool {
return err.StatusCode == http.StatusUnprocessableEntity && strings.Contains(err.Message, "not part")
}
// NewNotFoundError returns new VolumeIsNotExistError
func NewNotFoundError() APIError {
return notFoundError()
}
// NewHostIsNotExistError returns new HostIsNotExistError
func NewHostIsNotExistError() APIError {
return notFoundError()
}
// NewHostIsNotAttachedToVolume returns new HostIsNotAttachedToVolume error
func NewHostIsNotAttachedToVolume() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusBadRequest
return apiError
}
// NewVolumeAttachedToHostError returns new VolumeAttachedToHost error
func NewVolumeAttachedToHostError() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusUnprocessableEntity
return apiError
}
func notFoundError() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusNotFound
return apiError
}
func replicationRuleNotExists() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusNotFound
return apiError
}
func snapshotRuleNotExists() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusNotFound
return apiError
}
func protectionPolicyNotExists() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusNotFound
return apiError
}
func replicationGroupNotExists() APIError {
apiError := APIError{&api.ErrorMsg{}}
apiError.StatusCode = http.StatusNotFound
return apiError
}