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

Function runStorageDownloadURL

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

Source from the content-addressed store, hash-verified

459}
460
461func runStorageDownloadURL(cmd *cobra.Command, args []string) error {
462 ctx := context.Background()
463 nodeName := args[0]
464 storageName := args[1]
465 rawURL := args[2]
466
467 filename, _ := cmd.Flags().GetString("filename")
468 contentType, _ := cmd.Flags().GetString("content-type")
469
470 if contentType == "" {
471 contentType = inferContentTypeFromURL(rawURL)
472 }
473
474 if contentType == "" {
475 return printError(fmt.Errorf("cannot infer content type from URL %q — use --content-type iso|vztmpl|import", rawURL))
476 }
477
478 if filename == "" {
479 filename = rawURL
480 if idx := strings.LastIndex(filename, "/"); idx >= 0 {
481 filename = filename[idx+1:]
482 }
483 if idx := strings.Index(filename, "?"); idx >= 0 {
484 filename = filename[:idx]
485 }
486 }
487
488 session, err := initCLISession(cmd)
489 if err != nil {
490 return printError(err)
491 }
492
493 if session == nil {
494 return nil
495 }
496
497 client, err := session.clientForNode(ctx, nodeName)
498 if err != nil {
499 return printError(err)
500 }
501
502 upid, err := client.DownloadStorageContentFromURL(nodeName, storageName, api.StorageDownloadURLOptions{
503 URL: rawURL,
504 Content: contentType,
505 Filename: filename,
506 })
507 if err != nil {
508 return printError(fmt.Errorf("failed to start download: %w", err))
509 }
510
511 out := storageTaskOutput{
512 Node: nodeName,
513 Storage: storageName,
514 URL: rawURL,
515 Filename: filename,
516 UPID: upid,
517 Status: "running",
518 }

Callers

nothing calls this directly

Calls 8

inferContentTypeFromURLFunction · 0.85
printErrorFunction · 0.85
initCLISessionFunction · 0.85
getNoWaitFunction · 0.85
printJSONFunction · 0.85
waitForTaskFunction · 0.85
clientForNodeMethod · 0.80

Tested by

no test coverage detected