1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
10
"github.com/juju/errors"
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"
17
var ErrEnvironInfoAlreadyExists = errors.New("model info already exists")
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
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.
33
// CACert holds the CA certificate that
34
// signed the API server's key.
37
// ModelUUID holds the UUID for the environment we are connecting to.
38
// This may be empty if the environment has not been bootstrapped.
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
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.
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)
62
// CreateInfo creates some uninitialized information associated
63
// with the environment with the given name.
64
CreateInfo(envName string) EnvironInfo
66
// List returns a slice of existing environment names that the Storage
68
List() ([]string, error)
70
// ListSystems returns a slice of existing server names that the Storage
72
ListSystems() ([]string, error)
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)
81
// AdminModelName returns the name of the admin model for a given controller.
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):]
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.
101
// BootstrapConfig returns the configuration attributes
102
// that an environment will be bootstrapped with.
103
BootstrapConfig() map[string]interface{}
105
// APIEndpoint returns the current API endpoint information.
106
APIEndpoint() APIEndpoint
108
// APICredentials returns the current API credentials.
109
APICredentials() APICredentials
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{})
117
// SetAPIEndpoint sets the API endpoint information
118
// currently associated with the environment.
119
SetAPIEndpoint(APIEndpoint)
121
// SetAPICreds sets the API credentials currently
122
// associated with the environment.
123
SetAPICredentials(APICredentials)
125
// Location returns the location of the source of the environment
126
// information in a human readable format.
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.
136
// Destroy destroys the information associated with