本文整理汇总了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
}
示例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
}
示例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),
}
}
示例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
}
示例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,
}
}
示例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
}
示例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
}