github.com/openshift/installer@v1.4.17/pkg/types/baremetal/rootdevice.go (about)

     1  package baremetal
     2  
     3  // This package replicates the code from
     4  // https://github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/devicehints
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  
    10  	"github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
    11  )
    12  
    13  // RootDeviceHints holds the hints for specifying the storage location
    14  // for the root filesystem for the image.
    15  type RootDeviceHints struct {
    16  	// A Linux device name like "/dev/vda". The hint must match the
    17  	// actual value exactly.
    18  	DeviceName string `json:"deviceName,omitempty"`
    19  
    20  	// A SCSI bus address like 0:0:0:0. The hint must match the actual
    21  	// value exactly.
    22  	HCTL string `json:"hctl,omitempty"`
    23  
    24  	// A vendor-specific device identifier. The hint can be a
    25  	// substring of the actual value.
    26  	Model string `json:"model,omitempty"`
    27  
    28  	// The name of the vendor or manufacturer of the device. The hint
    29  	// can be a substring of the actual value.
    30  	Vendor string `json:"vendor,omitempty"`
    31  
    32  	// Device serial number. The hint must match the actual value
    33  	// exactly.
    34  	SerialNumber string `json:"serialNumber,omitempty"`
    35  
    36  	// The minimum size of the device in Gigabytes.
    37  	// +kubebuilder:validation:Minimum=0
    38  	MinSizeGigabytes int `json:"minSizeGigabytes,omitempty"`
    39  
    40  	// Unique storage identifier. The hint must match the actual value
    41  	// exactly.
    42  	WWN string `json:"wwn,omitempty"`
    43  
    44  	// Unique storage identifier with the vendor extension
    45  	// appended. The hint must match the actual value exactly.
    46  	WWNWithExtension string `json:"wwnWithExtension,omitempty"`
    47  
    48  	// Unique vendor storage identifier. The hint must match the
    49  	// actual value exactly.
    50  	WWNVendorExtension string `json:"wwnVendorExtension,omitempty"`
    51  
    52  	// True if the device should use spinning media, false otherwise.
    53  	Rotational *bool `json:"rotational,omitempty"`
    54  }
    55  
    56  // MakeHintMap converts a RootDeviceHints instance into a string map
    57  // suitable to pass to ironic.
    58  func (source *RootDeviceHints) MakeHintMap() map[string]string {
    59  	hints := map[string]string{}
    60  
    61  	if source == nil {
    62  		return hints
    63  	}
    64  
    65  	if source.DeviceName != "" {
    66  		if strings.HasPrefix(source.DeviceName, "/dev/disk/by-path/") {
    67  			hints["by_path"] = fmt.Sprintf("s== %s", source.DeviceName)
    68  		} else {
    69  			hints["name"] = fmt.Sprintf("s== %s", source.DeviceName)
    70  		}
    71  	}
    72  	if source.HCTL != "" {
    73  		hints["hctl"] = fmt.Sprintf("s== %s", source.HCTL)
    74  	}
    75  	if source.Model != "" {
    76  		hints["model"] = fmt.Sprintf("<in> %s", source.Model)
    77  	}
    78  	if source.Vendor != "" {
    79  		hints["vendor"] = fmt.Sprintf("<in> %s", source.Vendor)
    80  	}
    81  	if source.SerialNumber != "" {
    82  		hints["serial"] = fmt.Sprintf("s== %s", source.SerialNumber)
    83  	}
    84  	if source.MinSizeGigabytes != 0 {
    85  		hints["size"] = fmt.Sprintf(">= %d", source.MinSizeGigabytes)
    86  	}
    87  	if source.WWN != "" {
    88  		hints["wwn"] = fmt.Sprintf("s== %s", source.WWN)
    89  	}
    90  	if source.WWNWithExtension != "" {
    91  		hints["wwn_with_extension"] = fmt.Sprintf("s== %s", source.WWNWithExtension)
    92  	}
    93  	if source.WWNVendorExtension != "" {
    94  		hints["wwn_vendor_extension"] = fmt.Sprintf("s== %s", source.WWNVendorExtension)
    95  	}
    96  	switch {
    97  	case source.Rotational == nil:
    98  	case *source.Rotational:
    99  		hints["rotational"] = "true"
   100  	case !*source.Rotational:
   101  		hints["rotational"] = "false"
   102  	}
   103  
   104  	return hints
   105  }
   106  
   107  // MakeCRDHints returns the hints in the format needed to pass to
   108  // create a BareMetalHost resource.
   109  func (source *RootDeviceHints) MakeCRDHints() *v1alpha1.RootDeviceHints {
   110  	if source == nil {
   111  		return nil
   112  	}
   113  	return &v1alpha1.RootDeviceHints{
   114  		DeviceName:         source.DeviceName,
   115  		HCTL:               source.HCTL,
   116  		Model:              source.Model,
   117  		Vendor:             source.Vendor,
   118  		SerialNumber:       source.SerialNumber,
   119  		MinSizeGigabytes:   source.MinSizeGigabytes,
   120  		WWN:                source.WWN,
   121  		WWNWithExtension:   source.WWNWithExtension,
   122  		WWNVendorExtension: source.WWNVendorExtension,
   123  		Rotational:         source.Rotational,
   124  	}
   125  }