MCPcopy
hub / github.com/lxc/incus / tryCreateStoragePoolVolume

Method tryCreateStoragePoolVolume

client/incus_storage_volumes.go:567–625  ·  view source on GitHub ↗

tryCreateStoragePoolVolume attempts to create a storage volume in the specified storage pool. It will try to do this on every server in the provided list of urls, and waits for the creation to be complete.

(pool string, req api.StorageVolumesPost, urls []string)

Source from the content-addressed store, hash-verified

565// tryCreateStoragePoolVolume attempts to create a storage volume in the specified storage pool.
566// It will try to do this on every server in the provided list of urls, and waits for the creation to be complete.
567func (r *ProtocolIncus) tryCreateStoragePoolVolume(pool string, req api.StorageVolumesPost, urls []string) (RemoteOperation, error) {
568 if len(urls) == 0 {
569 return nil, errors.New("The source server isn't listening on the network")
570 }
571
572 rop := remoteOperation{
573 chDone: make(chan bool),
574 }
575
576 operation := req.Source.Operation
577
578 // Forward targetOp to remote op
579 go func() {
580 success := false
581 var errors []remoteOperationResult
582 for _, serverURL := range urls {
583 req.Source.Operation = fmt.Sprintf("%s/1.0/operations/%s", serverURL, url.PathEscape(operation))
584
585 // Send the request
586 path := fmt.Sprintf("/storage-pools/%s/volumes/%s", url.PathEscape(pool), url.PathEscape(req.Type))
587 top, _, err := r.queryOperation("POST", path, req, "")
588 if err != nil {
589 errors = append(errors, remoteOperationResult{URL: serverURL, Error: err})
590 continue
591 }
592
593 rop := remoteOperation{
594 targetOp: top,
595 chDone: make(chan bool),
596 }
597
598 for _, handler := range rop.handlers {
599 _, _ = rop.targetOp.AddHandler(handler)
600 }
601
602 err = rop.targetOp.Wait()
603 if err != nil {
604 errors = append(errors, remoteOperationResult{URL: serverURL, Error: err})
605
606 if localtls.IsConnectionError(err) {
607 continue
608 }
609
610 break
611 }
612
613 success = true
614 break
615 }
616
617 if !success {
618 rop.err = remoteOperationError("Failed storage volume creation", errors)
619 }
620
621 close(rop.chDone)
622 }()
623
624 return &rop, nil

Callers 1

CopyStoragePoolVolumeMethod · 0.95

Calls 4

queryOperationMethod · 0.95
remoteOperationErrorFunction · 0.85
AddHandlerMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected