Skip to content

Commit

Permalink
Implement Task Interface where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Dec 7, 2024
1 parent ca4e9bb commit bbff06e
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 182 deletions.
7 changes: 6 additions & 1 deletion cli/command/content/iso/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ var iso_downloadCmd = &cobra.Command{
if err != nil {
return
}
err = proxmox.DownloadIsoFromUrl(cli.Context(), c, config)
ctx := cli.Context()
var task proxmox.Task
task, err = proxmox.DownloadIsoFromUrl(ctx, c, config)
if err != nil {
return
}
if err = task.WaitForCompletion(ctx, c); err != nil {
return
}
cli.PrintItemCreated(isoCmd.OutOrStdout(), config.Filename, "ISO file")
return
},
Expand Down
7 changes: 6 additions & 1 deletion cli/command/content/template/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ var template_downloadCmd = &cobra.Command{
if err != nil {
return
}
err = proxmox.DownloadLxcTemplate(cli.Context(), c, config)
ctx := cli.Context()
var task proxmox.Task
task, err = proxmox.DownloadLxcTemplate(ctx, c, config)
if err != nil {
return
}
if err = task.WaitForCompletion(ctx, c); err != nil {
return
}
cli.PrintItemCreated(templateCmd.OutOrStdout(), config.Template, "LXC Template")
return
},
Expand Down
9 changes: 7 additions & 2 deletions cli/command/create/create-snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ var (
}
memory = false
client := cli.NewClient()
ctx := cli.Context()
vmr := proxmox.NewVmRef(id)
_, err = client.GetVmInfo(cli.Context(), vmr)
_, err = client.GetVmInfo(ctx, vmr)
if err != nil {
return
}
err = config.Create(cli.Context(), client, vmr)
var task proxmox.Task
task, err = config.Create(ctx, client, vmr)
if err != nil {
return
}
if err = task.WaitForCompletion(ctx, client); err != nil {
return
}
cli.PrintItemCreated(CreateCmd.OutOrStdout(), snapName, "Snapshot")
return
},
Expand Down
11 changes: 8 additions & 3 deletions cli/command/delete/delete-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ var delete_fileCmd = &cobra.Command{
if Type.Validate() != nil {
return
}
err = proxmox.DeleteFile(cli.Context(), c, args[0], proxmox.Content_File{
ctx := cli.Context()
var task proxmox.Task
task, err = proxmox.DeleteFile(ctx, c, args[0], proxmox.Content_File{
Storage: args[1],
ContentType: Type,
FilePath: args[3],
})
FilePath: args[3]})
if err != nil {
return
}
err = task.WaitForCompletion(ctx, c)
if err != nil {
return
}
Expand Down
11 changes: 5 additions & 6 deletions cli/command/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func init() {
}

func deleteID(ctx context.Context, args []string, IDtype string) (err error) {
var exitStatus string
var task proxmox.Task
id := cli.RequiredIDset(args, 0, IDtype+"ID")
c := cli.NewClient()
switch IDtype {
case "AcmeAccount":
exitStatus, err = c.DeleteAcmeAccount(ctx, id)
task, err = c.DeleteAcmeAccount(ctx, id)
case "Group":
err = proxmox.GroupName(id).Delete(ctx, c)
case "MetricServer":
Expand All @@ -42,11 +42,10 @@ func deleteID(ctx context.Context, args []string, IDtype string) (err error) {
err = proxmox.ConfigUser{User: userId}.DeleteUser(ctx, c)
}
if err != nil {
if exitStatus != "" {
err = fmt.Errorf("error deleting %s (%s): %v, error status: %s ", IDtype, id, err, exitStatus)
}
return
return fmt.Errorf("error deleting %s (%s): %v", IDtype, id, err)
}
task.WaitForCompletion(ctx, c)

cli.PrintItemDeleted(deleteCmd.OutOrStdout(), id, IDtype)
return
}
Loading

0 comments on commit bbff06e

Please sign in to comment.