github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/drivers/results.go (about)

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