(cmd *cobra.Command, args []string)
| 562 | } |
| 563 | |
| 564 | func runStorageDownloadTemplate(cmd *cobra.Command, args []string) error { |
| 565 | ctx := context.Background() |
| 566 | nodeName := args[0] |
| 567 | storageName := args[1] |
| 568 | templateArg := args[2] |
| 569 | |
| 570 | section, _ := cmd.Flags().GetString("section") |
| 571 | |
| 572 | session, err := initCLISession(cmd) |
| 573 | if err != nil { |
| 574 | return printError(err) |
| 575 | } |
| 576 | |
| 577 | if session == nil { |
| 578 | return nil |
| 579 | } |
| 580 | |
| 581 | client, err := session.clientForNode(ctx, nodeName) |
| 582 | if err != nil { |
| 583 | return printError(err) |
| 584 | } |
| 585 | |
| 586 | resolvedFilename := templateArg |
| 587 | if !strings.Contains(templateArg, ".") { |
| 588 | resolvedFilename, err = resolveTemplateName(client, nodeName, templateArg, section) |
| 589 | if err != nil { |
| 590 | return printError(err) |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | upid, err := client.DownloadApplianceTemplate(nodeName, storageName, resolvedFilename) |
| 595 | if err != nil { |
| 596 | return printError(fmt.Errorf("failed to start template download: %w", err)) |
| 597 | } |
| 598 | |
| 599 | out := storageTaskOutput{ |
| 600 | Node: nodeName, |
| 601 | Storage: storageName, |
| 602 | Template: resolvedFilename, |
| 603 | UPID: upid, |
| 604 | Status: "running", |
| 605 | } |
| 606 | |
| 607 | if getNoWait(cmd) { |
| 608 | return printJSON(out) |
| 609 | } |
| 610 | |
| 611 | exitStatus, waitErr := waitForTask(ctx, client, nodeName, upid, "download template") |
| 612 | out.Status = "complete" |
| 613 | out.ExitStatus = exitStatus |
| 614 | |
| 615 | if err := printJSON(out); err != nil { |
| 616 | return err |
| 617 | } |
| 618 | |
| 619 | if waitErr != nil { |
| 620 | return waitErr |
| 621 | } |
nothing calls this directly
no test coverage detected