本文整理汇总了Golang中github.com/codedellemc/libstorage/api/types.Store.GetAttachments方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.GetAttachments方法的具体用法?Golang Store.GetAttachments怎么用?Golang Store.GetAttachments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codedellemc/libstorage/api/types.Store
的用法示例。
在下文中一共展示了Store.GetAttachments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: List
// List returns all available volume mappings.
func (d *driver) List(
ctx types.Context,
opts types.Store) ([]types.VolumeMapping, error) {
client := context.MustClient(ctx)
vols, err := client.Storage().Volumes(
ctx,
&types.VolumesOpts{
Attachments: opts.GetAttachments(),
Opts: opts,
},
)
if err != nil {
return nil, err
}
serviceName, serviceNameOK := context.ServiceName(ctx)
if !serviceNameOK {
return nil, goof.New("service name is missing")
}
volMaps := []types.VolumeMapping{}
for _, v := range vols {
vs := make(map[string]interface{})
vs["name"] = v.Name
vs["size"] = v.Size
vs["iops"] = v.IOPS
vs["type"] = v.Type
vs["availabilityZone"] = v.AvailabilityZone
vs["fields"] = v.Fields
vs["service"] = serviceName
vs["server"] = serviceName
volMaps = append(volMaps, &volumeMapping{
Name: v.Name,
VolumeMountPoint: v.MountPoint(),
VolumeStatus: vs,
})
}
return volMaps, nil
}
示例2: volumesForService
func (r *router) volumesForService(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
filter, err := parseFilter(store)
if err != nil {
return err
}
if filter != nil {
store.Set("filter", filter)
}
service := context.MustService(ctx)
opts := &types.VolumesOpts{
Attachments: store.GetAttachments(),
Opts: store,
}
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
return getFilteredVolumes(ctx, req, store, svc, opts, filter)
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
service.TaskExecute(ctx, run, schema.VolumeMapSchema),
http.StatusOK)
}
示例3: volumeInspect
func (r *router) volumeInspect(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
attachments := store.GetAttachments()
service := context.MustService(ctx)
iid, iidOK := context.InstanceID(ctx)
if !iidOK && attachments.RequiresInstanceID() {
return utils.NewMissingInstanceIDError(service.Name())
}
opts := &types.VolumeInspectOpts{
Attachments: attachments,
Opts: store,
}
var run types.StorageTaskRunFunc
if store.IsSet("byName") {
run = func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
vols, err := svc.Driver().Volumes(
ctx,
&types.VolumesOpts{
Attachments: attachments,
Opts: store,
})
if err != nil {
return nil, err
}
volID := store.GetString("volumeID")
for _, v := range vols {
if strings.EqualFold(v.Name, volID) {
if !handleVolAttachments(ctx, nil, iid, v, attachments) {
return nil, utils.NewNotFoundError(volID)
}
if OnVolume != nil {
ok, err := OnVolume(ctx, req, store, v)
if err != nil {
return nil, err
}
if !ok {
return nil, utils.NewNotFoundError(volID)
}
}
return v, nil
}
}
return nil, utils.NewNotFoundError(volID)
}
} else {
run = func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
v, err := svc.Driver().VolumeInspect(
ctx, store.GetString("volumeID"), opts)
if err != nil {
return nil, err
}
if !handleVolAttachments(ctx, nil, iid, v, attachments) {
return nil, utils.NewNotFoundError(v.ID)
}
if OnVolume != nil {
ok, err := 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.StatusOK)
}
示例4: volumes
func (r *router) volumes(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
filter, err := parseFilter(store)
if err != nil {
return err
}
if filter != nil {
store.Set("filter", filter)
}
var (
tasks = map[string]*types.Task{}
taskIDs []int
opts = &types.VolumesOpts{
Attachments: store.GetAttachments(),
Opts: store,
}
reply = types.ServiceVolumeMap{}
)
for service := range services.StorageServices(ctx) {
run := func(
ctx types.Context,
svc types.StorageService) (interface{}, error) {
ctx = context.WithStorageService(ctx, svc)
var err error
if ctx, err = context.WithStorageSession(ctx); err != nil {
return nil, err
}
return getFilteredVolumes(ctx, req, store, svc, opts, filter)
}
task := service.TaskExecute(ctx, run, schema.VolumeMapSchema)
taskIDs = append(taskIDs, task.ID)
tasks[service.Name()] = task
}
run := func(ctx types.Context) (interface{}, error) {
services.TaskWaitAll(ctx, taskIDs...)
for k, v := range tasks {
if v.Error != nil {
return nil, utils.NewBatchProcessErr(reply, v.Error)
}
objMap, ok := v.Result.(types.VolumeMap)
if !ok {
return nil, utils.NewBatchProcessErr(
reply, goof.New("error casting to types.VolumeMap"))
}
reply[k] = objMap
}
return reply, nil
}
return httputils.WriteTask(
ctx,
r.config,
w,
store,
services.TaskExecute(ctx, run, schema.ServiceVolumeMapSchema),
http.StatusOK)
}