Skip to content

Commit 3874d65

Browse files
kamil cybulskika-myl
authored andcommitted
feat(storage): add partition and filesystem autoresize option
1 parent 21ea18d commit 3874d65

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

internal/commands/storage/modify.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/UpCloudLtd/upcloud-cli/internal/commands"
88
"github.com/UpCloudLtd/upcloud-cli/internal/completion"
9+
"github.com/UpCloudLtd/upcloud-cli/internal/config"
910
"github.com/UpCloudLtd/upcloud-cli/internal/output"
1011
"github.com/UpCloudLtd/upcloud-cli/internal/resolver"
1112
"github.com/UpCloudLtd/upcloud-cli/internal/ui"
@@ -20,7 +21,8 @@ type modifyCommand struct {
2021
*commands.BaseCommand
2122
completion.Storage
2223
resolver.CachingStorage
23-
params modifyParams
24+
params modifyParams
25+
autoresizePartitionFilesystem config.OptionalBoolean
2426
}
2527

2628
type modifyParams struct {
@@ -66,6 +68,7 @@ func (s *modifyCommand) InitCommand() {
6668
flagSet.StringVar(&s.params.backupTime, "backup-time", s.params.backupTime, "The time when to create a backup in HH:MM. Empty value means no backups.")
6769
flagSet.StringVar(&s.params.backupInterval, "backup-interval", "", "The interval of the backup.\nAvailable: daily,mon,tue,wed,thu,fri,sat,sun")
6870
flagSet.IntVar(&s.params.backupRetention, "backup-retention", 0, "How long to store the backups in days. The accepted range is 1-1095.")
71+
config.AddEnableOrDisableFlag(flagSet, &s.autoresizePartitionFilesystem, false, "filesystem-autoresize", "automatic resize of partition and filesystem when modifying storage size. Note that before the resize attempt is made, backup of the storage will be taken. If the resize attempt fails, the backup will be used to restore the storage and then deleted. If the resize attempt succeeds, backup will be kept. Taking and keeping backups incure costs.")
6972

7073
s.AddFlags(flagSet)
7174
}
@@ -129,6 +132,10 @@ func setBackupFields(storageUUID string, p modifyParams, service service.Storage
129132

130133
// Execute implements commands.MultipleArgumentCommand
131134
func (s *modifyCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) {
135+
if s.autoresizePartitionFilesystem.Value() && s.params.Size == 0 {
136+
return nil, fmt.Errorf("filesystem autoresize is enabled, but new size is not specified")
137+
}
138+
132139
svc := exec.Storage()
133140
msg := fmt.Sprintf("modifing storage %v", uuid)
134141
logline := exec.NewLogEntry(msg)
@@ -150,6 +157,19 @@ func (s *modifyCommand) Execute(exec commands.Executor, uuid string) (output.Out
150157
}
151158

152159
logline.SetMessage(fmt.Sprintf("%s: done", msg))
160+
161+
if s.autoresizePartitionFilesystem.Value() {
162+
logline.SetMessage(fmt.Sprintf("%s: starting partition and filesystem resize", msg))
163+
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+
}
171+
}
172+
153173
logline.MarkDone()
154174

155175
return output.OnlyMarshaled{Value: res}, nil

0 commit comments

Comments
 (0)