Skip to content

Commit 4999571

Browse files
committed
refactor(storage): modify command output
1 parent 3874d65 commit 4999571

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

internal/commands/storage/modify.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,34 @@ func (s *modifyCommand) Execute(exec commands.Executor, uuid string) (output.Out
156156
return nil, err
157157
}
158158

159-
logline.SetMessage(fmt.Sprintf("%s: done", msg))
159+
// If autoresize is not enabled, then just consider the whole operation done and output the modify API call response
160+
if !s.autoresizePartitionFilesystem.Value() {
161+
logline.SetMessage(fmt.Sprintf("%s: done", msg))
162+
logline.MarkDone()
160163

161-
if s.autoresizePartitionFilesystem.Value() {
162-
logline.SetMessage(fmt.Sprintf("%s: starting partition and filesystem resize", msg))
164+
return output.OnlyMarshaled{Value: res}, nil
165+
}
163166

164-
backup, err := svc.ResizeStorageFilesystem(&request.ResizeStorageFilesystemRequest{UUID: uuid})
165-
if err != nil {
166-
logline.SetMessage(ui.LiveLogEntryErrorColours.Sprintf("%s: partition and filesystem resize failed (%v); storage restored with the pre-resize attepmt backup", msg, err.Error()))
167-
logline.SetDetails(err.Error(), "error: ")
168-
} else {
169-
logline.SetMessage(fmt.Sprintf("%s: parition and filesystem resize done; created backup with UUID: %s", msg, backup.UUID))
170-
}
167+
logline.SetMessage(fmt.Sprintf("%s: resizing partition and filesystem", msg))
168+
backup, err := svc.ResizeStorageFilesystem(&request.ResizeStorageFilesystemRequest{UUID: uuid})
169+
170+
// If there was an error during resize attempt, we consider the overall modify operation successful and just log warning about failed resize
171+
if err != nil {
172+
logline.SetMessage(ui.LiveLogEntryWarningColours.Sprintf("%s: done, but partition and filesystem resize failed; storage was restored using backed taken right before resize attempt", msg))
173+
logline.SetDetails(err.Error(), "error: ")
174+
return output.OnlyMarshaled{Value: res}, nil
171175
}
172176

177+
logline.SetMessage(fmt.Sprintf("%s: done", msg))
173178
logline.MarkDone()
174179

175-
return output.OnlyMarshaled{Value: res}, nil
180+
out := struct {
181+
upcloud.StorageDetails
182+
LatestResizeBackup string `json:"latest_resize_backup,omitempty"`
183+
}{
184+
StorageDetails: *res,
185+
LatestResizeBackup: backup.UUID,
186+
}
187+
188+
return output.OnlyMarshaled{Value: out}, nil
176189
}

internal/ui/log.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ var (
2727
DisableLiveRendering: !terminal.IsStdoutTerminal(),
2828
Colours: liveLogDefaultColours,
2929
}
30+
// LiveLogEntryWarningColours specifies the colour used for warnings in LiveLog
31+
// TODO: remove cross-package dependency and make those private
32+
LiveLogEntryWarningColours = text.FgHiYellow
3033
// LiveLogEntryErrorColours specifies the colour used for errors in LiveLog
31-
// TODO: remove cross-package dependency and make this private
3234
LiveLogEntryErrorColours = text.FgHiRed
3335
)
3436

0 commit comments

Comments
 (0)