-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.go
59 lines (51 loc) · 1.61 KB
/
open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2011, 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package environs
import (
stdcontext "context"
"github.com/juju/errors"
"github.com/juju/juju/environs/context"
"github.com/juju/juju/jujuclient"
)
// AdminUser is the initial admin user created for all controllers.
const AdminUser = "admin"
// New returns a new environment based on the provided configuration.
func New(ctx stdcontext.Context, args OpenParams) (Environ, error) {
p, err := Provider(args.Cloud.Type)
if err != nil {
return nil, errors.Trace(err)
}
return Open(ctx, p, args)
}
// Open creates an Environ instance and errors if the provider is not for a cloud.
func Open(ctx stdcontext.Context, p EnvironProvider, args OpenParams) (Environ, error) {
if envProvider, ok := p.(CloudEnvironProvider); !ok {
return nil, errors.NotValidf("cloud environ provider %T", p)
} else {
return envProvider.Open(ctx, args)
}
}
// Destroy destroys the controller and, if successful,
// its associated configuration data from the given store.
func Destroy(
controllerName string,
env ControllerDestroyer,
ctx context.ProviderCallContext,
store jujuclient.ControllerStore,
) error {
details, err := store.ControllerByName(controllerName)
if errors.IsNotFound(err) {
// No controller details, nothing to do.
return nil
} else if err != nil {
return errors.Trace(err)
}
if err := env.DestroyController(ctx, details.ControllerUUID); err != nil {
return errors.Trace(err)
}
err = store.RemoveController(controllerName)
if err != nil && !errors.IsNotFound(err) {
return errors.Trace(err)
}
return nil
}