Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 1 | package nodes |
| 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 nodeResult 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 nodeResult as a Node, if possible. |
| 13 | func (r nodeResult) Extract() (*Node, error) { |
| 14 | var s Node |
| 15 | err := r.ExtractInto(&s) |
| 16 | return &s, err |
| 17 | } |
| 18 | |
| 19 | // Extract interprets a BootDeviceResult as BootDeviceOpts, if possible. |
| 20 | func (r BootDeviceResult) Extract() (*BootDeviceOpts, error) { |
| 21 | var s BootDeviceOpts |
| 22 | err := r.ExtractInto(&s) |
| 23 | return &s, err |
| 24 | } |
| 25 | |
| 26 | // Extract interprets a SupportedBootDeviceResult as an array of supported boot devices, if possible. |
| 27 | func (r SupportedBootDeviceResult) Extract() ([]string, error) { |
| 28 | var s struct { |
| 29 | Devices []string `json:"supported_boot_devices"` |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 30 | } |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 31 | |
| 32 | err := r.ExtractInto(&s) |
| 33 | return s.Devices, err |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 36 | // Extract interprets a ValidateResult as NodeValidation, if possible. |
| 37 | func (r ValidateResult) Extract() (*NodeValidation, error) { |
| 38 | var s NodeValidation |
| 39 | err := r.ExtractInto(&s) |
| 40 | return &s, err |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 43 | func (r nodeResult) ExtractInto(v interface{}) error { |
| 44 | return r.Result.ExtractIntoStructPtr(v, "") |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 47 | func ExtractNodesInto(r pagination.Page, v interface{}) error { |
| 48 | return r.(NodePage).Result.ExtractIntoSlicePtr(v, "nodes") |
| 49 | } |
| 50 | |
| 51 | // Node represents a node in the OpenStack Bare Metal API. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 52 | type Node struct { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 53 | // UUID for the resource. |
| 54 | UUID string `json:"uuid"` |
| 55 | |
| 56 | // Identifier for the Node resource. May be undefined. Certain words are reserved. |
| 57 | Name string `json:"name"` |
| 58 | |
| 59 | // Current power state of this Node. Usually, “power on” or “power off”, but may be “None” |
| 60 | // if Ironic is unable to determine the power state (eg, due to hardware failure). |
| 61 | PowerState string `json:"power_state"` |
| 62 | |
| 63 | // A power state transition has been requested, this field represents the requested (ie, “target”) |
| 64 | // state either “power on”, “power off”, “rebooting”, “soft power off” or “soft rebooting”. |
| 65 | TargetPowerState string `json:"target_power_state"` |
| 66 | |
| 67 | // Current provisioning state of this Node. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 68 | ProvisionState string `json:"provision_state"` |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 69 | |
| 70 | // A provisioning action has been requested, this field represents the requested (ie, “target”) state. Note |
| 71 | // that a Node may go through several states during its transition to this target state. For instance, when |
| 72 | // requesting an instance be deployed to an AVAILABLE Node, the Node may go through the following state |
| 73 | // change progression: AVAILABLE -> DEPLOYING -> DEPLOYWAIT -> DEPLOYING -> ACTIVE |
| 74 | TargetProvisionState string `json:"target_provision_state"` |
| 75 | |
| 76 | // Whether or not this Node is currently in “maintenance mode”. Setting a Node into maintenance mode removes it |
| 77 | // from the available resource pool and halts some internal automation. This can happen manually (eg, via an API |
| 78 | // request) or automatically when Ironic detects a hardware fault that prevents communication with the machine. |
| 79 | Maintenance bool `json:"maintenance"` |
| 80 | |
| 81 | // Description of the reason why this Node was placed into maintenance mode |
| 82 | MaintenanceReason string `json:"maintenance_reason"` |
| 83 | |
| 84 | // Fault indicates the active fault detected by ironic, typically the Node is in “maintenance mode”. None means no |
| 85 | // fault has been detected by ironic. “power failure” indicates ironic failed to retrieve power state from this |
| 86 | // node. There are other possible types, e.g., “clean failure” and “rescue abort failure”. |
| 87 | Fault string `json:"fault"` |
| 88 | |
| 89 | // Error from the most recent (last) transaction that started but failed to finish. |
| 90 | LastError string `json:"last_error"` |
| 91 | |
| 92 | // Name of an Ironic Conductor host which is holding a lock on this node, if a lock is held. Usually “null”, |
| 93 | // but this field can be useful for debugging. |
| 94 | Reservation string `json:"reservation"` |
| 95 | |
| 96 | // Name of the driver. |
| 97 | Driver string `json:"driver"` |
| 98 | |
| 99 | // The metadata required by the driver to manage this Node. List of fields varies between drivers, and can be |
| 100 | // retrieved from the /v1/drivers/<DRIVER_NAME>/properties resource. |
| 101 | DriverInfo map[string]interface{} `json:"driver_info"` |
| 102 | |
| 103 | // Metadata set and stored by the Node’s driver. This field is read-only. |
| 104 | DriverInternalInfo map[string]interface{} `json:"driver_internal_info"` |
| 105 | |
| 106 | // Characteristics of this Node. Populated by ironic-inspector during inspection. May be edited via the REST |
| 107 | // API at any time. |
| 108 | Properties map[string]interface{} `json:"properties"` |
| 109 | |
| 110 | // Used to customize the deployed image. May include root partition size, a base 64 encoded config drive, and other |
| 111 | // metadata. Note that this field is erased automatically when the instance is deleted (this is done by requesting |
| 112 | // the Node provision state be changed to DELETED). |
| 113 | InstanceInfo map[string]interface{} `json:"instance_info"` |
| 114 | |
| 115 | // ID of the Nova instance associated with this Node. |
| 116 | InstanceUUID string `json:"instance_uuid"` |
| 117 | |
| 118 | // ID of the chassis associated with this Node. May be empty or None. |
| 119 | ChassisUUID string `json:"chassis_uuid"` |
| 120 | |
| 121 | // Set of one or more arbitrary metadata key and value pairs. |
| 122 | Extra map[string]interface{} `json:"extra"` |
| 123 | |
| 124 | // Whether console access is enabled or disabled on this node. |
| 125 | ConsoleEnabled bool `json:"console_enabled"` |
| 126 | |
| 127 | // The current RAID configuration of the node. Introduced with the cleaning feature. |
| 128 | RAIDConfig map[string]interface{} `json:"raid_config"` |
| 129 | |
| 130 | // The requested RAID configuration of the node, which will be applied when the Node next transitions |
| 131 | // through the CLEANING state. Introduced with the cleaning feature. |
| 132 | TargetRAIDConfig map[string]interface{} `json:"target_raid_config"` |
| 133 | |
| 134 | // Current clean step. Introduced with the cleaning feature. |
| 135 | CleanStep map[string]interface{} `json:"clean_step"` |
| 136 | |
| 137 | // Current deploy step. |
| 138 | DeployStep map[string]interface{} `json:"deploy_step"` |
| 139 | |
| 140 | // String which can be used by external schedulers to identify this Node as a unit of a specific type of resource. |
| 141 | // For more details, see: https://docs.openstack.org/ironic/latest/install/configure-nova-flavors.html |
| 142 | ResourceClass string `json:"resource_class"` |
| 143 | |
| 144 | // Boot interface for a Node, e.g. “pxe”. |
| 145 | BootInterface string `json:"boot_interface"` |
| 146 | |
| 147 | // Console interface for a node, e.g. “no-console”. |
| 148 | ConsoleInterface string `json:"console_interface"` |
| 149 | |
| 150 | // Deploy interface for a node, e.g. “iscsi”. |
| 151 | DeployInterface string `json:"deploy_interface"` |
| 152 | |
| 153 | // Interface used for node inspection, e.g. “no-inspect”. |
| 154 | InspectInterface string `json:"inspect_interface"` |
| 155 | |
| 156 | // For out-of-band node management, e.g. “ipmitool”. |
| 157 | ManagementInterface string `json:"management_interface"` |
| 158 | |
| 159 | // Network Interface provider to use when plumbing the network connections for this Node. |
| 160 | NetworkInterface string `json:"network_interface"` |
| 161 | |
| 162 | // used for performing power actions on the node, e.g. “ipmitool”. |
| 163 | PowerInterface string `json:"power_interface"` |
| 164 | |
| 165 | // Used for configuring RAID on this node, e.g. “no-raid”. |
| 166 | RAIDInterface string `json:"raid_interface"` |
| 167 | |
| 168 | // Interface used for node rescue, e.g. “no-rescue”. |
| 169 | RescueInterface string `json:"rescue_interface"` |
| 170 | |
| 171 | // Used for attaching and detaching volumes on this node, e.g. “cinder”. |
| 172 | StorageInterface string `json:"storage_interface"` |
| 173 | |
| 174 | // Array of traits for this node. |
| 175 | Traits []string `json:"traits"` |
| 176 | |
| 177 | // For vendor-specific functionality on this node, e.g. “no-vendor”. |
| 178 | VendorInterface string `json:"vendor_interface"` |
| 179 | |
| 180 | // Conductor group for a node. Case-insensitive string up to 255 characters, containing a-z, 0-9, _, -, and .. |
| 181 | ConductorGroup string `json:"conductor_group"` |
| 182 | |
| 183 | // The node is protected from undeploying, rebuilding and deletion. |
| 184 | Protected bool `json:"protected"` |
| 185 | |
| 186 | // Reason the node is marked as protected. |
| 187 | ProtectedReason string `json:"protected_reason"` |
| 188 | |
| 189 | // A string or UUID of the tenant who owns the baremetal node. |
| 190 | Owner string `json:"owner"` |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 193 | // NodePage abstracts the raw results of making a List() request against |
| 194 | // the API. As OpenStack extensions may freely alter the response bodies of |
| 195 | // structures returned to the client, you may only safely access the data |
| 196 | // provided through the ExtractNodes call. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 197 | type NodePage struct { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 198 | pagination.LinkedPageBase |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 201 | // IsEmpty returns true if a page contains no Node results. |
| 202 | func (r NodePage) IsEmpty() (bool, error) { |
| 203 | s, err := ExtractNodes(r) |
| 204 | return len(s) == 0, err |
| 205 | } |
| 206 | |
| 207 | // NextPageURL uses the response's embedded link reference to navigate to the |
| 208 | // next page of results. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 209 | func (r NodePage) NextPageURL() (string, error) { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 210 | var s struct { |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 211 | Links []gophercloud.Link `json:"nodes_links"` |
| 212 | } |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 213 | err := r.ExtractInto(&s) |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 214 | if err != nil { |
| 215 | return "", err |
| 216 | } |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 217 | return gophercloud.ExtractNextURL(s.Links) |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 220 | // ExtractNodes interprets the results of a single page from a List() call, |
| 221 | // producing a slice of Node entities. |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 222 | func ExtractNodes(r pagination.Page) ([]Node, error) { |
Michal Kobus | f611358 | 2019-09-09 15:58:21 +0200 | [diff] [blame] | 223 | var s []Node |
| 224 | err := ExtractNodesInto(r, &s) |
| 225 | return s, err |
| 226 | } |
| 227 | |
| 228 | // GetResult is the response from a Get operation. Call its Extract |
| 229 | // method to interpret it as a Node. |
| 230 | type GetResult struct { |
| 231 | nodeResult |
| 232 | } |
| 233 | |
| 234 | // CreateResult is the response from a Create operation. |
| 235 | type CreateResult struct { |
| 236 | nodeResult |
| 237 | } |
| 238 | |
| 239 | // UpdateResult is the response from an Update operation. Call its Extract |
| 240 | // method to interpret it as a Node. |
| 241 | type UpdateResult struct { |
| 242 | nodeResult |
| 243 | } |
| 244 | |
| 245 | // DeleteResult is the response from a Delete operation. Call its ExtractErr |
| 246 | // method to determine if the call succeeded or failed. |
| 247 | type DeleteResult struct { |
| 248 | gophercloud.ErrResult |
| 249 | } |
| 250 | |
| 251 | // ValidateResult is the response from a Validate operation. Call its Extract |
| 252 | // method to interpret it as a NodeValidation struct. |
| 253 | type ValidateResult struct { |
| 254 | gophercloud.Result |
| 255 | } |
| 256 | |
| 257 | // InjectNMIResult is the response from an InjectNMI operation. Call its ExtractErr |
| 258 | // method to determine if the call succeeded or failed. |
| 259 | type InjectNMIResult struct { |
| 260 | gophercloud.ErrResult |
| 261 | } |
| 262 | |
| 263 | // BootDeviceResult is the response from a GetBootDevice operation. Call its Extract |
| 264 | // method to interpret it as a BootDeviceOpts struct. |
| 265 | type BootDeviceResult struct { |
| 266 | gophercloud.Result |
| 267 | } |
| 268 | |
| 269 | // BootDeviceResult is the response from a GetBootDevice operation. Call its Extract |
| 270 | // method to interpret it as a BootDeviceOpts struct. |
| 271 | type SetBootDeviceResult struct { |
| 272 | gophercloud.ErrResult |
| 273 | } |
| 274 | |
| 275 | // SupportedBootDeviceResult is the response from a GetSupportedBootDevices operation. Call its Extract |
| 276 | // method to interpret it as an array of supported boot device values. |
| 277 | type SupportedBootDeviceResult struct { |
| 278 | gophercloud.Result |
| 279 | } |
| 280 | |
| 281 | // ChangePowerStateResult is the response from a ChangePowerState operation. Call its ExtractErr |
| 282 | // method to determine if the call succeeded or failed. |
| 283 | type ChangePowerStateResult struct { |
| 284 | gophercloud.ErrResult |
| 285 | } |
| 286 | |
| 287 | // Each element in the response will contain a “result” variable, which will have a value of “true” or “false”, and |
| 288 | // also potentially a reason. A value of nil indicates that the Node’s driver does not support that interface. |
| 289 | type DriverValidation struct { |
| 290 | Result bool `json:"result"` |
| 291 | Reason string `json:"reason"` |
| 292 | } |
| 293 | |
| 294 | // Ironic validates whether the Node’s driver has enough information to manage the Node. This polls each interface on |
| 295 | // the driver, and returns the status of that interface as an DriverValidation struct. |
| 296 | type NodeValidation struct { |
| 297 | Boot DriverValidation `json:"boot"` |
| 298 | Console DriverValidation `json:"console"` |
| 299 | Deploy DriverValidation `json:"deploy"` |
| 300 | Inspect DriverValidation `json:"inspect"` |
| 301 | Management DriverValidation `json:"management"` |
| 302 | Network DriverValidation `json:"network"` |
| 303 | Power DriverValidation `json:"power"` |
| 304 | RAID DriverValidation `json:"raid"` |
| 305 | Rescue DriverValidation `json:"rescue"` |
| 306 | Storage DriverValidation `json:"storage"` |
| 307 | } |
| 308 | |
| 309 | // ChangeStateResult is the response from any state change operation. Call its ExtractErr |
| 310 | // method to determine if the call succeeded or failed. |
| 311 | type ChangeStateResult struct { |
| 312 | gophercloud.ErrResult |
Michal Kobus | a1c3ca9 | 2019-08-21 14:29:23 +0200 | [diff] [blame] | 313 | } |