-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflavors.go
144 lines (119 loc) · 4.1 KB
/
flavors.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
package edgecloud
import (
"context"
"net/http"
)
const (
flavorsBasePathV1 = "/v1/flavors"
bmflavorsBasePathV1 = "/v1/bmflavors"
)
// FlavorsService is an interface for creating and managing Flavors with the EdgecenterCloud API.
// See: https://apidocs.edgecenter.ru/cloud#tag/flavors
type FlavorsService interface {
List(context.Context, *FlavorListOptions) ([]Flavor, *Response, error)
ListBaremetal(context.Context, *FlavorListOptions) ([]Flavor, *Response, error)
ListBaremetalForClient(context.Context, *FlavorListOptions) ([]Flavor, *Response, error)
}
// FlavorsServiceOp handles communication with Flavors methods of the EdgecenterCloud API.
type FlavorsServiceOp struct {
client *Client
}
var _ FlavorsService = &FlavorsServiceOp{}
// Flavor represents an EdgecenterCloud Flavor.
type Flavor struct {
FlavorID string `json:"flavor_id"`
FlavorName string `json:"flavor_name"`
VCPUS int `json:"vcpus"`
RAM int `json:"ram"`
HardwareDescription HardwareDescription `json:"hardware_description,omitempty"`
Disabled bool `json:"disabled"`
ResourceClass string `json:"resource_class"`
}
type HardwareDescription struct {
CPU string `json:"cpu"`
RAM string `json:"ram"`
Disk string `json:"disk"`
Network string `json:"network"`
GPU string `json:"gpu"`
IPU string `json:"ipu,omitempty"`
PoplarCount string `json:"poplar_count,omitempty"`
SgxEPCSize string `json:"sgx_epc_size"`
}
// FlavorListOptions specifies the optional query parameters to List method.
type FlavorListOptions struct {
IncludePrices bool `url:"include_prices,omitempty" validate:"omitempty"`
Disabled bool `url:"disabled,omitempty" validate:"omitempty"`
ExcludeWindows bool `url:"exclude_windows,omitempty" validate:"omitempty"`
}
// FlavorsOptions specifies the optional query parameters to Get loadbalancer or instance flavor method.
type FlavorsOptions struct {
IncludePrices bool `url:"include_prices,omitempty" validate:"omitempty"`
}
// flavorsRoot represents a Flavors root.
type flavorsRoot struct {
Count int
Flavors []Flavor `json:"results"`
}
// List get flavors.
func (s *FlavorsServiceOp) List(ctx context.Context, opts *FlavorListOptions) ([]Flavor, *Response, error) {
if resp, err := s.client.Validate(); err != nil {
return nil, resp, err
}
path := s.client.addProjectRegionPath(flavorsBasePathV1)
path, err := addOptions(path, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(flavorsRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Flavors, resp, err
}
// ListBaremetal get baremetal flavors.
func (s *FlavorsServiceOp) ListBaremetal(ctx context.Context, opts *FlavorListOptions) ([]Flavor, *Response, error) {
if resp, err := s.client.Validate(); err != nil {
return nil, resp, err
}
path := s.client.addProjectRegionPath(bmflavorsBasePathV1)
path, err := addOptions(path, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(flavorsRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Flavors, resp, err
}
// ListBaremetalForClient get baremetal flavors from default project for current client.
func (s *FlavorsServiceOp) ListBaremetalForClient(ctx context.Context, opts *FlavorListOptions) ([]Flavor, *Response, error) {
if resp, err := s.client.Validate(); err != nil {
return nil, resp, err
}
path := s.client.addRegionPath(bmflavorsBasePathV1)
path, err := addOptions(path, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(flavorsRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Flavors, resp, err
}