本文整理汇总了Golang中github.com/codedellemc/libstorage/api/types.Store类的典型用法代码示例。如果您正苦于以下问题:Golang Store类的具体用法?Golang Store怎么用?Golang Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Handle
// Handle is the type's Handler function.
func (h *postArgsHandler) Handle(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
reqObj := ctx.Value("reqObj")
if reqObj == nil {
return fmt.Errorf("missing request object")
}
v := reflect.ValueOf(reqObj).Elem()
t := v.Type()
for i := 0; i < v.NumField(); i++ {
ft := t.Field(i)
fv := v.Field(i).Interface()
switch tfv := fv.(type) {
case nil:
// do nothing
case map[string]interface{}:
store.Set(getFieldName(ft), utils.NewStoreWithData(tfv))
default:
// add it to the store
store.Set(getFieldName(ft), fv)
}
}
return h.handler(ctx, w, req, store)
}
示例2: SnapshotCopy
func (d *driver) SnapshotCopy(
ctx types.Context,
snapshotID, snapshotName, destinationID string,
opts types.Store) (*types.Snapshot, error) {
context.MustSession(ctx)
ogSnap, err := d.getSnapshotByID(snapshotID)
if err != nil {
return nil, err
}
newSnap := &types.Snapshot{
ID: d.newSnapshotID(ogSnap.VolumeID),
VolumeID: ogSnap.VolumeID,
VolumeSize: ogSnap.VolumeSize,
Name: snapshotName,
Status: "online",
StartTime: time.Now().Unix(),
Fields: ogSnap.Fields,
}
if customFields := opts.GetStore("opts"); customFields != nil {
for _, k := range customFields.Keys() {
newSnap.Fields[k] = customFields.GetString(k)
}
}
if err := d.writeSnapshot(newSnap); err != nil {
return nil, err
}
return newSnap, nil
}
示例3: snapshotRemove
func (r *router) snapshotRemove(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
service := context.MustService(ctx)
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
return nil, svc.Driver().SnapshotRemove(
ctx,
store.GetString("snapshotID"),
store)
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, nil),
http.StatusResetContent)
}
示例4: WriteTask
// WriteTask writes a task to a ResponseWriter.
func WriteTask(
ctx types.Context,
config gofig.Config,
w http.ResponseWriter,
store types.Store,
task *types.Task,
okStatus int) error {
if store.GetBool("async") {
WriteJSON(w, http.StatusAccepted, task)
return nil
}
exeTimeoutDur, err := time.ParseDuration(
config.GetString(types.ConfigServerTasksExeTimeout))
if err != nil {
exeTimeoutDur = time.Duration(time.Second * 60)
}
exeTimeout := time.NewTimer(exeTimeoutDur)
select {
case <-services.TaskWaitC(ctx, task.ID):
if task.Error != nil {
return task.Error
}
WriteJSON(w, okStatus, task.Result)
case <-exeTimeout.C:
WriteJSON(w, http.StatusRequestTimeout, task)
}
return nil
}
示例5: volumeSnapshot
func (r *router) volumeSnapshot(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
service := context.MustService(ctx)
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
return svc.Driver().VolumeSnapshot(
ctx,
store.GetString("volumeID"),
store.GetString("snapshotName"),
store)
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, schema.SnapshotSchema),
http.StatusCreated)
}
示例6: VolumeSnapshot
func (d *driver) VolumeSnapshot(
ctx types.Context,
volumeID, snapshotName string,
opts types.Store) (*types.Snapshot, error) {
context.MustSession(ctx)
v, err := d.getVolumeByID(volumeID)
if err != nil {
return nil, err
}
s := &types.Snapshot{
ID: d.newSnapshotID(v.ID),
VolumeID: v.ID,
VolumeSize: v.Size,
Name: snapshotName,
Status: "online",
StartTime: time.Now().Unix(),
Fields: v.Fields,
}
if customFields := opts.GetStore("opts"); customFields != nil {
for _, k := range customFields.Keys() {
s.Fields[k] = customFields.GetString(k)
}
}
if err := d.writeSnapshot(s); err != nil {
return nil, err
}
return s, nil
}
示例7: VolumeCopy
func (d *driver) VolumeCopy(
ctx types.Context,
volumeID, volumeName string,
opts types.Store) (*types.Volume, error) {
context.MustSession(ctx)
ogVol, err := d.getVolumeByID(volumeID)
if err != nil {
return nil, err
}
newVol := &types.Volume{
ID: d.newVolumeID(),
Name: volumeName,
AvailabilityZone: ogVol.AvailabilityZone,
IOPS: ogVol.IOPS,
Size: ogVol.Size,
Type: ogVol.Type,
Fields: ogVol.Fields,
}
if customFields := opts.GetStore("opts"); customFields != nil {
for _, k := range customFields.Keys() {
newVol.Fields[k] = customFields.GetString(k)
}
}
if err := d.writeVolume(newVol); err != nil {
return nil, err
}
return newVol, nil
}
示例8: volumeDetach
func (r *router) volumeDetach(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
service := context.MustService(ctx)
if _, ok := context.InstanceID(ctx); !ok {
return utils.NewMissingInstanceIDError(service.Name())
}
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
v, err := svc.Driver().VolumeDetach(
ctx,
store.GetString("volumeID"),
&types.VolumeDetachOpts{
Force: store.GetBool("force"),
Opts: store,
})
if err != nil {
return nil, err
}
if v == nil {
return nil, nil
}
if OnVolume != nil {
ok, err := OnVolume(ctx, req, store, v)
if err != nil {
return nil, err
}
if !ok {
return nil, utils.NewNotFoundError(v.ID)
}
}
if v.AttachmentState == 0 {
v.AttachmentState = types.VolumeAvailable
}
return v, nil
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, nil),
http.StatusResetContent)
}
示例9: parseFilter
func parseFilter(store types.Store) (*types.Filter, error) {
if !store.IsSet("filter") {
return nil, nil
}
fsz := store.GetString("filter")
filter, err := filters.CompileFilter(fsz)
if err != nil {
return nil, utils.NewBadFilterErr(fsz, err)
}
return filter, nil
}
示例10: executorHead
func (r *router) executorHead(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
ei, err := executors.ExecutorInfoInspect(store.GetString("executor"), false)
if err != nil {
return err
}
return writeFile(w, ei)
}
示例11: volumeCreate
func (r *router) volumeCreate(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
service := context.MustService(ctx)
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
v, err := svc.Driver().VolumeCreateFromSnapshot(
ctx,
store.GetString("snapshotID"),
store.GetString("name"),
&types.VolumeCreateOpts{
AvailabilityZone: store.GetStringPtr("availabilityZone"),
IOPS: store.GetInt64Ptr("iops"),
Size: store.GetInt64Ptr("size"),
Type: store.GetStringPtr("type"),
Opts: store,
})
if err != nil {
return nil, err
}
if volume.OnVolume != nil {
ok, err := volume.OnVolume(ctx, req, store, v)
if err != nil {
return nil, err
}
if !ok {
return nil, utils.NewNotFoundError(v.ID)
}
}
return v, nil
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, schema.VolumeSchema),
http.StatusCreated)
}
示例12: volumeCopy
func (r *router) volumeCopy(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
service := context.MustService(ctx)
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
v, err := svc.Driver().VolumeCopy(
ctx,
store.GetString("volumeID"),
store.GetString("volumeName"),
store)
if err != nil {
return nil, err
}
if OnVolume != nil {
ok, err := OnVolume(ctx, req, store, v)
if err != nil {
return nil, err
}
if !ok {
return nil, utils.NewNotFoundError(v.ID)
}
}
if v.AttachmentState == 0 {
v.AttachmentState = types.VolumeAvailable
}
return v, nil
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, schema.VolumeSchema),
http.StatusCreated)
}
示例13: VolumeSnapshot
func (d *driver) VolumeSnapshot(
ctx types.Context,
volumeID, snapshotName string,
opts types.Store) (*types.Snapshot, error) {
ctx = d.requireCtx(ctx)
serviceName, ok := context.ServiceName(ctx)
if !ok {
return nil, goof.New("missing service name")
}
req := &types.VolumeSnapshotRequest{
SnapshotName: snapshotName,
Opts: opts.Map(),
}
return d.client.VolumeSnapshot(ctx, serviceName, volumeID, req)
}
示例14: Handle
// Handle is the type's Handler function.
func (h *serviceValidator) Handle(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
if !store.IsSet("service") {
return utils.NewStoreKeyErr("service")
}
serviceName := store.GetString("service")
service := services.GetStorageService(ctx, serviceName)
if service == nil {
return utils.NewNotFoundError(serviceName)
}
ctx = context.WithStorageService(ctx, service)
return h.handler(ctx, w, req, store)
}
示例15: SnapshotCopy
func (d *driver) SnapshotCopy(
ctx types.Context,
snapshotID, snapshotName, destinationID string,
opts types.Store) (*types.Snapshot, error) {
ctx = d.requireCtx(ctx)
serviceName, ok := context.ServiceName(ctx)
if !ok {
return nil, goof.New("missing service name")
}
req := &types.SnapshotCopyRequest{
SnapshotName: snapshotName,
DestinationID: destinationID,
Opts: opts.Map(),
}
return d.client.SnapshotCopy(ctx, serviceName, snapshotID, req)
}