This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
results.go
131 lines (98 loc) · 3.31 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
package flavor
import (
"github.com/gophercloud/gophercloud/pagination"
"github.com/gophercloud/gophercloud"
)
type Flavor struct {
// Specifies the ID of ECS specifications.
ID string `json:"id"`
// Specifies the name of the ECS specifications.
Name string `json:"name"`
// Specifies the number of CPU cores in the ECS specifications.
Vcpus string `json:"vcpus"`
// Specifies the memory size (MB) in the ECS specifications.
Ram int64 `json:"ram"`
// Specifies the system disk size in the ECS specifications.
// The value 0 indicates that the disk size is not limited.
Disk string `json:"disk"`
// Specifies shortcut links for ECS flavors.
Links []Link `json:"links"`
// Specifies extended ECS specifications.
OsExtraSpecs OsExtraSpecs `json:"os_extra_specs"`
// Reserved
Swap string `json:"swap"`
// Reserved
FlvEphemeral int64 `json:"OS-FLV-EXT-DATA:ephemeral"`
// Reserved
FlvDisabled bool `json:"OS-FLV-DISABLED:disabled"`
// Reserved
RxtxFactor int64 `json:"rxtx_factor"`
// Reserved
RxtxQuota string `json:"rxtx_quota"`
// Reserved
RxtxCap string `json:"rxtx_cap"`
// Reserved
AccessIsPublic bool `json:"os-flavor-access:is_public"`
}
type Link struct {
// Specifies the shortcut link marker name.
Rel string `json:"rel"`
// Provides the corresponding shortcut link.
Href string `json:"href"`
// Specifies the shortcut link type.
Type string `json:"type"`
}
type OsExtraSpecs struct {
// Specifies the ECS specifications types
PerformanceType string `json:"ecs:performancetype"`
// Specifies the resource type.
ResourceType string `json:"resource_type"`
// Specifies the generation of an ECS type
Generation string `json:"ecs:generation"`
// Specifies a virtualization type
VirtualizationEnvTypes string `json:"ecs:virtualization_env_types"`
// Indicates whether the GPU is passthrough.
PciPassthroughEnableGpu string `json:"pci_passthrough:enable_gpu"`
// Indicates the technology used on the G1 and G2 ECSs,
// including GPU virtualization and GPU passthrough.
PciPassthroughGpuSpecs string `json:"pci_passthrough:gpu_specs"`
// Indicates the model and quantity of passthrough-enabled GPUs on P1 ECSs.
PciPassthroughAlias string `json:"pci_passthrough:alias"`
}
// FlavorsPage is the page returned by a pager when traversing over a
// collection of flavor.
type FlavorsPage struct {
pagination.LinkedPageBase
}
// IsEmpty checks whether a FlavorsPage struct is empty.
func (r FlavorsPage) IsEmpty() (bool, error) {
is, err := ExtractFlavors(r)
return len(is) == 0, err
}
// ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct,
// and extracts the elements into a slice of flavor structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
var s struct {
Flavors []Flavor `json:"flavors"`
}
err := (r.(FlavorsPage)).ExtractInto(&s)
return s.Flavors, err
}
type Job struct {
Id string `json:"job_id"`
}
// ResizeResult represents the result of a create operation. Call its ExtractJob
// method to interpret it as a Job.
type ResizeResult struct {
flavorResult
}
type flavorResult struct {
gophercloud.Result
}
// ExtractJob is a function that accepts a result and extracts a Job.
func (r ResizeResult) ExtractJob() (Job, error) {
var j Job
err := r.ExtractInto(&j)
return j, err
}