1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
10
"gopkg.in/juju/environschema.v1"
12
"github.com/juju/juju/cloud"
13
"github.com/juju/juju/environs"
14
"github.com/juju/juju/environs/config"
15
"github.com/juju/juju/provider/lxd/lxdnames"
18
type environProvider struct {
19
environProviderCredentials
22
var providerInstance environProvider
24
// Open implements environs.EnvironProvider.
25
func (environProvider) Open(args environs.OpenParams) (environs.Environ, error) {
26
// TODO(ericsnow) verify prerequisites (see provider/local/prereq.go)?
27
// TODO(ericsnow) do something similar to correctLocalhostURLs()
28
// (in provider/local/environprovider.go)?
30
env, err := newEnviron(args.Config, newRawProvider)
31
return env, errors.Trace(err)
34
// PrepareConfig implements environs.EnvironProvider.
35
func (p environProvider) PrepareConfig(args environs.PrepareConfigParams) (*config.Config, error) {
36
return args.Config, nil
39
// RestrictedConfigAttributes is specified in the EnvironProvider interface.
40
func (environProvider) RestrictedConfigAttributes() []string {
49
// Validate implements environs.EnvironProvider.
50
func (environProvider) Validate(cfg, old *config.Config) (valid *config.Config, err error) {
52
ecfg, err := newValidConfig(cfg, configDefaults)
54
return nil, errors.Annotate(err, "invalid config")
56
return ecfg.Config, nil
59
// The defaults should be set already, so we pass nil.
60
ecfg, err := newValidConfig(old, nil)
62
return nil, errors.Annotate(err, "invalid base config")
65
if err := ecfg.update(cfg); err != nil {
66
return nil, errors.Annotate(err, "invalid config change")
69
return ecfg.Config, nil
72
// SecretAttrs implements environs.EnvironProvider.
73
func (environProvider) SecretAttrs(cfg *config.Config) (map[string]string, error) {
74
// The defaults should be set already, so we pass nil.
75
ecfg, err := newValidConfig(cfg, nil)
77
return nil, errors.Trace(err)
79
return ecfg.secret(), nil
82
// DetectRegions implements environs.CloudRegionDetector.
83
func (environProvider) DetectRegions() ([]cloud.Region, error) {
84
// For now we just return a hard-coded "localhost" region,
85
// i.e. the local LXD daemon. We may later want to detect
86
// locally-configured remotes.
87
return []cloud.Region{{Name: lxdnames.DefaultRegion}}, nil
90
// Schema returns the configuration schema for an environment.
91
func (environProvider) Schema() environschema.Fields {
92
fields, err := config.Schema(configSchema)