Skip to content

Commit 5b086cc

Browse files
committed
volume backup create sourcelabel fix
1 parent e5842a9 commit 5b086cc

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

internal/cmd/volume/backup/create/create.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,26 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
7373
projectLabel = model.ProjectId
7474
}
7575

76+
// Get source name for label (use ID if name not available)
77+
sourceLabel := model.SourceID
78+
if model.SourceType == "volume" {
79+
volume, err := apiClient.GetVolume(ctx, model.ProjectId, model.SourceID).Execute()
80+
if err != nil {
81+
params.Printer.Debug(print.ErrorLevel, "get volume name: %v", err)
82+
} else if volume != nil && volume.Name != nil {
83+
sourceLabel = *volume.Name
84+
}
85+
} else if model.SourceType == "snapshot" {
86+
snapshot, err := apiClient.GetSnapshot(ctx, model.ProjectId, model.SourceID).Execute()
87+
if err != nil {
88+
params.Printer.Debug(print.ErrorLevel, "get snapshot name: %v", err)
89+
} else if snapshot != nil && snapshot.Name != nil {
90+
sourceLabel = *snapshot.Name
91+
}
92+
}
93+
7694
if !model.AssumeYes {
77-
prompt := fmt.Sprintf("Are you sure you want to create backup from %s? (This cannot be undone)", model.SourceID)
95+
prompt := fmt.Sprintf("Are you sure you want to create backup from %s? (This cannot be undone)", sourceLabel)
7896
err = params.Printer.PromptForConfirmation(prompt)
7997
if err != nil {
8098
return err
@@ -88,21 +106,23 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
88106
return fmt.Errorf("create volume backup: %w", err)
89107
}
90108

91-
// TODO: How to check if "source-name" exists?
92-
// Get source label (use ID if name not available)
93-
// sourceLabel := model.SourceID
94-
109+
// Wait for async operation, if async mode not enabled
95110
if !model.Async {
96111
s := spinner.New(params.Printer)
97112
s.Start("Creating backup")
98-
_, err = wait.CreateBackupWaitHandler(ctx, apiClient, model.ProjectId, model.SourceID).WaitWithContext(ctx)
113+
resp, err = wait.CreateBackupWaitHandler(ctx, apiClient, model.ProjectId, *resp.Id).WaitWithContext(ctx)
99114
if err != nil {
100-
return fmt.Errorf("wait for volume backup creation: %w", err)
115+
return fmt.Errorf("wait for backup creation: %w", err)
101116
}
102117
s.Stop()
103118
}
104119

105-
return outputResult(params.Printer, model.OutputFormat, model.Async, model.SourceID, projectLabel, resp)
120+
if model.Async {
121+
params.Printer.Info("Triggered backup of %q in %q. Backup ID: %s\n", sourceLabel, projectLabel, *resp.Id)
122+
} else {
123+
params.Printer.Info("Created backup of %q in %q. Backup ID: %s\n", sourceLabel, projectLabel, *resp.Id)
124+
}
125+
return nil
106126
},
107127
}
108128

0 commit comments

Comments
 (0)