github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/inventory/plugindata.go (about)

     1  package inventory
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  type ExtraDataItem map[string]any
     9  
    10  type ExtraDataSection map[string]ExtraDataItem
    11  
    12  type ExtraDataType struct {
    13  	CPU      ExtraDataSection `json:"cpu"`
    14  	Disk     ExtraDataSection `json:"disk"`
    15  	Firmware ExtraDataSection `json:"firmware"`
    16  	IPMI     ExtraDataSection `json:"ipmi"`
    17  	Memory   ExtraDataSection `json:"memory"`
    18  	Network  ExtraDataSection `json:"network"`
    19  	System   ExtraDataSection `json:"system"`
    20  }
    21  
    22  type NUMATopology struct {
    23  	CPUs []NUMACPU `json:"cpus"`
    24  	NICs []NUMANIC `json:"nics"`
    25  	RAM  []NUMARAM `json:"ram"`
    26  }
    27  
    28  type NUMACPU struct {
    29  	CPU            int   `json:"cpu"`
    30  	NUMANode       int   `json:"numa_node"`
    31  	ThreadSiblings []int `json:"thread_siblings"`
    32  }
    33  
    34  type NUMANIC struct {
    35  	Name     string `json:"name"`
    36  	NUMANode int    `json:"numa_node"`
    37  }
    38  
    39  type NUMARAM struct {
    40  	NUMANode int `json:"numa_node"`
    41  	SizeKB   int `json:"size_kb"`
    42  }
    43  
    44  type LLDPTLVType struct {
    45  	Type  int
    46  	Value string
    47  }
    48  
    49  // UnmarshalJSON interprets an LLDP TLV [key, value] pair as an LLDPTLVType structure
    50  func (r *LLDPTLVType) UnmarshalJSON(data []byte) error {
    51  	var list []any
    52  	if err := json.Unmarshal(data, &list); err != nil {
    53  		return err
    54  	}
    55  
    56  	if len(list) != 2 {
    57  		return fmt.Errorf("Invalid LLDP TLV key-value pair")
    58  	}
    59  
    60  	fieldtype, ok := list[0].(float64)
    61  	if !ok {
    62  		return fmt.Errorf("LLDP TLV key is not number")
    63  	}
    64  
    65  	value, ok := list[1].(string)
    66  	if !ok {
    67  		return fmt.Errorf("LLDP TLV value is not string")
    68  	}
    69  
    70  	r.Type = int(fieldtype)
    71  	r.Value = value
    72  	return nil
    73  }
    74  
    75  type HardwareManager struct {
    76  	Name    string `json:"name"`
    77  	Version string `json:"version"`
    78  }
    79  
    80  type ConfigurationType struct {
    81  	// Collectors is a list of enabled collectors - ramdisk-side inspection
    82  	// plugins that populated the plugin data.
    83  	Collectors []string `json:"collectors"`
    84  	// Managers is a list of hardware managers - ramdisk-side plugins that
    85  	// implement all actions, such as writing images or collecting
    86  	// inventory.
    87  	Managers []HardwareManager `json:"managers"`
    88  }
    89  
    90  type ParsedLLDP = map[string]any
    91  
    92  type ProcessedInterfaceType struct {
    93  	InterfaceType
    94  	// Whether PXE was enabled on this interface during inspection
    95  	PXEEnabled bool `json:"pxe_enabled"`
    96  }
    97  
    98  // StandardPluginData represents the plugin data as collected and processes
    99  // by a standard ramdisk and a standard Ironic deployment.
   100  // The format and contents of the stored data depends on the ramdisk used
   101  // and plugins enabled both in the ramdisk and in inspector itself.
   102  // This structure has been provided for basic compatibility but it
   103  // will need extensions.
   104  type StandardPluginData struct {
   105  	AllInterfaces   map[string]ProcessedInterfaceType `json:"all_interfaces"`
   106  	BootInterface   string                            `json:"boot_interface"`
   107  	Configuration   ConfigurationType                 `json:"configuration"`
   108  	Error           string                            `json:"error"`
   109  	Extra           ExtraDataType                     `json:"extra"`
   110  	MACs            []string                          `json:"macs"`
   111  	NUMATopology    NUMATopology                      `json:"numa_topology"`
   112  	ParsedLLDP      map[string]ParsedLLDP             `json:"parsed_lldp"`
   113  	RawLLDP         map[string][]LLDPTLVType          `json:"lldp_raw"`
   114  	RootDisk        RootDiskType                      `json:"root_disk"`
   115  	ValidInterfaces map[string]ProcessedInterfaceType `json:"valid_interfaces"`
   116  }