Пример #1
0
func (d *VolumeDriver) Path(w http.ResponseWriter, r *http.Request) {
	req, err := util.JSONDecode(r)
	if err != nil {
		util.JSONResponse(w, map[string]interface{}{"Err": err})
		return
	}

	log.Printf("Path request: %v\n", req)
	name := req["Name"].(string)
	if v, ok := d.volumes[name]; ok {
		util.JSONResponse(w, map[string]interface{}{"Mountpoint": v.path, "Err": nil})
	} else {
		util.JSONResponse(w, map[string]interface{}{"Err": fmt.Errorf("volume %v not found", name)})
	}
}
Пример #2
0
func (d *VolumeDriver) Create(w http.ResponseWriter, r *http.Request) {
	req, err := util.JSONDecode(r)
	if err != nil {
		util.JSONResponse(w, map[string]interface{}{"Err": err})
		return
	}

	log.Printf("Create request: %v\n", req)

	name := req["Name"].(string)

	if _, found := d.volumes[name]; found {
		log.Println("volume %s already exists\n", name)
		util.JSONResponse(w, map[string]interface{}{"Err": nil})
		return
	}

	path := d.getPath(name)
	log.Println("creating volume path: %s\n", name)
	if err := os.MkdirAll(path, 0755); err != nil {
		if os.IsExist(err) {
			util.JSONResponse(w, map[string]interface{}{"Err": fmt.Errorf("volume already exists under %s", filepath.Dir(path))})
			return
		}
		util.JSONResponse(w, map[string]interface{}{"Err": err})
		return
	}

	d.volumes[name] = &volume{
		name: name,
		path: path,
	}
	d.watcher.Add(path)

	util.JSONResponse(w, map[string]interface{}{"Err": nil})
}
Пример #3
0
func (d *VolumeDriver) Remove(w http.ResponseWriter, r *http.Request) {
	req, err := util.JSONDecode(r)
	if err != nil {
		util.JSONResponse(w, map[string]interface{}{"Err": err})
		return
	}

	log.Printf("Remove request: %v\n", req)

	name := req["Name"].(string)
	v, found := d.volumes[name]
	if !found {
		util.JSONResponse(w, map[string]interface{}{"Err": fmt.Errorf("Volume %s not found", name)})
		return
	}

	realPath, err := filepath.EvalSymlinks(v.path)
	if err != nil {
		if !os.IsNotExist(err) {
			util.JSONResponse(w, map[string]interface{}{"Err": err})
			return
		}
		realPath = filepath.Dir(v.path)
	}

	if !d.scopedPath(realPath) {
		util.JSONResponse(w, map[string]interface{}{"Err": fmt.Errorf("Unable to remove a directory of out the Docker root %s: %s", d.base, realPath)})
		return
	}

	if err := removePath(realPath); err != nil {
		util.JSONResponse(w, map[string]interface{}{"Err": err})
		return
	}

	d.watcher.Remove(v.path)
	delete(d.volumes, v.name)
	if err = removePath(filepath.Dir(v.path)); err != nil {
		util.JSONResponse(w, map[string]interface{}{"Err": err})
	} else {
		util.JSONResponse(w, map[string]interface{}{"Err": nil})
	}
}
Пример #4
0
func (d *VolumeDriver) Unmount(w http.ResponseWriter, r *http.Request) {
	req, err := util.JSONDecode(r)
	log.Printf("Unmount request: %v\n", req)
	util.JSONResponse(w, map[string]interface{}{"Err": err})
}