github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/v1/drivers/results.go (about)

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