<commit_before>package client

import (
	"errors"
	"fmt"
	"github.com/libopenstorage/openstorage/api"
	"github.com/libopenstorage/openstorage/volume"
)

type volumeClient struct {
	c *Client
}

func newVolumeClient(c *Client) volume.VolumeDriver {
	return &volumeClient{c: c}
}

// String description of this driver.
func (v *volumeClient) String() string {
	return "VolumeDriver"
}

func (v *volumeClient) Type() volume.DriverType {
	// Block drivers implement the superset.
	return volume.Block
}

const (
	volumePath = "/volumes"
	snapPath   = "/snapshot"
)

// Create a new Vol for the specific volume spev.c.
// It returns a system generated VolumeID that uniquely identifies the volume
// If CreateOptions.FailIfExists is set and a volume matching the locator
// exists then this will fail with ErrEexist. Otherwise if a matching available
// volume is found then it is returned instead of creating a new volume.
func (v *volumeClient) Create(locator api.VolumeLocator,
	options *api.CreateOptions,
	spec *api.VolumeSpec) (api.VolumeID, error) {

	var response api.VolumeCreateResponse
	createReq := api.VolumeCreateRequest{
		Locator: locator,
		Options: options,
		Spec:    spec,
	}
	err := v.c.Post().Resource(volumePath).Body(&createReq).Do().Unmarshal(&response)
	if err != nil {
		return api.VolumeID(""), err
	}
	if response.Error != "" {
		return api.VolumeID(""), errors.New(response.Error)
	}
	return response.ID, nil
}

// Status diagnostic information
func (v *volumeClient) Status() [][2]string {
	return [][2]string{}
}

// Inspect specified volumes.
// Errors ErrEnoEnt may be returned.
func (v *volumeClient) Inspect(ids []api.VolumeID) ([]api.Volume, error) {
	var vols []api.Volume

	if len(ids) == 0 {
		return nil, fmt.Errorf("No volume IDs provided")
	}
	req := v.c.Get().Resource(volumePath)

	for _, v := range ids {
		req.QueryOption(string(api.OptVolumeID), string(v))
	}
	err := req.Do().Unmarshal(&vols)
	if err != nil {
		return nil, err
	}
	return vols, nil
}

// Delete volume.
// Errors ErrEnoEnt, ErrVolHasSnaps may be returned.
func (v *volumeClient) Delete(volumeID api.VolumeID) error {
<commit_msg>return zero volumes in inspect if no volume ID is specified instead of an error<commit_after>package client

import (
	"errors"
	"fmt"
	"github.com/libopenstorage/openstorage/api"
	"github.com/libopenstorage/openstorage/volume"
)

type volumeClient struct {
	c *Client
}

func newVolumeClient(c *Client) volume.VolumeDriver {
	return &volumeClient{c: c}
}

// String description of this driver.
func (v *volumeClient) String() string {
	return "VolumeDriver"
}

func (v *volumeClient) Type() volume.DriverType {
	// Block drivers implement the superset.
	return volume.Block
}

const (
	volumePath = "/volumes"
	snapPath   = "/snapshot"
)

// Create a new Vol for the specific volume spev.c.
// It returns a system generated VolumeID that uniquely identifies the volume
// If CreateOptions.FailIfExists is set and a volume matching the locator
// exists then this will fail with ErrEexist. Otherwise if a matching available
// volume is found then it is returned instead of creating a new volume.
func (v *volumeClient) Create(locator api.VolumeLocator,
	options *api.CreateOptions,
	spec *api.VolumeSpec) (api.VolumeID, error) {

	var response api.VolumeCreateResponse
	createReq := api.VolumeCreateRequest{
		Locator: locator,
		Options: options,
		Spec:    spec,
	}
	err := v.c.Post().Resource(volumePath).Body(&createReq).Do().Unmarshal(&response)
	if err != nil {
		return api.VolumeID(""), err
	}
	if response.Error != "" {
		return api.VolumeID(""), errors.New(response.Error)
	}
	return response.ID, nil
}

// Status diagnostic information
func (v *volumeClient) Status() [][2]string {
	return [][2]string{}
}

// Inspect specified volumes.
// Errors ErrEnoEnt may be returned.
func (v *volumeClient) Inspect(ids []api.VolumeID) ([]api.Volume, error) {
	var vols []api.Volume

	if len(ids) == 0 {
		return nil, nil
	}
	req := v.c.Get().Resource(volumePath)

	for _, v := range ids {
		req.QueryOption(string(api.OptVolumeID), string(v))
	}
	err := req.Do().Unmarshal(&vols)
	if err != nil {
		return nil, err
	}
	return vols, nil
}

// Delete volume.
// Errors ErrEnoEnt, ErrVolHasSnaps may be returned.
func (v *volumeClient) Delete(volumeID api.VolumeID) error {

{'fraction_non_alphanumeric': 0.12404358914908416, 'fraction_numerical': 0.0013911430558775793, 'mean_word_length': 4.178871548619448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5168767', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1380, 'n_words': 433}