-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
173 lines (156 loc) · 5.69 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
package cloudimages
import (
"encoding/json"
"time"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/pagination"
)
// Image represents an image found in the IMS.
type Image struct {
// the URL for uploading and downloading the image file
File string `json:"file"`
// the image owner
Owner string `json:"owner"`
// the image id
ID string `json:"id"`
// the image URL
Self string `json:"self"`
// the image schema
Schema string `json:"schema"`
// the image status, the value can be [queued, saving, deleted, killed,active]
Status string `json:"status"`
// the image tags
Tags []string `json:"tags"`
// whether the image can be seen by others
Visibility string `json:"visibility"`
// the image name
Name string `json:"name"`
// whether the image has been deleted
Deleted bool `json:"deleted"`
// whether the image is protected
Protected bool `json:"protected"`
// the container type
ContainerFormat string `json:"container_format"`
// the minimum memory size (MB) required for running the image
MinRam int `json:"min_ram"`
// the disk format, the value can be [vhd, raw, zvhd, qcow2]
DiskFormat string `json:"disk_format"`
// the minimum disk space (GB) required for running the image
MinDisk int `json:"min_disk"`
// the environment where the image is used
VirtualEnvType string `json:"virtual_env_type"`
// *size, virtual_size and checksum parameter are unavailable currently*
Size int64 `json:"size"`
VirtualSize int `json:"virtual_size"`
Checksum string `json:"checksum"`
// created_at and updated_at are in UTC format
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt string `json:"deleted_at"`
// the OS architecture: 32 or 64
OsBit string `json:"__os_bit"`
OsVersion string `json:"__os_version"`
Description string `json:"__description"`
OsType string `json:"__os_type"`
Isregistered string `json:"__isregistered"`
Platform string `json:"__platform"`
ImageSourceType string `json:"__image_source_type"`
Imagetype string `json:"__imagetype"`
WholeImage string `json:"__whole_image"`
Originalimagename string `json:"__originalimagename"`
Productcode string `json:"__productcode"`
ImageSize string `json:"__image_size"`
DataOrigin string `json:"__data_origin"`
LazyLoading string `json:"__lazyloading"`
OsFeatureList string `json:"__os_feature_list"`
SupportKvm string `json:"__support_kvm"`
SupportXen string `json:"__support_xen"`
SupportLargeMemory string `json:"__support_largememory"`
SupportDiskintensive string `json:"__support_diskintensive"`
SupportHighperformance string `json:"__support_highperformance"`
SupportXenGpuType string `json:"__support_xen_gpu_type"`
SupportKvmGpuType string `json:"__support_kvm_gpu_type"`
SupportXenHana string `json:"__support_xen_hana"`
SupportKvmInfiniband string `json:"__support_kvm_infiniband"`
SystemSupportMarket bool `json:"__system_support_market"`
IsOffshelved string `json:"__is_offshelved"`
RootOrigin string `json:"__root_origin"`
SequenceNum string `json:"__sequence_num"`
SupportFcInject string `json:"__support_fc_inject"`
HwDiskBus string `q:"hw_disk_bus"`
HwFirmwareType string `json:"hw_firmware_type"`
HwVifMultiqueueEnabled string `json:"hw_vif_multiqueue_enabled"`
SupportArm string `json:"__support_arm"`
SupportAgentList string `json:"__support_agent_list"`
SystemCmkid string `json:"__system__cmkid"`
AccountCode string `json:"__account_code"`
SupportAmd string `json:"__support_amd"`
}
func (r *Image) UnmarshalJSON(b []byte) error {
type tmp Image
var s struct {
tmp
CreatedAt golangsdk.JSONRFC3339Milli `json:"created_at"`
UpdatedAt golangsdk.JSONRFC3339Milli `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = Image(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
return err
}
type commonResult struct {
golangsdk.Result
}
// UpdateResult represents the result of an Update operation. Call its Extract
// method to interpret it as an Image.
type UpdateResult struct {
commonResult
}
// Extract will get the Image object out of the commonResult object.
func (r commonResult) Extract() (*Image, error) {
var s Image
err := r.ExtractInto(&s)
return &s, err
}
// ExtractInto converts our response data into a volume struct
func (r commonResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "images")
}
// ImagePage represents the results of a List request.
type ImagePage struct {
serviceURL string
pagination.LinkedPageBase
}
// IsEmpty returns true if an ImagePage contains no Images results.
func (r ImagePage) IsEmpty() (bool, error) {
images, err := ExtractImages(r)
return len(images) == 0, err
}
// NextPageURL uses the response's embedded link reference to navigate to
// the next page of results.
func (r ImagePage) NextPageURL() (string, error) {
var s struct {
Next string `json:"next"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
if s.Next == "" {
return "", nil
}
return nextPageURL(r.serviceURL, s.Next)
}
// ExtractImages interprets the results of a single page from a List() call,
// producing a slice of Image entities.
func ExtractImages(r pagination.Page) ([]Image, error) {
var s struct {
Images []Image `json:"images"`
}
err := (r.(ImagePage)).ExtractInto(&s)
return s.Images, err
}