github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/azure/init.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package azure
     5  
     6  import (
     7  	"github.com/juju/clock"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/utils/ssh"
    10  
    11  	"github.com/juju/juju/environs"
    12  	"github.com/juju/juju/provider/azure/internal/azureauth"
    13  	"github.com/juju/juju/provider/azure/internal/azurecli"
    14  	"github.com/juju/juju/provider/azure/internal/azurestorage"
    15  )
    16  
    17  const (
    18  	providerType = "azure"
    19  )
    20  
    21  // NewProvider instantiates and returns the Azure EnvironProvider using the
    22  // given configuration.
    23  func NewProvider(config ProviderConfig) (environs.CloudEnvironProvider, error) {
    24  	environProvider, err := NewEnvironProvider(config)
    25  	if err != nil {
    26  		return nil, errors.Trace(err)
    27  	}
    28  	return environProvider, nil
    29  }
    30  
    31  func init() {
    32  	environProvider, err := NewProvider(ProviderConfig{
    33  		NewStorageClient:           azurestorage.NewClient,
    34  		RetryClock:                 &clock.WallClock,
    35  		RandomWindowsAdminPassword: randomAdminPassword,
    36  		GenerateSSHKey:             ssh.GenerateKey,
    37  		ServicePrincipalCreator:    &azureauth.ServicePrincipalCreator{},
    38  		AzureCLI:                   azurecli.AzureCLI{},
    39  	})
    40  	if err != nil {
    41  		panic(err)
    42  	}
    43  
    44  	environs.RegisterProvider(providerType, environProvider)
    45  
    46  	// TODO(axw) register an image metadata data source that queries
    47  	// the Azure image registry, and introduce a way to disable the
    48  	// common simplestreams source.
    49  }