-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
191 lines (151 loc) · 4.86 KB
/
results.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
package volumeactions
import (
"encoding/json"
"time"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
)
// AttachResult contains the response body and error from an Attach request.
type AttachResult struct {
golangsdk.ErrResult
}
// BeginDetachingResult contains the response body and error from a BeginDetach
// request.
type BeginDetachingResult struct {
golangsdk.ErrResult
}
// DetachResult contains the response body and error from a Detach request.
type DetachResult struct {
golangsdk.ErrResult
}
// UploadImageResult contains the response body and error from an UploadImage
// request.
type UploadImageResult struct {
golangsdk.Result
}
// ReserveResult contains the response body and error from a Reserve request.
type ReserveResult struct {
golangsdk.ErrResult
}
// UnreserveResult contains the response body and error from an Unreserve
// request.
type UnreserveResult struct {
golangsdk.ErrResult
}
// TerminateConnectionResult contains the response body and error from a
// TerminateConnection request.
type TerminateConnectionResult struct {
golangsdk.ErrResult
}
// InitializeConnectionResult contains the response body and error from an
// InitializeConnection request.
type InitializeConnectionResult struct {
golangsdk.Result
}
// ExtendSizeResult contains the response body and error from an ExtendSize request.
type ExtendSizeResult struct {
golangsdk.ErrResult
}
// Extract will get the connection information out of the
// InitializeConnectionResult object.
//
// This will be a generic map[string]interface{} and the results will be
// dependent on the type of connection made.
func (r InitializeConnectionResult) Extract() (map[string]interface{}, error) {
var s struct {
ConnectionInfo map[string]interface{} `json:"connection_info"`
}
err := r.ExtractInto(&s)
return s.ConnectionInfo, err
}
// ImageVolumeType contains volume type information obtained from UploadImage
// action.
type ImageVolumeType struct {
// The ID of a volume type.
ID string `json:"id"`
// Human-readable display name for the volume type.
Name string `json:"name"`
// Human-readable description for the volume type.
Description string `json:"display_description"`
// Flag for public access.
IsPublic bool `json:"is_public"`
// Extra specifications for volume type.
ExtraSpecs map[string]interface{} `json:"extra_specs"`
// ID of quality of service specs.
QosSpecsID string `json:"qos_specs_id"`
// Flag for deletion status of volume type.
Deleted bool `json:"deleted"`
// The date when volume type was deleted.
DeletedAt time.Time `json:"-"`
// The date when volume type was created.
CreatedAt time.Time `json:"-"`
// The date when this volume was last updated.
UpdatedAt time.Time `json:"-"`
}
func (r *ImageVolumeType) UnmarshalJSON(b []byte) error {
type tmp ImageVolumeType
var s struct {
tmp
CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
DeletedAt golangsdk.JSONRFC3339MilliNoZ `json:"deleted_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = ImageVolumeType(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
r.DeletedAt = time.Time(s.DeletedAt)
return err
}
// VolumeImage contains information about volume uploaded to an image service.
type VolumeImage struct {
// The ID of a volume an image is created from.
VolumeID string `json:"id"`
// Container format, may be bare, ofv, ova, etc.
ContainerFormat string `json:"container_format"`
// Disk format, may be raw, qcow2, vhd, vdi, vmdk, etc.
DiskFormat string `json:"disk_format"`
// Human-readable description for the volume.
Description string `json:"display_description"`
// The ID of the created image.
ImageID string `json:"image_id"`
// Human-readable display name for the image.
ImageName string `json:"image_name"`
// Size of the volume in GB.
Size int `json:"size"`
// Current status of the volume.
Status string `json:"status"`
// The date when this volume was last updated.
UpdatedAt time.Time `json:"-"`
// Volume type object of used volume.
VolumeType ImageVolumeType `json:"volume_type"`
}
func (r *VolumeImage) UnmarshalJSON(b []byte) error {
type tmp VolumeImage
var s struct {
tmp
UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = VolumeImage(s.tmp)
r.UpdatedAt = time.Time(s.UpdatedAt)
return err
}
// Extract will get an object with info about the uploaded image out of the
// UploadImageResult object.
func (r UploadImageResult) Extract() (VolumeImage, error) {
var s struct {
VolumeImage VolumeImage `json:"os-volume_upload_image"`
}
err := r.ExtractInto(&s)
return s.VolumeImage, err
}
// ForceDeleteResult contains the response body and error from a ForceDelete request.
type ForceDeleteResult struct {
golangsdk.ErrResult
}