github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/rackspace/provider.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package rackspace 5 6 import ( 7 "strings" 8 9 "github.com/juju/errors" 10 "github.com/juju/jsonschema" 11 12 "github.com/juju/juju/environs" 13 "github.com/juju/juju/environs/config" 14 "github.com/juju/juju/environs/context" 15 ) 16 17 type environProvider struct { 18 environs.CloudEnvironProvider 19 } 20 21 var providerInstance *environProvider 22 23 // CloudSchema returns the schema used to validate input for add-cloud. Since 24 // this provider does not support custom clouds, this always returns nil. 25 func (p environProvider) CloudSchema() *jsonschema.Schema { 26 return nil 27 } 28 29 // Ping tests the connection to the cloud, to verify the endpoint is valid. 30 func (p environProvider) Ping(ctx context.ProviderCallContext, endpoint string) error { 31 return errors.NotImplementedf("Ping") 32 } 33 34 // PrepareConfig is part of the EnvironProvider interface. 35 func (p *environProvider) PrepareConfig(args environs.PrepareConfigParams) (*config.Config, error) { 36 args.Cloud = transformCloudSpec(args.Cloud) 37 return p.CloudEnvironProvider.PrepareConfig(args) 38 } 39 40 // Open is part of the EnvironProvider interface. 41 func (p *environProvider) Open(args environs.OpenParams) (environs.Environ, error) { 42 args.Cloud = transformCloudSpec(args.Cloud) 43 return p.CloudEnvironProvider.Open(args) 44 } 45 46 func transformCloudSpec(spec environs.CloudSpec) environs.CloudSpec { 47 // Rackspace regions are expected to be uppercase, but Juju 48 // stores and displays them in lowercase in the CLI. Ensure 49 // they're uppercase when they get to the Rackspace API. 50 spec.Region = strings.ToUpper(spec.Region) 51 return spec 52 }