本文整理汇总了Golang中github.com/libopenstorage/openstorage/api.VolumeID函数的典型用法代码示例。如果您正苦于以下问题:Golang VolumeID函数的具体用法?Golang VolumeID怎么用?Golang VolumeID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VolumeID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Create
func (d *nfsDriver) Create(locator api.VolumeLocator, opt *api.CreateOptions, spec *api.VolumeSpec) (api.VolumeID, error) {
// Validate options.
if spec.Format != "nfs" {
return "", errors.New("Unsupported filesystem format: " + string(spec.Format))
}
if spec.BlockSize != 0 {
log.Println("NFS driver will ignore the blocksize option.")
}
out, err := exec.Command("uuidgen").Output()
if err != nil {
log.Println(err)
return "", err
}
volumeID := string(out)
volumeID = strings.TrimSuffix(volumeID, "\n")
// Create a directory on the NFS server with this UUID.
err = os.MkdirAll(nfsMountPath+volumeID, 0744)
if err != nil {
log.Println(err)
return "", err
}
// Persist the volume spec. We use this for all subsequent operations on
// this volume ID.
err = d.put(volumeID,
&nfsVolume{Id: api.VolumeID(volumeID),
Device: nfsMountPath + volumeID,
Spec: *spec, Locator: locator})
return api.VolumeID(volumeID), err
}
开发者ID:portworx,项目名称:openstorage,代码行数:34,代码来源:nfs.go
示例2: TestSnapEnumerate
func TestSnapEnumerate(t *testing.T) {
snapID := api.VolumeID(snapName)
id := api.VolumeID(volName)
vol := api.Volume{
ID: id,
Locator: api.VolumeLocator{Name: volName, VolumeLabels: labels},
State: api.VolumeAvailable,
Spec: &api.VolumeSpec{},
}
err := e.CreateVol(&vol)
assert.NoError(t, err, "Failed in CreateVol")
snap := api.Volume{
ID: snapID,
Locator: api.VolumeLocator{Name: volName, VolumeLabels: labels},
State: api.VolumeAvailable,
Spec: &api.VolumeSpec{},
Source: &api.Source{Parent: id},
}
err = e.CreateVol(&snap)
assert.NoError(t, err, "Failed in CreateSnap")
snaps, err := e.SnapEnumerate([]api.VolumeID{id}, nil)
assert.NoError(t, err, "Failed in Enumerate")
assert.Equal(t, len(snaps), 1, "Number of snaps returned in enumerate should be 1")
if len(snaps) == 1 {
assert.Equal(t, snaps[0].ID, snap.ID, "Invalid snap returned in Enumerate")
}
snaps, err = e.SnapEnumerate([]api.VolumeID{id}, labels)
assert.NoError(t, err, "Failed in Enumerate")
assert.Equal(t, len(snaps), 1, "Number of snaps returned in enumerate should be 1")
if len(snaps) == 1 {
assert.Equal(t, snaps[0].ID, snap.ID, "Invalid snap returned in Enumerate")
}
snaps, err = e.SnapEnumerate(nil, labels)
assert.NoError(t, err, "Failed in Enumerate")
assert.True(t, len(snaps) >= 1, "Number of snaps returned in enumerate should be at least 1")
if len(snaps) == 1 {
assert.Equal(t, snaps[0].ID, snap.ID, "Invalid snap returned in Enumerate")
}
snaps, err = e.SnapEnumerate(nil, nil)
assert.NoError(t, err, "Failed in Enumerate")
assert.True(t, len(snaps) >= 1, "Number of snaps returned in enumerate should be at least 1")
if len(snaps) == 1 {
assert.Equal(t, snaps[0].ID, snap.ID, "Invalid snap returned in Enumerate")
}
err = e.DeleteVol(snapID)
assert.NoError(t, err, "Failed in Delete")
snaps, err = e.SnapEnumerate([]api.VolumeID{id}, labels)
assert.NotNil(t, snaps, "Inspect returned nil snaps")
assert.Equal(t, len(snaps), 0, "Number of snaps returned in enumerate should be 0")
err = e.DeleteVol(id)
assert.NoError(t, err, "Failed in Delete")
}
开发者ID:pombredanne,项目名称:openstorage,代码行数:57,代码来源:enumerator_test.go
示例3: volumeMount
func (v *VolDriver) volumeMount(c *cli.Context) {
v.volumeOptions(c)
fn := "mount"
if len(c.Args()) < 1 {
missingParameter(c, fn, "volumeID", "Invalid number of arguments")
return
}
volumeID := c.Args()[0]
path := c.String("path")
if path == "" {
missingParameter(c, fn, "path", "Target mount path")
return
}
err := v.volDriver.Mount(api.VolumeID(volumeID), path)
if err != nil {
cmdError(c, fn, err)
return
}
fmtOutput(c, &Format{UUID: []string{volumeID}})
}
开发者ID:portworx,项目名称:openstorage,代码行数:25,代码来源:volumes.go
示例4: parseVolumeID
func (vd *volApi) parseVolumeID(r *http.Request) (api.VolumeID, error) {
vars := mux.Vars(r)
if id, ok := vars["id"]; ok {
return api.VolumeID(id), nil
}
return api.BadVolumeID, fmt.Errorf("could not parse snap ID")
}
开发者ID:pault84,项目名称:openstorage,代码行数:7,代码来源:volume.go
示例5: Create
func (d *driver) Create(locator api.VolumeLocator, source *api.Source, spec *api.VolumeSpec) (api.VolumeID, error) {
volumeID := uuid.New()
volumeID = strings.TrimSuffix(volumeID, "\n")
// Create a directory on the NFS server with this UUID.
volPath := path.Join(nfsMountPath, volumeID)
err := os.MkdirAll(volPath, 0744)
if err != nil {
log.Println(err)
return api.BadVolumeID, err
}
if source != nil {
if len(source.Seed) != 0 {
seed, err := seed.New(source.Seed, spec.ConfigLabels)
if err != nil {
log.Warnf("Failed to initailize seed from %q : %v",
source.Seed, err)
return api.BadVolumeID, err
}
err = seed.Load(volPath)
if err != nil {
log.Warnf("Failed to seed from %q to %q: %v",
source.Seed, nfsMountPath, err)
return api.BadVolumeID, err
}
}
}
f, err := os.Create(path.Join(nfsMountPath, string(volumeID)+nfsBlockFile))
if err != nil {
log.Println(err)
return api.BadVolumeID, err
}
defer f.Close()
err = f.Truncate(int64(spec.Size))
if err != nil {
log.Println(err)
return api.BadVolumeID, err
}
v := &api.Volume{
ID: api.VolumeID(volumeID),
Source: source,
Locator: locator,
Ctime: time.Now(),
Spec: spec,
LastScan: time.Now(),
Format: "nfs",
State: api.VolumeAvailable,
Status: api.Up,
DevicePath: path.Join(nfsMountPath, string(volumeID)+nfsBlockFile),
}
err = d.CreateVol(v)
if err != nil {
return api.BadVolumeID, err
}
return v.ID, err
}
开发者ID:jvinod,项目名称:ost,代码行数:60,代码来源:nfs.go
示例6: TestEnumerate
func TestEnumerate(t *testing.T) {
id := api.VolumeID(volName)
vol := api.Volume{
ID: id,
Locator: api.VolumeLocator{Name: volName, VolumeLabels: labels},
State: api.VolumeAvailable,
Spec: &api.VolumeSpec{},
}
err := store.CreateVol(&vol)
assert.NoError(t, err, "Failed in CreateVol")
vols, err := store.Enumerate(api.VolumeLocator{}, nil)
assert.NoError(t, err, "Failed in Enumerate")
assert.Equal(t, 1, len(vols), "Number of volumes returned in enumerate should be 1")
vols, err = store.Enumerate(api.VolumeLocator{Name: volName}, nil)
assert.NoError(t, err, "Failed in Enumerate")
assert.Equal(t, 1, len(vols), "Number of volumes returned in enumerate should be 1")
if len(vols) == 1 {
assert.Equal(t, vols[0].ID, vol.ID, "Invalid volume returned in Enumerate")
}
vols, err = store.Enumerate(api.VolumeLocator{VolumeLabels: labels}, nil)
assert.NoError(t, err, "Failed in Enumerate")
assert.Equal(t, len(vols), 1, "Number of volumes returned in enumerate should be 1")
if len(vols) == 1 {
assert.Equal(t, vols[0].ID, vol.ID, "Invalid volume returned in Enumerate")
}
err = store.DeleteVol(id)
assert.NoError(t, err, "Failed in Delete")
vols, err = store.Enumerate(api.VolumeLocator{Name: volName}, nil)
assert.Equal(t, len(vols), 0, "Number of volumes returned in enumerate should be 0")
}
开发者ID:portworx,项目名称:openstorage,代码行数:31,代码来源:enumerator_test.go
示例7: snapEnumerate
func snapEnumerate(t *testing.T, ctx *Context) {
fmt.Println("snapEnumerate")
snaps, err := ctx.SnapEnumerate(nil, nil)
assert.NoError(t, err, "Failed in snapEnumerate")
assert.NotNil(t, snaps, "Nil snaps")
assert.Equal(t, 1, len(snaps), "Expect 1 snaps actual %v snaps", len(snaps))
assert.Equal(t, snaps[0].ID, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].ID)
labels := snaps[0].Locator.VolumeLabels
snaps, err = ctx.SnapEnumerate([]api.VolumeID{ctx.volID}, nil)
assert.NoError(t, err, "Failed in snapEnumerate")
assert.NotNil(t, snaps, "Nil snaps")
assert.Equal(t, len(snaps), 1, "Expect 1 snap actual %v snaps", len(snaps))
assert.Equal(t, snaps[0].ID, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].ID)
snaps, err = ctx.SnapEnumerate([]api.VolumeID{api.VolumeID("shouldNotExist")}, nil)
assert.Equal(t, len(snaps), 0, "Expect 0 snap actual %v snaps", len(snaps))
snaps, err = ctx.SnapEnumerate(nil, labels)
assert.NoError(t, err, "Failed in snapEnumerate")
assert.NotNil(t, snaps, "Nil snaps")
assert.Equal(t, len(snaps), 1, "Expect 1 snap actual %v snaps", len(snaps))
assert.Equal(t, snaps[0].ID, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].ID)
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:25,代码来源:driver.go
示例8: snapCreate
func (v *volDriver) snapCreate(context *cli.Context) {
var err error
var labels api.Labels
fn := "snapCreate"
if len(context.Args()) != 1 {
missingParameter(context, fn, "volumeID", "Invalid number of arguments")
return
}
volumeID := api.VolumeID(context.Args()[0])
v.volumeOptions(context)
if l := context.String("label"); l != "" {
if labels, err = processLabels(l); err != nil {
cmdError(context, fn, err)
return
}
}
locator := api.VolumeLocator{
Name: context.String("name"),
VolumeLabels: labels,
}
readonly := context.Bool("readonly")
id, err := v.volDriver.Snapshot(volumeID, readonly, locator)
if err != nil {
cmdError(context, fn, err)
return
}
fmtOutput(context, &Format{UUID: []string{string(id)}})
}
开发者ID:jvinod,项目名称:ost,代码行数:31,代码来源:volumes.go
示例9: Create
func (v *volumeDriver) Create(
volumeLocator api.VolumeLocator,
source *api.Source,
spec *api.VolumeSpec,
) (api.VolumeID, error) {
volumeID := strings.TrimSpace(string(uuid.New()))
dirPath := filepath.Join(v.baseDirPath, volumeID)
if err := os.MkdirAll(dirPath, 0777); err != nil {
return api.BadVolumeID, err
}
volume := &api.Volume{
ID: api.VolumeID(volumeID),
Locator: volumeLocator,
Ctime: time.Now(),
Spec: spec,
LastScan: time.Now(),
Format: "fuse",
State: api.VolumeAvailable,
Status: api.Up,
DevicePath: dirPath,
}
if err := v.CreateVol(volume); err != nil {
return api.BadVolumeID, err
}
if err := v.UpdateVol(volume); err != nil {
return api.BadVolumeID, err
}
return volume.ID, nil
}
开发者ID:pombredanne,项目名称:openstorage,代码行数:29,代码来源:volume_driver.go
示例10: Snapshot
// Snapshot create new subvolume from volume
func (d *driver) Snapshot(volumeID api.VolumeID, readonly bool, locator api.VolumeLocator) (api.VolumeID, error) {
vols, err := d.Inspect([]api.VolumeID{volumeID})
if err != nil {
return api.BadVolumeID, err
}
if len(vols) != 1 {
return api.BadVolumeID, fmt.Errorf("Failed to inspect %v len %v", volumeID, len(vols))
}
snapID := uuid.New()
vols[0].ID = api.VolumeID(snapID)
vols[0].Parent = volumeID
vols[0].Locator = locator
vols[0].Ctime = time.Now()
err = d.CreateVol(&vols[0])
if err != nil {
return api.BadVolumeID, err
}
chaos.Now(koStrayCreate)
err = d.btrfs.Create(snapID, string(volumeID))
if err != nil {
return api.BadVolumeID, err
}
return vols[0].ID, nil
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:26,代码来源:btrfs.go
示例11: Create
// Create a new subvolume. The volume spec is not taken into account.
func (d *driver) Create(locator api.VolumeLocator,
options *api.CreateOptions,
spec *api.VolumeSpec) (api.VolumeID, error) {
if spec.Format != "btrfs" && spec.Format != "" {
return api.BadVolumeID, fmt.Errorf("Filesystem format (%v) must be %v",
spec.Format, "btrfs")
}
volumeID := uuid.New()
v := &api.Volume{
ID: api.VolumeID(volumeID),
Locator: locator,
Ctime: time.Now(),
Spec: spec,
LastScan: time.Now(),
Format: "btrfs",
State: api.VolumeAvailable,
}
err := d.CreateVol(v)
if err != nil {
return api.BadVolumeID, err
}
err = d.btrfs.Create(volumeID, "")
if err != nil {
return api.BadVolumeID, err
}
v.DevicePath, err = d.btrfs.Get(volumeID, "")
if err != nil {
return v.ID, err
}
err = d.UpdateVol(v)
return v.ID, err
}
开发者ID:gourao,项目名称:openstorage,代码行数:36,代码来源:btrfs.go
示例12: Snapshot
func (d *Driver) Snapshot(volumeID api.VolumeID, readonly bool, locator api.VolumeLocator) (api.VolumeID, error) {
dryRun := false
vols, err := d.DefaultEnumerator.Inspect([]api.VolumeID{volumeID})
if err != nil {
return api.BadVolumeID, err
}
if len(vols) != 1 {
return api.BadVolumeID, fmt.Errorf("Failed to inspect %v len %v", volumeID, len(vols))
}
awsID := string(volumeID)
request := &ec2.CreateSnapshotInput{
VolumeID: &awsID,
DryRun: &dryRun,
}
snap, err := d.ec2.CreateSnapshot(request)
chaos.Now(koStrayCreate)
vols[0].ID = api.VolumeID(*snap.SnapshotID)
vols[0].Parent = volumeID
vols[0].Locator = locator
vols[0].Ctime = time.Now()
chaos.Now(koStrayCreate)
err = d.CreateVol(&vols[0])
if err != nil {
return api.BadVolumeID, err
}
return vols[0].ID, nil
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:28,代码来源:aws.go
示例13: Create
func (d *driver) Create(locator api.VolumeLocator, source *api.Source, spec *api.VolumeSpec) (api.VolumeID, error) {
volumeID := uuid.New()
volumeID = strings.TrimSuffix(volumeID, "\n")
// Create a directory on the Local machine with this UUID.
err := os.MkdirAll(path.Join(volumeBase, string(volumeID)), 0744)
if err != nil {
logrus.Println(err)
return api.BadVolumeID, err
}
v := &api.Volume{
ID: api.VolumeID(volumeID),
Locator: locator,
Ctime: time.Now(),
Spec: spec,
LastScan: time.Now(),
Format: "vfs",
State: api.VolumeAvailable,
Status: api.Up,
DevicePath: path.Join(volumeBase, string(volumeID)),
}
err = d.CreateVol(v)
if err != nil {
return api.BadVolumeID, err
}
err = d.UpdateVol(v)
return v.ID, err
}
开发者ID:pombredanne,项目名称:openstorage,代码行数:33,代码来源:vfs.go
示例14: Create
func (d *awsDriver) Create(l api.VolumeLocator, opt *api.CreateOptions, spec *api.VolumeSpec) (api.VolumeID, error) {
availabilityZone := "us-west-1a"
sz := int64(spec.Size / (1024 * 1024 * 1024))
iops := mapIops(spec.Cos)
req := &ec2.CreateVolumeInput{
AvailabilityZone: &availabilityZone,
Size: &sz,
IOPS: &iops}
v, err := d.ec2.CreateVolume(req)
if err != nil {
return api.VolumeID(""), err
}
// Persist the volume spec. We use this for all subsequent operations on
// this volume ID.
err = d.put(string(*v.VolumeID), &awsVolume{spec: *spec})
return api.VolumeID(*v.VolumeID), err
}
开发者ID:portworx,项目名称:openstorage,代码行数:19,代码来源:aws.go
示例15: Create
// Create a new Vol for the specific volume spev.c.
// It returns a system generated VolumeID that uniquely identifies the volume
func (v *volumeClient) Create(locator api.VolumeLocator,
source *api.Source,
spec *api.VolumeSpec) (api.VolumeID, error) {
var response api.VolumeCreateResponse
createReq := api.VolumeCreateRequest{
Locator: locator,
Source: source,
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
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:21,代码来源:volume.go
示例16: makeRequest
func makeRequest(t *testing.T) {
c, err := NewDriverClient(btrfs.Name)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
d := c.VolumeDriver()
_, err = d.Stats(api.VolumeID("foo"))
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:11,代码来源:client_test.go
示例17: volFromName
func (d *driver) volFromName(name string) (*volumeInfo, error) {
v, err := volume.Get(d.name)
if err != nil {
return nil, fmt.Errorf("Cannot locate volume driver for %s: %s", d.name, err.Error())
}
volumes, err := v.Inspect([]types.VolumeID{types.VolumeID(name)})
if err != nil || len(volumes) == 0 {
return nil, fmt.Errorf("Cannot locate volume %s", name)
}
return &volumeInfo{vol: &volumes[0]}, nil
}
开发者ID:jvinod,项目名称:ost,代码行数:11,代码来源:docker.go
示例18: makeRequest
func makeRequest(t *testing.T) {
c, err := NewDriverClient(nfs.Name)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
d := c.VolumeDriver()
_, err = d.Inspect([]api.VolumeID{api.VolumeID("foo")})
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
}
开发者ID:alwang1234,项目名称:openstorage,代码行数:11,代码来源:client_test.go
示例19: snapInspect
func snapInspect(t *testing.T, ctx *Context) {
fmt.Println("snapInspect")
snaps, err := ctx.Inspect([]api.VolumeID{ctx.snapID})
assert.NoError(t, err, "Failed in Inspect")
assert.NotNil(t, snaps, "Nil snaps")
assert.Equal(t, len(snaps), 1, "Expect 1 snaps actual %v snaps", len(snaps))
assert.Equal(t, snaps[0].ID, ctx.snapID, "Expect snapID %v actual %v", ctx.snapID, snaps[0].ID)
snaps, err = ctx.Inspect([]api.VolumeID{api.VolumeID("shouldNotExist")})
assert.Equal(t, 0, len(snaps), "Expect 0 snaps actual %v snaps", len(snaps))
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:12,代码来源:driver.go
示例20: inspect
func inspect(t *testing.T, ctx *Context) {
fmt.Println("inspect")
vols, err := ctx.Inspect([]api.VolumeID{ctx.volID})
assert.NoError(t, err, "Failed in Inspect")
assert.NotNil(t, vols, "Nil vols")
assert.Equal(t, len(vols), 1, "Expect 1 volume actual %v volumes", len(vols))
assert.Equal(t, vols[0].ID, ctx.volID, "Expect volID %v actual %v", ctx.volID, vols[0].ID)
vols, err = ctx.Inspect([]api.VolumeID{api.VolumeID("shouldNotExist")})
assert.Equal(t, 0, len(vols), "Expect 0 volume actual %v volumes", len(vols))
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:12,代码来源:driver.go
注:本文中的github.com/libopenstorage/openstorage/api.VolumeID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论