forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
356 lines (296 loc) · 12.7 KB
/
interface.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package jujuclient
import (
"net/http"
"github.com/juju/juju/cloud"
"github.com/juju/juju/controller"
)
// ControllerDetails holds the details needed to connect to a controller.
type ControllerDetails struct {
// ControllerUUID is the unique ID for the controller.
ControllerUUID string `yaml:"uuid"`
// APIEndpoints holds a list of API addresses. It may not be
// current, and it will be empty if the environment has not been
// bootstrapped.
APIEndpoints []string `yaml:"api-endpoints,flow"`
// DNSCache holds a map of hostname to IP addresses, holding
// a cache of the last time the API endpoints were looked up.
// The information held here is strictly optional so that we
// can avoid slow DNS queries in the usual case that the controller's
// IP addresses haven't changed since the last time we connected.
DNSCache map[string][]string `yaml:"dns-cache,omitempty,flow"`
// PublicDNSName holds the public host name associated with the controller.
// If this is non-empty, it indicates that the controller will use an
// officially signed certificate when connecting with this host name.
PublicDNSName string `yaml:"public-hostname,omitempty"`
// CACert is a security certificate for this controller.
CACert string `yaml:"ca-cert"`
// Cloud is the name of the cloud that this controller runs in.
Cloud string `yaml:"cloud"`
// CloudRegion is the name of the cloud region that this controller
// runs in. This will be empty for clouds without regions.
CloudRegion string `yaml:"region,omitempty"`
// AgentVersion is the version of the agent running on this controller.
// While this isn't strictly needed to connect to a controller, it is used
// in formatting show-controller output where this struct is also used.
AgentVersion string `yaml:"agent-version,omitempty"`
// ControllerMachineCount represents the number of controller machines
// It is cached here so under normal usage list-controllers
// does not need to hit the server.
ControllerMachineCount int `yaml:"controller-machine-count"`
// ActiveControllerMachineCount represents the number of controller machines
// and which are active in the HA cluster.
// It is cached here so under normal usage list-controllers
// does not need to hit the server.
ActiveControllerMachineCount int `yaml:"active-controller-machine-count"`
// MachineCount is the number of machines in all models to
// which a user has access. It is cached here so under normal
// usage list-controllers does not need to hit the server.
MachineCount *int `yaml:"machine-count,omitempty"`
}
// ModelDetails holds details of a model.
type ModelDetails struct {
// ModelUUID is the unique ID for the model.
ModelUUID string `yaml:"uuid"`
}
// AccountDetails holds details of an account.
type AccountDetails struct {
// User is the username for the account.
User string `yaml:"user"`
// Password is the password for the account.
Password string `yaml:"password,omitempty"`
// LastKnownAccess is the last known access level for the account.
LastKnownAccess string `yaml:"last-known-access,omitempty"`
}
// BootstrapConfig holds the configuration used to bootstrap a controller.
//
// This includes all non-sensitive information required to regenerate the
// bootstrap configuration. A reference to the credential used will be
// stored, rather than the credential itself.
type BootstrapConfig struct {
// ControllerConfig is the controller configuration.
ControllerConfig controller.Config `yaml:"controller-config"`
// Config is the complete configuration for the provider.
Config map[string]interface{} `yaml:"model-config"`
// ControllerModelUUID is the controller model UUID.
ControllerModelUUID string `yaml:"controller-model-uuid"`
// Credential is the name of the credential used to bootstrap.
//
// This will be empty if an auto-detected credential was used.
Credential string `yaml:"credential,omitempty"`
// Cloud is the name of the cloud to create the Juju controller in.
Cloud string `yaml:"cloud"`
// CloudType is the type of the cloud to create the Juju controller in.
CloudType string `yaml:"type"`
// CloudRegion is the name of the region of the cloud to create
// the Juju controller in. This will be empty for clouds without
// regions.
CloudRegion string `yaml:"region,omitempty"`
// CloudEndpoint is the location of the primary API endpoint to
// use when communicating with the cloud.
CloudEndpoint string `yaml:"endpoint,omitempty"`
// CloudIdentityEndpoint is the location of the API endpoint to use
// when communicating with the cloud's identity service. This will
// be empty for clouds that have no identity-specific API endpoint.
CloudIdentityEndpoint string `yaml:"identity-endpoint,omitempty"`
// CloudStorageEndpoint is the location of the API endpoint to use
// when communicating with the cloud's storage service. This will
// be empty for clouds that have no storage-specific API endpoint.
CloudStorageEndpoint string `yaml:"storage-endpoint,omitempty"`
}
// ControllerUpdater stores controller details.
type ControllerUpdater interface {
// AddController adds the given controller to the controller
// collection.
//
// Where UpdateController is concerned with the controller name,
// AddController uses the controller UUID and will not add a
// duplicate even if the name is different.
AddController(controllerName string, details ControllerDetails) error
// UpdateController updates the given controller in the controller
// collection.
//
// If a controller of controllerName exists it will be overwritten
// with the new details.
UpdateController(controllerName string, details ControllerDetails) error
// SetCurrentController sets the name of the current controller.
// If there exists no controller with the specified name, an error
// satisfying errors.IsNotFound will be returned.
SetCurrentController(controllerName string) error
}
// ControllerRemover removes controllers.
type ControllerRemover interface {
// RemoveController removes the controller with the given name from the
// controllers collection. Any other controllers with matching UUIDs
// will also be removed.
//
// Removing controllers will remove all information related to those
// controllers (models, accounts, bootstrap config.)
RemoveController(controllerName string) error
}
// ControllerGetter gets controllers.
type ControllerGetter interface {
// AllControllers gets all controllers.
AllControllers() (map[string]ControllerDetails, error)
// ControllerByName returns the controller with the specified name.
// If there exists no controller with the specified name, an error
// satisfying errors.IsNotFound will be returned.
ControllerByName(controllerName string) (*ControllerDetails, error)
// CurrentController returns the name of the current controller.
// If there is no current controller, an error satisfying
// errors.IsNotFound will be returned.
CurrentController() (string, error)
}
// ModelUpdater stores model details.
type ModelUpdater interface {
// UpdateModel adds the given model to the model collection.
//
// If the model does not already exist, it will be added.
// Otherwise, it will be overwritten with the new details.
UpdateModel(controllerName, modelName string, details ModelDetails) error
// SetModels updates the list of currently stored controller
// models in model store - models will be added, updated or removed from the
// store based on the supplied models collection.
SetModels(controllerName string, models map[string]ModelDetails) error
// SetCurrentModel sets the name of the current model for
// the specified controller and account. If there exists no
// model with the specified names, an error satisfying
// errors.IsNotFound will be returned.
SetCurrentModel(controllerName, modelName string) error
}
// ModelRemover removes models.
type ModelRemover interface {
// RemoveModel removes the model with the given controller, account,
// and model names from the models collection. If there is no model
// with the specified names, an errors satisfying errors.IsNotFound
// will be returned.
RemoveModel(controllerName, modelName string) error
}
// ModelGetter gets models.
type ModelGetter interface {
// AllModels gets all models for the specified controller as a map
// from model name to its details.
//
// If there is no controller with the specified
// name, or no models cached for the controller and account,
// an error satisfying errors.IsNotFound will be returned.
AllModels(controllerName string) (map[string]ModelDetails, error)
// CurrentModel returns the name of the current model for
// the specified controller. If there is no current
// model for the controller, an error satisfying
// errors.IsNotFound is returned.
CurrentModel(controllerName string) (string, error)
// ModelByName returns the model with the specified controller,
// and model name. If a model with the specified name does not
// exist, an error satisfying errors.IsNotFound will be
// returned.
ModelByName(controllerName, modelName string) (*ModelDetails, error)
}
// AccountUpdater stores account details.
type AccountUpdater interface {
// UpdateAccount updates the account associated with the
// given controller.
UpdateAccount(controllerName string, details AccountDetails) error
}
// AccountRemover removes accounts.
type AccountRemover interface {
// RemoveAccount removes the account associated with the given controller.
// If there is no associated account with the
// specified names, an errors satisfying errors.IsNotFound will be
// returned.
RemoveAccount(controllerName string) error
}
// AccountGetter gets accounts.
type AccountGetter interface {
// AccountByName returns the account associated with the given
// controller name. If no associated account exists, an error
// satisfying errors.IsNotFound will be returned.
AccountDetails(controllerName string) (*AccountDetails, error)
}
// CredentialGetter gets credentials.
type CredentialGetter interface {
// CredentialForCloud gets credentials for the named cloud.
CredentialForCloud(string) (*cloud.CloudCredential, error)
// AllCredentials gets all credentials.
AllCredentials() (map[string]cloud.CloudCredential, error)
}
// CredentialUpdater stores credentials.
type CredentialUpdater interface {
// UpdateCredential adds the given credentials to the credentials
// collection.
//
// If the cloud or credential name does not already exist, it will be added.
// Otherwise, it will be overwritten with the new details.
UpdateCredential(cloudName string, details cloud.CloudCredential) error
}
// BootstrapConfigUpdater stores bootstrap config.
type BootstrapConfigUpdater interface {
// UpdateBootstrapConfig adds the given bootstrap config to the
// bootstrap config collection for the controller with the given
// name.
//
// If the bootstrap config does not already exist, it will be added.
// Otherwise, it will be overwritten with the new value.
UpdateBootstrapConfig(controller string, cfg BootstrapConfig) error
}
// BootstrapConfigGetter gets bootstrap config.
type BootstrapConfigGetter interface {
// BootstrapConfigForController gets bootstrap config for the named
// controller.
BootstrapConfigForController(string) (*BootstrapConfig, error)
}
// CookieJar is the interface implemented by cookie jars.
type CookieJar interface {
http.CookieJar
// RemoveAll removes all the cookies (note: this doesn't
// save the cookie file).
RemoveAll()
// Save saves the cookies.
Save() error
}
// CookieStore allows the retrieval of cookie jars for storage
// of per-controller authorization information.
type CookieStore interface {
CookieJar(controllerName string) (CookieJar, error)
}
// ControllerStore is an amalgamation of ControllerUpdater, ControllerRemover,
// and ControllerGetter.
type ControllerStore interface {
ControllerUpdater
ControllerRemover
ControllerGetter
}
// ModelStore is an amalgamation of ModelUpdater, ModelRemover, and ModelGetter.
type ModelStore interface {
ModelUpdater
ModelRemover
ModelGetter
}
// AccountStore is an amalgamation of AccountUpdater, AccountRemover, and AccountGetter.
type AccountStore interface {
AccountUpdater
AccountRemover
AccountGetter
}
// CredentialStore is an amalgamation of CredentialsUpdater, and CredentialsGetter.
type CredentialStore interface {
CredentialGetter
CredentialUpdater
}
// BootstrapConfigStore is an amalgamation of BootstrapConfigUpdater and
// BootstrapConfigGetter.
type BootstrapConfigStore interface {
BootstrapConfigUpdater
BootstrapConfigGetter
}
// ClientStore is an amalgamation of AccountStore, BootstrapConfigStore,
// ControllerStore, CredentialStore, and ModelStore.
type ClientStore interface {
AccountStore
BootstrapConfigStore
ControllerStore
CredentialStore
ModelStore
CookieStore
}