MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runGuestsDelete

Function runGuestsDelete

internal/cli/guests.go:334–402  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

332}
333
334func runGuestsDelete(cmd *cobra.Command, args []string) error {
335 vmid, err := parseVMID(args[0])
336 if err != nil {
337 return printError(err)
338 }
339
340 purge, _ := cmd.Flags().GetBool("purge")
341 force, _ := cmd.Flags().GetBool("force")
342
343 session, err := initCLISession(cmd)
344 if err != nil {
345 return printError(err)
346 }
347
348 if session == nil {
349 return nil
350 }
351
352 ctx := context.Background()
353
354 vm, err := session.findVM(ctx, vmid)
355 if err != nil {
356 return printError(err)
357 }
358
359 client, err := session.clientForVM(vm)
360 if err != nil {
361 return printError(err)
362 }
363
364 upid, err := client.DeleteVMWithOptions(vm, &api.DeleteVMOptions{
365 Purge: purge,
366 Force: force,
367 })
368 if err != nil {
369 return printError(fmt.Errorf("failed to delete guest %d: %w", vmid, err))
370 }
371
372 out := struct {
373 VMID int `json:"vmid"`
374 Node string `json:"node"`
375 UPID string `json:"upid"`
376 Status string `json:"status"`
377 ExitStatus string `json:"exit_status,omitempty"`
378 }{
379 VMID: vmid,
380 Node: vm.Node,
381 UPID: upid,
382 Status: "running",
383 }
384
385 if getNoWait(cmd) {
386 return printJSON(out)
387 }
388
389 exitStatus, waitErr := waitForTask(ctx, client, vm.Node, upid, "delete guest")
390 out.Status = "complete"
391 out.ExitStatus = exitStatus

Callers

nothing calls this directly

Calls 9

parseVMIDFunction · 0.85
printErrorFunction · 0.85
initCLISessionFunction · 0.85
getNoWaitFunction · 0.85
printJSONFunction · 0.85
waitForTaskFunction · 0.85
findVMMethod · 0.80
clientForVMMethod · 0.80
DeleteVMWithOptionsMethod · 0.80

Tested by

no test coverage detected