예제 #1
0
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
0
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
0
파일: export_test.go 프로젝트: jkary/core
// 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
0
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
0
파일: export_test.go 프로젝트: jkary/core
// 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
0
// 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
0
파일: export_test.go 프로젝트: jkary/core
// 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
}