|
9 | 9 | "errors" |
10 | 10 | "fmt" |
11 | 11 | "net/url" |
| 12 | + "time" |
12 | 13 |
|
13 | 14 | "github.com/ovh/ovhcloud-cli/internal/display" |
14 | 15 | "github.com/ovh/ovhcloud-cli/internal/flags" |
@@ -169,7 +170,18 @@ func EditVolume(_ *cobra.Command, args []string) { |
169 | 170 | return |
170 | 171 | } |
171 | 172 |
|
172 | | - display.OutputInfo(&flags.OutputFormatConfig, updated, "✅ Volume %s updated successfully", args[0]) |
| 173 | + if !flags.WaitForTask { |
| 174 | + display.OutputInfo(&flags.OutputFormatConfig, updated, "⚡️ Volume %s update started", args[0]) |
| 175 | + return |
| 176 | + } |
| 177 | + |
| 178 | + ready, err := waitForCloudResourceReady(endpoint, 10*time.Minute) |
| 179 | + if err != nil { |
| 180 | + display.OutputError(&flags.OutputFormatConfig, "failed to wait for volume update: %s", err) |
| 181 | + return |
| 182 | + } |
| 183 | + |
| 184 | + display.OutputInfo(&flags.OutputFormatConfig, ready, "✅ Volume %s updated successfully", args[0]) |
173 | 185 | } |
174 | 186 |
|
175 | 187 | func CreateVolume(_ *cobra.Command, args []string) { |
@@ -214,7 +226,20 @@ func CreateVolume(_ *cobra.Command, args []string) { |
214 | 226 | return |
215 | 227 | } |
216 | 228 |
|
217 | | - display.OutputInfo(&flags.OutputFormatConfig, response, "✅ Volume %s created successfully", response["id"]) |
| 229 | + volumeID, _ := response["id"].(string) |
| 230 | + |
| 231 | + if !flags.WaitForTask { |
| 232 | + display.OutputInfo(&flags.OutputFormatConfig, response, "⚡️ Volume %s creation started", volumeID) |
| 233 | + return |
| 234 | + } |
| 235 | + |
| 236 | + ready, err := waitForCloudResourceReady(fmt.Sprintf("%s/%s", volumeV2Endpoint(projectID), url.PathEscape(volumeID)), 10*time.Minute) |
| 237 | + if err != nil { |
| 238 | + display.OutputError(&flags.OutputFormatConfig, "failed to wait for volume creation: %s", err) |
| 239 | + return |
| 240 | + } |
| 241 | + |
| 242 | + display.OutputInfo(&flags.OutputFormatConfig, ready, "✅ Volume %s created successfully", volumeID) |
218 | 243 | } |
219 | 244 |
|
220 | 245 | func DeleteVolume(_ *cobra.Command, args []string) { |
@@ -304,7 +329,20 @@ func CreateVolumeSnapshot(_ *cobra.Command, args []string) { |
304 | 329 | return |
305 | 330 | } |
306 | 331 |
|
307 | | - display.OutputInfo(&flags.OutputFormatConfig, response, "✅ Snapshot for volume %s created successfully, id : %s", args[0], response["id"]) |
| 332 | + snapshotID, _ := response["id"].(string) |
| 333 | + |
| 334 | + if !flags.WaitForTask { |
| 335 | + display.OutputInfo(&flags.OutputFormatConfig, response, "⚡️ Snapshot %s creation started for volume %s", snapshotID, args[0]) |
| 336 | + return |
| 337 | + } |
| 338 | + |
| 339 | + ready, err := waitForCloudResourceReady(fmt.Sprintf("%s/%s", endpoint, url.PathEscape(snapshotID)), 10*time.Minute) |
| 340 | + if err != nil { |
| 341 | + display.OutputError(&flags.OutputFormatConfig, "failed to wait for snapshot creation: %s", err) |
| 342 | + return |
| 343 | + } |
| 344 | + |
| 345 | + display.OutputInfo(&flags.OutputFormatConfig, ready, "✅ Snapshot %s created successfully for volume %s", snapshotID, args[0]) |
308 | 346 | } |
309 | 347 |
|
310 | 348 | func ListVolumeSnapshots(cmd *cobra.Command, _ []string) { |
@@ -406,7 +444,20 @@ func CreateVolumeBackup(_ *cobra.Command, args []string) { |
406 | 444 | return |
407 | 445 | } |
408 | 446 |
|
409 | | - display.OutputInfo(&flags.OutputFormatConfig, response, "✅ Volume backup for volume %s created successfully (id: %s)", args[0], response["id"]) |
| 447 | + backupID, _ := response["id"].(string) |
| 448 | + |
| 449 | + if !flags.WaitForTask { |
| 450 | + display.OutputInfo(&flags.OutputFormatConfig, response, "⚡️ Backup %s creation started for volume %s", backupID, args[0]) |
| 451 | + return |
| 452 | + } |
| 453 | + |
| 454 | + ready, err := waitForCloudResourceReady(fmt.Sprintf("%s/%s", endpoint, url.PathEscape(backupID)), 30*time.Minute) |
| 455 | + if err != nil { |
| 456 | + display.OutputError(&flags.OutputFormatConfig, "failed to wait for backup creation: %s", err) |
| 457 | + return |
| 458 | + } |
| 459 | + |
| 460 | + display.OutputInfo(&flags.OutputFormatConfig, ready, "✅ Volume backup %s created successfully for volume %s", backupID, args[0]) |
410 | 461 | } |
411 | 462 |
|
412 | 463 | // findVolumeBackupV1 locates a volume backup across all regions using the v1 API. |
|
0 commit comments