// ReleaseVolumes is specified on the storage.VolumeSource interface.
196492
func (s *oracleVolumeSource) ReleaseVolumes(ctx context.ProviderCallContext, volIds []string) ([]error, error) {
	releaseStorageVolume := func(volumeId string) error {
		details, err := s.api.StorageVolumeDetails(volumeId)
		if err != nil {
			return errors.Trace(err)
		}
		var newTags []string
		for _, tag := range details.Tags {
			fields := strings.Split(tag, "=")
			if len(fields) != 2 {
				newTags = append(newTags, tag)
				continue
			}
			switch fields[0] {
			case tags.JujuController, tags.JujuModel:
			default:
				newTags = append(newTags, tag)
			}
		}
		if len(newTags) == len(details.Tags) {
			return nil
		}
		details.Tags = newTags
		return errors.Trace(s.updateVolume(volumeId, details))
	}
	return foreachVolume(volIds, releaseStorageVolume), nil
}
669316
func (v *azureVolumeSource) CreateVolumes(ctx context.ProviderCallContext, params []storage.VolumeParams) (_ []storage.CreateVolumesResult, err error) {
	results := make([]storage.CreateVolumesResult, len(params))
	for i, p := range params {
		if err := v.ValidateVolumeParams(p); err != nil {
			results[i].Error = err
			continue
		}
	}
	if v.maybeStorageClient == nil {
		v.createManagedDiskVolumes(ctx, params, results)
		return results, nil
	}
	return results, v.createUnmanagedDiskVolumes(ctx, params, results)
}
1090563
func (s *MountPoint) SetSourceVolume(v string) *MountPoint {
	s.SourceVolume = &v
	return s
}
759115
func (s *cinderVolumeSource) CreateVolumes(ctx context.ProviderCallContext, args []storage.VolumeParams) ([]storage.CreateVolumesResult, error) {
	results := make([]storage.CreateVolumesResult, len(args))
	for i, arg := range args {
		volume, err := s.createVolume(arg)
		if err != nil {
			results[i].Error = errors.Trace(err)
			if denied := common.MaybeHandleCredentialError(IsAuthorisationFailure, err, ctx); denied {
				// If it is an unauthorised error, no need to continue since we will 100% fail...
				break
			}
			continue
		}
		results[i].Volume = volume
	}
	return results, nil
}
229866
func ReleaseResources(r *Resources, vm *uvm.UtilityVM, all bool) error {
	if vm != nil && r.addedNetNSToVM {
		if err := vm.RemoveNetNS(r.netNS); err != nil {
			logrus.Warn(err)
		}
		r.addedNetNSToVM = false
	}

	if r.createdNetNS {
		for len(r.networkEndpoints) != 0 {
			endpoint := r.networkEndpoints[len(r.networkEndpoints)-1]
			err := hns.RemoveNamespaceEndpoint(r.netNS, endpoint)
			if err != nil {
				if !os.IsNotExist(err) {
					return err
				}
				logrus.Warnf("removing endpoint %s from namespace %s: does not exist", endpoint, r.NetNS())
			}
			r.networkEndpoints = r.networkEndpoints[:len(r.networkEndpoints)-1]
		}
		r.networkEndpoints = nil
		err := hns.RemoveNamespace(r.netNS)
		if err != nil && !os.IsNotExist(err) {
			return err
		}
		r.createdNetNS = false
	}

	if len(r.layers) != 0 {
		op := UnmountOperationSCSI
		if vm == nil || all {
			op = UnmountOperationAll
		}
		err := UnmountContainerLayers(r.layers, r.containerRootInUVM, vm, op)
		if err != nil {
			return err
		}
		r.layers = nil
	}

	if all {
		for len(r.vsmbMounts) != 0 {
			mount := r.vsmbMounts[len(r.vsmbMounts)-1]
			if err := vm.RemoveVSMB(mount); err != nil {
				return err
			}
			r.vsmbMounts = r.vsmbMounts[:len(r.vsmbMounts)-1]
		}

		for len(r.plan9Mounts) != 0 {
			mount := r.plan9Mounts[len(r.plan9Mounts)-1]
			if err := vm.RemovePlan9(mount); err != nil {
				return err
			}
			r.plan9Mounts = r.plan9Mounts[:len(r.plan9Mounts)-1]
		}

		for _, path := range r.scsiMounts {
			if err := vm.RemoveSCSI(path); err != nil {
				return err
			}
			r.scsiMounts = nil
		}
	}

	return nil
}
1031933
func (sb *storageBackend) AllVolumes() ([]Volume, error) {
	volumes, err := sb.volumes(nil)
	if err != nil {
		return nil, errors.Annotate(err, "cannot get volumes")
	}
	return volumesToInterfaces(volumes), nil
}
1013572
func (s *noopFilesystemSource) ReleaseFilesystems(ctx environscontext.ProviderCallContext, filesystemIds []string) ([]error, error) {
	return make([]error, len(filesystemIds)), nil
}
619875
func (s *DeleteInstanceInput) SetDeleteVolumes(v bool) *DeleteInstanceInput {
	s.DeleteVolumes = &v
	return s
}
406775
func (d *driver) Volumes(
	ctx types.Context,
	opts *types.VolumesOpts) ([]*types.Volume, error) {

	list, err := mustSession(ctx).blobClient.ListBlobs(d.container,
		blobStorage.ListBlobsParameters{Include: "metadata"})
	if err != nil {
		return nil, goof.WithError("error listing blobs", err)
	}
	// Convert retrieved volumes to libStorage types.Volume
	vols, convErr := d.toTypesVolume(ctx, list.Blobs, opts.Attachments)
	if convErr != nil {
		return nil, goof.WithError(
			"error converting to types.Volume", convErr)
	}
	return vols, nil
}
1038298
func (s *ContainerProperties) SetVolumes(v []*Volume) *ContainerProperties {
	s.Volumes = v
	return s
}
746549
func (c *Server) RemoveVolume(volumePath string) error {
	c.Lock()
	defer c.Unlock()
	delete(c.volumes, volumePath)
	return nil
}
212850
func (s *VolumeSource) CreateVolumes(ctx context.ProviderCallContext, params []storage.VolumeParams) ([]storage.CreateVolumesResult, error) {
	s.MethodCall(s, "CreateVolumes", ctx, params)
	if s.CreateVolumesFunc != nil {
		return s.CreateVolumesFunc(ctx, params)
	}
	return nil, errors.NotImplementedf("CreateVolumes")
}
1238718
func (s *VolumeService) AttachVolume(p *AttachVolumeParams) (*AttachVolumeResponse, error) {
	resp, err := s.cs.newRequest("attachVolume", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r AttachVolumeResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
991523
func osdVolumeAttributes(v *api.Volume) map[string]string {
	return map[string]string{
		api.SpecParent: v.GetSource().GetParent(),
		api.SpecSecure: fmt.Sprintf("%v", v.GetSpec().GetEncrypted()),
		api.SpecShared: fmt.Sprintf("%v", v.GetSpec().GetShared()),
		"readonly":     fmt.Sprintf("%v", v.GetReadonly()),
		"attached":     v.AttachedState.String(),
		"state":        v.State.String(),
		"error":        v.GetError(),
	}
}
729625
func validateVolumeParams(
	volumeSource storage.VolumeSource, volumeParams []storage.VolumeParams,
) ([]storage.VolumeParams, []error) {
	valid := make([]storage.VolumeParams, 0, len(volumeParams))
	results := make([]error, len(volumeParams))
	for i, params := range volumeParams {
		err := volumeSource.ValidateVolumeParams(params)
		if err == nil {
			valid = append(valid, params)
		}
		results[i] = err
	}
	return valid, results
}
1322194
func DestroyVolumes(a mesos.AgentID, v ...mesos.Resource) *master.Call {
	return &master.Call{
		Type: master.Call_DESTROY_VOLUMES,
		DestroyVolumes: &master.Call_DestroyVolumes{
			AgentID: a,
			Volumes: v,
		},
	}
}
1313410
func (s *VolumeSource) DestroyVolumes(ctx context.ProviderCallContext, volIds []string) ([]error, error) {
	s.MethodCall(s, "DestroyVolumes", ctx, volIds)
	if s.DestroyVolumesFunc != nil {
		return s.DestroyVolumesFunc(ctx, volIds)
	}
	return nil, errors.NotImplementedf("DestroyVolumes")
}