コード例 #1
0
ファイル: volumes.go プロジェクト: ModelRocket/openstorage
func (v *volDriver) volumeCreate(context *cli.Context) {
	var err error
	var labels map[string]string
	locator := &api.VolumeLocator{}
	var id string
	fn := "create"

	if len(context.Args()) != 1 {
		missingParameter(context, fn, "name", "Invalid number of arguments")
		return
	}

	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.Args()[0],
		VolumeLabels: labels,
	}
	fsType, err := api.FSTypeSimpleValueOf(context.String("fs"))
	if err != nil {
		cmdError(context, fn, err)
		return
	}
	spec := &api.VolumeSpec{
		Size:             uint64(VolumeSzUnits(context.Int("s")) * MiB),
		Format:           fsType,
		BlockSize:        int64(context.Int("b") * 1024),
		HaLevel:          int64(context.Int("r")),
		Cos:              uint32(context.Int("cos")),
		SnapshotInterval: uint32(context.Int("si")),
	}
	source := &api.Source{
		Seed: context.String("seed"),
	}
	if id, err = v.volDriver.Create(locator, source, spec); err != nil {
		cmdError(context, fn, err)
		return
	}

	fmtOutput(context, &Format{UUID: []string{string(id)}})
}
コード例 #2
0
ファイル: docker.go プロジェクト: ModelRocket/openstorage
func (d *driver) specFromOpts(Opts map[string]string) *api.VolumeSpec {
	spec := api.VolumeSpec{
		VolumeLabels: make(map[string]string),
		Format:       api.FSType_FS_TYPE_EXT4,
	}

	for k, v := range Opts {
		switch k {
		case api.SpecEphemeral:
			spec.Ephemeral, _ = strconv.ParseBool(v)
		case api.SpecSize:
			sizeMulti := uint64(1024 * 1024 * 1024)
			if strings.HasSuffix(v, "G") || strings.HasSuffix(v, "g") {
				sizeMulti = 1024 * 1024 * 1024
				last := len(v) - 1
				v = v[:last]
			}

			size, _ := strconv.ParseUint(v, 10, 64)
			spec.Size = size * sizeMulti
		case api.SpecFilesystem:
			value, _ := api.FSTypeSimpleValueOf(v)
			spec.Format = value
		case api.SpecBlockSize:
			blockSize, _ := strconv.ParseInt(v, 10, 64)
			spec.BlockSize = blockSize
		case api.SpecHaLevel:
			haLevel, _ := strconv.ParseInt(v, 10, 64)
			spec.HaLevel = haLevel
		case api.SpecCos:
			value, _ := strconv.ParseUint(v, 10, 32)
			spec.Cos = uint32(value)
		case api.SpecDedupe:
			spec.Dedupe, _ = strconv.ParseBool(v)
		case api.SpecSnapshotInterval:
			snapshotInterval, _ := strconv.ParseUint(v, 10, 32)
			spec.SnapshotInterval = uint32(snapshotInterval)
		default:
			spec.VolumeLabels[k] = v
		}
	}
	return &spec
}