15
15
"launchpad.net/juju-core/environs"
16
16
"launchpad.net/juju-core/environs/cloudinit"
17
17
"launchpad.net/juju-core/environs/config"
18
"launchpad.net/juju-core/environs/imagemetadata"
18
19
"launchpad.net/juju-core/environs/instances"
20
"launchpad.net/juju-core/environs/simplestreams"
21
"launchpad.net/juju-core/environs/storage"
22
envtools "launchpad.net/juju-core/environs/tools"
19
23
"launchpad.net/juju-core/instance"
20
"launchpad.net/juju-core/provider"
24
"launchpad.net/juju-core/provider/common"
21
25
"launchpad.net/juju-core/state"
22
26
"launchpad.net/juju-core/state/api"
23
27
"launchpad.net/juju-core/tools"
59
63
ecfg *azureEnvironConfig
61
65
// storage is this environ's own private storage.
62
storage environs.Storage
66
storage storage.Storage
64
68
// publicStorage is the public storage that this environ uses.
65
publicStorage environs.StorageReader
69
publicStorage storage.StorageReader
67
71
// storageAccountKey holds an access key to this environment's
68
72
// private storage. This is automatically queried from Azure on
70
74
storageAccountKey string
73
// azureEnviron implements Environ.
77
// azureEnviron implements Environ and HasRegion.
74
78
var _ environs.Environ = (*azureEnviron)(nil)
79
var _ simplestreams.HasRegion = (*azureEnviron)(nil)
80
var _ imagemetadata.SupportsCustomSources = (*azureEnviron)(nil)
81
var _ envtools.SupportsCustomSources = (*azureEnviron)(nil)
76
83
// NewEnviron creates a new azureEnviron.
77
84
func NewEnviron(cfg *config.Config) (*azureEnviron, error) {
140
// PrecheckInstance is specified in the environs.Prechecker interface.
141
func (*azureEnviron) PrecheckInstance(series string, cons constraints.Value) error {
145
// PrecheckContainer is specified in the environs.Prechecker interface.
146
func (*azureEnviron) PrecheckContainer(series string, kind instance.ContainerType) error {
147
// This check can either go away or be relaxed when the azure
148
// provider manages container addressibility.
149
return environs.NewContainersUnsupported("azure provider does not support containers")
133
152
// Name is specified in the Environ interface.
134
153
func (env *azureEnviron) Name() string {
228
247
// Bootstrap is specified in the Environ interface.
229
func (env *azureEnviron) Bootstrap(cons constraints.Value, possibleTools tools.List, machineID string) (err error) {
248
func (env *azureEnviron) Bootstrap(cons constraints.Value, possibleTools tools.List) (err error) {
230
249
// The creation of the affinity group and the virtual network is specific to the Azure provider.
231
250
err = env.createAffinityGroup()
248
267
env.deleteVirtualNetwork()
251
err = provider.StartBootstrapInstance(env, cons, possibleTools, machineID)
270
err = common.Bootstrap(env, cons, possibleTools)
255
274
// StateInfo is specified in the Environ interface.
256
275
func (env *azureEnviron) StateInfo() (*state.Info, *api.Info, error) {
257
return provider.StateInfo(env)
276
return common.StateInfo(env)
260
279
// Config is specified in the Environ interface.
662
681
// Storage is specified in the Environ interface.
663
func (env *azureEnviron) Storage() environs.Storage {
682
func (env *azureEnviron) Storage() storage.Storage {
664
683
return env.getSnapshot().storage
667
686
// PublicStorage is specified in the Environ interface.
668
func (env *azureEnviron) PublicStorage() environs.StorageReader {
687
func (env *azureEnviron) PublicStorage() storage.StorageReader {
669
688
return env.getSnapshot().publicStorage
672
691
// Destroy is specified in the Environ interface.
673
func (env *azureEnviron) Destroy(ensureInsts []instance.Instance) error {
692
func (env *azureEnviron) Destroy() error {
674
693
logger.Debugf("destroying environment %q", env.name)
676
695
// Stop all instances.
679
698
return fmt.Errorf("cannot get instances: %v", err)
681
found := make(map[instance.Id]bool)
682
for _, inst := range insts {
683
found[inst.Id()] = true
686
// Add any instances we've been told about but haven't yet shown
687
// up in the instance list.
688
for _, inst := range ensureInsts {
691
insts = append(insts, inst)
695
700
err = env.StopInstances(insts)
697
702
return fmt.Errorf("cannot stop instances: %v", err)
895
900
// It contains the central databases for the released and daily streams, but this may
896
901
// become more configurable. This variable is here as a placeholder, but also
897
902
// as an injection point for tests.
898
var baseURLs = []string{
899
"http://cloud-images.ubuntu.com/daily",
904
// Note: Due to datasource fallback issues, the default daily stream has been removed.
905
// This var now only serves as an injection point for tests. See also:
906
// https://bugs.launchpad.net/juju-core/+bug/1233924
907
var baseURLs = []string{}
909
// GetImageSources returns a list of sources which are used to search for simplestreams image metadata.
910
func (env *azureEnviron) GetImageSources() ([]simplestreams.DataSource, error) {
911
sources := make([]simplestreams.DataSource, 1+len(baseURLs))
912
sources[0] = storage.NewStorageSimpleStreamsDataSource(env.Storage(), "")
913
for i, url := range baseURLs {
914
sources[i+1] = simplestreams.NewURLDataSource(url, simplestreams.VerifySSLHostnames)
902
// GetImageBaseURLs returns a list of URLs which are used to search for simplestreams image metadata.
903
func (e *azureEnviron) GetImageBaseURLs() ([]string, error) {
919
// GetToolsSources returns a list of sources which are used to search for simplestreams tools metadata.
920
func (env *azureEnviron) GetToolsSources() ([]simplestreams.DataSource, error) {
921
// Add the simplestreams source off the control bucket and public location.
922
sources := []simplestreams.DataSource{
923
storage.NewStorageSimpleStreamsDataSource(env.Storage(), storage.BaseToolsPath),
924
simplestreams.NewURLDataSource(
925
"https://jujutools.blob.core.windows.net/juju-tools/tools", simplestreams.VerifySSLHostnames)}
907
929
// getImageStream returns the name of the simplestreams stream from which
919
941
// this may have to change.
945
// Region is specified in the HasRegion interface.
946
func (env *azureEnviron) Region() (simplestreams.CloudSpec, error) {
947
ecfg := env.getSnapshot().ecfg
948
return simplestreams.CloudSpec{
949
Region: ecfg.location(),
950
Endpoint: string(gwacl.GetEndpoint(ecfg.location())),