Пример #1
0
func (d *driver) specFromOpts(Opts map[string]string) *api.VolumeSpec {
	var spec api.VolumeSpec
	for k, v := range Opts {
		switch k {
		case api.SpecEphemeral:
			spec.Ephemeral, _ = strconv.ParseBool(v)
		case api.SpecSize:
			spec.Size, _ = strconv.ParseUint(v, 10, 64)
		case api.SpecFilesystem:
			spec.Format = api.Filesystem(v)
		case api.SpecBlockSize:
			blockSize, _ := strconv.ParseInt(v, 10, 64)
			spec.BlockSize = int(blockSize)
		case api.SpecHaLevel:
			haLevel, _ := strconv.ParseInt(v, 10, 64)
			spec.HALevel = int(haLevel)
		case api.SpecCos:
			cos, _ := strconv.ParseInt(v, 10, 64)
			spec.Cos = api.VolumeCos(cos)
		case api.SpecDedupe:
			spec.Dedupe, _ = strconv.ParseBool(v)
		case api.SpecSnapshotInterval:
			snapshotInterval, _ := strconv.ParseInt(v, 10, 64)
			spec.SnapshotInterval = int(snapshotInterval)
		}
	}
	return &spec
}
Пример #2
0
func (v *volDriver) volumeCreate(context *cli.Context) {
	var err error
	var labels api.Labels
	var locator api.VolumeLocator
	var id api.VolumeID
	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,
	}
	spec := &api.VolumeSpec{
		Size:             uint64(VolumeSzUnits(context.Int("s")) * MiB),
		Format:           api.Filesystem(context.String("fs")),
		BlockSize:        context.Int("b") * 1024,
		HALevel:          context.Int("r"),
		Cos:              api.VolumeCos(context.Int("cos")),
		SnapshotInterval: 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)}})
}