1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/altoros/gosigma"
10
"github.com/juju/errors"
11
"github.com/juju/utils/arch"
13
"github.com/juju/juju/constraints"
14
"github.com/juju/juju/environs"
15
"github.com/juju/juju/environs/config"
16
"github.com/juju/juju/environs/simplestreams"
17
"github.com/juju/juju/instance"
18
"github.com/juju/juju/provider/common"
22
CloudsigmaCloudImagesURLTemplate = "https://%v.cloudsigma.com/"
25
// This file contains the core of the Environ implementation.
28
cloud environs.CloudSpec
35
supportedArchitectures []string
38
// Name returns the Environ's name.
39
func (env *environ) Name() string {
43
// Provider returns the EnvironProvider that created this Environ.
44
func (*environ) Provider() environs.EnvironProvider {
45
return providerInstance
48
// SetConfig updates the Environ's configuration.
50
// Calls to SetConfig do not affect the configuration of values previously obtained
52
func (env *environ) SetConfig(cfg *config.Config) error {
54
defer env.lock.Unlock()
56
ecfg, err := validateConfig(cfg, env.ecfg)
58
return errors.Trace(err)
65
// Config returns the configuration data with which the Environ was created.
66
// Note that this is not necessarily current; the canonical location
67
// for the configuration data is stored in the state.
68
func (env *environ) Config() *config.Config {
69
return env.ecfg.Config
72
// PrepareForBootstrap is part of the Environ interface.
73
func (env *environ) PrepareForBootstrap(ctx environs.BootstrapContext) error {
74
logger.Infof("preparing model %q", env.name)
78
// Create is part of the Environ interface.
79
func (env *environ) Create(environs.CreateParams) error {
83
// Bootstrap initializes the state for the environment, possibly
84
// starting one or more instances. If the configuration's
85
// AdminSecret is non-empty, the administrator password on the
86
// newly bootstrapped state will be set to a hash of it (see
87
// utils.PasswordHash), When first connecting to the
88
// environment via the juju package, the password hash will be
89
// automatically replaced by the real password.
91
// The supplied constraints are used to choose the initial instance
92
// specification, and will be stored in the new environment's state.
94
// Bootstrap is responsible for selecting the appropriate tools,
95
// and setting the agent-version configuration attribute prior to
96
// bootstrapping the environment.
97
func (env *environ) Bootstrap(ctx environs.BootstrapContext, params environs.BootstrapParams) (*environs.BootstrapResult, error) {
98
return common.Bootstrap(ctx, env, params)
101
func (e *environ) ControllerInstances(controllerUUID string) ([]instance.Id, error) {
102
return e.client.getControllerIds()
105
// Destroy shuts down all known machines and destroys the
106
// rest of the environment. Note that on some providers,
107
// very recently started instances may not be destroyed
108
// because they are not yet visible.
110
// When Destroy has been called, any Environ referring to the
111
// same remote environment may become invalid
112
func (env *environ) Destroy() error {
113
// You can probably ignore this method; the common implementation should work.
114
return common.Destroy(env)
117
// DestroyController implements the Environ interface.
118
func (env *environ) DestroyController(controllerUUID string) error {
119
// TODO(wallyworld): destroy hosted model resources
123
// PrecheckInstance performs a preflight check on the specified
124
// series and constraints, ensuring that they are possibly valid for
125
// creating an instance in this environment.
127
// PrecheckInstance is best effort, and not guaranteed to eliminate
128
// all invalid parameters. If PrecheckInstance returns nil, it is not
129
// guaranteed that the constraints are valid; if a non-nil error is
130
// returned, then the constraints are definitely invalid.
131
func (env *environ) PrecheckInstance(series string, cons constraints.Value, placement string) error {
135
// Region is specified in the HasRegion interface.
136
func (env *environ) Region() (simplestreams.CloudSpec, error) {
137
return simplestreams.CloudSpec{
138
Region: env.cloud.Region,
139
Endpoint: env.cloud.Endpoint,
143
func (env *environ) MetadataLookupParams(region string) (*simplestreams.MetadataLookupParams, error) {
145
defer env.lock.Unlock()
146
return &simplestreams.MetadataLookupParams{
148
Endpoint: gosigma.ResolveEndpoint(region),
149
Architectures: arch.AllSupportedArches,
150
Series: config.PreferredSeries(env.ecfg),