Skip to content

Commit c65dbbd

Browse files
committed
fix: review comments updates with names
1 parent 164ca11 commit c65dbbd

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

go/nautobotop/internal/nautobot/dcim/location.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (s *LocationService) Create(ctx context.Context, req nb.LocationRequest) (*
2727
s.client.AddReport("createNewLocation", "failed to create", "model", req.Name, "error", err.Error(), "response_body", bodyString)
2828
return nil, err
2929
}
30-
log.Info("CreateLocation", "created device type", locationType.Name)
30+
log.Info("CreateLocation", "created location", locationType.Name)
3131
return locationType, nil
3232
}
3333

@@ -72,7 +72,7 @@ func (s *LocationService) Update(ctx context.Context, id string, req nb.Location
7272
s.client.AddReport("UpdateLocation", "failed to update UpdateLocation", "id", id, "model", req.Name, "error", err.Error(), "response_body", bodyString)
7373
return nil, err
7474
}
75-
log.Info("successfully updated device type", "id", id, "model", locationType.GetName())
75+
log.Info("successfully updated location", "id", id, "model", locationType.GetName())
7676
return locationType, nil
7777
}
7878

go/nautobotop/internal/nautobot/sync/location.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,24 @@ func (s *LocationSync) syncLocationRecursive(ctx context.Context, location model
7272
func (s *LocationSync) syncSingleLocation(ctx context.Context, location models.Location, parentID *string) (*string, error) {
7373
existingLocation := s.locationSvc.GetByName(ctx, location.Name)
7474

75-
locationTypeRequest := nb.LocationRequest{
76-
Name: location.Name,
75+
locationRequest := nb.LocationRequest{
76+
Name: location.Name,
77+
7778
Description: nb.PtrString(location.Description),
7879
Parent: buildParentReference(parentID),
7980
LocationType: s.buildLocationTypeReference(ctx, location.LocationType),
8081
Status: s.buildStatusReference(ctx, location.Status),
8182
}
8283

8384
if existingLocation.Id == nil {
84-
return s.createLocation(ctx, locationTypeRequest)
85+
return s.createLocation(ctx, locationRequest)
8586
}
8687

87-
if !helpers.CompareJSONFields(existingLocation, locationTypeRequest) {
88-
return s.updateLocationType(ctx, *existingLocation.Id, locationTypeRequest)
88+
if !helpers.CompareJSONFields(existingLocation, locationRequest) {
89+
return s.updateLocationType(ctx, *existingLocation.Id, locationRequest)
8990
}
9091

91-
log.Info("location unchanged, skipping update", "name", locationTypeRequest.Name)
92+
log.Info("location unchanged, skipping update", "name", locationRequest.Name)
9293
return existingLocation.Id, nil
9394
}
9495

go/nautobotop/internal/nautobot/sync/rackGroup.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *RackGroupSync) SyncAll(ctx context.Context, data map[string]string) err
4141
}
4242

4343
for _, l := range rackGroups.RackGroup {
44-
if err := s.syncLocationRecursive(ctx, l, nil); err != nil {
44+
if err := s.syncRackGroupRecursive(ctx, l, nil); err != nil {
4545
return err
4646
}
4747
}
@@ -50,15 +50,15 @@ func (s *RackGroupSync) SyncAll(ctx context.Context, data map[string]string) err
5050
return nil
5151
}
5252

53-
// syncLocationRecursive processes a location and all its children recursively
54-
func (s *RackGroupSync) syncLocationRecursive(ctx context.Context, rackGroup models.RackGroup, parentID *string) error {
53+
// syncRackGroupRecursive processes a rackGroups and all its children recursively
54+
func (s *RackGroupSync) syncRackGroupRecursive(ctx context.Context, rackGroup models.RackGroup, parentID *string) error {
5555
currentID, err := s.syncSingleRackGroup(ctx, rackGroup, parentID)
5656
if err != nil {
5757
return err
5858
}
5959

6060
for _, child := range rackGroup.Children {
61-
if err := s.syncLocationRecursive(ctx, child, currentID); err != nil {
61+
if err := s.syncRackGroupRecursive(ctx, child, currentID); err != nil {
6262
return err
6363
}
6464
}
@@ -85,7 +85,7 @@ func (s *RackGroupSync) syncSingleRackGroup(ctx context.Context, rackGroup model
8585
return s.updateRackGroup(ctx, *existingRackGroup.Id, rackGroupRequest)
8686
}
8787

88-
log.Info("location unchanged, skipping update", "name", rackGroupRequest.Name)
88+
log.Info("rackGroup is unchanged, skipping update", "name", rackGroupRequest.Name)
8989
return rackGroupRequest.Id, nil
9090
}
9191

@@ -95,21 +95,21 @@ func (s *RackGroupSync) createRackGroup(ctx context.Context, request nb.RackGrou
9595
if err != nil || createdRackGroup == nil {
9696
return nil, fmt.Errorf("failed to create rackgroup %s: %w", request.Name, err)
9797
}
98-
log.Info("location created", "name", request.Name)
98+
log.Info("rackGroup created", "name", request.Name)
9999
return createdRackGroup.Id, nil
100100
}
101101

102102
// updateRackGroup updates an existing location in Nautobot
103103
func (s *RackGroupSync) updateRackGroup(ctx context.Context, id string, request nb.RackGroupRequest) (*string, error) {
104104
updatedRackGroup, err := s.rackGroupSvc.Update(ctx, id, request)
105105
if err != nil || updatedRackGroup == nil {
106-
return nil, fmt.Errorf("failed to update location %s: %w", request.Name, err)
106+
return nil, fmt.Errorf("failed to update rackGroup %s: %w", request.Name, err)
107107
}
108-
log.Info("location updated", "name", request.Name)
108+
log.Info("rackGroup updated", "name", request.Name)
109109
return updatedRackGroup.Id, nil
110110
}
111111

112-
// deleteObsoleteRackGroup removes location that are not defined in YAML
112+
// deleteObsoleteRackGroup removes rackGroup that are not defined in YAML
113113
func (s *RackGroupSync) deleteObsoleteRackGroup(ctx context.Context, rackGroups models.RackGroups) {
114114
desiredRackGroups := make(map[string]models.RackGroup)
115115
for _, rackGroup := range rackGroups.RackGroup {
@@ -123,19 +123,19 @@ func (s *RackGroupSync) deleteObsoleteRackGroup(ctx context.Context, rackGroups
123123
}
124124

125125
obsoleteRackGroup := lo.OmitByKeys(existingMap, lo.Keys(desiredRackGroups))
126-
s.deleteLocationWithDependencies(ctx, obsoleteRackGroup)
126+
s.deleteRackGroupWithDependencies(ctx, obsoleteRackGroup)
127127
}
128128

129-
// collectAllRackGroups recursively collects all location including nested children
129+
// collectAllRackGroups recursively collects all rackGroups including nested children
130130
func (s *RackGroupSync) collectAllRackGroups(rackGroup models.RackGroup, result map[string]models.RackGroup) {
131131
result[rackGroup.Name] = rackGroup
132132
for _, child := range rackGroup.Children {
133133
s.collectAllRackGroups(child, result)
134134
}
135135
}
136136

137-
// deleteLocationWithDependencies deletes location in correct order
138-
func (s *RackGroupSync) deleteLocationWithDependencies(ctx context.Context, obsoleteRackGroup map[string]nb.RackGroup) {
137+
// deleteRackGroupWithDependencies deletes rackGroups in correct order
138+
func (s *RackGroupSync) deleteRackGroupWithDependencies(ctx context.Context, obsoleteRackGroup map[string]nb.RackGroup) {
139139
idToName := make(map[string]string)
140140
for name, rackGroup := range obsoleteRackGroup {
141141
if rackGroup.Id != nil {
@@ -159,7 +159,7 @@ func (s *RackGroupSync) deleteLocationWithDependencies(ctx context.Context, obso
159159
}
160160
}
161161

162-
// deleteRackGroupRecursive deletes a location and all its children recursively
162+
// deleteRackGroupRecursive deletes a rackGroup and all its children recursively
163163
func (s *RackGroupSync) deleteRackGroupRecursive(ctx context.Context, name string, obsoleteRackGroup map[string]nb.RackGroup, childrenMap map[string][]string, deleted map[string]bool) {
164164
if deleted[name] {
165165
return

0 commit comments

Comments
 (0)