本文整理汇总了Golang中github.com/libopenstorage/openstorage/volume.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: unmount
func (d *driver) unmount(w http.ResponseWriter, r *http.Request) {
method := "unmount"
request, err := d.decode(method, w, r)
if err != nil {
return
}
volInfo, err := d.volFromName(request.Name)
if err != nil {
e := d.volNotFound(method, request.Name, err, w)
json.NewEncoder(w).Encode(&volumeResponse{Err: e.Error()})
return
}
v, err := volume.Get(d.name)
if err != nil {
json.NewEncoder(w).Encode(&volumeResponse{Err: err.Error()})
return
}
err = v.Detach(volInfo.vol.ID)
if err != nil {
d.logReq(request.Name, method).Warnf("%s", err.Error())
json.NewEncoder(w).Encode(&volumeResponse{Err: err.Error()})
return
}
d.emptyResponse(w)
}
示例2: Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
var volumeDriver string
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
switch key {
case Layer0VolumeDriver:
volumeDriver = val
default:
return nil, fmt.Errorf("Unknown option %s\n", key)
}
}
log.Infof("Layer0 volume driver: %v", volumeDriver)
volDriver, err := volume.Get(volumeDriver)
if err != nil {
return nil, err
}
ov, err := overlay.Init(home, options, uidMaps, gidMaps)
if err != nil {
volDriver.Shutdown()
return nil, err
}
d := &Layer0{
Driver: ov,
home: home,
volumes: make(map[string]*Layer0Vol),
volDriver: volDriver,
}
return d, nil
}
示例3: TestAll
func TestAll(t *testing.T) {
/*
cmd := exec.Command("dd", "if=/dev/zero", "of=/tmp/x", "bs=1M", "count=100")
err := cmd.Run()
if err != nil {
t.Fatalf("Failed to create file: %v", err)
}
cmd = exec.Command("/sbin/mkfs.btrfs", "/tmp/x")
err = cmd.Run()
if err != nil {
t.Fatalf("Failed to create btrfs:%v", err)
}
err = os.MkdirAll("/tmp/btrfs_test", 0755)
if err != nil {
t.Fatalf("Failed to create mkdir: %v", err)
}
err = syscall.Mount("/tmp/x", "/tmp/btrfs_test", "btrfs", syscall.MS_NODEV, "")
if err != nil {
t.Fatalf("Failed to mount btrfs: %v", err)
}
*/
_, err := volume.New(Name, volume.DriverParams{RootParam: "/tmp/btrfs_test"})
if err != nil {
t.Fatalf("Failed to initialize Driver: %v", err)
}
d, err := volume.Get(Name)
if err != nil {
t.Fatalf("Failed to initialize Volume Driver: %v", err)
}
ctx := test.NewContext(d)
ctx.Filesystem = api.FsBtrfs
test.Run(t, ctx)
}
示例4: mount
func (d *driver) mount(w http.ResponseWriter, r *http.Request) {
var response volumePathResponse
method := "mount"
request, err := d.decode(method, w, r)
if err != nil {
return
}
volInfo, err := d.volFromName(request.Name)
if err != nil {
e := d.volNotFound(method, request.Name, err, w)
json.NewEncoder(w).Encode(&volumePathResponse{Err: e.Error()})
return
}
response.Mountpoint = fmt.Sprintf("/mnt/%s", request.Name)
os.MkdirAll(response.Mountpoint, 0755)
v, err := volume.Get(d.name)
if err != nil {
json.NewEncoder(w).Encode(&volumePathResponse{Err: err.Error()})
return
}
path, err := v.Attach(volInfo.vol.ID)
if err != nil {
json.NewEncoder(w).Encode(&volumePathResponse{Err: err.Error()})
return
}
response.Mountpoint = path
d.logReq(method, request.Name).Debugf("response %v", path)
json.NewEncoder(w).Encode(&response)
}
示例5: inspect
func (vd *volApi) inspect(w http.ResponseWriter, r *http.Request) {
var err error
var volumeID string
method := "inspect"
d, err := volume.Get(vd.name)
if err != nil {
notFound(w, r)
return
}
if volumeID, err = vd.parseVolumeID(r); err != nil {
e := fmt.Errorf("Failed to parse parse volumeID: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
vd.logRequest(method, string(volumeID)).Infoln("")
dk, err := d.Inspect([]string{volumeID})
if err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusNotFound)
return
}
json.NewEncoder(w).Encode(dk)
}
示例6: alerts
func (vd *volApi) alerts(w http.ResponseWriter, r *http.Request) {
var volumeID api.VolumeID
var err error
method := "stats"
if volumeID, err = vd.parseVolumeID(r); err != nil {
e := fmt.Errorf("Failed to parse parse volumeID: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
d, err := volume.Get(vd.name)
if err != nil {
notFound(w, r)
return
}
alerts, err := d.Alerts(volumeID)
if err != nil {
e := fmt.Errorf("Failed to get alerts: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
json.NewEncoder(w).Encode(alerts)
}
示例7: snap
func (vd *volApi) snap(w http.ResponseWriter, r *http.Request) {
var snapReq api.SnapCreateRequest
var snapRes api.SnapCreateResponse
method := "snap"
if err := json.NewDecoder(r.Body).Decode(&snapReq); err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}
d, err := volume.Get(vd.name)
if err != nil {
notFound(w, r)
return
}
vd.logRequest(method, string(snapReq.Id)).Infoln("")
id, err := d.Snapshot(snapReq.Id, snapReq.Readonly, snapReq.Locator)
snapRes.VolumeCreateResponse = &api.VolumeCreateResponse{
Id: id,
VolumeResponse: &api.VolumeResponse{
Error: responseStatus(err),
},
}
json.NewEncoder(w).Encode(&snapRes)
}
示例8: list
func (d *driver) list(w http.ResponseWriter, r *http.Request) {
method := "list"
v, err := volume.Get(d.name)
if err != nil {
d.logRequest(method, "").Warnf("Cannot locate volume driver: %v", err.Error())
d.errorResponse(w, err)
return
}
vols, err := v.Enumerate(nil, nil)
if err != nil {
d.errorResponse(w, err)
return
}
volInfo := make([]volumeInfo, len(vols))
for i, v := range vols {
volInfo[i].Name = v.Locator.Name
if v.AttachPath != "" {
volInfo[i].Mountpoint = path.Join(v.AttachPath, config.DataDir)
}
}
json.NewEncoder(w).Encode(map[string][]volumeInfo{"Volumes": volInfo})
}
示例9: create
func (d *driver) create(w http.ResponseWriter, r *http.Request) {
var err error
method := "create"
request, err := d.decode(method, w, r)
if err != nil {
return
}
d.logReq(method, request.Name).Info("")
_, err = d.volFromName(request.Name)
if err != nil {
v, err := volume.Get(d.name)
if err != nil {
json.NewEncoder(w).Encode(&volumeResponse{Err: err})
return
}
spec := d.specFromOpts(request.Opts)
_, err = v.Create(api.VolumeLocator{Name: request.Name}, nil, spec)
if err != nil {
json.NewEncoder(w).Encode(&volumeResponse{Err: err})
return
}
}
json.NewEncoder(w).Encode(&volumeResponse{})
}
示例10: delete
func (vd *volApi) delete(w http.ResponseWriter, r *http.Request) {
var volumeID string
var err error
method := "delete"
if volumeID, err = vd.parseVolumeID(r); err != nil {
e := fmt.Errorf("Failed to parse parse volumeID: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
vd.logRequest(method, volumeID).Infoln("")
d, err := volume.Get(vd.name)
if err != nil {
notFound(w, r)
return
}
volumeResponse := &api.VolumeResponse{}
if err := d.Delete(volumeID); err != nil {
volumeResponse.Error = err.Error()
}
json.NewEncoder(w).Encode(volumeResponse)
}
示例11: stats
func (vd *volApi) stats(w http.ResponseWriter, r *http.Request) {
var volumeID string
var err error
method := "stats"
if volumeID, err = vd.parseVolumeID(r); err != nil {
e := fmt.Errorf("Failed to parse parse volumeID: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
vd.logRequest(method, string(volumeID)).Infoln("")
d, err := volume.Get(vd.name)
if err != nil {
notFound(w, r)
return
}
stats, err := d.Stats(volumeID)
if err != nil {
e := fmt.Errorf("Failed to get stats: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
json.NewEncoder(w).Encode(stats)
}
示例12: Init
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
logrus.Infof("Initializing Fuse Graph driver at home:%s and storage: %v...", home, virtPath)
var volumeDriver string
for _, option := range options {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
}
switch key {
case UnionFSVolumeDriver:
volumeDriver = val
default:
return nil, fmt.Errorf("Unknown option %s\n", key)
}
}
if volumeDriver == "" {
logrus.Warnf("Error - no volume driver specified for UnionFS")
return nil, fmt.Errorf("No volume driver specified for UnionFS")
}
logrus.Infof("UnionFS volume driver: %v", volumeDriver)
volDriver, err := volume.Get(volumeDriver)
if err != nil {
logrus.Warnf("Error while loading volume driver: %s", volumeDriver)
return nil, err
}
// In case it is mounted.
syscall.Unmount(virtPath, 0)
err = os.MkdirAll(virtPath, 0744)
if err != nil {
volDriver.Shutdown()
logrus.Warnf("Error while creating FUSE mount path: %v", err)
return nil, err
}
err = os.MkdirAll(physPath, 0744)
if err != nil {
volDriver.Shutdown()
logrus.Warnf("Error while creating FUSE mount path: %v", err)
return nil, err
}
cVirtPath := C.CString(virtPath)
cPhysPath := C.CString(physPath)
go C.start_unionfs(cPhysPath, cVirtPath)
d := &Driver{
volDriver: volDriver,
}
return d, nil
}
示例13: volFromName
func (d *driver) volFromName(name string) (*volumeInfo, error) {
v, err := volume.Get(d.name)
if err != nil {
return nil, fmt.Errorf("Cannot locate volume driver for %s: %s", d.name, err.Error())
}
volumes, err := v.Inspect([]types.VolumeID{types.VolumeID(name)})
if err != nil || len(volumes) == 0 {
return nil, fmt.Errorf("Cannot locate volume %s", name)
}
return &volumeInfo{vol: &volumes[0]}, nil
}
示例14: mount
func (d *driver) mount(w http.ResponseWriter, r *http.Request) {
var response volumePathResponse
method := "mount"
v, err := volume.Get(d.name)
if err != nil {
d.logReq(method, "").Warn("Cannot locate volume driver")
json.NewEncoder(w).Encode(&volumePathResponse{Err: err})
return
}
request, err := d.decode(method, w, r)
if err != nil {
json.NewEncoder(w).Encode(&volumePathResponse{Err: err})
return
}
d.logReq(method, request.Name).Debug("")
volInfo, err := d.volFromName(request.Name)
if err != nil {
json.NewEncoder(w).Encode(&volumePathResponse{Err: err})
return
}
// If this is a block driver, first attach the volume.
if v.Type()&volume.Block != 0 {
attachPath, err := v.Attach(volInfo.vol.ID)
if err != nil {
d.logReq(method, request.Name).Warnf("Cannot attach volume: %v", err.Error())
json.NewEncoder(w).Encode(&volumePathResponse{Err: err})
return
}
d.logReq(method, request.Name).Debugf("response %v", attachPath)
}
// Now mount it.
response.Mountpoint = path.Join(config.MountBase, request.Name)
os.MkdirAll(response.Mountpoint, 0755)
err = v.Mount(volInfo.vol.ID, response.Mountpoint)
if err != nil {
d.logReq(method, request.Name).Warnf("Cannot mount volume %v, %v",
response.Mountpoint, err)
json.NewEncoder(w).Encode(&volumePathResponse{Err: err})
return
}
response.Mountpoint = path.Join(response.Mountpoint, config.DataDir)
os.MkdirAll(response.Mountpoint, 0755)
d.logReq(method, request.Name).Infof("response %v", response.Mountpoint)
json.NewEncoder(w).Encode(&response)
}
示例15: snapEnumerate
func (vd *volDriver) snapEnumerate(w http.ResponseWriter, r *http.Request) {
var err error
var labels api.Labels
var ids []api.VolumeID
var snaps []api.VolumeSnap
method := "snapEnumerate"
d, err := volume.Get(vd.name)
if err != nil {
vd.notFound(w, r)
return
}
params := r.URL.Query()
v := params[string(api.OptLabel)]
if v != nil {
if err = json.Unmarshal([]byte(v[0]), &labels); err != nil {
e := fmt.Errorf("Failed to parse parse VolumeLabels: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
}
}
v, ok := params[string(api.OptSnapID)]
if ok && v != nil {
sids := make([]api.SnapID, len(params))
for i, s := range v {
sids[i] = api.SnapID(s)
}
snaps, err = d.SnapInspect(sids)
if err != nil {
e := fmt.Errorf("Failed to inspect snaps: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
} else {
v, ok = params[string(api.OptVolumeID)]
if v != nil && ok {
ids = make([]api.VolumeID, len(params))
for i, s := range v {
ids[i] = api.VolumeID(s)
}
}
snaps, err = d.SnapEnumerate(ids, labels)
if err != nil {
e := fmt.Errorf("Failed to enumerate snaps: %s", err.Error())
vd.sendError(vd.name, method, w, e.Error(), http.StatusBadRequest)
return
}
}
json.NewEncoder(w).Encode(snaps)
}