当前位置: 首页>>代码示例>>Golang>>正文


Golang Storage.Put方法代码示例

本文整理汇总了Golang中github.com/juju/juju/environs/storage.Storage.Put方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.Put方法的具体用法?Golang Storage.Put怎么用?Golang Storage.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/juju/juju/environs/storage.Storage的用法示例。


在下文中一共展示了Storage.Put方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: restoreBootstrapVerificationFile

func restoreBootstrapVerificationFile(c *gc.C, stor storage.Storage) {
	content := "juju-core storage writing verified: ok\n"
	contentReader := strings.NewReader(content)
	err := stor.Put("bootstrap-verify", contentReader,
		int64(len(content)))
	c.Assert(err, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:7,代码来源:livetests.go

示例2: VerifyStorage

// VerifyStorage writes the bootstrap init file to the storage to indicate
// that the storage is writable.
func VerifyStorage(stor storage.Storage) error {
	reader := strings.NewReader(verificationContent)
	err := stor.Put(VerificationFilename, reader,
		int64(len(verificationContent)))
	if err != nil {
		logger.Warningf("failed to write bootstrap-verify file: %v", err)
		return VerifyStorageError
	}
	return nil
}
开发者ID:zhouqt,项目名称:juju,代码行数:12,代码来源:open.go

示例3: UseTestImageMetadata

func UseTestImageMetadata(c *gc.C, stor storage.Storage) {
	files := map[string]string{
		"images/streams/v1/index.json":                          indexData,
		"images/streams/v1/com.ubuntu.cloud:released:maas.json": imagesData,
	}
	for f, d := range files {
		rdr := strings.NewReader(d)
		err := stor.Put(f, rdr, int64(len(d)))
		c.Assert(err, jc.ErrorIsNil)
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:11,代码来源:export_test.go

示例4: uploadMetadataFile

func uploadMetadataFile(stor storage.Storage, metadataDir, fileName string, size int64) error {
	fullSourceFilename := filepath.Join(metadataDir, fileName)
	logger.Debugf("uploading metadata file %s", fileName)
	f, err := os.Open(fullSourceFilename)
	if err != nil {
		return err
	}
	defer f.Close()
	destMetadataDir := path.Join(storage.BaseImagesPath, simplestreams.StreamsDir)
	return stor.Put(path.Join(destMetadataDir, fileName), f, size)
}
开发者ID:jiasir,项目名称:juju,代码行数:11,代码来源:upload.go

示例5: UseTestImageData

func UseTestImageData(stor envstorage.Storage, cred *identity.Credentials) {
	// Put some image metadata files into the public storage.
	t := template.Must(template.New("").Parse(indexData))
	var metadata bytes.Buffer
	if err := t.Execute(&metadata, cred); err != nil {
		panic(fmt.Errorf("cannot generate index metdata: %v", err))
	}
	data := metadata.Bytes()
	stor.Put(simplestreams.UnsignedIndex("v1", 1), bytes.NewReader(data), int64(len(data)))
	stor.Put(
		productMetadatafile, strings.NewReader(imagesData), int64(len(imagesData)))
}
开发者ID:Pankov404,项目名称:juju,代码行数:12,代码来源:export_test.go

示例6: storageCopy

func storageCopy(source storage.Storage, sourcePath string, target storage.Storage, targetPath string) error {
	rc, err := storage.Get(source, sourcePath)
	if err != nil {
		return err
	}
	var buf bytes.Buffer
	_, err = io.Copy(&buf, rc)
	rc.Close()
	if err != nil {
		return err
	}
	return target.Put(targetPath, &buf, int64(buf.Len()))
}
开发者ID:klyachin,项目名称:juju,代码行数:13,代码来源:livetests.go

示例7: uploadFakeToolsVersion

func uploadFakeToolsVersion(stor storage.Storage, toolsDir string, vers version.Binary) (*coretools.Tools, error) {
	logger.Infof("uploading FAKE tools %s", vers)
	tgz, checksum := makeFakeTools(vers)
	size := int64(len(tgz))
	name := envtools.StorageName(vers, toolsDir)
	if err := stor.Put(name, bytes.NewReader(tgz), size); err != nil {
		return nil, err
	}
	url, err := stor.URL(name)
	if err != nil {
		return nil, err
	}
	return &coretools.Tools{URL: url, Version: vers, Size: size, SHA256: checksum}, nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:14,代码来源:tools.go

示例8: uploadFakeToolsVersion

func uploadFakeToolsVersion(stor storage.Storage, vers version.Binary) (*coretools.Tools, error) {
	logger.Infof("uploading FAKE tools %s", vers)
	tgz, checksum := coretesting.TarGz(
		coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String()))
	size := int64(len(tgz))
	name := envtools.StorageName(vers)
	if err := stor.Put(name, bytes.NewReader(tgz), size); err != nil {
		return nil, err
	}
	url, err := stor.URL(name)
	if err != nil {
		return nil, err
	}
	return &coretools.Tools{URL: url, Version: vers, Size: size, SHA256: checksum}, nil
}
开发者ID:jiasir,项目名称:juju,代码行数:15,代码来源:tools.go

示例9: copyOneToolsPackage

// copyOneToolsPackage copies one tool from the source to the target.
func copyOneToolsPackage(tool *coretools.Tools, dest storage.Storage) error {
	toolsName := envtools.StorageName(tool.Version)
	logger.Infof("copying %v", toolsName)
	resp, err := utils.GetValidatingHTTPClient().Get(tool.URL)
	if err != nil {
		return err
	}
	buf := &bytes.Buffer{}
	srcFile := resp.Body
	defer srcFile.Close()
	tool.SHA256, tool.Size, err = utils.ReadSHA256(io.TeeReader(srcFile, buf))
	if err != nil {
		return err
	}
	sizeInKB := (tool.Size + 512) / 1024
	logger.Infof("downloaded %v (%dkB), uploading", toolsName, sizeInKB)
	logger.Infof("download %dkB, uploading", sizeInKB)
	return dest.Put(toolsName, buf, tool.Size)
}
开发者ID:jiasir,项目名称:juju,代码行数:20,代码来源:sync.go

示例10: checkRemoveAll

func checkRemoveAll(c *gc.C, stor storage.Storage) {
	contents := []byte("File contents.")
	aFile := "a-file.txt"
	err := stor.Put(aFile, bytes.NewBuffer(contents), int64(len(contents)))
	c.Assert(err, gc.IsNil)
	err = stor.Put("empty-file", bytes.NewBuffer(nil), 0)
	c.Assert(err, gc.IsNil)

	err = stor.RemoveAll()
	c.Assert(err, gc.IsNil)

	files, err := storage.List(stor, "")
	c.Assert(err, gc.IsNil)
	c.Check(files, gc.HasLen, 0)

	_, err = storage.Get(stor, aFile)
	c.Assert(err, gc.NotNil)
	c.Check(err, gc.ErrorMatches, fmt.Sprintf("file %q not found", aFile))
}
开发者ID:kapilt,项目名称:juju,代码行数:19,代码来源:storage_test.go

示例11: writeMetadata

// writeMetadata generates some basic simplestreams metadata using the specified cloud and image details and writes
// it to the supplied store.
func writeMetadata(metadata []*ImageMetadata, cloudSpec []simplestreams.CloudSpec,
	metadataStore storage.Storage) error {

	index, products, err := MarshalImageMetadataJSON(metadata, cloudSpec, time.Now())
	if err != nil {
		return err
	}
	metadataInfo := []MetadataFile{
		{IndexStoragePath(), index},
		{ProductMetadataStoragePath(), products},
	}
	for _, md := range metadataInfo {
		err = metadataStore.Put(md.Path, bytes.NewReader(md.Data), int64(len(md.Data)))
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:Pankov404,项目名称:juju,代码行数:21,代码来源:generate.go

示例12: SignFileData

func SignFileData(stor storage.Storage, fileName string) error {
	r, err := stor.Get(fileName)
	if err != nil {
		return err
	}
	defer r.Close()

	fileData, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}

	signedName, signedContent, err := sstesting.SignMetadata(fileName, fileData)
	if err != nil {
		return err
	}

	err = stor.Put(signedName, strings.NewReader(string(signedContent)), int64(len(string(signedContent))))
	if err != nil {
		return err
	}
	return nil
}
开发者ID:pmatulis,项目名称:juju,代码行数:23,代码来源:tools.go

示例13: UploadToStorage

// UploadToStorage uploads tools and metadata for the specified versions to storage.
func UploadToStorage(c *gc.C, stor storage.Storage, stream string, versions ...version.Binary) map[version.Binary]string {
	uploaded := map[version.Binary]string{}
	if len(versions) == 0 {
		return uploaded
	}
	var err error
	for _, vers := range versions {
		filename := fmt.Sprintf("tools/%s/tools-%s.tar.gz", stream, vers.String())
		// Put a file in images since the dummy storage provider requires a
		// file to exist before the URL can be found. This is to ensure it behaves
		// the same way as MAAS.
		err = stor.Put(filename, strings.NewReader("dummy"), 5)
		c.Assert(err, jc.ErrorIsNil)
		uploaded[vers], err = stor.URL(filename)
		c.Assert(err, jc.ErrorIsNil)
	}
	objects := generateMetadata(c, stream, versions...)
	for _, object := range objects {
		toolspath := path.Join("tools", object.path)
		err = stor.Put(toolspath, bytes.NewReader(object.data), int64(len(object.data)))
		c.Assert(err, jc.ErrorIsNil)
	}
	return uploaded
}
开发者ID:kakamessi99,项目名称:juju,代码行数:25,代码来源:testing.go

示例14: WriteMetadata

// WriteMetadata writes the given tools metadata to the given storage.
func WriteMetadata(stor storage.Storage, metadata []*ToolsMetadata, writeMirrors ShouldWriteMirrors) error {
	updated := time.Now()
	index, products, err := MarshalToolsMetadataJSON(metadata, updated)
	if err != nil {
		return err
	}
	metadataInfo := []MetadataFile{
		{simplestreams.UnsignedIndex, index},
		{ProductMetadataPath, products},
	}
	if writeMirrors {
		mirrorsUpdated := updated.Format("20060102") // YYYYMMDD
		mirrorsInfo := strings.Replace(PublicMirrorsInfo, "{{updated}}", mirrorsUpdated, -1)
		metadataInfo = append(metadataInfo, MetadataFile{simplestreams.UnsignedMirror, []byte(mirrorsInfo)})
	}
	for _, md := range metadataInfo {
		logger.Infof("Writing %s", "tools/"+md.Path)
		err = stor.Put(path.Join(storage.BaseToolsPath, md.Path), bytes.NewReader(md.Data), int64(len(md.Data)))
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:rogpeppe,项目名称:juju,代码行数:25,代码来源:simplestreams.go


注:本文中的github.com/juju/juju/environs/storage.Storage.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。