~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/environs/configstore/interface.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package configstore
5
 
 
6
 
import (
7
 
        "fmt"
8
 
        "strings"
9
 
 
10
 
        "github.com/juju/errors"
11
 
)
12
 
 
13
 
// DefaultAdminUsername is used as the username to connect as in the
14
 
// absense of any explicit username being defined in the config store.
15
 
var DefaultAdminUsername = "admin"
16
 
 
17
 
var ErrEnvironInfoAlreadyExists = errors.New("model info already exists")
18
 
 
19
 
// APIEndpoint holds information about an API endpoint.
20
 
type APIEndpoint struct {
21
 
        // APIAddress holds a list of API addresses. It may not be
22
 
        // current, and it will be empty if the environment has not been
23
 
        // bootstrapped.
24
 
        Addresses []string
25
 
 
26
 
        // Hostnames holds a list of API addresses which may contain
27
 
        // unresolved hostnames. It's used to compare more recent API
28
 
        // addresses before resolving hostnames to determine if the cached
29
 
        // addresses have changed and therefore perform (a possibly slow)
30
 
        // local DNS resolution before comparing them against Addresses.
31
 
        Hostnames []string
32
 
 
33
 
        // CACert holds the CA certificate that
34
 
        // signed the API server's key.
35
 
        CACert string
36
 
 
37
 
        // ModelUUID holds the UUID for the environment we are connecting to.
38
 
        // This may be empty if the environment has not been bootstrapped.
39
 
        ModelUUID string
40
 
 
41
 
        // ServerUUID holds the UUID for the server environment. This may be empty
42
 
        // if the server is old and not sending the server uuid in the login
43
 
        // repsonse.
44
 
        ServerUUID string
45
 
}
46
 
 
47
 
// APICredentials hold credentials for connecting to an API endpoint.
48
 
type APICredentials struct {
49
 
        // User holds the name of the user to connect as.
50
 
        User     string
51
 
        Password string
52
 
}
53
 
 
54
 
// Storage stores environment and server configuration data.
55
 
type Storage interface {
56
 
        // ReadInfo reads information associated with
57
 
        // the environment with the given name.
58
 
        // If there is no such information, it will
59
 
        // return an errors.NotFound error.
60
 
        ReadInfo(envName string) (EnvironInfo, error)
61
 
 
62
 
        // CreateInfo creates some uninitialized information associated
63
 
        // with the environment with the given name.
64
 
        CreateInfo(envName string) EnvironInfo
65
 
 
66
 
        // List returns a slice of existing environment names that the Storage
67
 
        // knows about.
68
 
        List() ([]string, error)
69
 
 
70
 
        // ListSystems returns a slice of existing server names that the Storage
71
 
        // knows about.
72
 
        ListSystems() ([]string, error)
73
 
}
74
 
 
75
 
// EnvironInfoName returns a name suitable for use in the Storage.CreateInfo
76
 
// and ReadInfo methods.
77
 
func EnvironInfoName(controller, model string) string {
78
 
        return fmt.Sprintf("%s:%s", controller, model)
79
 
}
80
 
 
81
 
// AdminModelName returns the name of the admin model for a given controller.
82
 
//
83
 
// NOTE(axw) when configstore is gone, and CI is updated, we'll get rid of
84
 
// this; the admin model name will always be "admin" in future.
85
 
func AdminModelName(controller string) string {
86
 
        const prefix = "local."
87
 
        if strings.HasPrefix(controller, prefix) {
88
 
                return controller[len(prefix):]
89
 
        }
90
 
        // Hack for tests.
91
 
        return controller
92
 
}
93
 
 
94
 
// EnvironInfo holds information associated with an environment.
95
 
type EnvironInfo interface {
96
 
        // Initialized returns whether the environment information has
97
 
        // been initialized. It will return true for EnvironInfo instances
98
 
        // that have been created but not written.
99
 
        Initialized() bool
100
 
 
101
 
        // BootstrapConfig returns the configuration attributes
102
 
        // that an environment will be bootstrapped with.
103
 
        BootstrapConfig() map[string]interface{}
104
 
 
105
 
        // APIEndpoint returns the current API endpoint information.
106
 
        APIEndpoint() APIEndpoint
107
 
 
108
 
        // APICredentials returns the current API credentials.
109
 
        APICredentials() APICredentials
110
 
 
111
 
        // SetBootstrapConfig sets the configuration attributes
112
 
        // to be used for bootstrapping.
113
 
        // This method may only be called on an EnvironInfo
114
 
        // obtained using ConfigStorage.CreateInfo.
115
 
        SetBootstrapConfig(map[string]interface{})
116
 
 
117
 
        // SetAPIEndpoint sets the API endpoint information
118
 
        // currently associated with the environment.
119
 
        SetAPIEndpoint(APIEndpoint)
120
 
 
121
 
        // SetAPICreds sets the API credentials currently
122
 
        // associated with the environment.
123
 
        SetAPICredentials(APICredentials)
124
 
 
125
 
        // Location returns the location of the source of the environment
126
 
        // information in a human readable format.
127
 
        Location() string
128
 
 
129
 
        // Write writes the current information to persistent storage. A
130
 
        // subsequent call to ConfigStorage.ReadInfo can retrieve it. After this
131
 
        // call succeeds, Initialized will return true.
132
 
        // It return ErrAlreadyExists if the EnvironInfo is not yet Initialized
133
 
        // and the EnvironInfo has been written before.
134
 
        Write() error
135
 
 
136
 
        // Destroy destroys the information associated with
137
 
        // the environment.
138
 
        Destroy() error
139
 
}