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


Golang swift.New函數代碼示例

本文整理匯總了Golang中launchpad/net/goose/swift.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PublicStorage

func (e *environ) PublicStorage() environs.StorageReader {
	e.publicStorageMutex.Lock()
	defer e.publicStorageMutex.Unlock()
	ecfg := e.ecfg()
	// If public storage has already been determined, return that instance.
	publicStorage := e.publicStorageUnlocked
	if publicStorage == nil && ecfg.publicBucket() == "" {
		// If there is no public bucket name, then there can be no public storage.
		e.publicStorageUnlocked = environs.EmptyStorage
		publicStorage = e.publicStorageUnlocked
	}
	if publicStorage != nil {
		return publicStorage
	}
	// If there is a public bucket URL defined, set up a public storage client referencing that URL,
	// otherwise create a new public bucket using the user's credentials on the authenticated client.
	publicBucketURL := e.publicBucketURL()
	if publicBucketURL == "" {
		e.publicStorageUnlocked = &storage{
			containerName: ecfg.publicBucket(),
			// this is possibly just a hack - if the ACL is swift.Private,
			// the machine won't be able to get the tools (401 error)
			containerACL: swift.PublicRead,
			swift:        swift.New(e.client)}
	} else {
		pc := client.NewPublicClient(publicBucketURL, nil)
		e.publicStorageUnlocked = &storage{
			containerName: ecfg.publicBucket(),
			containerACL:  swift.PublicRead,
			swift:         swift.New(pc)}
	}
	publicStorage = e.publicStorageUnlocked
	return publicStorage
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:34,代碼來源:provider.go

示例2: SetConfig

func (e *environ) SetConfig(cfg *config.Config) error {
	ecfg, err := providerInstance.newConfig(cfg)
	if err != nil {
		return err
	}
	// At this point, the authentication method config value has been validated so we extract it's value here
	// to avoid having to validate again each time when creating the OpenStack client.
	var authMethodCfg AuthMethod
	e.ecfgMutex.Lock()
	defer e.ecfgMutex.Unlock()
	e.name = ecfg.Name()
	authMethodCfg = AuthMethod(ecfg.authMethod())
	e.ecfgUnlocked = ecfg

	novaClient := e.client(ecfg, authMethodCfg)
	e.novaUnlocked = nova.New(novaClient)

	// create new storage instances, existing instances continue
	// to reference their existing configuration.
	e.storageUnlocked = &storage{
		containerName: ecfg.controlBucket(),
		containerACL:  swift.Private,
		swift:         swift.New(e.client(ecfg, authMethodCfg))}
	if ecfg.publicBucket() != "" && ecfg.publicBucketURL() != "" {
		e.publicStorageUnlocked = &storage{
			containerName: ecfg.publicBucket(),
			containerACL:  swift.PublicRead,
			swift:         swift.New(e.publicClient(ecfg))}
	} else {
		e.publicStorageUnlocked = nil
	}

	return nil
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:34,代碼來源:provider.go

示例3: ImageMetadataStorage

// ImageMetadataStorage returns a Storage object pointing where the goose
// infrastructure sets up its keystone entry for image metadata
func ImageMetadataStorage(e environs.Environ) storage.Storage {
	env := e.(*environ)
	return &openstackstorage{
		containerName: "imagemetadata",
		swift:         swift.New(env.client),
	}
}
開發者ID:jkary,項目名稱:core,代碼行數:9,代碼來源:export_test.go

示例4: SetConfig

func (e *environ) SetConfig(cfg *config.Config) error {
	ecfg, err := providerInstance.newConfig(cfg)
	if err != nil {
		return err
	}
	// At this point, the authentication method config value has been validated so we extract it's value here
	// to avoid having to validate again each time when creating the OpenStack client.
	var authModeCfg AuthMode
	e.ecfgMutex.Lock()
	defer e.ecfgMutex.Unlock()
	authModeCfg = AuthMode(ecfg.authMode())
	e.ecfgUnlocked = ecfg

	e.client = e.authClient(ecfg, authModeCfg)
	e.novaUnlocked = nova.New(e.client)

	// create new control storage instance, existing instances continue
	// to reference their existing configuration.
	// public storage instance creation is deferred until needed since authenticated
	// access to the identity service is required so that any juju-tools endpoint can be used.
	e.storageUnlocked = &storage{
		containerName: ecfg.controlBucket(),
		// this is possibly just a hack - if the ACL is swift.Private,
		// the machine won't be able to get the tools (401 error)
		containerACL: swift.PublicRead,
		swift:        swift.New(e.client)}
	e.publicStorageUnlocked = nil
	return nil
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:29,代碼來源:provider.go

示例5: CreateCustomStorage

// CreateCustomStorage creates a swift container and returns the Storage object
// so you can put data into it.
func CreateCustomStorage(e environs.Environ, containerName string) storage.Storage {
	env := e.(*environ)
	swiftClient := swift.New(env.client)
	if err := swiftClient.CreateContainer(containerName, swift.PublicRead); err != nil {
		panic(err)
	}
	return &openstackstorage{
		containerName: containerName,
		swift:         swiftClient,
	}
}
開發者ID:jkary,項目名稱:core,代碼行數:13,代碼來源:export_test.go

示例6: WritablePublicStorage

// WritablePublicStorage returns a Storage instance which is authorised to write to the PublicStorage bucket.
// It is used by tests which need to upload files.
func WritablePublicStorage(e environs.Environ) environs.Storage {
	ecfg := e.(*environ).ecfg()
	authModeCfg := AuthMode(ecfg.authMode())
	writablePublicStorage := &storage{
		containerName: ecfg.publicBucket(),
		swift:         swift.New(e.(*environ).authClient(ecfg, authModeCfg)),
	}

	// Ensure the container exists.
	err := writablePublicStorage.makeContainer(ecfg.publicBucket(), swift.PublicRead)
	if err != nil {
		panic(fmt.Errorf("cannot create writable public container: %v", err))
	}
	return writablePublicStorage
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:17,代碼來源:export_test.go

示例7: MetadataStorage

// MetadataStorage returns a Storage instance which is used to store simplestreams metadata for tests.
func MetadataStorage(e environs.Environ) storage.Storage {
	ecfg := e.(*environ).ecfg()
	authModeCfg := AuthMode(ecfg.authMode())
	container := "juju-dist-test"
	metadataStorage := &openstackstorage{
		containerName: container,
		swift:         swift.New(e.(*environ).authClient(ecfg, authModeCfg)),
	}

	// Ensure the container exists.
	err := metadataStorage.makeContainer(container, swift.PublicRead)
	if err != nil {
		panic(fmt.Errorf("cannot create %s container: %v", container, err))
	}
	return metadataStorage
}
開發者ID:jkary,項目名稱:core,代碼行數:17,代碼來源:export_test.go


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