Sync baremetal openstack with upstream
Change-Id: I125fc08e2cc4433aeaa470de48823dd4434c2030
Related-PROD: PROD-33018
diff --git a/openstack/baremetal/v1/nodes/doc.go b/openstack/baremetal/v1/nodes/doc.go
new file mode 100644
index 0000000..37f60b5
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/doc.go
@@ -0,0 +1,130 @@
+/*
+Package nodes provides information and interaction with the nodes API
+resource in the OpenStack Bare Metal service.
+
+Example to List Nodes with Detail
+
+ nodes.ListDetail(client, nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ nodeList, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ for _, n := range nodeList {
+ // Do something
+ }
+
+ return true, nil
+ })
+
+Example to List Nodes
+
+ listOpts := nodes.ListOpts{
+ ProvisionState: nodes.Deploying,
+ Fields: []string{"name"},
+ }
+
+ nodes.List(client, listOpts).EachPage(func(page pagination.Page) (bool, error) {
+ nodeList, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ for _, n := range nodeList {
+ // Do something
+ }
+
+ return true, nil
+ })
+
+Example to Create Node
+
+ createOpts := nodes.CreateOpts
+ Driver: "ipmi",
+ BootInterface: "pxe",
+ Name: "coconuts",
+ DriverInfo: map[string]interface{}{
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin",
+ },
+ }
+
+ createNode, err := nodes.Create(client, createOpts).Extract()
+ if err != nil {
+ panic(err)
+ }
+
+Example to Get Node
+
+ showNode, err := nodes.Get(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").Extract()
+ if err != nil {
+ panic(err)
+ }
+
+Example to Update Node
+
+ updateOpts := nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Op: ReplaceOp,
+ Path: "/maintenance",
+ Value: "true",
+ },
+ }
+
+ updateNode, err := nodes.Update(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474", updateOpts).Extract()
+ if err != nil {
+ panic(err)
+ }
+
+Example to Delete Node
+
+ err = nodes.Delete(client, "c9afd385-5d89-4ecb-9e1c-68194da6b474").ExtractErr()
+ if err != nil {
+ panic(err)
+ }
+
+Example to Validate Node
+
+ validation, err := nodes.Validate(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
+ if err != nil {
+ panic(err)
+ }
+
+Example to inject non-masking interrupts
+
+ err := nodes.InjectNMI(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").ExtractErr()
+ if err != nil {
+ panic(err)
+ }
+
+Example to get array of supported boot devices for a node
+
+ bootDevices, err := nodes.GetSupportedBootDevices(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
+ if err != nil {
+ panic(err)
+ }
+
+Example to set boot device for a node
+
+ bootOpts := nodes.BootDeviceOpts{
+ BootDevice: "pxe",
+ Persistent: false,
+ }
+
+ err := nodes.SetBootDevice(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8", bootOpts).ExtractErr()
+ if err != nil {
+ panic(err)
+ }
+
+Example to get boot device for a node
+
+ bootDevice, err := nodes.GetBootDevice(client, "a62b8495-52e2-407b-b3cb-62775d04c2b8").Extract()
+ if err != nil {
+ panic(err)
+ }
+*/
+package nodes
diff --git a/openstack/baremetal/v1/nodes/requests.go b/openstack/baremetal/v1/nodes/requests.go
index 32264a0..d247bf9 100644
--- a/openstack/baremetal/v1/nodes/requests.go
+++ b/openstack/baremetal/v1/nodes/requests.go
@@ -1,12 +1,593 @@
package nodes
import (
+ "fmt"
+
"gerrit.mcp.mirantis.net/debian/gophercloud.git"
"gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
)
-func List(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, listURL(c), func(r pagination.PageResult) pagination.Page {
- return NodePage{pagination.SinglePageBase(r)}
+// ListOptsBuilder allows extensions to add additional parameters to the
+// List request.
+type ListOptsBuilder interface {
+ ToNodeListQuery() (string, error)
+ ToNodeListDetailQuery() (string, error)
+}
+
+// Provision state reports the current provision state of the node, these are only used in filtering
+type ProvisionState string
+
+const (
+ Enroll ProvisionState = "enroll"
+ Verifying ProvisionState = "verifying"
+ Manageable ProvisionState = "manageable"
+ Available ProvisionState = "available"
+ Active ProvisionState = "active"
+ DeployWait ProvisionState = "wait call-back"
+ Deploying ProvisionState = "deploying"
+ DeployFail ProvisionState = "deploy failed"
+ DeployDone ProvisionState = "deploy complete"
+ Deleting ProvisionState = "deleting"
+ Deleted ProvisionState = "deleted"
+ Cleaning ProvisionState = "cleaning"
+ CleanWait ProvisionState = "clean wait"
+ CleanFail ProvisionState = "clean failed"
+ Error ProvisionState = "error"
+ Rebuild ProvisionState = "rebuild"
+ Inspecting ProvisionState = "inspecting"
+ InspectFail ProvisionState = "inspect failed"
+ InspectWait ProvisionState = "inspect wait"
+ Adopting ProvisionState = "adopting"
+ AdoptFail ProvisionState = "adopt failed"
+ Rescue ProvisionState = "rescue"
+ RescueFail ProvisionState = "rescue failed"
+ Rescuing ProvisionState = "rescuing"
+ UnrescueFail ProvisionState = "unrescue failed"
+)
+
+// TargetProvisionState is used when setting the provision state for a node.
+type TargetProvisionState string
+
+const (
+ TargetActive TargetProvisionState = "active"
+ TargetDeleted TargetProvisionState = "deleted"
+ TargetManage TargetProvisionState = "manage"
+ TargetProvide TargetProvisionState = "provide"
+ TargetInspect TargetProvisionState = "inspect"
+ TargetAbort TargetProvisionState = "abort"
+ TargetClean TargetProvisionState = "clean"
+ TargetAdopt TargetProvisionState = "adopt"
+ TargetRescue TargetProvisionState = "rescue"
+ TargetUnrescue TargetProvisionState = "unrescue"
+)
+
+// ListOpts allows the filtering and sorting of paginated collections through
+// the API. Filtering is achieved by passing in struct field values that map to
+// the node attributes you want to see returned. Marker and Limit are used
+// for pagination.
+type ListOpts struct {
+ // Filter the list by specific instance UUID
+ InstanceUUID string `q:"instance_uuid"`
+
+ // Filter the list by chassis UUID
+ ChassisUUID string `q:"chassis_uuid"`
+
+ // Filter the list by maintenance set to True or False
+ Maintenance bool `q:"maintenance"`
+
+ // Nodes which are, or are not, associated with an instance_uuid.
+ Associated bool `q:"associated"`
+
+ // Only return those with the specified provision_state.
+ ProvisionState ProvisionState `q:"provision_state"`
+
+ // Filter the list with the specified driver.
+ Driver string `q:"driver"`
+
+ // Filter the list with the specified resource class.
+ ResourceClass string `q:"resource_class"`
+
+ // Filter the list with the specified conductor_group.
+ ConductorGroup string `q:"conductor_group"`
+
+ // Filter the list with the specified fault.
+ Fault string `q:"fault"`
+
+ // One or more fields to be returned in the response.
+ Fields []string `q:"fields"`
+
+ // Requests a page size of items.
+ Limit int `q:"limit"`
+
+ // The ID of the last-seen item.
+ Marker string `q:"marker"`
+
+ // Sorts the response by the requested sort direction.
+ SortDir string `q:"sort_dir"`
+
+ // Sorts the response by the this attribute value.
+ SortKey string `q:"sort_key"`
+
+ // A string or UUID of the tenant who owns the baremetal node.
+ Owner string `q:"owner"`
+}
+
+// ToNodeListQuery formats a ListOpts into a query string.
+func (opts ListOpts) ToNodeListQuery() (string, error) {
+ q, err := gophercloud.BuildQueryString(opts)
+ return q.String(), err
+}
+
+// List makes a request against the API to list nodes accessible to you.
+func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
+ url := listURL(client)
+ if opts != nil {
+ query, err := opts.ToNodeListQuery()
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query
+ }
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return NodePage{pagination.LinkedPageBase{PageResult: r}}
})
}
+
+// ToNodeListDetailQuery formats a ListOpts into a query string for the list details API.
+func (opts ListOpts) ToNodeListDetailQuery() (string, error) {
+ // Detail endpoint can't filter by Fields
+ if len(opts.Fields) > 0 {
+ return "", fmt.Errorf("fields is not a valid option when getting a detailed listing of nodes")
+ }
+
+ q, err := gophercloud.BuildQueryString(opts)
+ return q.String(), err
+}
+
+// Return a list of bare metal Nodes with complete details. Some filtering is possible by passing in flags in ListOpts,
+// but you cannot limit by the fields returned.
+func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
+ // This URL is deprecated. In the future, we should compare the microversion and if >= 1.43, hit the listURL
+ // with ListOpts{Detail: true,}
+ url := listDetailURL(client)
+ if opts != nil {
+ query, err := opts.ToNodeListDetailQuery()
+ if err != nil {
+ return pagination.Pager{Err: err}
+ }
+ url += query
+ }
+ return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
+ return NodePage{pagination.LinkedPageBase{PageResult: r}}
+ })
+}
+
+// Get requests details on a single node, by ID.
+func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
+ _, r.Err = client.Get(getURL(client, id), &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// CreateOptsBuilder allows extensions to add additional parameters to the
+// Create request.
+type CreateOptsBuilder interface {
+ ToNodeCreateMap() (map[string]interface{}, error)
+}
+
+// CreateOpts specifies node creation parameters.
+type CreateOpts struct {
+ // The boot interface for a Node, e.g. “pxe”.
+ BootInterface string `json:"boot_interface,omitempty"`
+
+ // The conductor group for a node. Case-insensitive string up to 255 characters, containing a-z, 0-9, _, -, and ..
+ ConductorGroup string `json:"conductor_group,omitempty"`
+
+ // The console interface for a node, e.g. “no-console”.
+ ConsoleInterface string `json:"console_interface,omitempty"`
+
+ // The deploy interface for a node, e.g. “iscsi”.
+ DeployInterface string `json:"deploy_interface,omitempty"`
+
+ // All the metadata required by the driver to manage this Node. List of fields varies between drivers, and can
+ // be retrieved from the /v1/drivers/<DRIVER_NAME>/properties resource.
+ DriverInfo map[string]interface{} `json:"driver_info,omitempty"`
+
+ // name of the driver used to manage this Node.
+ Driver string `json:"driver,omitempty"`
+
+ // A set of one or more arbitrary metadata key and value pairs.
+ Extra map[string]interface{} `json:"extra,omitempty"`
+
+ // The interface used for node inspection, e.g. “no-inspect”.
+ InspectInterface string `json:"inspect_interface,omitempty"`
+
+ // Interface for out-of-band node management, e.g. “ipmitool”.
+ ManagementInterface string `json:"management_interface,omitempty"`
+
+ // Human-readable identifier for the Node resource. May be undefined. Certain words are reserved.
+ Name string `json:"name,omitempty"`
+
+ // Which Network Interface provider to use when plumbing the network connections for this Node.
+ NetworkInterface string `json:"network_interface,omitempty"`
+
+ // Interface used for performing power actions on the node, e.g. “ipmitool”.
+ PowerInterface string `json:"power_interface,omitempty"`
+
+ // Physical characteristics of this Node. Populated during inspection, if performed. Can be edited via the REST
+ // API at any time.
+ Properties map[string]interface{} `json:"properties,omitempty"`
+
+ // Interface used for configuring RAID on this node, e.g. “no-raid”.
+ RAIDInterface string `json:"raid_interface,omitempty"`
+
+ // The interface used for node rescue, e.g. “no-rescue”.
+ RescueInterface string `json:"rescue_interface,omitempty"`
+
+ // A string which can be used by external schedulers to identify this Node as a unit of a specific type
+ // of resource.
+ ResourceClass string `json:"resource_class,omitempty"`
+
+ // Interface used for attaching and detaching volumes on this node, e.g. “cinder”.
+ StorageInterface string `json:"storage_interface,omitempty"`
+
+ // The UUID for the resource.
+ UUID string `json:"uuid,omitempty"`
+
+ // Interface for vendor-specific functionality on this node, e.g. “no-vendor”.
+ VendorInterface string `json:"vendor_interface,omitempty"`
+
+ // A string or UUID of the tenant who owns the baremetal node.
+ Owner string `json:"owner,omitempty"`
+}
+
+// ToNodeCreateMap assembles a request body based on the contents of a CreateOpts.
+func (opts CreateOpts) ToNodeCreateMap() (map[string]interface{}, error) {
+ body, err := gophercloud.BuildRequestBody(opts, "")
+ if err != nil {
+ return nil, err
+ }
+
+ return body, nil
+}
+
+// Create requests a node to be created
+func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
+ reqBody, err := opts.ToNodeCreateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ _, r.Err = client.Post(createURL(client), reqBody, &r.Body, nil)
+ return
+}
+
+type Patch interface {
+ ToNodeUpdateMap() (map[string]interface{}, error)
+}
+
+// UpdateOpts is a slice of Patches used to update a node
+type UpdateOpts []Patch
+
+type UpdateOp string
+
+const (
+ ReplaceOp UpdateOp = "replace"
+ AddOp UpdateOp = "add"
+ RemoveOp UpdateOp = "remove"
+)
+
+type UpdateOperation struct {
+ Op UpdateOp `json:"op" required:"true"`
+ Path string `json:"path" required:"true"`
+ Value interface{} `json:"value,omitempty"`
+}
+
+func (opts UpdateOperation) ToNodeUpdateMap() (map[string]interface{}, error) {
+ return gophercloud.BuildRequestBody(opts, "")
+}
+
+// Update requests that a node be updated
+func Update(client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
+ body := make([]map[string]interface{}, len(opts))
+ for i, patch := range opts {
+ result, err := patch.ToNodeUpdateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ body[i] = result
+ }
+ _, r.Err = client.Patch(updateURL(client, id), body, &r.Body, &gophercloud.RequestOpts{
+ JSONBody: &body,
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// Delete requests that a node be removed
+func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
+ _, r.Err = client.Delete(deleteURL(client, id), nil)
+ return
+}
+
+// Request that Ironic validate whether the Node’s driver has enough information to manage the Node. This polls each
+// interface on the driver, and returns the status of that interface.
+func Validate(client *gophercloud.ServiceClient, id string) (r ValidateResult) {
+ _, r.Err = client.Get(validateURL(client, id), &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// Inject NMI (Non-Masking Interrupts) for the given Node. This feature can be used for hardware diagnostics, and
+// actual support depends on a driver.
+func InjectNMI(client *gophercloud.ServiceClient, id string) (r InjectNMIResult) {
+ _, r.Err = client.Put(injectNMIURL(client, id), map[string]string{}, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+ return
+}
+
+type BootDeviceOpts struct {
+ BootDevice string `json:"boot_device"` // e.g., 'pxe', 'disk', etc.
+ Persistent bool `json:"persistent"` // Whether this is one-time or not
+}
+
+// BootDeviceOptsBuilder allows extensions to add additional parameters to the
+// SetBootDevice request.
+type BootDeviceOptsBuilder interface {
+ ToBootDeviceMap() (map[string]interface{}, error)
+}
+
+// ToBootDeviceSetMap assembles a request body based on the contents of a BootDeviceOpts.
+func (opts BootDeviceOpts) ToBootDeviceMap() (map[string]interface{}, error) {
+ body, err := gophercloud.BuildRequestBody(opts, "")
+ if err != nil {
+ return nil, err
+ }
+
+ return body, nil
+}
+
+// Set the boot device for the given Node, and set it persistently or for one-time boot. The exact behaviour
+// of this depends on the hardware driver.
+func SetBootDevice(client *gophercloud.ServiceClient, id string, bootDevice BootDeviceOptsBuilder) (r SetBootDeviceResult) {
+ reqBody, err := bootDevice.ToBootDeviceMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ _, r.Err = client.Put(bootDeviceURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+ return
+}
+
+// Get the current boot device for the given Node.
+func GetBootDevice(client *gophercloud.ServiceClient, id string) (r BootDeviceResult) {
+ _, r.Err = client.Get(bootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// Retrieve the acceptable set of supported boot devices for a specific Node.
+func GetSupportedBootDevices(client *gophercloud.ServiceClient, id string) (r SupportedBootDeviceResult) {
+ _, r.Err = client.Get(supportedBootDeviceURL(client, id), &r.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200},
+ })
+ return
+}
+
+// A cleaning step has required keys ‘interface’ and ‘step’, and optional key ‘args’. If specified,
+// the value for ‘args’ is a keyword variable argument dictionary that is passed to the cleaning step
+// method.
+type CleanStep struct {
+ Interface string `json:"interface" required:"true"`
+ Step string `json:"step" required:"true"`
+ Args map[string]interface{} `json:"args,omitempty"`
+}
+
+// ProvisionStateOptsBuilder allows extensions to add additional parameters to the
+// ChangeProvisionState request.
+type ProvisionStateOptsBuilder interface {
+ ToProvisionStateMap() (map[string]interface{}, error)
+}
+
+// Starting with Ironic API version 1.56, a configdrive may be a JSON object with structured data.
+// Prior to this version, it must be a base64-encoded, gzipped ISO9660 image.
+type ConfigDrive struct {
+ MetaData map[string]interface{} `json:"meta_data,omitempty"`
+ NetworkData map[string]interface{} `json:"network_data,omitempty"`
+ UserData interface{} `json:"user_data,omitempty"`
+}
+
+// ProvisionStateOpts for a request to change a node's provision state. A config drive should be base64-encoded
+// gzipped ISO9660 image.
+type ProvisionStateOpts struct {
+ Target TargetProvisionState `json:"target" required:"true"`
+ ConfigDrive interface{} `json:"configdrive,omitempty"`
+ CleanSteps []CleanStep `json:"clean_steps,omitempty"`
+ RescuePassword string `json:"rescue_password,omitempty"`
+}
+
+// ToProvisionStateMap assembles a request body based on the contents of a CreateOpts.
+func (opts ProvisionStateOpts) ToProvisionStateMap() (map[string]interface{}, error) {
+ body, err := gophercloud.BuildRequestBody(opts, "")
+ if err != nil {
+ return nil, err
+ }
+
+ return body, nil
+}
+
+// Request a change to the Node’s provision state. Acceptable target states depend on the Node’s current provision
+// state. More detailed documentation of the Ironic State Machine is available in the developer docs.
+func ChangeProvisionState(client *gophercloud.ServiceClient, id string, opts ProvisionStateOptsBuilder) (r ChangeStateResult) {
+ reqBody, err := opts.ToProvisionStateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ _, r.Err = client.Put(provisionStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
+
+type TargetPowerState string
+
+// TargetPowerState is used when changing the power state of a node.
+const (
+ PowerOn TargetPowerState = "power on"
+ PowerOff TargetPowerState = "power off"
+ Rebooting TargetPowerState = "rebooting"
+ SoftPowerOff TargetPowerState = "soft power off"
+ SoftRebooting TargetPowerState = "soft rebooting"
+)
+
+// PowerStateOptsBuilder allows extensions to add additional parameters to the ChangePowerState request.
+type PowerStateOptsBuilder interface {
+ ToPowerStateMap() (map[string]interface{}, error)
+}
+
+// PowerStateOpts for a request to change a node's power state.
+type PowerStateOpts struct {
+ Target TargetPowerState `json:"target" required:"true"`
+ Timeout int `json:"timeout,omitempty"`
+}
+
+// ToPowerStateMap assembles a request body based on the contents of a PowerStateOpts.
+func (opts PowerStateOpts) ToPowerStateMap() (map[string]interface{}, error) {
+ body, err := gophercloud.BuildRequestBody(opts, "")
+ if err != nil {
+ return nil, err
+ }
+
+ return body, nil
+}
+
+// Request to change a Node's power state.
+func ChangePowerState(client *gophercloud.ServiceClient, id string, opts PowerStateOptsBuilder) (r ChangePowerStateResult) {
+ reqBody, err := opts.ToPowerStateMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ _, r.Err = client.Put(powerStateURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{202},
+ })
+ return
+}
+
+// This is the desired RAID configuration on the bare metal node.
+type RAIDConfigOpts struct {
+ LogicalDisks []LogicalDisk `json:"logical_disks"`
+}
+
+// RAIDConfigOptsBuilder allows extensions to modify a set RAID config request.
+type RAIDConfigOptsBuilder interface {
+ ToRAIDConfigMap() (map[string]interface{}, error)
+}
+
+// RAIDLevel type is used to specify the RAID level for a logical disk.
+type RAIDLevel string
+
+const (
+ RAID0 RAIDLevel = "0"
+ RAID1 RAIDLevel = "1"
+ RAID2 RAIDLevel = "2"
+ RAID5 RAIDLevel = "5"
+ RAID6 RAIDLevel = "6"
+ RAID10 RAIDLevel = "1+0"
+ RAID50 RAIDLevel = "5+0"
+ RAID60 RAIDLevel = "6+0"
+)
+
+// DiskType is used to specify the disk type for a logical disk, e.g. hdd or ssd.
+type DiskType string
+
+const (
+ HDD DiskType = "hdd"
+ SSD DiskType = "ssd"
+)
+
+// InterfaceType is used to specify the interface for a logical disk.
+type InterfaceType string
+
+const (
+ SATA InterfaceType = "sata"
+ SCSI InterfaceType = "scsi"
+ SAS InterfaceType = "sas"
+)
+
+type LogicalDisk struct {
+ // Size (Integer) of the logical disk to be created in GiB. If unspecified, "MAX" will be used.
+ SizeGB *int `json:"size_gb"`
+
+ // RAID level for the logical disk.
+ RAIDLevel RAIDLevel `json:"raid_level" required:"true"`
+
+ // Name of the volume. Should be unique within the Node. If not specified, volume name will be auto-generated.
+ VolumeName string `json:"volume_name,omitempty"`
+
+ // Set to true if this is the root volume. At most one logical disk can have this set to true.
+ IsRootVolume *bool `json:"is_root_volume,omitempty"`
+
+ // Set to true if this logical disk can share physical disks with other logical disks.
+ SharePhysicalDisks *bool `json:"share_physical_disks,omitempty"`
+
+ // If this is not specified, disk type will not be a criterion to find backing physical disks
+ DiskType DiskType `json:"disk_type,omitempty"`
+
+ // If this is not specified, interface type will not be a criterion to find backing physical disks.
+ InterfaceType InterfaceType `json:"interface_type,omitempty"`
+
+ // Integer, number of disks to use for the logical disk. Defaults to minimum number of disks required
+ // for the particular RAID level.
+ NumberOfPhysicalDisks int `json:"number_of_physical_disks,omitempty"`
+
+ // The name of the controller as read by the RAID interface.
+ Controller string `json:"controller,omitempty"`
+
+ // A list of physical disks to use as read by the RAID interface.
+ PhysicalDisks []string `json:"physical_disks,omitempty"`
+}
+
+func (opts RAIDConfigOpts) ToRAIDConfigMap() (map[string]interface{}, error) {
+ body, err := gophercloud.BuildRequestBody(opts, "")
+ if err != nil {
+ return nil, err
+ }
+
+ for _, v := range body["logical_disks"].([]interface{}) {
+ if logicalDisk, ok := v.(map[string]interface{}); ok {
+ if logicalDisk["size_gb"] == nil {
+ logicalDisk["size_gb"] = "MAX"
+ }
+ }
+ }
+
+ return body, nil
+}
+
+// Request to change a Node's RAID config.
+func SetRAIDConfig(client *gophercloud.ServiceClient, id string, raidConfigOptsBuilder RAIDConfigOptsBuilder) (r ChangeStateResult) {
+ reqBody, err := raidConfigOptsBuilder.ToRAIDConfigMap()
+ if err != nil {
+ r.Err = err
+ return
+ }
+
+ _, r.Err = client.Put(raidConfigURL(client, id), reqBody, nil, &gophercloud.RequestOpts{
+ OkCodes: []int{204},
+ })
+ return
+}
diff --git a/openstack/baremetal/v1/nodes/results.go b/openstack/baremetal/v1/nodes/results.go
index 459ed1b..be335b9 100644
--- a/openstack/baremetal/v1/nodes/results.go
+++ b/openstack/baremetal/v1/nodes/results.go
@@ -5,60 +5,309 @@
"gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
)
-type commonResult struct {
+type nodeResult struct {
gophercloud.Result
}
-func (r commonResult) Extract() (*Node, error) {
- var n struct {
- Node *Node `json:"node"`
+// Extract interprets any nodeResult as a Node, if possible.
+func (r nodeResult) Extract() (*Node, error) {
+ var s Node
+ err := r.ExtractInto(&s)
+ return &s, err
+}
+
+// Extract interprets a BootDeviceResult as BootDeviceOpts, if possible.
+func (r BootDeviceResult) Extract() (*BootDeviceOpts, error) {
+ var s BootDeviceOpts
+ err := r.ExtractInto(&s)
+ return &s, err
+}
+
+// Extract interprets a SupportedBootDeviceResult as an array of supported boot devices, if possible.
+func (r SupportedBootDeviceResult) Extract() ([]string, error) {
+ var s struct {
+ Devices []string `json:"supported_boot_devices"`
}
- err := r.ExtractInto(&n)
- return n.Node, err
+
+ err := r.ExtractInto(&s)
+ return s.Devices, err
}
-type GetResult struct {
- commonResult
+// Extract interprets a ValidateResult as NodeValidation, if possible.
+func (r ValidateResult) Extract() (*NodeValidation, error) {
+ var s NodeValidation
+ err := r.ExtractInto(&s)
+ return &s, err
}
-type Link struct {
- Href string `json:"href"`
- Rel string `json:"rel"`
+func (r nodeResult) ExtractInto(v interface{}) error {
+ return r.Result.ExtractIntoStructPtr(v, "")
}
+func ExtractNodesInto(r pagination.Page, v interface{}) error {
+ return r.(NodePage).Result.ExtractIntoSlicePtr(v, "nodes")
+}
+
+// Node represents a node in the OpenStack Bare Metal API.
type Node struct {
- UUID string `json:"uuid"`
- InstanceUUID string `json:"InstanceUUID"`
- PowerState string `json:"power_state"`
+ // UUID for the resource.
+ UUID string `json:"uuid"`
+
+ // Identifier for the Node resource. May be undefined. Certain words are reserved.
+ Name string `json:"name"`
+
+ // Current power state of this Node. Usually, “power on” or “power off”, but may be “None”
+ // if Ironic is unable to determine the power state (eg, due to hardware failure).
+ PowerState string `json:"power_state"`
+
+ // A power state transition has been requested, this field represents the requested (ie, “target”)
+ // state either “power on”, “power off”, “rebooting”, “soft power off” or “soft rebooting”.
+ TargetPowerState string `json:"target_power_state"`
+
+ // Current provisioning state of this Node.
ProvisionState string `json:"provision_state"`
- Maintenance bool `json:"maintenance"`
- Links []Link `json:"links"`
+
+ // A provisioning action has been requested, this field represents the requested (ie, “target”) state. Note
+ // that a Node may go through several states during its transition to this target state. For instance, when
+ // requesting an instance be deployed to an AVAILABLE Node, the Node may go through the following state
+ // change progression: AVAILABLE -> DEPLOYING -> DEPLOYWAIT -> DEPLOYING -> ACTIVE
+ TargetProvisionState string `json:"target_provision_state"`
+
+ // Whether or not this Node is currently in “maintenance mode”. Setting a Node into maintenance mode removes it
+ // from the available resource pool and halts some internal automation. This can happen manually (eg, via an API
+ // request) or automatically when Ironic detects a hardware fault that prevents communication with the machine.
+ Maintenance bool `json:"maintenance"`
+
+ // Description of the reason why this Node was placed into maintenance mode
+ MaintenanceReason string `json:"maintenance_reason"`
+
+ // Fault indicates the active fault detected by ironic, typically the Node is in “maintenance mode”. None means no
+ // fault has been detected by ironic. “power failure” indicates ironic failed to retrieve power state from this
+ // node. There are other possible types, e.g., “clean failure” and “rescue abort failure”.
+ Fault string `json:"fault"`
+
+ // Error from the most recent (last) transaction that started but failed to finish.
+ LastError string `json:"last_error"`
+
+ // Name of an Ironic Conductor host which is holding a lock on this node, if a lock is held. Usually “null”,
+ // but this field can be useful for debugging.
+ Reservation string `json:"reservation"`
+
+ // Name of the driver.
+ Driver string `json:"driver"`
+
+ // The metadata required by the driver to manage this Node. List of fields varies between drivers, and can be
+ // retrieved from the /v1/drivers/<DRIVER_NAME>/properties resource.
+ DriverInfo map[string]interface{} `json:"driver_info"`
+
+ // Metadata set and stored by the Node’s driver. This field is read-only.
+ DriverInternalInfo map[string]interface{} `json:"driver_internal_info"`
+
+ // Characteristics of this Node. Populated by ironic-inspector during inspection. May be edited via the REST
+ // API at any time.
+ Properties map[string]interface{} `json:"properties"`
+
+ // Used to customize the deployed image. May include root partition size, a base 64 encoded config drive, and other
+ // metadata. Note that this field is erased automatically when the instance is deleted (this is done by requesting
+ // the Node provision state be changed to DELETED).
+ InstanceInfo map[string]interface{} `json:"instance_info"`
+
+ // ID of the Nova instance associated with this Node.
+ InstanceUUID string `json:"instance_uuid"`
+
+ // ID of the chassis associated with this Node. May be empty or None.
+ ChassisUUID string `json:"chassis_uuid"`
+
+ // Set of one or more arbitrary metadata key and value pairs.
+ Extra map[string]interface{} `json:"extra"`
+
+ // Whether console access is enabled or disabled on this node.
+ ConsoleEnabled bool `json:"console_enabled"`
+
+ // The current RAID configuration of the node. Introduced with the cleaning feature.
+ RAIDConfig map[string]interface{} `json:"raid_config"`
+
+ // The requested RAID configuration of the node, which will be applied when the Node next transitions
+ // through the CLEANING state. Introduced with the cleaning feature.
+ TargetRAIDConfig map[string]interface{} `json:"target_raid_config"`
+
+ // Current clean step. Introduced with the cleaning feature.
+ CleanStep map[string]interface{} `json:"clean_step"`
+
+ // Current deploy step.
+ DeployStep map[string]interface{} `json:"deploy_step"`
+
+ // String which can be used by external schedulers to identify this Node as a unit of a specific type of resource.
+ // For more details, see: https://docs.openstack.org/ironic/latest/install/configure-nova-flavors.html
+ ResourceClass string `json:"resource_class"`
+
+ // Boot interface for a Node, e.g. “pxe”.
+ BootInterface string `json:"boot_interface"`
+
+ // Console interface for a node, e.g. “no-console”.
+ ConsoleInterface string `json:"console_interface"`
+
+ // Deploy interface for a node, e.g. “iscsi”.
+ DeployInterface string `json:"deploy_interface"`
+
+ // Interface used for node inspection, e.g. “no-inspect”.
+ InspectInterface string `json:"inspect_interface"`
+
+ // For out-of-band node management, e.g. “ipmitool”.
+ ManagementInterface string `json:"management_interface"`
+
+ // Network Interface provider to use when plumbing the network connections for this Node.
+ NetworkInterface string `json:"network_interface"`
+
+ // used for performing power actions on the node, e.g. “ipmitool”.
+ PowerInterface string `json:"power_interface"`
+
+ // Used for configuring RAID on this node, e.g. “no-raid”.
+ RAIDInterface string `json:"raid_interface"`
+
+ // Interface used for node rescue, e.g. “no-rescue”.
+ RescueInterface string `json:"rescue_interface"`
+
+ // Used for attaching and detaching volumes on this node, e.g. “cinder”.
+ StorageInterface string `json:"storage_interface"`
+
+ // Array of traits for this node.
+ Traits []string `json:"traits"`
+
+ // For vendor-specific functionality on this node, e.g. “no-vendor”.
+ VendorInterface string `json:"vendor_interface"`
+
+ // Conductor group for a node. Case-insensitive string up to 255 characters, containing a-z, 0-9, _, -, and ..
+ ConductorGroup string `json:"conductor_group"`
+
+ // The node is protected from undeploying, rebuilding and deletion.
+ Protected bool `json:"protected"`
+
+ // Reason the node is marked as protected.
+ ProtectedReason string `json:"protected_reason"`
+
+ // A string or UUID of the tenant who owns the baremetal node.
+ Owner string `json:"owner"`
}
+// NodePage abstracts the raw results of making a List() request against
+// the API. As OpenStack extensions may freely alter the response bodies of
+// structures returned to the client, you may only safely access the data
+// provided through the ExtractNodes call.
type NodePage struct {
- pagination.SinglePageBase
+ pagination.LinkedPageBase
}
+// IsEmpty returns true if a page contains no Node results.
+func (r NodePage) IsEmpty() (bool, error) {
+ s, err := ExtractNodes(r)
+ return len(s) == 0, err
+}
+
+// NextPageURL uses the response's embedded link reference to navigate to the
+// next page of results.
func (r NodePage) NextPageURL() (string, error) {
- var n struct {
+ var s struct {
Links []gophercloud.Link `json:"nodes_links"`
}
- err := r.ExtractInto(&n)
+ err := r.ExtractInto(&s)
if err != nil {
return "", err
}
- return gophercloud.ExtractNextURL(n.Links)
+ return gophercloud.ExtractNextURL(s.Links)
}
-func (r NodePage) IsEmpty() (bool, error) {
- is, err := ExtractNodes(r)
- return len(is) == 0, err
-}
-
+// ExtractNodes interprets the results of a single page from a List() call,
+// producing a slice of Node entities.
func ExtractNodes(r pagination.Page) ([]Node, error) {
- var n struct {
- Nodes []Node `json:"nodes"`
- }
- err := (r.(NodePage)).ExtractInto(&n)
- return n.Nodes, err
+ var s []Node
+ err := ExtractNodesInto(r, &s)
+ return s, err
+}
+
+// GetResult is the response from a Get operation. Call its Extract
+// method to interpret it as a Node.
+type GetResult struct {
+ nodeResult
+}
+
+// CreateResult is the response from a Create operation.
+type CreateResult struct {
+ nodeResult
+}
+
+// UpdateResult is the response from an Update operation. Call its Extract
+// method to interpret it as a Node.
+type UpdateResult struct {
+ nodeResult
+}
+
+// DeleteResult is the response from a Delete operation. Call its ExtractErr
+// method to determine if the call succeeded or failed.
+type DeleteResult struct {
+ gophercloud.ErrResult
+}
+
+// ValidateResult is the response from a Validate operation. Call its Extract
+// method to interpret it as a NodeValidation struct.
+type ValidateResult struct {
+ gophercloud.Result
+}
+
+// InjectNMIResult is the response from an InjectNMI operation. Call its ExtractErr
+// method to determine if the call succeeded or failed.
+type InjectNMIResult struct {
+ gophercloud.ErrResult
+}
+
+// BootDeviceResult is the response from a GetBootDevice operation. Call its Extract
+// method to interpret it as a BootDeviceOpts struct.
+type BootDeviceResult struct {
+ gophercloud.Result
+}
+
+// BootDeviceResult is the response from a GetBootDevice operation. Call its Extract
+// method to interpret it as a BootDeviceOpts struct.
+type SetBootDeviceResult struct {
+ gophercloud.ErrResult
+}
+
+// SupportedBootDeviceResult is the response from a GetSupportedBootDevices operation. Call its Extract
+// method to interpret it as an array of supported boot device values.
+type SupportedBootDeviceResult struct {
+ gophercloud.Result
+}
+
+// ChangePowerStateResult is the response from a ChangePowerState operation. Call its ExtractErr
+// method to determine if the call succeeded or failed.
+type ChangePowerStateResult struct {
+ gophercloud.ErrResult
+}
+
+// Each element in the response will contain a “result” variable, which will have a value of “true” or “false”, and
+// also potentially a reason. A value of nil indicates that the Node’s driver does not support that interface.
+type DriverValidation struct {
+ Result bool `json:"result"`
+ Reason string `json:"reason"`
+}
+
+// Ironic validates whether the Node’s driver has enough information to manage the Node. This polls each interface on
+// the driver, and returns the status of that interface as an DriverValidation struct.
+type NodeValidation struct {
+ Boot DriverValidation `json:"boot"`
+ Console DriverValidation `json:"console"`
+ Deploy DriverValidation `json:"deploy"`
+ Inspect DriverValidation `json:"inspect"`
+ Management DriverValidation `json:"management"`
+ Network DriverValidation `json:"network"`
+ Power DriverValidation `json:"power"`
+ RAID DriverValidation `json:"raid"`
+ Rescue DriverValidation `json:"rescue"`
+ Storage DriverValidation `json:"storage"`
+}
+
+// ChangeStateResult is the response from any state change operation. Call its ExtractErr
+// method to determine if the call succeeded or failed.
+type ChangeStateResult struct {
+ gophercloud.ErrResult
}
diff --git a/openstack/baremetal/v1/nodes/testing/doc.go b/openstack/baremetal/v1/nodes/testing/doc.go
new file mode 100644
index 0000000..df83778
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/doc.go
@@ -0,0 +1,2 @@
+// nodes unit tests
+package testing
diff --git a/openstack/baremetal/v1/nodes/testing/fixtures.go b/openstack/baremetal/v1/nodes/testing/fixtures.go
new file mode 100644
index 0000000..c073329
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/fixtures.go
@@ -0,0 +1,1033 @@
+package testing
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/nodes"
+ th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
+)
+
+// NodeListBody contains the canned body of a nodes.List response, without detail.
+const NodeListBody = `
+ {
+ "nodes": [
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "foo",
+ "power_state": null,
+ "provision_state": "enroll"
+ },
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "bar",
+ "power_state": null,
+ "provision_state": "enroll"
+ },
+ {
+ "instance_uuid": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "name": "baz",
+ "power_state": null,
+ "provision_state": "enroll"
+ }
+ ]
+}
+`
+
+// NodeListDetailBody contains the canned body of a nodes.ListDetail response.
+const NodeListDetailBody = `
+ {
+ "nodes": [
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:28+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin"
+
+ },
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "foo",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:29+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {},
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "bar",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/08c84581-58f5-4ea2-a0c6-dd2e5d2b3662/volume",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ {
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:30+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {},
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "baz",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/c9afd385-5d89-4ecb-9e1c-68194da6b474/volume",
+ "rel": "bookmark"
+ }
+ ]
+ }
+ ]
+}
+`
+
+// SingleNodeBody is the canned body of a Get request on an existing node.
+const SingleNodeBody = `
+{
+ "bios_interface": "no-bios",
+ "boot_interface": "pxe",
+ "chassis_uuid": null,
+ "clean_step": {},
+ "conductor_group": "",
+ "console_enabled": false,
+ "console_interface": "no-console",
+ "created_at": "2019-01-31T19:59:28+00:00",
+ "deploy_interface": "iscsi",
+ "deploy_step": {},
+ "driver": "ipmi",
+ "driver_info": {
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin"
+ },
+ "driver_internal_info": {},
+ "extra": {},
+ "fault": null,
+ "inspect_interface": "no-inspect",
+ "inspection_finished_at": null,
+ "inspection_started_at": null,
+ "instance_info": {},
+ "instance_uuid": null,
+ "last_error": null,
+ "links": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e",
+ "rel": "bookmark"
+ }
+ ],
+ "maintenance": false,
+ "maintenance_reason": null,
+ "management_interface": "ipmitool",
+ "name": "foo",
+ "network_interface": "flat",
+ "portgroups": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/portgroups",
+ "rel": "bookmark"
+ }
+ ],
+ "ports": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/ports",
+ "rel": "bookmark"
+ }
+ ],
+ "power_interface": "ipmitool",
+ "power_state": null,
+ "properties": {},
+ "provision_state": "enroll",
+ "provision_updated_at": null,
+ "raid_config": {},
+ "raid_interface": "no-raid",
+ "rescue_interface": "no-rescue",
+ "reservation": null,
+ "resource_class": null,
+ "states": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/states",
+ "rel": "bookmark"
+ }
+ ],
+ "storage_interface": "noop",
+ "target_power_state": null,
+ "target_provision_state": null,
+ "target_raid_config": {},
+ "traits": [],
+ "updated_at": null,
+ "uuid": "d2630783-6ec8-4836-b556-ab427c4b581e",
+ "vendor_interface": "ipmitool",
+ "volume": [
+ {
+ "href": "http://ironic.example.com:6385/v1/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "self"
+ },
+ {
+ "href": "http://ironic.example.com:6385/nodes/d2630783-6ec8-4836-b556-ab427c4b581e/volume",
+ "rel": "bookmark"
+ }
+ ]
+}
+`
+
+const NodeValidationBody = `
+{
+ "bios": {
+ "reason": "Driver ipmi does not support bios (disabled or not implemented).",
+ "result": false
+ },
+ "boot": {
+ "reason": "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
+ "result": false
+ },
+ "console": {
+ "reason": "Driver ipmi does not support console (disabled or not implemented).",
+ "result": false
+ },
+ "deploy": {
+ "reason": "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
+ "result": false
+ },
+ "inspect": {
+ "reason": "Driver ipmi does not support inspect (disabled or not implemented).",
+ "result": false
+ },
+ "management": {
+ "result": true
+ },
+ "network": {
+ "result": true
+ },
+ "power": {
+ "result": true
+ },
+ "raid": {
+ "reason": "Driver ipmi does not support raid (disabled or not implemented).",
+ "result": false
+ },
+ "rescue": {
+ "reason": "Driver ipmi does not support rescue (disabled or not implemented).",
+ "result": false
+ },
+ "storage": {
+ "result": true
+ }
+}
+`
+
+const NodeBootDeviceBody = `
+{
+ "boot_device":"pxe",
+ "persistent":false
+}
+`
+
+const NodeSupportedBootDeviceBody = `
+{
+ "supported_boot_devices": [
+ "pxe",
+ "disk"
+ ]
+}
+`
+
+const NodeProvisionStateActiveBody = `
+{
+ "target": "active",
+ "configdrive": "http://127.0.0.1/images/test-node-config-drive.iso.gz"
+}
+`
+const NodeProvisionStateCleanBody = `
+{
+ "target": "clean",
+ "clean_steps": [
+ {
+ "interface": "deploy",
+ "step": "upgrade_firmware",
+ "args": {
+ "force": "True"
+ }
+ }
+ ]
+}
+`
+
+const NodeProvisionStateConfigDriveBody = `
+{
+ "target": "active",
+ "configdrive": {
+ "user_data": {
+ "ignition": {
+ "version": "2.2.0"
+ },
+ "systemd": {
+ "units": [
+ {
+ "enabled": true,
+ "name": "example.service"
+ }
+ ]
+ }
+ }
+ }
+}
+`
+
+var (
+ NodeFoo = nodes.Node{
+ UUID: "d2630783-6ec8-4836-b556-ab427c4b581e",
+ Name: "foo",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin",
+ },
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ NodeFooValidation = nodes.NodeValidation{
+ Boot: nodes.DriverValidation{
+ Result: false,
+ Reason: "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
+ },
+ Console: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support console (disabled or not implemented).",
+ },
+ Deploy: nodes.DriverValidation{
+ Result: false,
+ Reason: "Cannot validate image information for node a62b8495-52e2-407b-b3cb-62775d04c2b8 because one or more parameters are missing from its instance_info and insufficent information is present to boot from a remote volume. Missing are: ['ramdisk', 'kernel', 'image_source']",
+ },
+ Inspect: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support inspect (disabled or not implemented).",
+ },
+ Management: nodes.DriverValidation{
+ Result: true,
+ },
+ Network: nodes.DriverValidation{
+ Result: true,
+ },
+ Power: nodes.DriverValidation{
+ Result: true,
+ },
+ RAID: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support raid (disabled or not implemented).",
+ },
+ Rescue: nodes.DriverValidation{
+ Result: false,
+ Reason: "Driver ipmi does not support rescue (disabled or not implemented).",
+ },
+ Storage: nodes.DriverValidation{
+ Result: true,
+ },
+ }
+
+ NodeBootDevice = nodes.BootDeviceOpts{
+ BootDevice: "pxe",
+ Persistent: false,
+ }
+
+ NodeSupportedBootDevice = []string{
+ "pxe",
+ "disk",
+ }
+
+ NodeBar = nodes.Node{
+ UUID: "08c84581-58f5-4ea2-a0c6-dd2e5d2b3662",
+ Name: "bar",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{},
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ NodeBaz = nodes.Node{
+ UUID: "c9afd385-5d89-4ecb-9e1c-68194da6b474",
+ Name: "baz",
+ PowerState: "",
+ TargetPowerState: "",
+ ProvisionState: "enroll",
+ TargetProvisionState: "",
+ Maintenance: false,
+ MaintenanceReason: "",
+ Fault: "",
+ LastError: "",
+ Reservation: "",
+ Driver: "ipmi",
+ DriverInfo: map[string]interface{}{},
+ DriverInternalInfo: map[string]interface{}{},
+ Properties: map[string]interface{}{},
+ InstanceInfo: map[string]interface{}{},
+ InstanceUUID: "",
+ ChassisUUID: "",
+ Extra: map[string]interface{}{},
+ ConsoleEnabled: false,
+ RAIDConfig: map[string]interface{}{},
+ TargetRAIDConfig: map[string]interface{}{},
+ CleanStep: map[string]interface{}{},
+ DeployStep: map[string]interface{}{},
+ ResourceClass: "",
+ BootInterface: "pxe",
+ ConsoleInterface: "no-console",
+ DeployInterface: "iscsi",
+ InspectInterface: "no-inspect",
+ ManagementInterface: "ipmitool",
+ NetworkInterface: "flat",
+ PowerInterface: "ipmitool",
+ RAIDInterface: "no-raid",
+ RescueInterface: "no-rescue",
+ StorageInterface: "noop",
+ Traits: []string{},
+ VendorInterface: "ipmitool",
+ ConductorGroup: "",
+ Protected: false,
+ ProtectedReason: "",
+ }
+
+ ConfigDriveMap = nodes.ConfigDrive{
+ UserData: map[string]interface{}{
+ "ignition": map[string]string{
+ "version": "2.2.0",
+ },
+ "systemd": map[string]interface{}{
+ "units": []map[string]interface{}{{
+ "name": "example.service",
+ "enabled": true,
+ },
+ },
+ },
+ },
+ }
+)
+
+// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
+func HandleNodeListSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.Header().Add("Content-Type", "application/json")
+ r.ParseForm()
+
+ marker := r.Form.Get("marker")
+ switch marker {
+ case "":
+ fmt.Fprintf(w, NodeListBody)
+
+ case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
+ fmt.Fprintf(w, `{ "servers": [] }`)
+ default:
+ t.Fatalf("/nodes invoked with unexpected marker=[%s]", marker)
+ }
+ })
+}
+
+// HandleNodeListSuccessfully sets up the test server to respond to a server List request.
+func HandleNodeListDetailSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/detail", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.Header().Add("Content-Type", "application/json")
+ r.ParseForm()
+
+ fmt.Fprintf(w, NodeListDetailBody)
+ })
+}
+
+// HandleServerCreationSuccessfully sets up the test server to respond to a server creation request
+// with a given response.
+func HandleNodeCreationSuccessfully(t *testing.T, response string) {
+ th.Mux.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "boot_interface": "pxe",
+ "driver": "ipmi",
+ "driver_info": {
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_address": "192.168.122.1",
+ "ipmi_password": "admin",
+ "ipmi_port": "6230",
+ "ipmi_username": "admin"
+ },
+ "name": "foo"
+ }`)
+
+ w.WriteHeader(http.StatusAccepted)
+ w.Header().Add("Content-Type", "application/json")
+ fmt.Fprintf(w, response)
+ })
+}
+
+// HandleNodeDeletionSuccessfully sets up the test server to respond to a server deletion request.
+func HandleNodeDeletionSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/asdfasdfasdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "DELETE")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+func HandleNodeGetSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ fmt.Fprintf(w, SingleNodeBody)
+ })
+}
+
+func HandleNodeUpdateSuccessfully(t *testing.T, response string) {
+ th.Mux.HandleFunc("/nodes/1234asdf", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PATCH")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestJSONRequest(t, r, `[{"op": "replace", "path": "/properties", "value": {"root_gb": 25}}]`)
+
+ fmt.Fprintf(w, response)
+ })
+}
+
+func HandleNodeValidateSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/validate", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestHeader(t, r, "Accept", "application/json")
+
+ fmt.Fprintf(w, NodeValidationBody)
+ })
+}
+
+// HandleInjectNMISuccessfully sets up the test server to respond to a node InjectNMI request
+func HandleInjectNMISuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/inject_nmi", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, "{}")
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+// HandleSetBootDeviceSuccessfully sets up the test server to respond to a set boot device request for a node
+func HandleSetBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeBootDeviceBody)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
+func HandleGetBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, NodeBootDeviceBody)
+ })
+}
+
+// HandleGetBootDeviceSuccessfully sets up the test server to respond to a get boot device request for a node
+func HandleGetSupportedBootDeviceSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/management/boot_device/supported", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, NodeSupportedBootDeviceBody)
+ })
+}
+
+func HandleNodeChangeProvisionStateActive(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateActiveBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func HandleNodeChangeProvisionStateClean(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+func HandleNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateCleanBody)
+ w.WriteHeader(http.StatusConflict)
+ })
+}
+
+func HandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/provision", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, NodeProvisionStateConfigDriveBody)
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+// HandleChangePowerStateSuccessfully sets up the test server to respond to a change power state request for a node
+func HandleChangePowerStateSuccessfully(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "target": "power on",
+ "timeout": 100
+ }`)
+
+ w.WriteHeader(http.StatusAccepted)
+ })
+}
+
+// HandleChangePowerStateWithConflict sets up the test server to respond to a change power state request for a node with a 409 error
+func HandleChangePowerStateWithConflict(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/power", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `{
+ "target": "power on",
+ "timeout": 100
+ }`)
+
+ w.WriteHeader(http.StatusConflict)
+ })
+}
+
+func HandleSetRAIDConfig(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `
+ {
+ "logical_disks" : [
+ {
+ "size_gb" : 100,
+ "is_root_volume" : true,
+ "raid_level" : "1"
+ }
+ ]
+ }
+ `)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
+
+func HandleSetRAIDConfigMaxSize(t *testing.T) {
+ th.Mux.HandleFunc("/nodes/1234asdf/states/raid", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
+ th.TestJSONRequest(t, r, `
+ {
+ "logical_disks" : [
+ {
+ "size_gb" : "MAX",
+ "is_root_volume" : true,
+ "raid_level" : "1"
+ }
+ ]
+ }
+ `)
+
+ w.WriteHeader(http.StatusNoContent)
+ })
+}
diff --git a/openstack/baremetal/v1/nodes/testing/requests_test.go b/openstack/baremetal/v1/nodes/testing/requests_test.go
new file mode 100644
index 0000000..aa1ac58
--- /dev/null
+++ b/openstack/baremetal/v1/nodes/testing/requests_test.go
@@ -0,0 +1,432 @@
+package testing
+
+import (
+ "testing"
+
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/nodes"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
+ th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
+ "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
+)
+
+func TestListDetailNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeListDetailSuccessfully(t)
+
+ pages := 0
+ err := nodes.ListDetail(client.ServiceClient(), nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ if len(actual) != 3 {
+ t.Fatalf("Expected 3 nodes, got %d", len(actual))
+ }
+ th.CheckDeepEquals(t, NodeFoo, actual[0])
+ th.CheckDeepEquals(t, NodeBar, actual[1])
+ th.CheckDeepEquals(t, NodeBaz, actual[2])
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+
+ if pages != 1 {
+ t.Errorf("Expected 1 page, saw %d", pages)
+ }
+}
+
+func TestListNodes(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeListSuccessfully(t)
+
+ pages := 0
+ err := nodes.List(client.ServiceClient(), nodes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := nodes.ExtractNodes(page)
+ if err != nil {
+ return false, err
+ }
+
+ if len(actual) != 3 {
+ t.Fatalf("Expected 3 nodes, got %d", len(actual))
+ }
+ th.AssertEquals(t, "foo", actual[0].Name)
+ th.AssertEquals(t, "bar", actual[1].Name)
+ th.AssertEquals(t, "baz", actual[2].Name)
+
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+
+ if pages != 1 {
+ t.Errorf("Expected 1 page, saw %d", pages)
+ }
+}
+
+func TestListOpts(t *testing.T) {
+ // Detail cannot take Fields
+ opts := nodes.ListOpts{
+ Fields: []string{"name", "uuid"},
+ }
+
+ _, err := opts.ToNodeListDetailQuery()
+ th.AssertEquals(t, err.Error(), "fields is not a valid option when getting a detailed listing of nodes")
+
+ // Regular ListOpts can
+ query, err := opts.ToNodeListQuery()
+ th.AssertEquals(t, query, "?fields=name&fields=uuid")
+ th.AssertNoErr(t, err)
+}
+
+func TestCreateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeCreationSuccessfully(t, SingleNodeBody)
+
+ actual, err := nodes.Create(client.ServiceClient(), nodes.CreateOpts{
+ Name: "foo",
+ Driver: "ipmi",
+ BootInterface: "pxe",
+ DriverInfo: map[string]interface{}{
+ "ipmi_port": "6230",
+ "ipmi_username": "admin",
+ "deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
+ "ipmi_address": "192.168.122.1",
+ "deploy_ramdisk": "http://172.22.0.1/images/tinyipa-stable-rocky.gz",
+ "ipmi_password": "admin",
+ },
+ }).Extract()
+ th.AssertNoErr(t, err)
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestDeleteNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeDeletionSuccessfully(t)
+
+ res := nodes.Delete(client.ServiceClient(), "asdfasdfasdf")
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestGetNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeGetSuccessfully(t)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Get(c, "1234asdf").Extract()
+ if err != nil {
+ t.Fatalf("Unexpected Get error: %v", err)
+ }
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestUpdateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeUpdateSuccessfully(t, SingleNodeBody)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Op: nodes.ReplaceOp,
+ Path: "/properties",
+ Value: map[string]interface{}{
+ "root_gb": 25,
+ },
+ },
+ }).Extract()
+ if err != nil {
+ t.Fatalf("Unexpected Update error: %v", err)
+ }
+
+ th.CheckDeepEquals(t, NodeFoo, *actual)
+}
+
+func TestUpdateRequiredOp(t *testing.T) {
+ c := client.ServiceClient()
+ _, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Path: "/driver",
+ Value: "new-driver",
+ },
+ }).Extract()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+
+}
+
+func TestUpdateRequiredPath(t *testing.T) {
+ c := client.ServiceClient()
+ _, err := nodes.Update(c, "1234asdf", nodes.UpdateOpts{
+ nodes.UpdateOperation{
+ Op: nodes.ReplaceOp,
+ Value: "new-driver",
+ },
+ }).Extract()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestValidateNode(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeValidateSuccessfully(t)
+
+ c := client.ServiceClient()
+ actual, err := nodes.Validate(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeFooValidation, *actual)
+}
+
+func TestInjectNMI(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleInjectNMISuccessfully(t)
+
+ c := client.ServiceClient()
+ err := nodes.InjectNMI(c, "1234asdf").ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestSetBootDevice(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ err := nodes.SetBootDevice(c, "1234asdf", nodes.BootDeviceOpts{
+ BootDevice: "pxe",
+ Persistent: false,
+ }).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestGetBootDevice(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleGetBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ bootDevice, err := nodes.GetBootDevice(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeBootDevice, *bootDevice)
+}
+
+func TestGetSupportedBootDevices(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleGetSupportedBootDeviceSuccessfully(t)
+
+ c := client.ServiceClient()
+ bootDevices, err := nodes.GetSupportedBootDevices(c, "1234asdf").Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, NodeSupportedBootDevice, bootDevices)
+}
+
+func TestNodeChangeProvisionStateActive(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateActive(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetActive,
+ ConfigDrive: "http://127.0.0.1/images/test-node-config-drive.iso.gz",
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestHandleNodeChangeProvisionStateConfigDrive(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleNodeChangeProvisionStateConfigDrive(t)
+
+ c := client.ServiceClient()
+
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetActive,
+ ConfigDrive: ConfigDriveMap,
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestNodeChangeProvisionStateClean(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateClean(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ th.AssertNoErr(t, err)
+}
+
+func TestNodeChangeProvisionStateCleanWithConflict(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleNodeChangeProvisionStateCleanWithConflict(t)
+
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrDefault409); !ok {
+ t.Fatal("ErrDefault409 was expected to occur")
+ }
+}
+
+func TestCleanStepRequiresInterface(t *testing.T) {
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Step: "upgrade_firmware",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestCleanStepRequiresStep(t *testing.T) {
+ c := client.ServiceClient()
+ err := nodes.ChangeProvisionState(c, "1234asdf", nodes.ProvisionStateOpts{
+ Target: nodes.TargetClean,
+ CleanSteps: []nodes.CleanStep{
+ {
+ Interface: "deploy",
+ Args: map[string]interface{}{
+ "force": "True",
+ },
+ },
+ },
+ }).ExtractErr()
+
+ if _, ok := err.(gophercloud.ErrMissingInput); !ok {
+ t.Fatal("ErrMissingInput was expected to occur")
+ }
+}
+
+func TestChangePowerState(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleChangePowerStateSuccessfully(t)
+
+ opts := nodes.PowerStateOpts{
+ Target: nodes.PowerOn,
+ Timeout: 100,
+ }
+
+ c := client.ServiceClient()
+ err := nodes.ChangePowerState(c, "1234asdf", opts).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+func TestChangePowerStateWithConflict(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleChangePowerStateWithConflict(t)
+
+ opts := nodes.PowerStateOpts{
+ Target: nodes.PowerOn,
+ Timeout: 100,
+ }
+
+ c := client.ServiceClient()
+ err := nodes.ChangePowerState(c, "1234asdf", opts).ExtractErr()
+ if _, ok := err.(gophercloud.ErrDefault409); !ok {
+ t.Fatal("ErrDefault409 was expected to occur")
+ }
+}
+
+func TestSetRAIDConfig(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetRAIDConfig(t)
+
+ sizeGB := 100
+ isRootVolume := true
+
+ config := nodes.RAIDConfigOpts{
+ LogicalDisks: []nodes.LogicalDisk{
+ {
+ SizeGB: &sizeGB,
+ IsRootVolume: &isRootVolume,
+ RAIDLevel: nodes.RAID1,
+ },
+ },
+ }
+
+ c := client.ServiceClient()
+ err := nodes.SetRAIDConfig(c, "1234asdf", config).ExtractErr()
+ th.AssertNoErr(t, err)
+}
+
+// Without specifying a size, we need to send a string: "MAX"
+func TestSetRAIDConfigMaxSize(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleSetRAIDConfigMaxSize(t)
+
+ isRootVolume := true
+
+ config := nodes.RAIDConfigOpts{
+ LogicalDisks: []nodes.LogicalDisk{
+ {
+ IsRootVolume: &isRootVolume,
+ RAIDLevel: nodes.RAID1,
+ },
+ },
+ }
+
+ c := client.ServiceClient()
+ err := nodes.SetRAIDConfig(c, "1234asdf", config).ExtractErr()
+ th.AssertNoErr(t, err)
+}
diff --git a/openstack/baremetal/v1/nodes/urls.go b/openstack/baremetal/v1/nodes/urls.go
index 02aedbf..75b4726 100644
--- a/openstack/baremetal/v1/nodes/urls.go
+++ b/openstack/baremetal/v1/nodes/urls.go
@@ -2,6 +2,58 @@
import "gerrit.mcp.mirantis.net/debian/gophercloud.git"
-func listURL(c *gophercloud.ServiceClient) string {
- return c.ServiceURL("nodes")
+func createURL(client *gophercloud.ServiceClient) string {
+ return client.ServiceURL("nodes")
+}
+
+func listURL(client *gophercloud.ServiceClient) string {
+ return createURL(client)
+}
+
+func listDetailURL(client *gophercloud.ServiceClient) string {
+ return client.ServiceURL("nodes", "detail")
+}
+
+func deleteURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("nodes", id)
+}
+
+func getURL(client *gophercloud.ServiceClient, id string) string {
+ return deleteURL(client, id)
+}
+
+func updateURL(client *gophercloud.ServiceClient, id string) string {
+ return deleteURL(client, id)
+}
+
+func validateURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("nodes", id, "validate")
+}
+
+func injectNMIURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("nodes", id, "management", "inject_nmi")
+}
+
+func bootDeviceURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("nodes", id, "management", "boot_device")
+}
+
+func supportedBootDeviceURL(client *gophercloud.ServiceClient, id string) string {
+ return client.ServiceURL("nodes", id, "management", "boot_device", "supported")
+}
+
+func statesResourceURL(client *gophercloud.ServiceClient, id string, state string) string {
+ return client.ServiceURL("nodes", id, "states", state)
+}
+
+func powerStateURL(client *gophercloud.ServiceClient, id string) string {
+ return statesResourceURL(client, id, "power")
+}
+
+func provisionStateURL(client *gophercloud.ServiceClient, id string) string {
+ return statesResourceURL(client, id, "provision")
+}
+
+func raidConfigURL(client *gophercloud.ServiceClient, id string) string {
+ return statesResourceURL(client, id, "raid")
}