本文整理汇总了Golang中github.com/juju/juju/state/binarystorage.Storage类的典型用法代码示例。如果您正苦于以下问题:Golang Storage类的具体用法?Golang Storage怎么用?Golang Storage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Storage类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setupGUIArchive
// setupGUIArchive creates a Juju GUI tar.bz2 archive with the given version
// and files and saves it into the given storage. The Juju GUI archive SHA256
// hash is returned.
func setupGUIArchive(c *gc.C, storage binarystorage.Storage, vers string, files map[string]string) (hash string) {
r, hash, size := makeGUIArchive(c, vers, files)
err := storage.Add(r, binarystorage.Metadata{
Version: vers,
Size: size,
SHA256: hash,
})
c.Assert(err, jc.ErrorIsNil)
return hash
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:gui_test.go
示例2: guiVersionAndHash
// guiVersionAndHash returns the version and the SHA256 hash of the current
// Juju GUI archive.
func guiVersionAndHash(st *state.State, storage binarystorage.Storage) (vers, hash string, err error) {
currentVers, err := st.GUIVersion()
if errors.IsNotFound(err) {
return "", "", errors.NotFoundf("Juju GUI")
}
if err != nil {
return "", "", errors.Annotate(err, "cannot retrieve current GUI version")
}
metadata, err := storage.Metadata(currentVers.String())
if err != nil {
return "", "", errors.Annotate(err, "cannot retrieve GUI metadata")
}
return metadata.Version, metadata.SHA256, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:16,代码来源:gui.go
示例3: fetchAndCacheTools
// fetchAndCacheTools fetches tools with the specified version by searching for a URL
// in simplestreams and GETting it, caching the result in tools storage before returning
// to the caller.
func (h *toolsDownloadHandler) fetchAndCacheTools(v version.Binary, stor binarystorage.Storage, st *state.State) (io.ReadCloser, error) {
envcfg, err := st.ModelConfig()
if err != nil {
return nil, err
}
env, err := environs.New(envcfg)
if err != nil {
return nil, err
}
tools, err := envtools.FindExactTools(env, v.Number, v.Series, v.Arch)
if err != nil {
return nil, err
}
// No need to verify the server's identity because we verify the SHA-256 hash.
logger.Infof("fetching %v tools from %v", v, tools.URL)
resp, err := utils.GetNonValidatingHTTPClient().Get(tools.URL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
msg := fmt.Sprintf("bad HTTP response: %v", resp.Status)
if body, err := ioutil.ReadAll(resp.Body); err == nil {
msg += fmt.Sprintf(" (%s)", bytes.TrimSpace(body))
}
return nil, errors.New(msg)
}
data, sha256, err := readAndHash(resp.Body)
if err != nil {
return nil, err
}
if int64(len(data)) != tools.Size {
return nil, errors.Errorf("size mismatch for %s", tools.URL)
}
if sha256 != tools.SHA256 {
return nil, errors.Errorf("hash mismatch for %s", tools.URL)
}
// Cache tarball in tools storage before returning.
metadata := binarystorage.Metadata{
Version: v.String(),
Size: tools.Size,
SHA256: tools.SHA256,
}
if err := stor.Add(bytes.NewReader(data), metadata); err != nil {
return nil, errors.Annotate(err, "error caching tools")
}
return ioutil.NopCloser(bytes.NewReader(data)), nil
}
开发者ID:makyo,项目名称:juju,代码行数:53,代码来源:tools.go
注:本文中的github.com/juju/juju/state/binarystorage.Storage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论