diff --git a/.version b/.version index ba0a7191..a63cb35e 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.51.0 +1.52.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7925ea29..0f307e32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.52.0] - 2022-06-03 + +### Changed + +- HSM now uses the 'Class' from SLS + ## [1.51.0] - 2022-05-10 ### Changed diff --git a/cmd/smd/components.go b/cmd/smd/components.go index d86f7dba..b72f9bf9 100644 --- a/cmd/smd/components.go +++ b/cmd/smd/components.go @@ -1,6 +1,6 @@ // MIT License // -// (C) Copyright [2018-2021] Hewlett Packard Enterprise Development LP +// (C) Copyright [2018-2022] Hewlett Packard Enterprise Development LP // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -103,7 +103,15 @@ func (s *SmD) DiscoverComponentChassis(chEP *rf.EpChassis) *base.Component { comp.Class = base.ClassMountain.String() // Just incase our redfish endpoint didn't exist when our child // components were discovered, update them to be Mountain too. - children, err := s.db.GetComponentsQuery(nil, hmsds.FLTR_ID_ONLY, []string{comp.ID}) + f := hmsds.ComponentFilter{ + Type: []string{ + base.NodeBMC.String(), + base.NodeEnclosure.String(), + base.Node.String(), + base.RouterBMC.String(), + }, + } + children, err := s.db.GetComponentsQuery(&f, hmsds.FLTR_ID_ONLY, []string{comp.ID}) if err != nil { s.LogAlways("DiscoverComponentChassis: Could not get child components for %s: %s", comp.ID, err) } else { @@ -174,9 +182,9 @@ func (s *SmD) DiscoverComponentSystem(sysEP *rf.EpSystem) *base.Component { comp.Subtype = sysEP.Subtype comp.Arch = sysEP.Arch comp.NetType = sysEP.NetType - comp.Class = sysEP.DefaultClass - newNID, defRole, defSubRole := s.GetCompDefaults(comp.ID, sysEP.DefaultRole, sysEP.DefaultSubRole) + newNID, defRole, defSubRole, defClass := s.GetCompDefaults(comp.ID, sysEP.DefaultRole, sysEP.DefaultSubRole, sysEP.DefaultClass) + comp.Class = defClass comp.Role = defRole comp.SubRole = defSubRole comp.NID = json.Number(strconv.FormatUint(newNID, 10)) @@ -328,11 +336,12 @@ func (s *SmD) DiscoverComponentOutlet(outEP *rf.EpOutlet) *base.Component { } // Get default NID and Role from SLS or the uploaded NodeMaps in priority order. -func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64, string, string) { +func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole, defaultClass string) (uint64, string, string, string) { var ( nid uint64 role string subRole string + class string ) if s.sls != nil { nodeInfo, err := s.sls.GetNodeInfo(xname) @@ -342,6 +351,7 @@ func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64 nid = uint64(nodeInfo.NID) role = nodeInfo.Role subRole = nodeInfo.SubRole + class = nodeInfo.Class } } if nid == 0 || len(role) == 0 { @@ -368,7 +378,10 @@ func (s *SmD) GetCompDefaults(xname, defaultRole, defaultSubRole string) (uint64 role = defaultRole subRole = defaultSubRole } - return nid, role, subRole + if class == "" { + class = defaultClass + } + return nid, role, subRole, class } // Get a bogus nid for an xname diff --git a/cmd/smd/smd-api.go b/cmd/smd/smd-api.go index b0ae48ad..37c1a0ff 100644 --- a/cmd/smd/smd-api.go +++ b/cmd/smd/smd-api.go @@ -506,8 +506,8 @@ func (s *SmD) doComponentsPost(w http.ResponseWriter, r *http.Request) { // Get the nid and role defaults for all node types for _, comp := range compsIn.Components { if comp.Type == base.Node.String() { - if len(comp.Role) == 0 || len(comp.NID) == 0 { - newNID, defRole, defSubRole := s.GetCompDefaults(comp.ID, base.RoleCompute.String(), "") + if len(comp.Role) == 0 || len(comp.NID) == 0 || len(comp.Class) == 0 { + newNID, defRole, defSubRole, defClass := s.GetCompDefaults(comp.ID, base.RoleCompute.String(), "", "") if len(comp.Role) == 0 { comp.Role = defRole } @@ -517,6 +517,9 @@ func (s *SmD) doComponentsPost(w http.ResponseWriter, r *http.Request) { if len(comp.NID) == 0 { comp.NID = json.Number(strconv.FormatUint(newNID, 10)) } + if len(comp.Class) == 0 { + comp.Class = defClass + } } } } @@ -1048,8 +1051,8 @@ func (s *SmD) doComponentPut(w http.ResponseWriter, r *http.Request) { } // Get the nid and role defaults for all node types if component.Type == base.Node.String() { - if len(component.Role) == 0 || len(component.NID) == 0 { - newNID, defRole, defSubRole := s.GetCompDefaults(component.ID, base.RoleCompute.String(), "") + if len(component.Role) == 0 || len(component.NID) == 0 || len(component.Class) == 0 { + newNID, defRole, defSubRole, defClass := s.GetCompDefaults(component.ID, base.RoleCompute.String(), "", "") if len(component.Role) == 0 { component.Role = defRole } @@ -1059,6 +1062,9 @@ func (s *SmD) doComponentPut(w http.ResponseWriter, r *http.Request) { if len(component.NID) == 0 { component.NID = json.Number(strconv.FormatUint(newNID, 10)) } + if len(component.Class) == 0 { + component.Class = defClass + } } } changeMap, err := s.db.UpsertComponents([]*base.Component{component}, compIn.Force) diff --git a/internal/slsapi/slsapi.go b/internal/slsapi/slsapi.go index 550a7c5a..160f8bd6 100644 --- a/internal/slsapi/slsapi.go +++ b/internal/slsapi/slsapi.go @@ -1,6 +1,6 @@ // MIT License // -// (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP +// (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -64,6 +64,13 @@ type ComptypeNode struct { SubRole string `json:"SubRole"` } +type NodeInfo struct { + NID int `json:"NID,omitempty"` + Role string `json:"Role"` + SubRole string `json:"SubRole"` + Class string `json:"Class"` +} + var serviceName string // Allocate and initialize new SLS struct. @@ -125,38 +132,46 @@ func (sls *SLS) IsReady() (bool, error) { // Query SLS for node information. This just picks up the ExtraProperties // struct for nodes from SLS. -func (sls *SLS) GetNodeInfo(id string) (ComptypeNode, error) { +func (sls *SLS) GetNodeInfo(id string) (NodeInfo, error) { var nh NodeHardware // Validate inputs if sls.Url == nil { - return ComptypeNode{}, fmt.Errorf("SLS struct has no URL") + return NodeInfo{}, fmt.Errorf("SLS struct has no URL") } if len(id) == 0 { - return ComptypeNode{}, fmt.Errorf("Id is missing") + return NodeInfo{}, fmt.Errorf("Id is missing") } // Construct a GET to /hardware/ for SLS to get the node info uri := sls.Url.String() + "/hardware/" + id req, err := http.NewRequest(http.MethodGet, uri, nil) if err != nil { - return ComptypeNode{}, err + return NodeInfo{}, err } body, err := sls.doRequest(req) if err != nil { - return ComptypeNode{}, err + return NodeInfo{}, err } // SLS returns null if the component was not found if body == nil { - return ComptypeNode{}, nil + return NodeInfo{}, nil } err = json.Unmarshal(body, &nh) if err != nil { - return ComptypeNode{}, err + return NodeInfo{}, err + } + + // Grab the fields we care about + nodeInfo := NodeInfo{ + NID: nh.ExtraProperties.NID, + Role: nh.ExtraProperties.Role, + SubRole: nh.ExtraProperties.SubRole, + Class: nh.Class, } - return nh.ExtraProperties, nil + return nodeInfo, nil } // doRequest sends a HTTP request to SLS