當前位置: 首頁>>代碼示例>>Golang>>正文


Golang api.VolumeID函數代碼示例

本文整理匯總了Golang中github.com/libopenstorage/openstorage/api.VolumeID函數的典型用法代碼示例。如果您正苦於以下問題:Golang VolumeID函數的具體用法?Golang VolumeID怎麽用?Golang VolumeID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了VolumeID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/libopenstorage/openstorage/api.VolumeID函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。