github.com/mattyw/juju@v0.0.0-20140610034352-732aecd63861/provider/azure/environprovider.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package azure
     5  
     6  import (
     7  	"github.com/juju/loggo"
     8  
     9  	"github.com/juju/juju/environs"
    10  	"github.com/juju/juju/environs/config"
    11  )
    12  
    13  // Register the Azure provider with Juju.
    14  func init() {
    15  	environs.RegisterProvider("azure", azureEnvironProvider{})
    16  }
    17  
    18  // Logger for the Azure provider.
    19  var logger = loggo.GetLogger("juju.provider.azure")
    20  
    21  type azureEnvironProvider struct{}
    22  
    23  // azureEnvironProvider implements EnvironProvider.
    24  var _ environs.EnvironProvider = (*azureEnvironProvider)(nil)
    25  
    26  // Open is specified in the EnvironProvider interface.
    27  func (prov azureEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
    28  	logger.Debugf("opening environment %q.", cfg.Name())
    29  	// We can't return NewEnviron(cfg) directly here because otherwise,
    30  	// when err is not nil, we end up with a non-nil returned environ and
    31  	// this breaks the loop in cmd/jujud/upgrade.go:run() (see
    32  	// http://golang.org/doc/faq#nil_error for the gory details).
    33  	environ, err := NewEnviron(cfg)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	return environ, nil
    38  }
    39  
    40  // Prepare is specified in the EnvironProvider interface.
    41  func (prov azureEnvironProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
    42  	// Set availability-sets-enabled to true
    43  	// by default, unless the user set a value.
    44  	if _, ok := cfg.AllAttrs()["availability-sets-enabled"]; !ok {
    45  		var err error
    46  		cfg, err = cfg.Apply(map[string]interface{}{"availability-sets-enabled": true})
    47  		if err != nil {
    48  			return nil, err
    49  		}
    50  	}
    51  	return prov.Open(cfg)
    52  }