Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Task Interface for long running functions #389

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading