Skip to content

Commit

Permalink
refactor: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng-20 committed Oct 7, 2024
1 parent b3f2d72 commit 9f47172
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/api/api_default_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (cfm *CfmApiService) BladesUpdateById(ctx context.Context, applianceId stri
}

//Rename the appliance with the new id
newBlade, err := manager.RenameBlade(ctx, blade, newBladeId)
newBlade, err := manager.RenameBlade(ctx, appliance, blade, newBladeId)
if err != nil {
return formatErrorResp(ctx, err.(*common.RequestError))
}
Expand Down
22 changes: 3 additions & 19 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,10 @@ func RenameAppliance(ctx context.Context, appliance *Appliance, newApplianceId s
logger := klog.FromContext(ctx)
logger.V(4).Info(">>>>>> RenameApplianceById: ", "applianceId", appliance.Id)

// query cache
existingAppliance, ok := deviceCache.GetApplianceByIdOk(appliance.Id)
if !ok {
newErr := fmt.Errorf("failed to get appliance [%s]", appliance.Id)
logger.Error(newErr, "failure: get appliance by id")
return nil, &common.RequestError{StatusCode: common.StatusApplianceIdDoesNotExist, Err: newErr}
}

// Store the associated blades information locally, which is needed when adding back the blades
bladesInfo := make(map[string]*Blade)
for _, id := range existingAppliance.GetAllBladeIds() {
bladesInfo[id] = existingAppliance.Blades[id]
for _, id := range appliance.GetAllBladeIds() {
bladesInfo[id] = appliance.Blades[id]
}

// delete appliance and the associated blades
Expand Down Expand Up @@ -178,18 +170,10 @@ func RenameAppliance(ctx context.Context, appliance *Appliance, newApplianceId s
}
}

func RenameBlade(ctx context.Context, blade *Blade, newBladeId string) (*Blade, error) {
func RenameBlade(ctx context.Context, appliance *Appliance, blade *Blade, newBladeId string) (*Blade, error) {
logger := klog.FromContext(ctx)
logger.V(4).Info(">>>>>> RenameBladeById: ", "bladeId", blade.Id)

// query cache
appliance, ok := deviceCache.GetApplianceByIdOk(blade.ApplianceId)
if !ok {
newErr := fmt.Errorf("failed to get appliance [%s]", blade.ApplianceId)
logger.Error(newErr, "failure: get appliance by id")
return nil, &common.RequestError{StatusCode: common.StatusApplianceIdDoesNotExist, Err: newErr}
}

// Save the blade credentials for adding back with the new name
c := &openapi.Credentials{
Username: blade.creds.Username,
Expand Down

0 comments on commit 9f47172

Please sign in to comment.