Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 1 | package drivers |
| 2 | |
| 3 | import ( |
| 4 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
| 5 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
| 6 | ) |
| 7 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 8 | type driverResult struct { |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 9 | gophercloud.Result |
| 10 | } |
| 11 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 12 | // Extract interprets any driverResult as a Driver, if possible. |
| 13 | func (r driverResult) Extract() (*Driver, error) { |
| 14 | var s Driver |
| 15 | err := r.ExtractInto(&s) |
| 16 | return &s, err |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 17 | } |
| 18 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 19 | func (r driverResult) ExtractInto(v interface{}) error { |
| 20 | return r.Result.ExtractIntoStructPtr(v, "") |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 21 | } |
| 22 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 23 | func ExtractDriversInto(r pagination.Page, v interface{}) error { |
| 24 | return r.(DriverPage).Result.ExtractIntoSlicePtr(v, "drivers") |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 25 | } |
| 26 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 27 | // Driver represents a driver in the OpenStack Bare Metal API. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 28 | type Driver struct { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 29 | // 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 Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 129 | // DriverPage abstracts the raw results of making a ListDrivers() request |
| 130 | // against the API. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 131 | type DriverPage struct { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 132 | pagination.LinkedPageBase |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 135 | // IsEmpty returns true if a page contains no Driver results. |
| 136 | func (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 Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 143 | func (r DriverPage) NextPageURL() (string, error) { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 144 | var s struct { |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 145 | Links []gophercloud.Link `json:"drivers_links"` |
| 146 | } |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 147 | err := r.ExtractInto(&s) |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 148 | if err != nil { |
| 149 | return "", err |
| 150 | } |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 151 | return gophercloud.ExtractNextURL(s.Links) |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 154 | // ExtractDrivers interprets the results of a single page from ListDrivers() |
| 155 | // call, producing a slice of Driver entities. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 156 | func ExtractDrivers(r pagination.Page) ([]Driver, error) { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 157 | 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. |
| 164 | type GetDriverResult struct { |
| 165 | driverResult |
| 166 | } |
| 167 | |
| 168 | // DriverProperties represents driver properties in the OpenStack Bare Metal API. |
| 169 | type DriverProperties map[string]interface{} |
| 170 | |
| 171 | // Extract interprets any GetPropertiesResult as DriverProperties, if possible. |
| 172 | func (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. |
| 180 | type GetPropertiesResult struct { |
| 181 | gophercloud.Result |
| 182 | } |
| 183 | |
| 184 | // DiskProperties represents driver disk properties in the OpenStack Bare Metal API. |
| 185 | type DiskProperties map[string]interface{} |
| 186 | |
| 187 | // Extract interprets any GetDiskPropertiesResult as DiskProperties, if possible. |
| 188 | func (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. |
| 196 | type GetDiskPropertiesResult struct { |
| 197 | gophercloud.Result |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 198 | } |