Skip to content

Commit

Permalink
keep the sepatrate call for components
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVin committed Jun 19, 2023
1 parent aaf4dfa commit dd2d077
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
27 changes: 15 additions & 12 deletions internal/store/serverservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,40 @@ func (s *Serverservice) AssetByID(ctx context.Context, id string) (*model.Asset,
asset.BmcUsername = credential.Username
asset.BmcPassword = credential.Password

// query attributes
attributes, _, err := s.client.ListAttributes(ctx, deviceUUID, nil)
// query the server object
srv, _, err := s.client.Get(ctx, deviceUUID)
if err != nil {
return nil, errors.Wrap(ErrServerserviceQuery, err.Error())
}

asset.FacilityCode = srv.FacilityCode

// set bmc address
asset.BmcAddress, err = s.bmcAddressFromAttributes(attributes)
asset.BmcAddress, err = s.bmcAddressFromAttributes(srv.Attributes)
if err != nil {
return nil, err
}

// set device state attribute
asset.State, err = s.assetStateAttribute(attributes)
asset.State, err = s.assetStateAttribute(srv.Attributes)
if err != nil {
return nil, err
}

// set asset vendor attributes
asset.Vendor, asset.Model, asset.Serial, err = s.vendorModelFromAttributes(attributes)
asset.Vendor, asset.Model, asset.Serial, err = s.vendorModelFromAttributes(srv.Attributes)
if err != nil {
return nil, errors.Wrap(ErrVendorModelAttributes, err.Error())
}

// query asset component inventory
// set device state attribute
asset.State, err = s.assetStateAttribute(srv.Attributes)
if err != nil {
return nil, err
}

// query asset component inventory -- the default on the server object do not
// include all required information
components, _, err := s.client.GetComponents(ctx, deviceUUID, nil)
if err != nil {
return nil, errors.Wrap(ErrServerserviceQuery, "device component query error: "+err.Error())
Expand All @@ -198,12 +207,6 @@ func (s *Serverservice) AssetByID(ctx context.Context, id string) (*model.Asset,
// convert from serverservice components to Asset.Components
asset.Components = s.fromServerserviceComponents(components)

// set device state attribute
asset.State, err = s.assetStateAttribute(attributes)
if err != nil {
return nil, err
}

return asset, nil
}

Expand Down
12 changes: 9 additions & 3 deletions internal/worker/kv_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ type statusKVPublisher struct {

// Publish implements the statemachine Publisher interface.
func (s *statusKVPublisher) Publish(hCtx *sm.HandlerContext) {
key := fmt.Sprintf("%s.%s", hCtx.Asset.FacilityCode, hCtx.Task.ID.String())
facility := "facility"
if hCtx.Asset.FacilityCode != "" {
facility = hCtx.Asset.FacilityCode
}
key := fmt.Sprintf("%s.%s", facility, hCtx.Task.ID.String())
payload := statusFromContext(hCtx)

var err error
Expand All @@ -44,8 +48,10 @@ func (s *statusKVPublisher) Publish(hCtx *sm.HandlerContext) {

if err != nil {
s.log.WithError(err).WithFields(logrus.Fields{
"task_id": hCtx.Task.ID.String(),
"last_rev": hCtx.LastRev,
"asset_id": hCtx.Asset.ID.String(),
"asset_facility": hCtx.Asset.FacilityCode,
"task_id": hCtx.Task.ID.String(),
"last_rev": hCtx.LastRev,
}).Warn("unable to write task status")
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func New(
id, _ := os.Hostname()

return &Worker{
name: fmt.Sprintf("flasher-%s", id),
name: id,
facilityCode: facilityCode,
dryrun: dryrun,
useStatusKV: useStatusKV,
Expand Down

0 comments on commit dd2d077

Please sign in to comment.