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

Method CopyStoragePoolVolume

client/incus_storage_volumes.go:628–842  ·  view source on GitHub ↗

CopyStoragePoolVolume copies an existing storage volume.

(pool string, source InstanceServer, sourcePool string, volume api.StorageVolume, args *StoragePoolVolumeCopyArgs)

Source from the content-addressed store, hash-verified

626
627// CopyStoragePoolVolume copies an existing storage volume.
628func (r *ProtocolIncus) CopyStoragePoolVolume(pool string, source InstanceServer, sourcePool string, volume api.StorageVolume, args *StoragePoolVolumeCopyArgs) (RemoteOperation, error) {
629 if !r.HasExtension("storage_api_local_volume_handling") {
630 return nil, errors.New("The server is missing the required \"storage_api_local_volume_handling\" API extension")
631 }
632
633 if args != nil && args.VolumeOnly && !r.HasExtension("storage_api_volume_snapshots") {
634 return nil, errors.New("The target server is missing the required \"storage_api_volume_snapshots\" API extension")
635 }
636
637 if args != nil && args.Refresh && !r.HasExtension("custom_volume_refresh") {
638 return nil, errors.New("The target server is missing the required \"custom_volume_refresh\" API extension")
639 }
640
641 if args != nil && args.RefreshExcludeOlder && !r.HasExtension("custom_volume_refresh_exclude_older_snapshots") {
642 return nil, errors.New("The target server is missing the required \"custom_volume_refresh_exclude_older_snapshots\" API extension")
643 }
644
645 req := api.StorageVolumesPost{
646 Name: args.Name,
647 Type: volume.Type,
648 Source: api.StorageVolumeSource{
649 Name: volume.Name,
650 Type: "copy",
651 Pool: sourcePool,
652 VolumeOnly: args.VolumeOnly,
653 Refresh: args.Refresh,
654 RefreshExcludeOlder: args.RefreshExcludeOlder,
655 },
656 }
657
658 req.Config = volume.Config
659 req.Description = volume.Description
660 req.ContentType = volume.ContentType
661
662 sourceInfo, err := source.GetConnectionInfo()
663 if err != nil {
664 return nil, fmt.Errorf("Failed to get source connection info: %w", err)
665 }
666
667 destInfo, err := r.GetConnectionInfo()
668 if err != nil {
669 return nil, fmt.Errorf("Failed to get destination connection info: %w", err)
670 }
671
672 clusterInternalVolumeCopy := r.CheckExtension("cluster_internal_custom_volume_copy") == nil
673
674 // Copy the storage pool volume locally.
675 if destInfo.URL == sourceInfo.URL && destInfo.SocketPath == sourceInfo.SocketPath && (volume.Location == r.clusterTarget || (volume.Location == "none" && r.clusterTarget == "") || clusterInternalVolumeCopy) {
676 // Project handling
677 if destInfo.Project != sourceInfo.Project {
678 if !r.HasExtension("storage_api_project") {
679 return nil, errors.New("The server is missing the required \"storage_api_project\" API extension")
680 }
681
682 req.Source.Project = sourceInfo.Project
683 }
684
685 if clusterInternalVolumeCopy {

Callers

nothing calls this directly

Calls 12

HasExtensionMethod · 0.95
GetConnectionInfoMethod · 0.95
CheckExtensionMethod · 0.95
queryOperationMethod · 0.95
proxyMigrationMethod · 0.95
ErrorfMethod · 0.80
GetConnectionInfoMethod · 0.65
WaitMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected