예제 #1
0
func (v *volDriver) snapEnumerate(c *cli.Context) {
	var locator api.VolumeLocator
	var err error

	fn := "enumerate"
	locator.Name = c.String("name")
	if l := c.String("label"); l != "" {
		locator.VolumeLabels, err = processLabels(l)
		if err != nil {
			cmdError(c, fn, err)
			return
		}
	}

	v.volumeOptions(c)
	snaps, err := v.volDriver.Enumerate(locator, nil)
	if err != nil {
		cmdError(c, fn, err)
		return
	}
	if snaps == nil {
		cmdError(c, fn, err)
		return
	}
	cmdOutput(c, snaps)
}
예제 #2
0
func (vd *volApi) enumerate(w http.ResponseWriter, r *http.Request) {
	var locator api.VolumeLocator
	var configLabels api.Labels
	var err error
	var vols []api.Volume

	method := "enumerate"

	d, err := volume.Get(vd.name)
	if err != nil {
		notFound(w, r)
		return
	}
	params := r.URL.Query()
	v := params[string(api.OptName)]
	if v != nil {
		locator.Name = v[0]
	}
	v = params[string(api.OptLabel)]
	if v != nil {
		if err = json.Unmarshal([]byte(v[0]), &locator.VolumeLabels); err != nil {
			e := fmt.Errorf("Failed to parse parse VolumeLabels: %s", err.Error())
			vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
		}
	}
	v = params[string(api.OptConfigLabel)]
	if v != nil {
		if err = json.Unmarshal([]byte(v[0]), &configLabels); err != nil {
			e := fmt.Errorf("Failed to parse parse configLabels: %s", err.Error())
			vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
		}
	}
	v = params[string(api.OptVolumeID)]
	if v != nil {
		ids := make([]api.VolumeID, len(v))
		for i, s := range v {
			ids[i] = api.VolumeID(s)
		}
		vols, err = d.Inspect(ids)
		if err != nil {
			e := fmt.Errorf("Failed to inspect volumeID: %s", err.Error())
			vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
			return
		}
	} else {
		vols, _ = d.Enumerate(locator, configLabels)
	}
	json.NewEncoder(w).Encode(vols)
}