Skip to content

Commit

Permalink
WIP use ironic inventory API
Browse files Browse the repository at this point in the history
  • Loading branch information
dtantsur committed Sep 13, 2023
1 parent 04764be commit 6525397
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
15 changes: 8 additions & 7 deletions cmd/get-hardware-details/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"os"
"strings"

"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"
"github.com/gophercloud/gophercloud/openstack/baremetal/v1/nodes"
"k8s.io/klog/v2"

"github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/clients"
"github.com/metal3-io/baremetal-operator/pkg/provisioner/ironic/hardwaredetails"
Expand All @@ -34,20 +35,20 @@ func main() {
InsecureSkipVerify: ironicInsecure,
}

inspector, err := clients.InspectorClient(opts.Endpoint, opts.AuthConfig, tlsConf)
ironic, err := clients.IronicClient(opts.Endpoint, opts.AuthConfig, tlsConf)
if err != nil {
fmt.Printf("could not get inspector client: %s", err)
fmt.Printf("could not get ironic client: %s", err)
os.Exit(1)
}

introData := introspection.GetIntrospectionData(inspector, opts.NodeID)
introData := nodes.GetInventory(ironic, opts.NodeID)
data, err := introData.Extract()
if err != nil {
fmt.Printf("could not get introspection data: %s", err)
fmt.Printf("could not get inspection data: %s", err)
os.Exit(1)
}

json, err := json.MarshalIndent(hardwaredetails.GetHardwareDetails(data), "", "\t")
json, err := json.MarshalIndent(hardwaredetails.GetHardwareDetails(data, klog.NewKlogr()), "", "\t")
if err != nil {
fmt.Printf("could not convert introspection data: %s", err)
os.Exit(1)
Expand All @@ -58,7 +59,7 @@ func main() {

func getOptions() (o options) {
if len(os.Args) != 3 {
fmt.Println("Usage: get-hardware-details <inspector URI> <node UUID>")
fmt.Println("Usage: get-hardware-details <ironic URI> <node UUID>")
os.Exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/provisioner/ironic/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func IronicClient(ironicEndpoint string, auth AuthConfig, tls TLSConfig) (client

// Ensure we have a microversion high enough to get the features
// we need. Update docs/configuration.md when updating the version.
// Version 1.74 allows retrival of the BIOS Registry
client.Microversion = "1.74"
// Version 1.81 allows retrival of Node inventory
client.Microversion = "1.81"

return updateHTTPClient(client, tls)
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/provisioner/ironic/hardwaredetails/hardwaredetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ import (
"sort"
"strings"

"github.com/go-logr/logr"
"github.com/gophercloud/gophercloud/openstack/baremetal/inventory"
"github.com/gophercloud/gophercloud/openstack/baremetal/v1/nodes"
"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"

metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
)

// GetHardwareDetails converts Ironic introspection data into BareMetalHost HardwareDetails.
func GetHardwareDetails(data *introspection.Data) *metal3api.HardwareDetails {
func GetHardwareDetails(data *nodes.InventoryData, logger logr.Logger) *metal3api.HardwareDetails {
inspectorData, err := data.PluginData.AsInspectorData()
if err != nil {
logger.Error(err, "cannot get plugin data from inventory, some fields will not be available")
}

details := new(metal3api.HardwareDetails)
details.Firmware = getFirmwareDetails(data.Inventory.SystemVendor.Firmware)
details.SystemVendor = getSystemVendorDetails(data.Inventory.SystemVendor)
details.RAMMebibytes = data.MemoryMB
details.NIC = getNICDetails(data.Inventory.Interfaces, data.AllInterfaces)
details.RAMMebibytes = data.Inventory.Memory.PhysicalMb
details.NIC = getNICDetails(data.Inventory.Interfaces, inspectorData.AllInterfaces)
details.Storage = getStorageDetails(data.Inventory.Disks)
details.CPU = getCPUDetails(&data.Inventory.CPU)
details.Hostname = data.Inventory.Hostname
Expand Down
7 changes: 3 additions & 4 deletions pkg/provisioner/ironic/ironic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/baremetal/v1/nodes"
"github.com/gophercloud/gophercloud/openstack/baremetal/v1/ports"
"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -844,8 +843,8 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar
return
}

// TODO(dtantsur): change this to use Ironic native inspection data API.
response := introspection.GetIntrospectionData(p.inspector, ironicNode.UUID)
p.log.Info("getting hardware details from inspection")
response := nodes.GetInventory(p.client, ironicNode.UUID)
introData, err := response.Extract()
if err != nil {
if _, isNotFound := err.(gophercloud.ErrDefault404); isNotFound {
Expand All @@ -860,7 +859,7 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar
// Introspection is done
p.log.Info("inspection finished successfully", "data", response.Body)

details = hardwaredetails.GetHardwareDetails(introData)
details = hardwaredetails.GetHardwareDetails(introData, p.log)
p.publisher("InspectionComplete", "Hardware inspection completed")
result, err = operationComplete()
return
Expand Down

0 comments on commit 6525397

Please sign in to comment.