本文整理汇总了Golang中github.com/vmware/vic/lib/apiservers/portlayer/restapi/operations.PortLayerAPI.StorageGetImageHandler方法的典型用法代码示例。如果您正苦于以下问题:Golang PortLayerAPI.StorageGetImageHandler方法的具体用法?Golang PortLayerAPI.StorageGetImageHandler怎么用?Golang PortLayerAPI.StorageGetImageHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/lib/apiservers/portlayer/restapi/operations.PortLayerAPI
的用法示例。
在下文中一共展示了PortLayerAPI.StorageGetImageHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Configure
// Configure assigns functions to all the storage api handlers
func (handler *StorageHandlersImpl) Configure(api *operations.PortLayerAPI, handlerCtx *HandlerContext) {
var err error
ctx := context.Background()
sessionconfig := &session.Config{
Service: options.PortLayerOptions.SDK,
Insecure: options.PortLayerOptions.Insecure,
Keepalive: options.PortLayerOptions.Keepalive,
DatacenterPath: options.PortLayerOptions.DatacenterPath,
ClusterPath: options.PortLayerOptions.ClusterPath,
PoolPath: options.PortLayerOptions.PoolPath,
DatastorePath: options.PortLayerOptions.DatastorePath,
}
storageSession, err := session.NewSession(sessionconfig).Create(ctx)
if err != nil {
log.Fatalf("StorageHandler ERROR: %s", err)
}
if len(spl.Config.ImageStores) == 0 {
log.Panicf("No image stores provided; unable to instantiate storage layer")
}
imageStoreURL := spl.Config.ImageStores[0]
// TODO: support multiple image stores. Right now we only support the first one
if len(spl.Config.ImageStores) > 1 {
log.Warningf("Multiple image stores found. Multiple image stores are not yet supported. Using [%s] %s", imageStoreURL.Host, imageStoreURL.Path)
}
ds, err := vsphereSpl.NewImageStore(ctx, storageSession, &imageStoreURL)
if err != nil {
log.Panicf("Cannot instantiate storage layer: %s", err)
}
// The imagestore is implemented via a cache which is backed via an
// implementation that writes to disks. The cache is used to avoid
// expensive metadata lookups.
storageImageLayer = spl.NewLookupCache(ds)
vsVolumeStore, err := vsphereSpl.NewVolumeStore(context.TODO(), storageSession)
if err != nil {
log.Panicf("Cannot instantiate the volume store: %s", err)
}
// Get the datastores for volumes.
// Each volume store name maps to a datastore + path, which can be referred to by the name.
dstores, err := datastore.GetDatastores(context.TODO(), storageSession, spl.Config.VolumeLocations)
if err != nil {
log.Panicf("Cannot find datastores: %s", err)
}
// Add datastores to the vsphere volume store impl
for volStoreName, volDatastore := range dstores {
log.Infof("Adding volume store %s (%s)", volStoreName, volDatastore.RootURL)
_, err := vsVolumeStore.AddStore(context.TODO(), volDatastore, volStoreName)
if err != nil {
log.Errorf("volume addition error %s", err)
}
}
storageVolumeLayer, err = spl.NewVolumeLookupCache(context.TODO(), vsVolumeStore)
if err != nil {
log.Panicf("Cannot instantiate the Volume Lookup cache: %s", err)
}
api.StorageCreateImageStoreHandler = storage.CreateImageStoreHandlerFunc(handler.CreateImageStore)
api.StorageGetImageHandler = storage.GetImageHandlerFunc(handler.GetImage)
api.StorageGetImageTarHandler = storage.GetImageTarHandlerFunc(handler.GetImageTar)
api.StorageListImagesHandler = storage.ListImagesHandlerFunc(handler.ListImages)
api.StorageWriteImageHandler = storage.WriteImageHandlerFunc(handler.WriteImage)
api.StorageVolumeStoresListHandler = storage.VolumeStoresListHandlerFunc(handler.VolumeStoresList)
api.StorageCreateVolumeHandler = storage.CreateVolumeHandlerFunc(handler.CreateVolume)
api.StorageRemoveVolumeHandler = storage.RemoveVolumeHandlerFunc(handler.RemoveVolume)
api.StorageVolumeJoinHandler = storage.VolumeJoinHandlerFunc(handler.VolumeJoin)
api.StorageListVolumesHandler = storage.ListVolumesHandlerFunc(handler.VolumesList)
}
示例2: Configure
// Configure assigns functions to all the storage api handlers
func (h *StorageHandlersImpl) Configure(api *operations.PortLayerAPI, handlerCtx *HandlerContext) {
var err error
ctx := context.Background()
op := trace.NewOperation(ctx, "configure")
if len(spl.Config.ImageStores) == 0 {
log.Panicf("No image stores provided; unable to instantiate storage layer")
}
imageStoreURL := spl.Config.ImageStores[0]
// TODO: support multiple image stores. Right now we only support the first one
if len(spl.Config.ImageStores) > 1 {
log.Warningf("Multiple image stores found. Multiple image stores are not yet supported. Using [%s] %s", imageStoreURL.Host, imageStoreURL.Path)
}
ds, err := vsphereSpl.NewImageStore(op, handlerCtx.Session, &imageStoreURL)
if err != nil {
log.Panicf("Cannot instantiate storage layer: %s", err)
}
// The imagestore is implemented via a cache which is backed via an
// implementation that writes to disks. The cache is used to avoid
// expensive metadata lookups.
h.imageCache = spl.NewLookupCache(ds)
// The same is done for volumes. It's implemented via a cache which writes
// to an implementation that takes a datastore to write to.
vsVolumeStore, err := vsphereSpl.NewVolumeStore(op, handlerCtx.Session)
if err != nil {
log.Panicf("Cannot instantiate the volume store: %s", err)
}
// Get the datastores for volumes.
// Each volume store name maps to a datastore + path, which can be referred to by the name.
dstores, err := datastore.GetDatastores(context.TODO(), handlerCtx.Session, spl.Config.VolumeLocations)
if err != nil {
log.Panicf("Cannot find datastores: %s", err)
}
// Add datastores to the vsphere volume store impl
for volStoreName, volDatastore := range dstores {
log.Infof("Adding volume store %s (%s)", volStoreName, volDatastore.RootURL)
_, err := vsVolumeStore.AddStore(op, volDatastore, volStoreName)
if err != nil {
log.Errorf("volume addition error %s", err)
}
}
h.volumeCache, err = spl.NewVolumeLookupCache(op, vsVolumeStore)
if err != nil {
log.Panicf("Cannot instantiate the Volume Lookup cache: %s", err)
}
api.StorageCreateImageStoreHandler = storage.CreateImageStoreHandlerFunc(h.CreateImageStore)
api.StorageGetImageHandler = storage.GetImageHandlerFunc(h.GetImage)
api.StorageGetImageTarHandler = storage.GetImageTarHandlerFunc(h.GetImageTar)
api.StorageListImagesHandler = storage.ListImagesHandlerFunc(h.ListImages)
api.StorageWriteImageHandler = storage.WriteImageHandlerFunc(h.WriteImage)
api.StorageDeleteImageHandler = storage.DeleteImageHandlerFunc(h.DeleteImage)
api.StorageVolumeStoresListHandler = storage.VolumeStoresListHandlerFunc(h.VolumeStoresList)
api.StorageCreateVolumeHandler = storage.CreateVolumeHandlerFunc(h.CreateVolume)
api.StorageRemoveVolumeHandler = storage.RemoveVolumeHandlerFunc(h.RemoveVolume)
api.StorageVolumeJoinHandler = storage.VolumeJoinHandlerFunc(h.VolumeJoin)
api.StorageListVolumesHandler = storage.ListVolumesHandlerFunc(h.VolumesList)
api.StorageGetVolumeHandler = storage.GetVolumeHandlerFunc(h.GetVolume)
}