當前位置: 首頁>>代碼示例>>Golang>>正文


Golang State.ImageStorage方法代碼示例

本文整理匯總了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
}
開發者ID:imoapps,項目名稱:juju,代碼行數:32,代碼來源:images.go

示例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
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:9,代碼來源:images_test.go

示例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)
}
開發者ID:pmatulis,項目名稱:juju,代碼行數:14,代碼來源:images_test.go


注:本文中的github.com/juju/juju/state.State.ImageStorage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。