• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang volumes.Create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.Create函数的典型用法代码示例。如果您正苦于以下问题:Golang Create函数的具体用法?Golang Create怎么用?Golang Create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Create函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: CreateVolume

// Create a volume of given size (in GiB)
func (os *OpenStack) CreateVolume(name string, size int, tags *map[string]string) (volumeName string, err error) {

	sClient, err := openstack.NewBlockStorageV1(os.provider, gophercloud.EndpointOpts{
		Region: os.region,
	})

	if err != nil || sClient == nil {
		glog.Errorf("Unable to initialize cinder client for region: %s", os.region)
		return "", err
	}

	opts := volumes.CreateOpts{
		Name: name,
		Size: size,
	}
	if tags != nil {
		opts.Metadata = *tags
	}
	vol, err := volumes.Create(sClient, opts).Extract()
	if err != nil {
		glog.Errorf("Failed to create a %d GB volume: %v", size, err)
		return "", err
	}
	glog.Infof("Created volume %v", vol.ID)
	return vol.ID, err
}
开发者ID:RyanBinfeng,项目名称:kubernetes,代码行数:27,代码来源:openstack.go


示例2: Execute

func (command *commandCreate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsCreate).opts
	volume, err := osVolumes.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = volumeSingle(volume)
}
开发者ID:flazz,项目名称:rack,代码行数:9,代码来源:create.go


示例3: TestSnapshots

func TestSnapshots(t *testing.T) {

	client, err := newClient(t)
	th.AssertNoErr(t, err)

	v, err := volumes.Create(client, &volumes.CreateOpts{
		Name: "gophercloud-test-volume",
		Size: 1,
	}).Extract()
	th.AssertNoErr(t, err)

	err = volumes.WaitForStatus(client, v.ID, "available", 120)
	th.AssertNoErr(t, err)

	t.Logf("Created volume: %v\n", v)

	ss, err := snapshots.Create(client, &snapshots.CreateOpts{
		Name:     "gophercloud-test-snapshot",
		VolumeID: v.ID,
	}).Extract()
	th.AssertNoErr(t, err)

	err = snapshots.WaitForStatus(client, ss.ID, "available", 120)
	th.AssertNoErr(t, err)

	t.Logf("Created snapshot: %+v\n", ss)

	err = snapshots.Delete(client, ss.ID).ExtractErr()
	th.AssertNoErr(t, err)

	err = gophercloud.WaitFor(120, func() (bool, error) {
		_, err := snapshots.Get(client, ss.ID).Extract()
		if err != nil {
			return true, nil
		}

		return false, nil
	})
	th.AssertNoErr(t, err)

	t.Log("Deleted snapshot\n")

	err = volumes.Delete(client, v.ID).ExtractErr()
	th.AssertNoErr(t, err)

	err = gophercloud.WaitFor(120, func() (bool, error) {
		_, err := volumes.Get(client, v.ID).Extract()
		if err != nil {
			return true, nil
		}

		return false, nil
	})
	th.AssertNoErr(t, err)

	t.Log("Deleted volume\n")
}
开发者ID:RomainVabre,项目名称:origin,代码行数:57,代码来源:snapshots_test.go


示例4: resourceBlockStorageVolumeV1Create

func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	blockStorageClient, err := config.blockStorageV1Client(d.Get("region").(string))
	if err != nil {
		return fmt.Errorf("Error creating OpenStack block storage client: %s", err)
	}

	createOpts := &volumes.CreateOpts{
		Description:  d.Get("description").(string),
		Availability: d.Get("availability_zone").(string),
		Name:         d.Get("name").(string),
		Size:         d.Get("size").(int),
		SnapshotID:   d.Get("snapshot_id").(string),
		SourceVolID:  d.Get("source_vol_id").(string),
		ImageID:      d.Get("image_id").(string),
		VolumeType:   d.Get("volume_type").(string),
		Metadata:     resourceContainerMetadataV2(d),
	}

	log.Printf("[DEBUG] Create Options: %#v", createOpts)
	v, err := volumes.Create(blockStorageClient, createOpts).Extract()
	if err != nil {
		return fmt.Errorf("Error creating OpenStack volume: %s", err)
	}
	log.Printf("[INFO] Volume ID: %s", v.ID)

	// Store the ID now
	d.SetId(v.ID)

	// Wait for the volume to become available.
	log.Printf(
		"[DEBUG] Waiting for volume (%s) to become available",
		v.ID)

	stateConf := &resource.StateChangeConf{
		Pending:    []string{"downloading", "creating"},
		Target:     []string{"available"},
		Refresh:    VolumeV1StateRefreshFunc(blockStorageClient, v.ID),
		Timeout:    10 * time.Minute,
		Delay:      10 * time.Second,
		MinTimeout: 3 * time.Second,
	}

	_, err = stateConf.WaitForState()
	if err != nil {
		return fmt.Errorf(
			"Error waiting for volume (%s) to become ready: %s",
			v.ID, err)
	}

	return resourceBlockStorageVolumeV1Read(d, meta)
}
开发者ID:chandy,项目名称:terraform,代码行数:52,代码来源:resource_openstack_blockstorage_volume_v1.go


示例5: createVAVolume

func createVAVolume(t *testing.T, blockClient *gophercloud.ServiceClient) (*volumes.Volume, error) {
	volume, err := volumes.Create(blockClient, &volumes.CreateOpts{
		Size: 1,
		Name: "gophercloud-test-volume",
	}).Extract()
	th.AssertNoErr(t, err)
	defer func() {
		err = volumes.WaitForStatus(blockClient, volume.ID, "available", 60)
		th.AssertNoErr(t, err)
	}()

	return volume, err
}
开发者ID:RomainVabre,项目名称:origin,代码行数:13,代码来源:volumeattach_test.go


示例6: TestVolumes

func TestVolumes(t *testing.T) {
	client, err := newClient(t)
	th.AssertNoErr(t, err)

	cv, err := volumes.Create(client, &volumes.CreateOpts{
		Size: 1,
		Name: "gophercloud-test-volume",
	}).Extract()
	th.AssertNoErr(t, err)
	defer func() {
		err = volumes.WaitForStatus(client, cv.ID, "available", 60)
		th.AssertNoErr(t, err)
		err = volumes.Delete(client, cv.ID).ExtractErr()
		th.AssertNoErr(t, err)
	}()

	_, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{
		Name: "gophercloud-updated-volume",
	}).Extract()
	th.AssertNoErr(t, err)

	v, err := volumes.Get(client, cv.ID).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Got volume: %+v\n", v)

	if v.Name != "gophercloud-updated-volume" {
		t.Errorf("Unable to update volume: Expected name: gophercloud-updated-volume\nActual name: %s", v.Name)
	}

	err = volumes.List(client, &volumes.ListOpts{Name: "gophercloud-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) {
		vols, err := volumes.ExtractVolumes(page)
		th.CheckEquals(t, 1, len(vols))
		return true, err
	})
	th.AssertNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:36,代码来源:volumes_test.go


示例7: CreateVolume

func (d *driver) CreateVolume(
	runAsync bool,
	volumeName string,
	volumeID string,
	snapshotID string,
	volumeType string,
	IOPS int64,
	size int64,
	availabilityZone string) (*core.Volume, error) {

	fields := map[string]interface{}{
		"provider":         providerName,
		"runAsync":         runAsync,
		"volumeName":       volumeName,
		"volumeId":         volumeID,
		"snapshotId":       snapshotID,
		"volumeType":       volumeType,
		"iops":             IOPS,
		"size":             size,
		"availabilityZone": availabilityZone,
	}

	if volumeID != "" && runAsync {
		return nil, errors.ErrRunAsyncFromVolume
	}

	d.createVolumeEnsureAvailabilityZone(&availabilityZone)

	var err error

	if err = d.createVolumeHandleSnapshotID(
		&size, snapshotID, fields); err != nil {
		return nil, err
	}

	var volume []*core.Volume
	if volume, err = d.createVolumeHandleVolumeID(
		&availabilityZone, &snapshotID, &volumeID, &size, fields); err != nil {
		return nil, err
	}

	createVolumeEnsureSize(&size)

	options := &volumes.CreateOpts{
		Name:         volumeName,
		Size:         int(size),
		SnapshotID:   snapshotID,
		VolumeType:   volumeType,
		Availability: availabilityZone,
	}
	resp, err := volumes.Create(d.clientBlockStorage, options).Extract()
	if err != nil {
		return nil,
			errors.WithFields(fields, "error creating volume")
	}

	if !runAsync {
		log.Debug("waiting for volume creation to complete")
		err = volumes.WaitForStatus(d.clientBlockStorage, resp.ID, "available", 120)
		if err != nil {
			return nil,
				errors.WithFields(fields,
					"error waiting for volume creation to complete")
		}

		if volumeID != "" {
			err := d.RemoveSnapshot(snapshotID)
			if err != nil {
				return nil,
					errors.WithFields(fields,
						"error removing snapshot")
			}
		}
	}

	fields["volumeId"] = resp.ID
	fields["volumeName"] = ""

	volume, err = d.GetVolume(resp.ID, "")
	if err != nil {
		return nil, errors.WithFields(fields,
			"error removing snapshot")
	}

	log.WithFields(fields).Debug("created volume")
	return volume[0], nil
}
开发者ID:nutmegdevelopment,项目名称:rexray,代码行数:87,代码来源:openstack.go


示例8: CreateVolume

func (driver *Driver) CreateVolume(
	runAsync bool,
	volumeName string,
	volumeID string,
	snapshotID string,
	volumeType string,
	IOPS int64,
	size int64,
	availabilityZone string) (*storage.Volume, error) {

	fields := map[string]interface{}{
		"provider":         ProviderName,
		"runAsync":         runAsync,
		"volumeName":       volumeName,
		"volumeId":         volumeID,
		"snapshotId":       snapshotID,
		"volumeType":       volumeType,
		"iops":             IOPS,
		"size":             size,
		"availabilityZone": availabilityZone,
	}

	if volumeID != "" && runAsync {
		return nil, errors.WithFields(fields,
			"cannot create volume from volume & run async")
	}

	if snapshotID != "" {
		snapshot, err := driver.GetSnapshot("", snapshotID, "")
		if err != nil {
			return nil,
				errors.WithFieldsE(fields, "error getting snapshot", err)
		}

		if len(snapshot) == 0 {
			return nil,
				errors.WithFields(fields, "snapshot array is empty")
		}

		volSize := snapshot[0].VolumeSize
		sizeInt, err := strconv.Atoi(volSize)
		if err != nil {
			f := errors.Fields{
				"volumeSize": volSize,
			}
			for k, v := range fields {
				f[k] = v
			}
			return nil,
				errors.WithFieldsE(f, "error casting volume size", err)
		}
		size = int64(sizeInt)
	}

	var volume []*storage.Volume
	var err error
	if volumeID != "" {
		volume, err = driver.GetVolume(volumeID, "")
		if err != nil {
			return nil, errors.WithFields(fields, "error getting volume")
		}

		if len(volume) == 0 {
			return nil,
				errors.WithFields(fields, "volume array is empty")
		}

		volSize := volume[0].Size
		sizeInt, err := strconv.Atoi(volSize)
		if err != nil {
			f := errors.Fields{
				"volumeSize": volSize,
			}
			for k, v := range fields {
				f[k] = v
			}
			return nil,
				errors.WithFieldsE(f, "error casting volume size", err)
		}
		size = int64(sizeInt)

		volumeID := volume[0].VolumeID
		snapshot, err := driver.CreateSnapshot(
			false, fmt.Sprintf("temp-%s", volumeID), volumeID, "")
		if err != nil {
			return nil,
				errors.WithFields(fields, "error creating snapshot")
		}

		snapshotID = snapshot[0].SnapshotID

		if availabilityZone == "" {
			availabilityZone = volume[0].AvailabilityZone
		}

	}

	if size != 0 && size < minSize {
		size = minSize
	}
//.........这里部分代码省略.........
开发者ID:robnolen,项目名称:rexray,代码行数:101,代码来源:storage.go


示例9: CreateVolume

func (driver *Driver) CreateVolume(runAsync bool, volumeName string, volumeID string, snapshotID string, volumeType string, IOPS int64, size int64, availabilityZone string) (*storagedriver.Volume, error) {
	if volumeID != "" && runAsync {
		return nil, errors.New("Cannot create volume from volume and run asynchronously")
	}

	if snapshotID != "" {
		snapshot, err := driver.GetSnapshot("", snapshotID, "")
		if err != nil {
			return nil, err
		}

		sizeInt, err := strconv.Atoi(snapshot[0].VolumeSize)
		if err != nil {
			return nil, err
		}
		size = int64(sizeInt)
	}

	var volume []*storagedriver.Volume
	var err error
	if volumeID != "" {
		volume, err = driver.GetVolume(volumeID, "")
		if err != nil {
			return nil, err
		}

		sizeInt, err := strconv.Atoi(volume[0].Size)
		if err != nil {
			return nil, err
		}
		size = int64(sizeInt)

		volumeID := volume[0].VolumeID
		snapshot, err := driver.CreateSnapshot(false, fmt.Sprintf("temp-%s", volumeID), volumeID, "")
		if err != nil {
			return nil, err
		}

		snapshotID = snapshot[0].SnapshotID

		if availabilityZone == "" {
			availabilityZone = volume[0].AvailabilityZone
		}

	}

	if size != 0 && size < minSize {
		size = minSize
	}

	options := &volumes.CreateOpts{
		Name:         volumeName,
		Size:         int(size),
		SnapshotID:   snapshotID,
		VolumeType:   volumeType,
		Availability: availabilityZone,
	}
	resp, err := volumes.Create(driver.ClientBlockStorage, options).Extract()
	if err != nil {
		return nil, err
	}

	if !runAsync {
		log.Println("Waiting for volume creation to complete")
		err = volumes.WaitForStatus(driver.ClientBlockStorage, resp.ID, "available", 120)
		if err != nil {
			return nil, err
		}

		if volumeID != "" {
			err := driver.RemoveSnapshot(snapshotID)
			if err != nil {
				return nil, err
			}
		}
	}

	volume, err = driver.GetVolume(resp.ID, "")
	if err != nil {
		return nil, err
	}

	// log.Println(fmt.Sprintf("Created volume: %+v", volume[0]))
	return volume[0], nil
}
开发者ID:bkeyoumarsi,项目名称:rexray,代码行数:85,代码来源:storage.go


示例10: Create

// Create will create a new Volume based on the values in CreateOpts. To extract
// the Volume object from the response, call the Extract method on the
// CreateResult.
func Create(client *gophercloud.ServiceClient, opts os.CreateOptsBuilder) CreateResult {
	return CreateResult{os.Create(client, opts)}
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:6,代码来源:delegate.go


示例11: createVolume

func (d *driver) createVolume(
	ctx types.Context,
	volumeName string,
	volumeSourceID string,
	snapshotID string,
	opts *types.VolumeCreateOpts) (*types.Volume, error) {
	var (
		volumeType       string
		IOPS             int64
		size             int64
		availabilityZone string
	)
	if opts.Type != nil {
		volumeType = *(opts.Type)
	}
	if opts.IOPS != nil {
		IOPS = *(opts.IOPS)
	}
	if opts.Size != nil {
		size = *(opts.Size)
	}
	if opts.AvailabilityZone != nil {
		availabilityZone = *(opts.AvailabilityZone)
	}

	//check some fields...
	createVolumeEnsureSize(&size)
	vsize := int(size)

	fields := map[string]interface{}{
		"availabilityZone": availabilityZone,
		"iops":             IOPS,
		"provider":         d.Name(),
		"size":             size,
		"snapshotId":       snapshotID,
		"volumeName":       volumeName,
		"volumeSourceID":   volumeSourceID,
		"volumeType":       volumeType,
	}

	options := &volumes.CreateOpts{
		Name:       volumeName,
		Size:       vsize,
		SnapshotID: snapshotID,
		VolumeType: volumeType,
		//AvailabilityZone: availabilityZone, //Not in old Rackspace
		//SourceReplica:    volumeSourceID,
	}
	resp, err := volumes.Create(d.clientBlockStorage, options).Extract()
	if err != nil {
		return nil,
			goof.WithFields(fields, "error creating volume")
	}
	fields["volumeId"] = resp.ID
	//for openstack must test before rackspace integration
	err = volumes.WaitForStatus(d.clientBlockStorage, resp.ID, "available", 120)
	if err != nil {
		return nil,
			goof.WithFieldsE(fields,
				"error waiting for volume creation to complete", err)
	}
	log.WithFields(fields).Debug("created volume")
	return translateVolume(resp, types.VolAttReqTrue), nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:64,代码来源:rackspace_storage.go



注:本文中的github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes.Create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang volumes.Delete函数代码示例发布时间:2022-05-28
下一篇:
Golang openstack.NewNetworkV2函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap