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 676e06a commit a84273b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 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
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
4 changes: 2 additions & 2 deletions pkg/provisioner/ironic/ironic.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,15 +853,15 @@ func (p *ironicProvisioner) InspectHardware(data provisioner.InspectData, restar

// Introspection is done
p.log.Info("getting hardware details from inspection")
response := introspection.GetIntrospectionData(p.inspector, ironicNode.UUID)
response := nodes.GetInventory(p.client, ironicNode.UUID)
introData, err := response.Extract()
if err != nil {
result, err = transientError(errors.Wrap(err, "failed to retrieve hardware introspection data"))
return
}
p.log.Info("received introspection data", "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 a84273b

Please sign in to comment.