blob: c453a0991f15ab0d1606ac175f804495c214f643 [file] [log] [blame]
Michal Kobusa1c3ca92019-08-21 14:29:23 +02001package drivers
2
3import (
4 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
5 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
6)
7
Michal Kobusf6113582019-09-09 15:58:21 +02008type driverResult struct {
Michal Kobusa1c3ca92019-08-21 14:29:23 +02009 gophercloud.Result
10}
11
Michal Kobusf6113582019-09-09 15:58:21 +020012// Extract interprets any driverResult as a Driver, if possible.
13func (r driverResult) Extract() (*Driver, error) {
14 var s Driver
15 err := r.ExtractInto(&s)
16 return &s, err
Michal Kobusa1c3ca92019-08-21 14:29:23 +020017}
18
Michal Kobusf6113582019-09-09 15:58:21 +020019func (r driverResult) ExtractInto(v interface{}) error {
20 return r.Result.ExtractIntoStructPtr(v, "")
Michal Kobusa1c3ca92019-08-21 14:29:23 +020021}
22
Michal Kobusf6113582019-09-09 15:58:21 +020023func ExtractDriversInto(r pagination.Page, v interface{}) error {
24 return r.(DriverPage).Result.ExtractIntoSlicePtr(v, "drivers")
Michal Kobusa1c3ca92019-08-21 14:29:23 +020025}
26
Michal Kobusf6113582019-09-09 15:58:21 +020027// Driver represents a driver in the OpenStack Bare Metal API.
Michal Kobusa1c3ca92019-08-21 14:29:23 +020028type Driver struct {
Michal Kobusf6113582019-09-09 15:58:21 +020029 // Name and Identifier of the driver
30 Name string `json:"name"`
31
32 // A list of active hosts that support this driver
33 Hosts []string `json:"hosts"`
34
35 // Type of this driver (“classic” or “dynamic”)
36 Type string `json:"type"`
37
38 // The default bios interface used for a node with a dynamic driver,
39 // if no bios interface is specified for the node.
40 DefaultBiosInterface string `json:"default_bios_interface"`
41
42 // The default boot interface used for a node with a dynamic driver,
43 // if no boot interface is specified for the node.
44 DefaultBootInterface string `json:"default_boot_interface"`
45
46 // The default console interface used for a node with a dynamic driver,
47 // if no console interface is specified for the node.
48 DefaultConsoleInterface string `json:"default_console_interface"`
49
50 // The default deploy interface used for a node with a dynamic driver,
51 // if no deploy interface is specified for the node.
52 DefaultDeployInterface string `json:"default_deploy_interface"`
53
54 // The default inspection interface used for a node with a dynamic driver,
55 // if no inspection interface is specified for the node.
56 DefaultInspectInterface string `json:"default_inspect_interface"`
57
58 // The default management interface used for a node with a dynamic driver,
59 // if no management interface is specified for the node.
60 DefaultManagementInterface string `json:"default_management_interface"`
61
62 // The default network interface used for a node with a dynamic driver,
63 // if no network interface is specified for the node.
64 DefaultNetworkInterface string `json:"default_network_interface"`
65
66 // The default power interface used for a node with a dynamic driver,
67 // if no power interface is specified for the node.
68 DefaultPowerInterface string `json:"default_power_interface"`
69
70 // The default RAID interface used for a node with a dynamic driver,
71 // if no RAID interface is specified for the node.
72 DefaultRaidInterface string `json:"default_raid_interface"`
73
74 // The default rescue interface used for a node with a dynamic driver,
75 // if no rescue interface is specified for the node.
76 DefaultRescueInterface string `json:"default_rescue_interface"`
77
78 // The default storage interface used for a node with a dynamic driver,
79 // if no storage interface is specified for the node.
80 DefaultStorageInterface string `json:"default_storage_interface"`
81
82 // The default vendor interface used for a node with a dynamic driver,
83 // if no vendor interface is specified for the node.
84 DefaultVendorInterface string `json:"default_vendor_interface"`
85
86 // The enabled bios interfaces for this driver.
87 EnabledBiosInterfaces []string `json:"enabled_bios_interfaces"`
88
89 // The enabled boot interfaces for this driver.
90 EnabledBootInterfaces []string `json:"enabled_boot_interfaces"`
91
92 // The enabled console interfaces for this driver.
93 EnabledConsoleInterface []string `json:"enabled_console_interfaces"`
94
95 // The enabled deploy interfaces for this driver.
96 EnabledDeployInterfaces []string `json:"enabled_deploy_interfaces"`
97
98 // The enabled inspection interfaces for this driver.
99 EnabledInspectInterfaces []string `json:"enabled_inspect_interfaces"`
100
101 // The enabled management interfaces for this driver.
102 EnabledManagementInterfaces []string `json:"enabled_management_interfaces"`
103
104 // The enabled network interfaces for this driver.
105 EnabledNetworkInterfaces []string `json:"enabled_network_interfaces"`
106
107 // The enabled power interfaces for this driver.
108 EnabledPowerInterfaces []string `json:"enabled_power_interfaces"`
109
110 // The enabled rescue interfaces for this driver.
111 EnabledRescueInterfaces []string `json:"enabled_rescue_interfaces"`
112
113 // The enabled RAID interfaces for this driver.
114 EnabledRaidInterfaces []string `json:"enabled_raid_interfaces"`
115
116 // The enabled storage interfaces for this driver.
117 EnabledStorageInterfaces []string `json:"enabled_storage_interfaces"`
118
119 // The enabled vendor interfaces for this driver.
120 EnabledVendorInterfaces []string `json:"enabled_vendor_interfaces"`
121
122 //A list of relative links. Includes the self and bookmark links.
123 Links []interface{} `json:"links"`
124
125 // A list of links to driver properties.
126 Properties []interface{} `json:"properties"`
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200127}
128
Michal Kobusf6113582019-09-09 15:58:21 +0200129// DriverPage abstracts the raw results of making a ListDrivers() request
130// against the API.
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200131type DriverPage struct {
Michal Kobusf6113582019-09-09 15:58:21 +0200132 pagination.LinkedPageBase
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200133}
134
Michal Kobusf6113582019-09-09 15:58:21 +0200135// IsEmpty returns true if a page contains no Driver results.
136func (r DriverPage) IsEmpty() (bool, error) {
137 s, err := ExtractDrivers(r)
138 return len(s) == 0, err
139}
140
141// NextPageURL uses the response's embedded link reference to navigate to the
142// next page of results.
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200143func (r DriverPage) NextPageURL() (string, error) {
Michal Kobusf6113582019-09-09 15:58:21 +0200144 var s struct {
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200145 Links []gophercloud.Link `json:"drivers_links"`
146 }
Michal Kobusf6113582019-09-09 15:58:21 +0200147 err := r.ExtractInto(&s)
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200148 if err != nil {
149 return "", err
150 }
Michal Kobusf6113582019-09-09 15:58:21 +0200151 return gophercloud.ExtractNextURL(s.Links)
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200152}
153
Michal Kobusf6113582019-09-09 15:58:21 +0200154// ExtractDrivers interprets the results of a single page from ListDrivers()
155// call, producing a slice of Driver entities.
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200156func ExtractDrivers(r pagination.Page) ([]Driver, error) {
Michal Kobusf6113582019-09-09 15:58:21 +0200157 var s []Driver
158 err := ExtractDriversInto(r, &s)
159 return s, err
160}
161
162// GetDriverResult is the response from a Get operation.
163// Call its Extract method to interpret it as a Driver.
164type GetDriverResult struct {
165 driverResult
166}
167
168// DriverProperties represents driver properties in the OpenStack Bare Metal API.
169type DriverProperties map[string]interface{}
170
171// Extract interprets any GetPropertiesResult as DriverProperties, if possible.
172func (r GetPropertiesResult) Extract() (*DriverProperties, error) {
173 var s DriverProperties
174 err := r.ExtractInto(&s)
175 return &s, err
176}
177
178// GetPropertiesResult is the response from a GetDriverProperties operation.
179// Call its Extract method to interpret it as DriverProperties.
180type GetPropertiesResult struct {
181 gophercloud.Result
182}
183
184// DiskProperties represents driver disk properties in the OpenStack Bare Metal API.
185type DiskProperties map[string]interface{}
186
187// Extract interprets any GetDiskPropertiesResult as DiskProperties, if possible.
188func (r GetDiskPropertiesResult) Extract() (*DiskProperties, error) {
189 var s DiskProperties
190 err := r.ExtractInto(&s)
191 return &s, err
192}
193
194// GetDiskPropertiesResult is the response from a GetDriverDiskProperties operation.
195// Call its Extract method to interpret it as DiskProperties.
196type GetDiskPropertiesResult struct {
197 gophercloud.Result
Michal Kobusa1c3ca92019-08-21 14:29:23 +0200198}