~juju-qa/juju-core/1.16-packaging

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/provider/azure/environ.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-10-10 18:07:45 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20131010180745-wuo0vv7hq7faavdk
Tags: 1.16.0-0ubuntu1
New upstream stable release (LP: #1219879).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
60
64
 
61
65
        // storage is this environ's own private storage.
62
 
        storage environs.Storage
 
66
        storage storage.Storage
63
67
 
64
68
        // publicStorage is the public storage that this environ uses.
65
 
        publicStorage environs.StorageReader
 
69
        publicStorage storage.StorageReader
66
70
 
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
71
75
}
72
76
 
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)
75
82
 
76
83
// NewEnviron creates a new azureEnviron.
77
84
func NewEnviron(cfg *config.Config) (*azureEnviron, error) {
130
137
        return key, nil
131
138
}
132
139
 
 
140
// PrecheckInstance is specified in the environs.Prechecker interface.
 
141
func (*azureEnviron) PrecheckInstance(series string, cons constraints.Value) error {
 
142
        return nil
 
143
}
 
144
 
 
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")
 
150
}
 
151
 
133
152
// Name is specified in the Environ interface.
134
153
func (env *azureEnviron) Name() string {
135
154
        return env.name
226
245
}
227
246
 
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()
232
251
        if err != nil {
248
267
                        env.deleteVirtualNetwork()
249
268
                }
250
269
        }()
251
 
        err = provider.StartBootstrapInstance(env, cons, possibleTools, machineID)
 
270
        err = common.Bootstrap(env, cons, possibleTools)
252
271
        return err
253
272
}
254
273
 
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)
258
277
}
259
278
 
260
279
// Config is specified in the Environ interface.
660
679
}
661
680
 
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
665
684
}
666
685
 
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
670
689
}
671
690
 
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)
675
694
 
676
695
        // Stop all instances.
678
697
        if err != nil {
679
698
                return fmt.Errorf("cannot get instances: %v", err)
680
699
        }
681
 
        found := make(map[instance.Id]bool)
682
 
        for _, inst := range insts {
683
 
                found[inst.Id()] = true
684
 
        }
685
 
 
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 {
689
 
                id := inst.Id()
690
 
                if !found[id] {
691
 
                        insts = append(insts, inst)
692
 
                        found[id] = true
693
 
                }
694
 
        }
695
700
        err = env.StopInstances(insts)
696
701
        if err != nil {
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",
 
903
//
 
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{}
 
908
 
 
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)
 
915
        }
 
916
        return sources, nil
900
917
}
901
918
 
902
 
// GetImageBaseURLs returns a list of URLs which are used to search for simplestreams image metadata.
903
 
func (e *azureEnviron) GetImageBaseURLs() ([]string, error) {
904
 
        return baseURLs, nil
 
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)}
 
926
        return sources, nil
905
927
}
906
928
 
907
929
// getImageStream returns the name of the simplestreams stream from which
919
941
        // this may have to change.
920
942
        return true
921
943
}
 
944
 
 
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())),
 
951
        }, nil
 
952
}