github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/nodes/results.go (about) 1 package nodes 2 3 import ( 4 "time" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 type nodeResult struct { 11 gophercloud.Result 12 } 13 14 // Extract interprets any nodeResult as a Node, if possible. 15 func (r nodeResult) Extract() (*Node, error) { 16 var s Node 17 err := r.ExtractInto(&s) 18 return &s, err 19 } 20 21 // Extract interprets a BootDeviceResult as BootDeviceOpts, if possible. 22 func (r BootDeviceResult) Extract() (*BootDeviceOpts, error) { 23 var s BootDeviceOpts 24 err := r.ExtractInto(&s) 25 return &s, err 26 } 27 28 // Extract interprets a SupportedBootDeviceResult as an array of supported boot devices, if possible. 29 func (r SupportedBootDeviceResult) Extract() ([]string, error) { 30 var s struct { 31 Devices []string `json:"supported_boot_devices"` 32 } 33 34 err := r.ExtractInto(&s) 35 return s.Devices, err 36 } 37 38 // Extract interprets a ValidateResult as NodeValidation, if possible. 39 func (r ValidateResult) Extract() (*NodeValidation, error) { 40 var s NodeValidation 41 err := r.ExtractInto(&s) 42 return &s, err 43 } 44 45 func (r nodeResult) ExtractInto(v interface{}) error { 46 return r.Result.ExtractIntoStructPtr(v, "") 47 } 48 49 func ExtractNodesInto(r pagination.Page, v interface{}) error { 50 return r.(NodePage).Result.ExtractIntoSlicePtr(v, "nodes") 51 } 52 53 // Extract interprets a BIOSSettingsResult as an array of BIOSSetting structs, if possible. 54 func (r ListBIOSSettingsResult) Extract() ([]BIOSSetting, error) { 55 var s struct { 56 Settings []BIOSSetting `json:"bios"` 57 } 58 59 err := r.ExtractInto(&s) 60 return s.Settings, err 61 } 62 63 // Extract interprets a SingleBIOSSettingResult as a BIOSSetting struct, if possible. 64 func (r GetBIOSSettingResult) Extract() (*BIOSSetting, error) { 65 var s SingleBIOSSetting 66 err := r.ExtractInto(&s) 67 return &s.Setting, err 68 } 69 70 // Extract interprets a VendorPassthruMethod as 71 func (r VendorPassthruMethodsResult) Extract() (*VendorPassthruMethods, error) { 72 var s VendorPassthruMethods 73 err := r.ExtractInto(&s) 74 return &s, err 75 } 76 77 func (r GetAllSubscriptionsVendorPassthruResult) Extract() (*GetAllSubscriptionsVendorPassthru, error) { 78 var s GetAllSubscriptionsVendorPassthru 79 err := r.ExtractInto(&s) 80 return &s, err 81 } 82 83 func (r SubscriptionVendorPassthruResult) Extract() (*SubscriptionVendorPassthru, error) { 84 var s SubscriptionVendorPassthru 85 err := r.ExtractInto(&s) 86 return &s, err 87 } 88 89 // Node represents a node in the OpenStack Bare Metal API. 90 type Node struct { 91 // Whether automated cleaning is enabled or disabled on this node. 92 // Requires microversion 1.47 or later. 93 AutomatedClean *bool `json:"automated_clean"` 94 95 // UUID for the resource. 96 UUID string `json:"uuid"` 97 98 // Identifier for the Node resource. May be undefined. Certain words are reserved. 99 Name string `json:"name"` 100 101 // Current power state of this Node. Usually, “power on” or “power off”, but may be “None” 102 // if Ironic is unable to determine the power state (eg, due to hardware failure). 103 PowerState string `json:"power_state"` 104 105 // A power state transition has been requested, this field represents the requested (ie, “target”) 106 // state either “power on”, “power off”, “rebooting”, “soft power off” or “soft rebooting”. 107 TargetPowerState string `json:"target_power_state"` 108 109 // Current provisioning state of this Node. 110 ProvisionState string `json:"provision_state"` 111 112 // A provisioning action has been requested, this field represents the requested (ie, “target”) state. Note 113 // that a Node may go through several states during its transition to this target state. For instance, when 114 // requesting an instance be deployed to an AVAILABLE Node, the Node may go through the following state 115 // change progression: AVAILABLE -> DEPLOYING -> DEPLOYWAIT -> DEPLOYING -> ACTIVE 116 TargetProvisionState string `json:"target_provision_state"` 117 118 // Whether or not this Node is currently in “maintenance mode”. Setting a Node into maintenance mode removes it 119 // from the available resource pool and halts some internal automation. This can happen manually (eg, via an API 120 // request) or automatically when Ironic detects a hardware fault that prevents communication with the machine. 121 Maintenance bool `json:"maintenance"` 122 123 // Description of the reason why this Node was placed into maintenance mode 124 MaintenanceReason string `json:"maintenance_reason"` 125 126 // Fault indicates the active fault detected by ironic, typically the Node is in “maintenance mode”. None means no 127 // fault has been detected by ironic. “power failure” indicates ironic failed to retrieve power state from this 128 // node. There are other possible types, e.g., “clean failure” and “rescue abort failure”. 129 Fault string `json:"fault"` 130 131 // Error from the most recent (last) transaction that started but failed to finish. 132 LastError string `json:"last_error"` 133 134 // Name of an Ironic Conductor host which is holding a lock on this node, if a lock is held. Usually “null”, 135 // but this field can be useful for debugging. 136 Reservation string `json:"reservation"` 137 138 // Name of the driver. 139 Driver string `json:"driver"` 140 141 // The metadata required by the driver to manage this Node. List of fields varies between drivers, and can be 142 // retrieved from the /v1/drivers/<DRIVER_NAME>/properties resource. 143 DriverInfo map[string]interface{} `json:"driver_info"` 144 145 // Metadata set and stored by the Node’s driver. This field is read-only. 146 DriverInternalInfo map[string]interface{} `json:"driver_internal_info"` 147 148 // Characteristics of this Node. Populated by ironic-inspector during inspection. May be edited via the REST 149 // API at any time. 150 Properties map[string]interface{} `json:"properties"` 151 152 // Used to customize the deployed image. May include root partition size, a base 64 encoded config drive, and other 153 // metadata. Note that this field is erased automatically when the instance is deleted (this is done by requesting 154 // the Node provision state be changed to DELETED). 155 InstanceInfo map[string]interface{} `json:"instance_info"` 156 157 // ID of the Nova instance associated with this Node. 158 InstanceUUID string `json:"instance_uuid"` 159 160 // ID of the chassis associated with this Node. May be empty or None. 161 ChassisUUID string `json:"chassis_uuid"` 162 163 // Set of one or more arbitrary metadata key and value pairs. 164 Extra map[string]interface{} `json:"extra"` 165 166 // Whether console access is enabled or disabled on this node. 167 ConsoleEnabled bool `json:"console_enabled"` 168 169 // The current RAID configuration of the node. Introduced with the cleaning feature. 170 RAIDConfig map[string]interface{} `json:"raid_config"` 171 172 // The requested RAID configuration of the node, which will be applied when the Node next transitions 173 // through the CLEANING state. Introduced with the cleaning feature. 174 TargetRAIDConfig map[string]interface{} `json:"target_raid_config"` 175 176 // Current clean step. Introduced with the cleaning feature. 177 CleanStep map[string]interface{} `json:"clean_step"` 178 179 // Current deploy step. 180 DeployStep map[string]interface{} `json:"deploy_step"` 181 182 // String which can be used by external schedulers to identify this Node as a unit of a specific type of resource. 183 // For more details, see: https://docs.openstack.org/ironic/latest/install/configure-nova-flavors.html 184 ResourceClass string `json:"resource_class"` 185 186 // BIOS interface for a Node, e.g. “redfish”. 187 BIOSInterface string `json:"bios_interface"` 188 189 // Boot interface for a Node, e.g. “pxe”. 190 BootInterface string `json:"boot_interface"` 191 192 // Console interface for a node, e.g. “no-console”. 193 ConsoleInterface string `json:"console_interface"` 194 195 // Deploy interface for a node, e.g. “iscsi”. 196 DeployInterface string `json:"deploy_interface"` 197 198 // Interface used for node inspection, e.g. “no-inspect”. 199 InspectInterface string `json:"inspect_interface"` 200 201 // For out-of-band node management, e.g. “ipmitool”. 202 ManagementInterface string `json:"management_interface"` 203 204 // Network Interface provider to use when plumbing the network connections for this Node. 205 NetworkInterface string `json:"network_interface"` 206 207 // used for performing power actions on the node, e.g. “ipmitool”. 208 PowerInterface string `json:"power_interface"` 209 210 // Used for configuring RAID on this node, e.g. “no-raid”. 211 RAIDInterface string `json:"raid_interface"` 212 213 // Interface used for node rescue, e.g. “no-rescue”. 214 RescueInterface string `json:"rescue_interface"` 215 216 // Used for attaching and detaching volumes on this node, e.g. “cinder”. 217 StorageInterface string `json:"storage_interface"` 218 219 // Array of traits for this node. 220 Traits []string `json:"traits"` 221 222 // For vendor-specific functionality on this node, e.g. “no-vendor”. 223 VendorInterface string `json:"vendor_interface"` 224 225 // Conductor group for a node. Case-insensitive string up to 255 characters, containing a-z, 0-9, _, -, and .. 226 ConductorGroup string `json:"conductor_group"` 227 228 // The node is protected from undeploying, rebuilding and deletion. 229 Protected bool `json:"protected"` 230 231 // Reason the node is marked as protected. 232 ProtectedReason string `json:"protected_reason"` 233 234 // A string or UUID of the tenant who owns the baremetal node. 235 Owner string `json:"owner"` 236 237 // Static network configuration to use during deployment and cleaning. 238 NetworkData map[string]interface{} `json:"network_data"` 239 240 // The UTC date and time when the resource was created, ISO 8601 format. 241 CreatedAt time.Time `json:"created_at"` 242 243 // The UTC date and time when the resource was updated, ISO 8601 format. May be “null”. 244 UpdatedAt time.Time `json:"updated_at"` 245 246 // The UTC date and time when the provision state was updated, ISO 8601 format. May be “null”. 247 ProvisionUpdatedAt time.Time `json:"provision_updated_at"` 248 249 // The UTC date and time when the last inspection was started, ISO 8601 format. May be “null” if inspection hasn't been started yet. 250 InspectionStartedAt *time.Time `json:"inspection_started_at"` 251 252 // The UTC date and time when the last inspection was finished, ISO 8601 format. May be “null” if inspection hasn't been finished yet. 253 InspectionFinishedAt *time.Time `json:"inspection_finished_at"` 254 } 255 256 // NodePage abstracts the raw results of making a List() request against 257 // the API. As OpenStack extensions may freely alter the response bodies of 258 // structures returned to the client, you may only safely access the data 259 // provided through the ExtractNodes call. 260 type NodePage struct { 261 pagination.LinkedPageBase 262 } 263 264 // IsEmpty returns true if a page contains no Node results. 265 func (r NodePage) IsEmpty() (bool, error) { 266 if r.StatusCode == 204 { 267 return true, nil 268 } 269 270 s, err := ExtractNodes(r) 271 return len(s) == 0, err 272 } 273 274 // NextPageURL uses the response's embedded link reference to navigate to the 275 // next page of results. 276 func (r NodePage) NextPageURL() (string, error) { 277 var s struct { 278 Links []gophercloud.Link `json:"nodes_links"` 279 } 280 err := r.ExtractInto(&s) 281 if err != nil { 282 return "", err 283 } 284 return gophercloud.ExtractNextURL(s.Links) 285 } 286 287 // ExtractNodes interprets the results of a single page from a List() call, 288 // producing a slice of Node entities. 289 func ExtractNodes(r pagination.Page) ([]Node, error) { 290 var s []Node 291 err := ExtractNodesInto(r, &s) 292 return s, err 293 } 294 295 // GetResult is the response from a Get operation. Call its Extract 296 // method to interpret it as a Node. 297 type GetResult struct { 298 nodeResult 299 } 300 301 // CreateResult is the response from a Create operation. 302 type CreateResult struct { 303 nodeResult 304 } 305 306 // UpdateResult is the response from an Update operation. Call its Extract 307 // method to interpret it as a Node. 308 type UpdateResult struct { 309 nodeResult 310 } 311 312 // DeleteResult is the response from a Delete operation. Call its ExtractErr 313 // method to determine if the call succeeded or failed. 314 type DeleteResult struct { 315 gophercloud.ErrResult 316 } 317 318 // ValidateResult is the response from a Validate operation. Call its Extract 319 // method to interpret it as a NodeValidation struct. 320 type ValidateResult struct { 321 gophercloud.Result 322 } 323 324 // InjectNMIResult is the response from an InjectNMI operation. Call its ExtractErr 325 // method to determine if the call succeeded or failed. 326 type InjectNMIResult struct { 327 gophercloud.ErrResult 328 } 329 330 // BootDeviceResult is the response from a GetBootDevice operation. Call its Extract 331 // method to interpret it as a BootDeviceOpts struct. 332 type BootDeviceResult struct { 333 gophercloud.Result 334 } 335 336 // SetBootDeviceResult is the response from a SetBootDevice operation. Call its Extract 337 // method to interpret it as a BootDeviceOpts struct. 338 type SetBootDeviceResult struct { 339 gophercloud.ErrResult 340 } 341 342 // SupportedBootDeviceResult is the response from a GetSupportedBootDevices operation. Call its Extract 343 // method to interpret it as an array of supported boot device values. 344 type SupportedBootDeviceResult struct { 345 gophercloud.Result 346 } 347 348 // ChangePowerStateResult is the response from a ChangePowerState operation. Call its ExtractErr 349 // method to determine if the call succeeded or failed. 350 type ChangePowerStateResult struct { 351 gophercloud.ErrResult 352 } 353 354 // ListBIOSSettingsResult is the response from a ListBIOSSettings operation. Call its Extract 355 // method to interpret it as an array of BIOSSetting structs. 356 type ListBIOSSettingsResult struct { 357 gophercloud.Result 358 } 359 360 // GetBIOSSettingResult is the response from a GetBIOSSetting operation. Call its Extract 361 // method to interpret it as a BIOSSetting struct. 362 type GetBIOSSettingResult struct { 363 gophercloud.Result 364 } 365 366 // VendorPassthruMethodsResult is the response from a GetVendorPassthruMethods operation. Call its Extract 367 // method to interpret it as an array of allowed vendor methods. 368 type VendorPassthruMethodsResult struct { 369 gophercloud.Result 370 } 371 372 // GetAllSubscriptionsVendorPassthruResult is the response from GetAllSubscriptions operation. Call its 373 // Extract method to interpret it as a GetAllSubscriptionsVendorPassthru struct. 374 type GetAllSubscriptionsVendorPassthruResult struct { 375 gophercloud.Result 376 } 377 378 // SubscriptionVendorPassthruResult is the response from GetSubscription and CreateSubscription operation. Call its Extract 379 // method to interpret it as a SubscriptionVendorPassthru struct. 380 type SubscriptionVendorPassthruResult struct { 381 gophercloud.Result 382 } 383 384 // DeleteSubscriptionVendorPassthruResult is the response from DeleteSubscription operation. Call its 385 // ExtractErr method to determine if the call succeeded of failed. 386 type DeleteSubscriptionVendorPassthruResult struct { 387 gophercloud.ErrResult 388 } 389 390 // Each element in the response will contain a “result” variable, which will have a value of “true” or “false”, and 391 // also potentially a reason. A value of nil indicates that the Node’s driver does not support that interface. 392 type DriverValidation struct { 393 Result bool `json:"result"` 394 Reason string `json:"reason"` 395 } 396 397 // Ironic validates whether the Node’s driver has enough information to manage the Node. This polls each interface on 398 // the driver, and returns the status of that interface as an DriverValidation struct. 399 type NodeValidation struct { 400 BIOS DriverValidation `json:"bios"` 401 Boot DriverValidation `json:"boot"` 402 Console DriverValidation `json:"console"` 403 Deploy DriverValidation `json:"deploy"` 404 Inspect DriverValidation `json:"inspect"` 405 Management DriverValidation `json:"management"` 406 Network DriverValidation `json:"network"` 407 Power DriverValidation `json:"power"` 408 RAID DriverValidation `json:"raid"` 409 Rescue DriverValidation `json:"rescue"` 410 Storage DriverValidation `json:"storage"` 411 } 412 413 // A particular BIOS setting for a node in the OpenStack Bare Metal API. 414 type BIOSSetting struct { 415 416 // Identifier for the BIOS setting. 417 Name string `json:"name"` 418 419 // Value of the BIOS setting. 420 Value string `json:"value"` 421 422 // The following fields are returned in microversion 1.74 or later 423 // when using the `details` option 424 425 // The type of setting - Enumeration, String, Integer, or Boolean. 426 AttributeType string `json:"attribute_type"` 427 428 // The allowable value for an Enumeration type setting. 429 AllowableValues []string `json:"allowable_values"` 430 431 // The lowest value for an Integer type setting. 432 LowerBound *int `json:"lower_bound"` 433 434 // The highest value for an Integer type setting. 435 UpperBound *int `json:"upper_bound"` 436 437 // Minimum length for a String type setting. 438 MinLength *int `json:"min_length"` 439 440 // Maximum length for a String type setting. 441 MaxLength *int `json:"max_length"` 442 443 // Whether or not this setting is read only. 444 ReadOnly *bool `json:"read_only"` 445 446 // Whether or not a reset is required after changing this setting. 447 ResetRequired *bool `json:"reset_required"` 448 449 // Whether or not this setting's value is unique to this node, e.g. 450 // a serial number. 451 Unique *bool `json:"unique"` 452 } 453 454 type SingleBIOSSetting struct { 455 Setting BIOSSetting 456 } 457 458 // ChangeStateResult is the response from any state change operation. Call its ExtractErr 459 // method to determine if the call succeeded or failed. 460 type ChangeStateResult struct { 461 gophercloud.ErrResult 462 } 463 464 type VendorPassthruMethods struct { 465 CreateSubscription CreateSubscriptionMethod `json:"create_subscription,omitempty"` 466 DeleteSubscription DeleteSubscriptionMethod `json:"delete_subscription,omitempty"` 467 GetSubscription GetSubscriptionMethod `json:"get_subscription,omitempty"` 468 GetAllSubscriptions GetAllSubscriptionsMethod `json:"get_all_subscriptions,omitempty"` 469 } 470 471 // Below you can find all vendor passthru methods structs 472 473 type CreateSubscriptionMethod struct { 474 HTTPMethods []string `json:"http_methods"` 475 Async bool `json:"async"` 476 Description string `json:"description"` 477 Attach bool `json:"attach"` 478 RequireExclusiveLock bool `json:"require_exclusive_lock"` 479 } 480 481 type DeleteSubscriptionMethod struct { 482 HTTPMethods []string `json:"http_methods"` 483 Async bool `json:"async"` 484 Description string `json:"description"` 485 Attach bool `json:"attach"` 486 RequireExclusiveLock bool `json:"require_exclusive_lock"` 487 } 488 489 type GetSubscriptionMethod struct { 490 HTTPMethods []string `json:"http_methods"` 491 Async bool `json:"async"` 492 Description string `json:"description"` 493 Attach bool `json:"attach"` 494 RequireExclusiveLock bool `json:"require_exclusive_lock"` 495 } 496 497 type GetAllSubscriptionsMethod struct { 498 HTTPMethods []string `json:"http_methods"` 499 Async bool `json:"async"` 500 Description string `json:"description"` 501 Attach bool `json:"attach"` 502 RequireExclusiveLock bool `json:"require_exclusive_lock"` 503 } 504 505 // A List of subscriptions from a node in the OpenStack Bare Metal API. 506 type GetAllSubscriptionsVendorPassthru struct { 507 Context string `json:"@odata.context"` 508 Etag string `json:"@odata.etag"` 509 Id string `json:"@odata.id"` 510 Type string `json:"@odata.type"` 511 Description string `json:"Description"` 512 Name string `json:"Name"` 513 Members []map[string]string `json:"Members"` 514 MembersCount int `json:"Members@odata.count"` 515 } 516 517 // A Subscription from a node in the OpenStack Bare Metal API. 518 type SubscriptionVendorPassthru struct { 519 Id string `json:"Id"` 520 Context string `json:"Context"` 521 Destination string `json:"Destination"` 522 EventTypes []string `json:"EventTypes"` 523 Protocol string `json:"Protocol"` 524 } 525 526 // SetMaintenanceResult is the response from a SetMaintenance operation. Call its ExtractErr 527 // method to determine if the call succeeded or failed. 528 type SetMaintenanceResult struct { 529 gophercloud.ErrResult 530 }