本文整理汇总了Golang中github.com/juju/juju/state.State.ImageStorage方法的典型用法代码示例。如果您正苦于以下问题:Golang State.ImageStorage方法的具体用法?Golang State.ImageStorage怎么用?Golang State.ImageStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/state.State
的用法示例。
在下文中一共展示了State.ImageStorage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loadImage
// loadImage loads an os image from the blobstore,
// downloading and caching it if necessary.
func (h *imagesDownloadHandler) loadImage(st *state.State, envuuid, kind, series, arch string) (
*imagestorage.Metadata, io.ReadCloser, error,
) {
// We want to ensure that if an image needs to be downloaded and cached,
// this only happens once.
imageIdent := fmt.Sprintf("image-%s-%s-%s-%s", envuuid, kind, series, arch)
lockDir := filepath.Join(h.dataDir, "locks")
lock, err := fslock.NewLock(lockDir, imageIdent, fslock.Defaults())
if err != nil {
return nil, nil, errors.Trace(err)
}
lock.Lock("fetch and cache image " + imageIdent)
defer lock.Unlock()
storage := st.ImageStorage()
metadata, imageReader, err := storage.Image(kind, series, arch)
// Not in storage, so go fetch it.
if errors.IsNotFound(err) {
if err := h.fetchAndCacheLxcImage(storage, envuuid, series, arch); err != nil {
return nil, nil, errors.Annotate(err, "error fetching and caching image")
}
err = networkOperationWitDefaultRetries(func() error {
metadata, imageReader, err = storage.Image(string(instance.LXC), series, arch)
return err
}, "streaming os image from blobstore")()
}
if err != nil {
return nil, nil, errors.Trace(err)
}
return metadata, imageReader, nil
}
示例2: getImageFromStorage
func (s *imageSuite) getImageFromStorage(c *gc.C, st *state.State, kind, series, arch string) (*imagestorage.Metadata, []byte) {
storage := st.ImageStorage()
metadata, r, err := storage.Image(kind, series, arch)
c.Assert(err, gc.IsNil)
data, err := ioutil.ReadAll(r)
r.Close()
c.Assert(err, gc.IsNil)
return metadata, data
}
示例3: storeFakeImage
func (s *imageSuite) storeFakeImage(c *gc.C, st *state.State, kind, series, arch string) {
storage := st.ImageStorage()
metadata := &imagestorage.Metadata{
ModelUUID: st.ModelUUID(),
Kind: kind,
Series: series,
Arch: arch,
Size: int64(len(testImageData)),
SHA256: testImageChecksum,
SourceURL: "http://path",
}
err := storage.AddImage(strings.NewReader(testImageData), metadata)
c.Assert(err, gc.IsNil)
}